Lines
67.14%
47 / 70
Functions and Methods
71.42%
5 / 7
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ProcessSearchHistory | 67.14% | 47 / 70 | 71.42% | 5 / 7 | 10.27 | 0.00% | 0 / 1 | |||
| getEntityMapping | 0.00% | 0 / 20 | 0.00% | 0 / 1 | 2 | |||||
| addConditionHistoryKey | 100.00% | 6 / 6 | 100.00% | 1 / 1 | 1 | |||||
| addConditionOlderThan | 100.00% | 6 / 6 | 100.00% | 1 / 1 | 1 | |||||
| addCountValue | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 1 | |||||
| addValuesNewHistory | 90.62% | 29 / 32 | 0.00% | 0 / 1 | 2.00 | |||||
| formatDateTime | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| formatNullableDateTime | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | namespace BO\Zmsbackend\ProcessSearchHistory\Repository; | |
| 4 | ||
| 5 | class ProcessSearchHistory extends \BO\Zmsbackend\Query\Base implements | |
| 6 | \BO\Zmsbackend\Query\MappingInterface | |
| 7 | { | |
| 8 | public const string TABLE = 'process_search_history'; | |
| 9 | public const string ALIAS = 'psh'; | |
| 10 | ||
| 11 | #[\Override] | |
| 12 | public function getEntityMapping(): array | |
| 13 | { | |
| 14 | return [ | |
| 15 | 'id' => self::ALIAS . '.id', | |
| 16 | 'historyKey' => self::ALIAS . '.history_key', | |
| 17 | ||
| 18 | 'processId' => self::ALIAS . '.process_id', | |
| 19 | 'scopeId' => self::ALIAS . '.scope_id', | |
| 20 | 'displayNumber' => self::ALIAS . '.display_number', | |
| 21 | ||
| 22 | 'appointmentAt' => self::ALIAS . '.appointment_at', | |
| 23 | 'bookedAt' => self::ALIAS . '.booked_at', | |
| 24 | 'calledAt' => self::ALIAS . '.called_at', | |
| 25 | 'finalizedAt' => self::ALIAS . '.finalized_at', | |
| 26 | ||
| 27 | 'status' => self::ALIAS . '.status', | |
| 28 | ||
| 29 | 'citizenName' => self::ALIAS . '.citizen_name', | |
| 30 | 'telephone' => self::ALIAS . '.telephone', | |
| 31 | 'citizenEmail' => self::ALIAS . '.citizen_email', | |
| 32 | 'amendment' => self::ALIAS . '.amendment', | |
| 33 | ||
| 34 | 'locationName' => self::ALIAS . '.location_name', | |
| 35 | 'providerName' => self::ALIAS . '.provider_name', | |
| 36 | 'services' => self::ALIAS . '.services', | |
| 37 | ||
| 38 | 'createdAt' => self::ALIAS . '.created_at', | |
| 39 | ]; | |
| 40 | } | |
| 41 | ||
| 42 | public function addConditionHistoryKey(string $historyKey): self | |
| 43 | { | |
| 44 | $this->query->where( | |
| 45 | self::ALIAS . '.history_key', | |
| 46 | '=', | |
| 47 | $historyKey | |
| 48 | ); | |
| 49 | ||
| 50 | return $this; | |
| 51 | } | |
| 52 | ||
| 53 | public function addConditionOlderThan( | |
| 54 | \DateTimeInterface $dateTime | |
| 55 | ): self { | |
| 56 | $this->query->where( | |
| 57 | self::ALIAS . '.appointment_at', | |
| 58 | '<', | |
| 59 | $this->formatDateTime($dateTime) | |
| 60 | ); | |
| 61 | ||
| 62 | return $this; | |
| 63 | } | |
| 64 | ||
| 65 | public function addCountValue(): self | |
| 66 | { | |
| 67 | $this->query->select([ | |
| 68 | 'historyCount' => self::expression('COUNT(*)'), | |
| 69 | ]); | |
| 70 | ||
| 71 | return $this; | |
| 72 | } | |
| 73 | ||
| 74 | public function addValuesNewHistory(array $data): self | |
| 75 | { | |
| 76 | $values = [ | |
| 77 | 'history_key' => $data['historyKey'], | |
| 78 | ||
| 79 | 'process_id' => $data['processId'], | |
| 80 | 'scope_id' => $data['scopeId'], | |
| 81 | 'display_number' => $data['displayNumber'] ?? null, | |
| 82 | ||
| 83 | 'appointment_at' => $this->formatDateTime( | |
| 84 | $data['appointmentAt'] | |
| 85 | ), | |
| 86 | 'booked_at' => $this->formatNullableDateTime( | |
| 87 | $data['bookedAt'] ?? null | |
| 88 | ), | |
| 89 | 'called_at' => $this->formatNullableDateTime( | |
| 90 | $data['calledAt'] ?? null | |
| 91 | ), | |
| 92 | 'finalized_at' => $this->formatDateTime( | |
| 93 | $data['finalizedAt'] | |
| 94 | ), | |
| 95 | ||
| 96 | 'status' => $data['status'], | |
| 97 | ||
| 98 | 'citizen_name' => $data['citizenName'], | |
| 99 | 'telephone' => $data['telephone'], | |
| 100 | 'citizen_email' => $data['citizenEmail'], | |
| 101 | 'amendment' => $data['amendment'] ?? null, | |
| 102 | ||
| 103 | 'location_name' => $data['locationName'], | |
| 104 | 'provider_name' => $data['providerName'], | |
| 105 | 'services' => $data['services'] ?? null, | |
| 106 | ]; | |
| 107 | ||
| 108 | if (isset($data['createdAt'])) { | |
| 109 | $values['created_at'] = $this->formatDateTime( | |
| 110 | $data['createdAt'] | |
| 111 | ); | |
| 112 | } | |
| 113 | ||
| 114 | $this->addValues($values); | |
| 115 | ||
| 116 | return $this; | |
| 117 | } | |
| 118 | ||
| 119 | private function formatDateTime( | |
| 120 | \DateTimeInterface $dateTime | |
| 121 | ): string { | |
| 122 | return $dateTime->format('Y-m-d H:i:s'); | |
| 123 | } | |
| 124 | ||
| 125 | private function formatNullableDateTime( | |
| 126 | ?\DateTimeInterface $dateTime | |
| 127 | ): ?string { | |
| 128 | return $dateTime?->format('Y-m-d H:i:s'); | |
| 129 | } | |
| 130 | } |