Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
38.61% |
39 / 101 |
|
29.41% |
5 / 17 |
CRAP | |
0.00% |
0 / 1 |
| ProcessStatus | |
38.61% |
39 / 101 |
|
29.41% |
5 / 17 |
892.75 | |
0.00% |
0 / 1 |
| writeUpdatedStatus | |
100.00% |
26 / 26 |
|
100.00% |
1 / 1 |
3 | |||
| readProcessStatus | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
3 | |||
| setStatusPreconfirmed | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| setStatusConfirmed | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| setStatusCalled | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| setStatusReserved | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| isBlockedProcess | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| isQueuedProcess | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
42 | |||
| isPreconfirmedProcess | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
30 | |||
| isConfirmedProcess | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
30 | |||
| isReservedProcess | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
20 | |||
| isCalledProcess | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
42 | |||
| isProcessingProcess | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
30 | |||
| isPendingProcess | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
42 | |||
| isMissedProcess | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
30 | |||
| isParkedProcess | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
30 | |||
| isDeletedProcess | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BO\Zmsdb\Helper; |
| 4 | |
| 5 | use BO\Zmsdb\Log; |
| 6 | |
| 7 | /** |
| 8 | * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) |
| 9 | */ |
| 10 | class ProcessStatus extends \BO\Zmsdb\Process |
| 11 | { |
| 12 | public function writeUpdatedStatus( |
| 13 | \BO\Zmsentities\Process $process, |
| 14 | $status, |
| 15 | \DateTimeInterface $dateTime, |
| 16 | $resolveReferences, |
| 17 | $userAccount |
| 18 | ) { |
| 19 | $query = new \BO\Zmsdb\Query\Process(\BO\Zmsdb\Query\Base::UPDATE); |
| 20 | $query->addConditionProcessId($process['id']); |
| 21 | $query->addConditionAuthKey($process['authKey']); |
| 22 | |
| 23 | $statusList = [ |
| 24 | 'reserved' => 'setStatusReserved', |
| 25 | 'confirmed' => 'setStatusConfirmed', |
| 26 | 'preconfirmed' => 'setStatusPreconfirmed', |
| 27 | 'called' => 'setStatusCalled' |
| 28 | ]; |
| 29 | |
| 30 | $entity = call_user_func_array(array($this, $statusList[$status]), array($process)); |
| 31 | $query->addValuesStatusData($entity, $dateTime); |
| 32 | $checksum = ($userAccount) ? sha1($process->id . '-' . $userAccount->getId()) : ''; |
| 33 | |
| 34 | $this->writeItem($query, 'process', $query::TABLE); |
| 35 | $this->perform(\BO\Zmsdb\Query\Process::QUERY_UPDATE_FOLLOWING_PROCESS, [ |
| 36 | 'reserved' => ($process->status == 'reserved') ? 1 : 0, |
| 37 | 'processID' => $process->getId(), |
| 38 | ]); |
| 39 | $process = $this->readEntity($process['id'], $process['authKey'], $resolveReferences); |
| 40 | $process['status'] = $this->readProcessStatus($process['id'], $process['authKey']); |
| 41 | |
| 42 | Log::writeProcessLog( |
| 43 | "UPDATE (ProcessStatus::writeUpdatedStatus) $process $checksum", |
| 44 | Log::ACTION_STATUS_CHANGE, |
| 45 | $process, |
| 46 | $userAccount |
| 47 | ); |
| 48 | |
| 49 | return $process; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * get the current process status from given Id and authKey |
| 54 | * |
| 55 | * @return String |
| 56 | */ |
| 57 | public function readProcessStatus($processId, $authKey) |
| 58 | { |
| 59 | $processData = $this->getReader()->fetchOne( |
| 60 | 'SELECT |
| 61 | * |
| 62 | FROM buerger AS b |
| 63 | WHERE |
| 64 | b.BuergerID = "' . $processId . '" |
| 65 | AND b.absagecode = "' . $authKey . '" |
| 66 | LIMIT 1 |
| 67 | ' |
| 68 | ); |
| 69 | |
| 70 | return $processData['status']; |
| 71 | |
| 72 | $statusList = [ |
| 73 | 'free' => true, |
| 74 | 'reserved' => $this->isReservedProcess($processData), |
| 75 | 'confirmed' => $this->isConfirmedProcess($processData), |
| 76 | 'preconfirmed' => $this->isPreconfirmedProcess($processData), |
| 77 | 'queued' => $this->isQueuedProcess($processData), |
| 78 | 'called' => $this->isCalledProcess($processData), |
| 79 | 'processing' => $this->isProcessingProcess($processData), |
| 80 | 'pending' => $this->isPendingProcess($processData), |
| 81 | 'missed' => $this->isMissedProcess($processData), |
| 82 | 'parked' => $this->isParkedProcess($processData), |
| 83 | 'blocked' => $this->isBlockedProcess($processData), |
| 84 | 'deleted' => $this->isDeletedProcess($processData), |
| 85 | ]; |
| 86 | foreach ($statusList as $statusType => $statusCheck) { |
| 87 | if ($statusCheck) { |
| 88 | $status = $statusType; |
| 89 | } |
| 90 | } |
| 91 | return $status; |
| 92 | } |
| 93 | |
| 94 | protected function setStatusPreconfirmed($process) |
| 95 | { |
| 96 | $process['status'] = $process::STATUS_PRECONFIRMED; |
| 97 | return $process; |
| 98 | } |
| 99 | |
| 100 | protected function setStatusConfirmed($process) |
| 101 | { |
| 102 | $process['status'] = $process::STATUS_CONFIRMED; |
| 103 | return $process; |
| 104 | } |
| 105 | |
| 106 | protected function setStatusCalled($process) |
| 107 | { |
| 108 | $process['status'] = $process::STATUS_CALLED; |
| 109 | return $process; |
| 110 | } |
| 111 | |
| 112 | protected function setStatusReserved($process) |
| 113 | { |
| 114 | $process['status'] = $process::STATUS_RESERVED; |
| 115 | return $process; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * check if it is a blocked appointment |
| 120 | * |
| 121 | * @return Bool |
| 122 | */ |
| 123 | protected function isBlockedProcess($process) |
| 124 | { |
| 125 | return ($process['Name'] == 'dereferenced'); |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * check if it is a queued appointment |
| 130 | * |
| 131 | * @return Bool |
| 132 | */ |
| 133 | protected function isQueuedProcess($process) |
| 134 | { |
| 135 | return ($process['Name'] != 'dereferenced' |
| 136 | && $process['vorlaeufigeBuchung'] == 0 |
| 137 | && $process['StandortID'] != 0 |
| 138 | && $process['wsm_aufnahmezeit'] != '00:00:00' |
| 139 | && $process['aufrufzeit'] != '00:00:00' |
| 140 | && empty($process['istFolgeterminvon']) |
| 141 | ); |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * check if it is a confirmed appointment |
| 146 | * |
| 147 | * @return Bool |
| 148 | */ |
| 149 | protected function isPreconfirmedProcess($process) |
| 150 | { |
| 151 | return ($process['Name'] != 'dereferenced' |
| 152 | && $process['vorlaeufigeBuchung'] == 0 |
| 153 | && $process['StandortID'] != 0 |
| 154 | && $process['bestaetigt'] == 0 |
| 155 | && empty($process['istFolgeterminvon']) |
| 156 | ); |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * check if it is a confirmed appointment |
| 161 | * |
| 162 | * @return Bool |
| 163 | */ |
| 164 | protected function isConfirmedProcess($process) |
| 165 | { |
| 166 | return ($process['Name'] != 'dereferenced' |
| 167 | && $process['vorlaeufigeBuchung'] == 0 |
| 168 | && $process['bestaetigt'] == 1 |
| 169 | && $process['StandortID'] != 0 |
| 170 | && empty($process['istFolgeterminvon']) |
| 171 | ); |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * check if it is a reserved appointment |
| 176 | * |
| 177 | * @return Bool |
| 178 | */ |
| 179 | protected function isReservedProcess($process) |
| 180 | { |
| 181 | return ($process['Name'] != 'dereferenced' |
| 182 | && $process['vorlaeufigeBuchung'] == 1 |
| 183 | && $process['StandortID'] != 0 |
| 184 | && empty($process['istFolgeterminvon']) |
| 185 | ); |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * check if it is a called appointment |
| 190 | * |
| 191 | * @return Bool |
| 192 | */ |
| 193 | protected function isCalledProcess($process) |
| 194 | { |
| 195 | return ($process['Name'] != 'dereferenced' |
| 196 | && $process['vorlaeufigeBuchung'] == 0 |
| 197 | && $process['StandortID'] != 0 |
| 198 | && $process['aufrufzeit'] != '00:00:00' |
| 199 | && $process['aufruferfolgreich'] == 0 |
| 200 | && empty($process['istFolgeterminvon']) |
| 201 | ); |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * check if it is a processing appointment |
| 206 | * |
| 207 | * @return Bool |
| 208 | */ |
| 209 | protected function isProcessingProcess($process) |
| 210 | { |
| 211 | return ($process['Name'] != 'dereferenced' |
| 212 | && $process['vorlaeufigeBuchung'] == 0 |
| 213 | && $process['StandortID'] != 0 |
| 214 | && $process['aufruferfolgreich'] != 0 |
| 215 | && empty($process['istFolgeterminvon']) |
| 216 | ); |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * check if it is a processing appointment |
| 221 | * |
| 222 | * @return Bool |
| 223 | */ |
| 224 | protected function isPendingProcess($process) |
| 225 | { |
| 226 | return ($process['Name'] != 'dereferenced' |
| 227 | && $process['vorlaeufigeBuchung'] == 0 |
| 228 | && $process['StandortID'] != 0 |
| 229 | && $process['Abholer'] != 0 |
| 230 | && $process['AbholortID'] != 0 |
| 231 | && empty($process['istFolgeterminvon']) |
| 232 | ); |
| 233 | } |
| 234 | |
| 235 | /** |
| 236 | * check if it is a missed appointment |
| 237 | * |
| 238 | * @return Bool |
| 239 | */ |
| 240 | protected function isMissedProcess($process) |
| 241 | { |
| 242 | return ($process['Name'] != 'dereferenced' |
| 243 | && $process['vorlaeufigeBuchung'] == 0 |
| 244 | && $process['StandortID'] != 0 |
| 245 | && $process['nicht_erschienen'] != 0 |
| 246 | && empty($process['istFolgeterminvon']) |
| 247 | ); |
| 248 | } |
| 249 | |
| 250 | /** |
| 251 | * check if it is a missed appointment |
| 252 | * |
| 253 | * @return Bool |
| 254 | */ |
| 255 | protected function isParkedProcess($process) |
| 256 | { |
| 257 | return ($process['Name'] != 'dereferenced' |
| 258 | && $process['vorlaeufigeBuchung'] == 0 |
| 259 | && $process['StandortID'] != 0 |
| 260 | && $process['parked'] != 0 |
| 261 | && empty($process['istFolgeterminvon']) |
| 262 | ); |
| 263 | } |
| 264 | |
| 265 | /** |
| 266 | * check if it is a deleted appointment |
| 267 | * |
| 268 | * @return Bool |
| 269 | */ |
| 270 | protected function isDeletedProcess($process) |
| 271 | { |
| 272 | return ($process['Name'] == '(abgesagt)' |
| 273 | && empty($process['istFolgeterminvon']) |
| 274 | ); |
| 275 | } |
| 276 | } |