@@ -23,14 +23,14 @@ discard block |
||
23 | 23 | * @param null|int $maxResult |
24 | 24 | * @return mixed |
25 | 25 | */ |
26 | - public function getCurrentAppoiments($eventCode,$start=null,$maxResult=null){ |
|
27 | - if(!$start){ |
|
26 | + public function getCurrentAppoiments($eventCode, $start = null, $maxResult = null) { |
|
27 | + if (!$start) { |
|
28 | 28 | $start = 0; |
29 | 29 | } |
30 | - if(!$maxResult){ |
|
30 | + if (!$maxResult) { |
|
31 | 31 | $maxResult = 999999; |
32 | 32 | } |
33 | - return $this->certainAppointmentsList = $this->appointmentsCertain->get($eventCode,['start_index'=>$start,'max_results'=>$maxResult])->getResults()->appointments; |
|
33 | + return $this->certainAppointmentsList = $this->appointmentsCertain->get($eventCode, ['start_index'=>$start, 'max_results'=>$maxResult])->getResults()->appointments; |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -38,21 +38,21 @@ discard block |
||
38 | 38 | * @param array $appointmentsNew |
39 | 39 | * @return bool |
40 | 40 | */ |
41 | - public function hasChanged(array $appointmentsOld,array $appointmentsNew){ |
|
41 | + public function hasChanged(array $appointmentsOld, array $appointmentsNew) { |
|
42 | 42 | $hasChanged = false; |
43 | 43 | $appointmentsOld = self::recursiveArrayObjectToFullArray($appointmentsOld); |
44 | 44 | $appointmentsNew = self::recursiveArrayObjectToFullArray($appointmentsNew); |
45 | 45 | //Has change by update or delete |
46 | - foreach ($appointmentsOld as $appointmentOld){ |
|
47 | - if(!in_array($appointmentOld,$appointmentsNew)){ |
|
46 | + foreach ($appointmentsOld as $appointmentOld) { |
|
47 | + if (!in_array($appointmentOld, $appointmentsNew)) { |
|
48 | 48 | $hasChanged = true; |
49 | 49 | break; |
50 | 50 | } |
51 | 51 | } |
52 | 52 | //Has changes by insertion or update |
53 | - if(!$hasChanged){ |
|
54 | - foreach ($appointmentsNew as $appointmentNew){ |
|
55 | - if(!in_array($appointmentNew,$appointmentsOld)){ |
|
53 | + if (!$hasChanged) { |
|
54 | + foreach ($appointmentsNew as $appointmentNew) { |
|
55 | + if (!in_array($appointmentNew, $appointmentsOld)) { |
|
56 | 56 | $hasChanged = true; |
57 | 57 | break; |
58 | 58 | } |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @return array |
67 | 67 | */ |
68 | 68 | public static function objectToArray($object) { |
69 | - if(is_object($object)){ |
|
69 | + if (is_object($object)) { |
|
70 | 70 | |
71 | 71 | return (array) $object; |
72 | 72 | } |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * @param $appointments |
78 | 78 | * @return array |
79 | 79 | */ |
80 | - public static function recursiveArrayObjectToFullArray($appointments){ |
|
80 | + public static function recursiveArrayObjectToFullArray($appointments) { |
|
81 | 81 | return json_decode(json_encode($appointments), true); |
82 | 82 | } |
83 | 83 | |
@@ -88,8 +88,8 @@ discard block |
||
88 | 88 | */ |
89 | 89 | private function arrayRecursiveDiff(array $arrayOlds, array $arrayNews) { |
90 | 90 | $difference = []; |
91 | - foreach($arrayOlds as $key => $arrayOld){ |
|
92 | - if(!in_array($arrayOld,$arrayNews)){ |
|
91 | + foreach ($arrayOlds as $key => $arrayOld) { |
|
92 | + if (!in_array($arrayOld, $arrayNews)) { |
|
93 | 93 | $difference[$key] = $arrayOld; |
94 | 94 | } |
95 | 95 | } |
@@ -104,9 +104,9 @@ discard block |
||
104 | 104 | */ |
105 | 105 | private function arrayRecursiveDiffNew(array $arrayOlds, array $arrayNews, array $existedUpdateOrDelete) { |
106 | 106 | $difference = []; |
107 | - foreach($arrayNews as $key => $arrayNew){ |
|
108 | - if(!in_array($arrayNew,$arrayOlds) |
|
109 | - && !in_array(self::recursiveArrayObjectToFullArray($arrayNew), $existedUpdateOrDelete)){ |
|
107 | + foreach ($arrayNews as $key => $arrayNew) { |
|
108 | + if (!in_array($arrayNew, $arrayOlds) |
|
109 | + && !in_array(self::recursiveArrayObjectToFullArray($arrayNew), $existedUpdateOrDelete)) { |
|
110 | 110 | $difference[$key] = $arrayNew; |
111 | 111 | } |
112 | 112 | } |
@@ -118,13 +118,13 @@ discard block |
||
118 | 118 | * @param array $appointmentsNew |
119 | 119 | * @return array |
120 | 120 | */ |
121 | - public function getListChangings(array $appointmentsOld,array $appointmentsNew){ |
|
121 | + public function getListChangings(array $appointmentsOld, array $appointmentsNew) { |
|
122 | 122 | $appointmentsOld = self::recursiveArrayObjectToFullArray($appointmentsOld); |
123 | 123 | $appointmentsNew = self::recursiveArrayObjectToFullArray($appointmentsNew); |
124 | 124 | $changesListUpdateOrDelete = []; |
125 | 125 | $changesListInsert = []; |
126 | - if($this->hasChanged($appointmentsOld,$appointmentsNew)){ |
|
127 | - $changesListUpdateOrDelete = self::recursiveArrayObjectToFullArray($this->arrayRecursiveDiff($appointmentsOld,$appointmentsNew)); |
|
126 | + if ($this->hasChanged($appointmentsOld, $appointmentsNew)) { |
|
127 | + $changesListUpdateOrDelete = self::recursiveArrayObjectToFullArray($this->arrayRecursiveDiff($appointmentsOld, $appointmentsNew)); |
|
128 | 128 | $changesListInsert = self::recursiveArrayObjectToFullArray($this->arrayRecursiveDiffNew($appointmentsOld, $appointmentsNew, $changesListUpdateOrDelete)); |
129 | 129 | } |
130 | 130 | $changesList = array_merge($changesListUpdateOrDelete, $changesListInsert); |
@@ -137,31 +137,31 @@ discard block |
||
137 | 137 | * @param array $changingsDetected |
138 | 138 | * @return array ['deleted'=>[],'updated'=>[]] |
139 | 139 | */ |
140 | - public function detectDeleteOrUpdatedOrInserted(array $currentAppointments, array $changingsDetected){ |
|
140 | + public function detectDeleteOrUpdatedOrInserted(array $currentAppointments, array $changingsDetected) { |
|
141 | 141 | $delete = []; |
142 | 142 | $update = []; |
143 | 143 | $insert = []; |
144 | 144 | //@Todo: Detect Fields has changed |
145 | 145 | $appointmentsNew = self::recursiveArrayObjectToFullArray($currentAppointments); |
146 | 146 | $changings = self::recursiveArrayObjectToFullArray($changingsDetected); |
147 | - foreach ($changings as $changing){ |
|
147 | + foreach ($changings as $changing) { |
|
148 | 148 | $registration = $changing['registration']['regCode']; |
149 | 149 | $registrationTarget = $changing['targetRegistration']['regCode']; |
150 | - foreach ($appointmentsNew as $currentAppointment){ |
|
151 | - if($changing == $currentAppointment){ |
|
150 | + foreach ($appointmentsNew as $currentAppointment) { |
|
151 | + if ($changing == $currentAppointment) { |
|
152 | 152 | $insert[] = $changing; |
153 | 153 | break; |
154 | 154 | } |
155 | 155 | $registrationCurrent = $currentAppointment['registration']['regCode']; |
156 | 156 | $registrationTargetCurrent = $currentAppointment['targetRegistration']['regCode']; |
157 | - if(in_array($registration,[$registrationCurrent,$registrationTargetCurrent]) |
|
158 | - && in_array($registrationTarget,[$registrationCurrent,$registrationTargetCurrent]) |
|
159 | - && !in_array($changing,$insert) && !in_array($changing,$update) && !in_array($changing,$delete)) { |
|
157 | + if (in_array($registration, [$registrationCurrent, $registrationTargetCurrent]) |
|
158 | + && in_array($registrationTarget, [$registrationCurrent, $registrationTargetCurrent]) |
|
159 | + && !in_array($changing, $insert) && !in_array($changing, $update) && !in_array($changing, $delete)) { |
|
160 | 160 | $update[] = $changing; |
161 | 161 | break; |
162 | 162 | } |
163 | 163 | } |
164 | - if(!in_array($changing,$insert) && !in_array($changing,$update) && !in_array($changing,$delete)){ |
|
164 | + if (!in_array($changing, $insert) && !in_array($changing, $update) && !in_array($changing, $delete)) { |
|
165 | 165 | $delete[] = $changing; |
166 | 166 | } |
167 | 167 | |
@@ -178,8 +178,8 @@ discard block |
||
178 | 178 | * @param $timestamp |
179 | 179 | * @return array |
180 | 180 | */ |
181 | - public static function insertDateTimeChanges(array $appointments,$timestamp){ |
|
182 | - foreach ($appointments as $key => $appointment){ |
|
181 | + public static function insertDateTimeChanges(array $appointments, $timestamp) { |
|
182 | + foreach ($appointments as $key => $appointment) { |
|
183 | 183 | $appointments[$key]['dateDetectChanges'] = $timestamp; |
184 | 184 | } |
185 | 185 | return $appointments; |
@@ -191,12 +191,12 @@ discard block |
||
191 | 191 | * @param string $timestamp |
192 | 192 | * @return array ['deleted'=>[],'updated'=>[]] |
193 | 193 | */ |
194 | - public function detectAppointmentsChangings(array $appointmentsOld,array $appointmentsNew,$timestamp){ |
|
195 | - $changings = $this->getListChangings($appointmentsOld,$appointmentsNew); |
|
196 | - $changesList = $this->detectDeleteOrUpdatedOrInserted($appointmentsNew,$changings); |
|
197 | - $changesList['inserted'] = self::insertDateTimeChanges($changesList['inserted'],$timestamp); |
|
198 | - $changesList['updated'] = self::insertDateTimeChanges($changesList['updated'],$timestamp); |
|
199 | - $changesList['deleted'] = self::insertDateTimeChanges($changesList['deleted'],$timestamp); |
|
194 | + public function detectAppointmentsChangings(array $appointmentsOld, array $appointmentsNew, $timestamp) { |
|
195 | + $changings = $this->getListChangings($appointmentsOld, $appointmentsNew); |
|
196 | + $changesList = $this->detectDeleteOrUpdatedOrInserted($appointmentsNew, $changings); |
|
197 | + $changesList['inserted'] = self::insertDateTimeChanges($changesList['inserted'], $timestamp); |
|
198 | + $changesList['updated'] = self::insertDateTimeChanges($changesList['updated'], $timestamp); |
|
199 | + $changesList['deleted'] = self::insertDateTimeChanges($changesList['deleted'], $timestamp); |
|
200 | 200 | return $changesList; |
201 | 201 | } |
202 | 202 |