Test Setup Failed
Pull Request — master (#304)
by Mohamed
07:04
created
app/Providers/ShaHashServiceProvider.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
 
13 13
     public function register()
14 14
     {
15
-        $this->app->singleton('hash',function (){
15
+        $this->app->singleton('hash', function() {
16 16
             return new SHAHasher($this->app);
17 17
         });
18 18
     }
Please login to merge, or discard this patch.
app/Providers/RouteServiceProvider.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -52,8 +52,8 @@  discard block
 block discarded – undo
52 52
     protected function mapWebRoutes()
53 53
     {
54 54
         Route::middleware('web')
55
-             ->namespace($this->namespace)
56
-             ->group(base_path('routes/web.php'));
55
+                ->namespace($this->namespace)
56
+                ->group(base_path('routes/web.php'));
57 57
     }
58 58
 
59 59
     /**
@@ -66,8 +66,8 @@  discard block
 block discarded – undo
66 66
     protected function mapApiRoutes()
67 67
     {
68 68
         Route::prefix('api')
69
-             ->middleware('api')
70
-             ->namespace($this->namespace)
71
-             ->group(base_path('routes/api.php'));
69
+                ->middleware('api')
70
+                ->namespace($this->namespace)
71
+                ->group(base_path('routes/api.php'));
72 72
     }
73 73
 }
Please login to merge, or discard this patch.
app/Console/Commands/PromoteStudents.php 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -212,7 +212,7 @@
 block discarded – undo
212 212
                 'created_user_id' => $student['created_user_id']
213 213
             ];
214 214
             try{
215
-               Institution_student::where('id',(string)$student['id'])->update($studentData);
215
+                Institution_student::where('id',(string)$student['id'])->update($studentData);
216 216
                 $output = new \Symfony\Component\Console\Output\ConsoleOutput();
217 217
                 $output->writeln('----------------- '. $student['admission_id'] . ' to ' . $studentData['education_grade_id']);
218 218
 
Please login to merge, or discard this patch.
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -63,14 +63,14 @@  discard block
 block discarded – undo
63 63
     {
64 64
         $year = $this->argument('year');
65 65
         $institution = $this->argument('institution');
66
-        $institutionGrade = $this->instituion_grade->getInstitutionGradeToPromoted($year,$institution);
66
+        $institutionGrade = $this->instituion_grade->getInstitutionGradeToPromoted($year, $institution);
67 67
 //        dd($institutionGrade);
68
-        array_walk($institutionGrade,array($this,'processGrades'),$year);
68
+        array_walk($institutionGrade, array($this, 'processGrades'), $year);
69 69
     }
70 70
 
71
-    public function processGrades($institutionGrade,$count,$year){
72
-        if(!empty($institutionGrade) && $this->institutions->isActive($institutionGrade['institution_id'])) {
73
-            $this->instituion_grade->updatePromoted($year,$institutionGrade['id']);
71
+    public function processGrades($institutionGrade, $count, $year) {
72
+        if (!empty($institutionGrade) && $this->institutions->isActive($institutionGrade['institution_id'])) {
73
+            $this->instituion_grade->updatePromoted($year, $institutionGrade['id']);
74 74
             $isAvailableforPromotion = 0;
75 75
             $nextGrade = $this->education_grades->getNextGrade($institutionGrade['education_grade_id']);
76 76
 
@@ -79,9 +79,9 @@  discard block
 block discarded – undo
79 79
             }
80 80
 
81 81
             if (!empty($isAvailableforPromotion)) {
82
-                $this->process($institutionGrade,$nextGrade,$year,1);
83
-            }else{
84
-                $this->process($institutionGrade,$nextGrade,$year,3);
82
+                $this->process($institutionGrade, $nextGrade, $year, 1);
83
+            }else {
84
+                $this->process($institutionGrade, $nextGrade, $year, 3);
85 85
             }
86 86
         }
87 87
     }
@@ -97,9 +97,9 @@  discard block
 block discarded – undo
97 97
      * @param array $parallelClasses
98 98
      * @param $status
99 99
      */
100
-        public function promotion($institutionGrade,$nextGrade,$academicPeriod,$nextAcademicPeriod,$parallelClasses = [],$status){
101
-            $institution = Institution::where( 'id',$institutionGrade['institution_id'])->get()->first();
102
-            $studentListToPromote = $this->institution_students->getStudentListToPromote($institutionGrade,$academicPeriod);
100
+        public function promotion($institutionGrade, $nextGrade, $academicPeriod, $nextAcademicPeriod, $parallelClasses = [], $status) {
101
+            $institution = Institution::where('id', $institutionGrade['institution_id'])->get()->first();
102
+            $studentListToPromote = $this->institution_students->getStudentListToPromote($institutionGrade, $academicPeriod);
103 103
 
104 104
             $params = [
105 105
                 $nextAcademicPeriod,
@@ -108,15 +108,15 @@  discard block
 block discarded – undo
108 108
                 $status
109 109
             ];
110 110
 
111
-            try{
112
-                array_walk($studentListToPromote,array($this,'promote'),$params);
111
+            try {
112
+                array_walk($studentListToPromote, array($this, 'promote'), $params);
113 113
 
114 114
                 $output = new \Symfony\Component\Console\Output\ConsoleOutput();
115 115
                 $output->writeln('##########################################################################################################################');
116
-                $output->writeln('Promoting from '. $institutionGrade['name'] .' IN '.$institution->name.' No of Students: '. count($studentListToPromote));
116
+                $output->writeln('Promoting from '.$institutionGrade['name'].' IN '.$institution->name.' No of Students: '.count($studentListToPromote));
117 117
 
118 118
 
119
-                if(!empty($parallelClasses)){
119
+                if (!empty($parallelClasses)) {
120 120
                     $params = [
121 121
                         $nextAcademicPeriod,
122 122
                         $institutionGrade,
@@ -124,10 +124,10 @@  discard block
 block discarded – undo
124 124
                         $parallelClasses,
125 125
                         $status
126 126
                     ];
127
-                    array_walk($studentListToPromote,array($this,'assingeToClasses'),$params);
128
-                    array_walk($parallelClasses,array($this,'updateStudentCount'));
127
+                    array_walk($studentListToPromote, array($this, 'assingeToClasses'), $params);
128
+                    array_walk($parallelClasses, array($this, 'updateStudentCount'));
129 129
                 }
130
-            }catch (\Exception $e){
130
+            }catch (\Exception $e) {
131 131
                 dd($e);
132 132
                 Log::error($e->getMessage());
133 133
             }
@@ -135,10 +135,10 @@  discard block
 block discarded – undo
135 135
 
136 136
 
137 137
 
138
-        public function updateStudentCount($class){
138
+        public function updateStudentCount($class) {
139 139
             $studentCounts = Institution_class_student::getStudentsCount($class['id']);
140 140
             unset($studentCounts['total']);
141
-            Institution_class::query()->where('id',$class['id'])->update($studentCounts);
141
+            Institution_class::query()->where('id', $class['id'])->update($studentCounts);
142 142
         }
143 143
 
144 144
 
@@ -150,38 +150,38 @@  discard block
 block discarded – undo
150 150
      * @param $year
151 151
      * @return int
152 152
      */
153
-        public function process($institutionGrade,$nextGrade,$year){
154
-            $academicPeriod = Academic_period::query()->where('code',$year -1)->get()->first();
155
-            $nextAcademicPeriod = Academic_period::query()->where('code',$year)->get()->first();
153
+        public function process($institutionGrade, $nextGrade, $year) {
154
+            $academicPeriod = Academic_period::query()->where('code', $year - 1)->get()->first();
155
+            $nextAcademicPeriod = Academic_period::query()->where('code', $year)->get()->first();
156 156
 
157 157
             $nextGradeObj = null;
158
-                    if($nextGrade !== []  && !is_null($nextGrade) ){
159
-                        $currentGradeObj = $this->instituion_grade->getParallelClasses($institutionGrade['id'],$institutionGrade['institution_id'],$institutionGrade['education_grade_id'],$academicPeriod->id);
160
-                        $nextGradeObj = $this->instituion_grade->getParallelClasses($institutionGrade['id'],$institutionGrade['institution_id'],$nextGrade->id,$nextAcademicPeriod->id);
158
+                    if ($nextGrade !== [] && !is_null($nextGrade)) {
159
+                        $currentGradeObj = $this->instituion_grade->getParallelClasses($institutionGrade['id'], $institutionGrade['institution_id'], $institutionGrade['education_grade_id'], $academicPeriod->id);
160
+                        $nextGradeObj = $this->instituion_grade->getParallelClasses($institutionGrade['id'], $institutionGrade['institution_id'], $nextGrade->id, $nextAcademicPeriod->id);
161 161
 
162 162
                     }
163 163
 
164
-            if(!is_null($nextGradeObj)){
165
-                if($nextGradeObj->count() == 1){
164
+            if (!is_null($nextGradeObj)) {
165
+                if ($nextGradeObj->count() == 1) {
166 166
                     // promote parallel classes
167
-                    $this->promotion($institutionGrade,$nextGrade,$academicPeriod,$nextAcademicPeriod,$nextGradeObj->toArray(),1);
167
+                    $this->promotion($institutionGrade, $nextGrade, $academicPeriod, $nextAcademicPeriod, $nextGradeObj->toArray(), 1);
168 168
                     return 1;
169
-                }elseif (($nextGradeObj->count() > 1) && ($nextGradeObj->count() !==  $currentGradeObj->count())){
169
+                }elseif (($nextGradeObj->count() > 1) && ($nextGradeObj->count() !== $currentGradeObj->count())) {
170 170
                     // promote pool promotion
171
-                    $this->promotion($institutionGrade,$nextGrade,$academicPeriod,$nextAcademicPeriod,[],1);
171
+                    $this->promotion($institutionGrade, $nextGrade, $academicPeriod, $nextAcademicPeriod, [], 1);
172 172
                     return 2;
173
-                }elseif(($nextGradeObj->count() > 1) && $currentGradeObj->count() == $nextGradeObj->count()){
173
+                }elseif (($nextGradeObj->count() > 1) && $currentGradeObj->count() == $nextGradeObj->count()) {
174 174
                     // Promote matching class name with previous class
175
-                    $this->promotion($institutionGrade,$nextGrade,$academicPeriod,$nextAcademicPeriod,$nextGradeObj->toArray(),1);
175
+                    $this->promotion($institutionGrade, $nextGrade, $academicPeriod, $nextAcademicPeriod, $nextGradeObj->toArray(), 1);
176 176
                     return 1;
177
-                }else{
177
+                }else {
178 178
                     // default pool promotion
179
-                    $this->promotion($institutionGrade,$nextGrade,$academicPeriod,$nextAcademicPeriod,[],1);
179
+                    $this->promotion($institutionGrade, $nextGrade, $academicPeriod, $nextAcademicPeriod, [], 1);
180 180
                     return 2;
181 181
                 }
182
-            }else{
182
+            }else {
183 183
                 // default pool promotion
184
-                $this->promotion($institutionGrade,$nextGrade,$academicPeriod,$nextAcademicPeriod,[],3);
184
+                $this->promotion($institutionGrade, $nextGrade, $academicPeriod, $nextAcademicPeriod, [], 3);
185 185
                 return 2;
186 186
             }
187 187
         }
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
      * @param $count
195 195
      * @param $params
196 196
      */
197
-        public function promote($student,$count,$params){
197
+        public function promote($student, $count, $params) {
198 198
 
199 199
             $academicPeriod = $params[0];
200 200
             $nextGrade = $params[2];
@@ -204,19 +204,19 @@  discard block
 block discarded – undo
204 204
                 'education_grade_id' => $nextGrade !== null ? $nextGrade->id : $student['education_grade_id'],
205 205
                 'academic_period_id' => $academicPeriod->id,
206 206
                 'start_date' => $academicPeriod->start_date,
207
-                'start_year' =>$academicPeriod->start_year ,
207
+                'start_year' =>$academicPeriod->start_year,
208 208
                 'end_date' => $academicPeriod->end_date,
209
-                'end_year' =>   $academicPeriod->end_year ,
209
+                'end_year' =>   $academicPeriod->end_year,
210 210
                 'institution_id' => $student['institution_id'],
211 211
                 'admission_id' => $student['admission_id'],
212 212
                 'created_user_id' => $student['created_user_id']
213 213
             ];
214
-            try{
215
-               Institution_student::where('id',(string)$student['id'])->update($studentData);
214
+            try {
215
+               Institution_student::where('id', (string) $student['id'])->update($studentData);
216 216
                 $output = new \Symfony\Component\Console\Output\ConsoleOutput();
217
-                $output->writeln('----------------- '. $student['admission_id'] . ' to ' . $studentData['education_grade_id']);
217
+                $output->writeln('----------------- '.$student['admission_id'].' to '.$studentData['education_grade_id']);
218 218
 
219
-            }catch (\Exception $e){
219
+            }catch (\Exception $e) {
220 220
                 dd($e);
221 221
                 Log::error($e->getMessage());
222 222
             }
@@ -232,11 +232,11 @@  discard block
 block discarded – undo
232 232
      * @param $classes
233 233
      * @return false|int|string|null
234 234
      */
235
-    public function getStudentClass($student,$educationGrade,$nextGrade,$classes){
235
+    public function getStudentClass($student, $educationGrade, $nextGrade, $classes) {
236 236
         $studentClass = $this->institution_class_students->getStudentNewClass($student);
237
-        if(!is_null($studentClass)){
238
-            return  array_search(str_replace($educationGrade['name'],$nextGrade->name,$studentClass->name),array_column($classes,'name'));
239
-        }else{
237
+        if (!is_null($studentClass)) {
238
+            return  array_search(str_replace($educationGrade['name'], $nextGrade->name, $studentClass->name), array_column($classes, 'name'));
239
+        }else {
240 240
             return false;
241 241
         }
242 242
 
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
      * @param $count
250 250
      * @param $params
251 251
      */
252
-    public function assingeToClasses($student,$count,$params){
252
+    public function assingeToClasses($student, $count, $params) {
253 253
         $academicPeriod = $params[0];
254 254
         $educationGrade = $params[1];
255 255
         $nextGrade = $params[2];
@@ -257,15 +257,15 @@  discard block
 block discarded – undo
257 257
         $status = $params[4];
258 258
 
259 259
 
260
-        $class = $this->getStudentClass($student,$educationGrade,$nextGrade,$classes);
261
-        if(is_numeric($class)){
260
+        $class = $this->getStudentClass($student, $educationGrade, $nextGrade, $classes);
261
+        if (is_numeric($class)) {
262 262
             $class = $classes[$class];
263 263
 
264
-            if(count($classes) == 1){
264
+            if (count($classes) == 1) {
265 265
                 $class = $classes[0];
266 266
             }
267 267
 
268
-            if(!is_null($class)){
268
+            if (!is_null($class)) {
269 269
 
270 270
                 $studentObj = [
271 271
                     'student_id' => $student['student_id'],
@@ -276,14 +276,14 @@  discard block
 block discarded – undo
276 276
                     'student_status_id' => $status,
277 277
                     'created_user_id' => $student['created_user_id']
278 278
                 ];
279
-                if(!$this->institution_class_students->isDuplicated($studentObj)){
279
+                if (!$this->institution_class_students->isDuplicated($studentObj)) {
280 280
                     $this->institution_class_students->create($studentObj);
281 281
                     $output = new \Symfony\Component\Console\Output\ConsoleOutput();
282
-                    $output->writeln('----------------- '. $student['student_id']. 'to ' . $class['name']);
283
-                }else{
284
-                    $this->institution_class_students->where('id',(string)$student['id'])->update($studentObj);
282
+                    $output->writeln('----------------- '.$student['student_id'].'to '.$class['name']);
283
+                }else {
284
+                    $this->institution_class_students->where('id', (string) $student['id'])->update($studentObj);
285 285
                     $output = new \Symfony\Component\Console\Output\ConsoleOutput();
286
-                    $output->writeln('----------------- '. $student['student_id']. 'to ' . $class['name']);
286
+                    $output->writeln('----------------- '.$student['student_id'].'to '.$class['name']);
287 287
                 }
288 288
             }
289 289
         }
Please login to merge, or discard this patch.
Braces   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 
81 81
             if (!empty($isAvailableforPromotion)) {
82 82
                 $this->process($institutionGrade,$nextGrade,$year,1);
83
-            }else{
83
+            } else{
84 84
                 $this->process($institutionGrade,$nextGrade,$year,3);
85 85
             }
86 86
         }
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
                     array_walk($studentListToPromote,array($this,'assingeToClasses'),$params);
128 128
                     array_walk($parallelClasses,array($this,'updateStudentCount'));
129 129
                 }
130
-            }catch (\Exception $e){
130
+            } catch (\Exception $e){
131 131
                 dd($e);
132 132
                 Log::error($e->getMessage());
133 133
             }
@@ -166,20 +166,20 @@  discard block
 block discarded – undo
166 166
                     // promote parallel classes
167 167
                     $this->promotion($institutionGrade,$nextGrade,$academicPeriod,$nextAcademicPeriod,$nextGradeObj->toArray(),1);
168 168
                     return 1;
169
-                }elseif (($nextGradeObj->count() > 1) && ($nextGradeObj->count() !==  $currentGradeObj->count())){
169
+                } elseif (($nextGradeObj->count() > 1) && ($nextGradeObj->count() !==  $currentGradeObj->count())){
170 170
                     // promote pool promotion
171 171
                     $this->promotion($institutionGrade,$nextGrade,$academicPeriod,$nextAcademicPeriod,[],1);
172 172
                     return 2;
173
-                }elseif(($nextGradeObj->count() > 1) && $currentGradeObj->count() == $nextGradeObj->count()){
173
+                } elseif(($nextGradeObj->count() > 1) && $currentGradeObj->count() == $nextGradeObj->count()){
174 174
                     // Promote matching class name with previous class
175 175
                     $this->promotion($institutionGrade,$nextGrade,$academicPeriod,$nextAcademicPeriod,$nextGradeObj->toArray(),1);
176 176
                     return 1;
177
-                }else{
177
+                } else{
178 178
                     // default pool promotion
179 179
                     $this->promotion($institutionGrade,$nextGrade,$academicPeriod,$nextAcademicPeriod,[],1);
180 180
                     return 2;
181 181
                 }
182
-            }else{
182
+            } else{
183 183
                 // default pool promotion
184 184
                 $this->promotion($institutionGrade,$nextGrade,$academicPeriod,$nextAcademicPeriod,[],3);
185 185
                 return 2;
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
                 $output = new \Symfony\Component\Console\Output\ConsoleOutput();
217 217
                 $output->writeln('----------------- '. $student['admission_id'] . ' to ' . $studentData['education_grade_id']);
218 218
 
219
-            }catch (\Exception $e){
219
+            } catch (\Exception $e){
220 220
                 dd($e);
221 221
                 Log::error($e->getMessage());
222 222
             }
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
         $studentClass = $this->institution_class_students->getStudentNewClass($student);
237 237
         if(!is_null($studentClass)){
238 238
             return  array_search(str_replace($educationGrade['name'],$nextGrade->name,$studentClass->name),array_column($classes,'name'));
239
-        }else{
239
+        } else{
240 240
             return false;
241 241
         }
242 242
 
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
                     $this->institution_class_students->create($studentObj);
281 281
                     $output = new \Symfony\Component\Console\Output\ConsoleOutput();
282 282
                     $output->writeln('----------------- '. $student['student_id']. 'to ' . $class['name']);
283
-                }else{
283
+                } else{
284 284
                     $this->institution_class_students->where('id',(string)$student['id'])->update($studentObj);
285 285
                     $output = new \Symfony\Component\Console\Output\ConsoleOutput();
286 286
                     $output->writeln('----------------- '. $student['student_id']. 'to ' . $class['name']);
Please login to merge, or discard this patch.
app/Console/Commands/StudentsIdGen.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -46,16 +46,16 @@  discard block
 block discarded – undo
46 46
         $this->start_time = microtime(TRUE);
47 47
         ini_set('memory_limit', '2048M');
48 48
         $students = $this->students->query()
49
-            ->where('is_student',1)
49
+            ->where('is_student', 1)
50 50
             ->limit(100000)
51 51
             ->offset($this->argument('offset'))
52 52
             ->get()->toArray();
53 53
         $this->output->writeln('no of students'.count($students));
54 54
         $this->output->writeln('Update started');
55
-        array_walk($students,array($this,'updateNewUUID'));
55
+        array_walk($students, array($this, 'updateNewUUID'));
56 56
         $this->end_time = microtime(TRUE);
57 57
         $this->output->writeln('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$');
58
-        $this->output->writeln('The cook took ' . ($this->end_time - $this->start_time) . ' seconds to complete');
58
+        $this->output->writeln('The cook took '.($this->end_time - $this->start_time).' seconds to complete');
59 59
         $this->output->writeln('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$');
60 60
     }
61 61
 
@@ -64,12 +64,12 @@  discard block
 block discarded – undo
64 64
      * @param $student
65 65
      * @throws \Exception
66 66
      */
67
-    public function updateNewUUID($student){
68
-        if(!MoeUuid::isValidMoeUuid(3)){
67
+    public function updateNewUUID($student) {
68
+        if (!MoeUuid::isValidMoeUuid(3)) {
69 69
             $newId = MoeUuid::getUniqueAlphanumeric(3);
70 70
             $this->output->writeln('Updating student:'.$student['id']);
71
-            Security_user::query()->where('id',$student['id'])
72
-                ->update(['openemis_no' => $newId , 'username' => str_replace('-','',$newId)]);
71
+            Security_user::query()->where('id', $student['id'])
72
+                ->update(['openemis_no' => $newId, 'username' => str_replace('-', '', $newId)]);
73 73
         }
74 74
     }
75 75
 }
Please login to merge, or discard this patch.
app/Console/Commands/ProcessTerminatedFiles.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -45,19 +45,19 @@  discard block
 block discarded – undo
45 45
     {
46 46
             $files = $this->getFiles();
47 47
             try {
48
-                if(!empty($files)){
49
-                    array_walk($files,array($this,'process'));
48
+                if (!empty($files)) {
49
+                    array_walk($files, array($this, 'process'));
50 50
                     unset($files);
51 51
                     exit();
52 52
 
53
-                }else{
53
+                }else {
54 54
                     $output = new \Symfony\Component\Console\Output\ConsoleOutput();
55 55
                     $output->writeln('No files found,Waiting for files');
56 56
                     exit();
57 57
 
58 58
                 }
59 59
 
60
-            }catch (Exception $e){
60
+            }catch (Exception $e) {
61 61
                 $output = new \Symfony\Component\Console\Output\ConsoleOutput();
62 62
                 $output->writeln($e);
63 63
                 sleep(300);
@@ -67,25 +67,25 @@  discard block
 block discarded – undo
67 67
 
68 68
     }
69 69
 
70
-    protected function getFiles(){
70
+    protected function getFiles() {
71 71
         $files = Upload::where('is_processed', '=', 3)
72
-            ->where('is_email_sent','=',0)
72
+            ->where('is_email_sent', '=', 0)
73 73
             ->where('updated_at', '<=', Carbon::now()->tz('Asia/Colombo')->subHours(3))
74 74
             ->limit(50)
75 75
             ->get()->toArray();
76 76
         return $files;
77 77
     }
78 78
 
79
-    protected function  process($file){
79
+    protected function  process($file) {
80 80
         $time = Carbon::now()->tz('Asia/Colombo');
81 81
         $this->processSheet($file);
82 82
         $output = new \Symfony\Component\Console\Output\ConsoleOutput();
83 83
         $now = Carbon::now()->tz('Asia/Colombo');
84
-        $output->writeln('=============== Time taken to batch ' .$now->diffInMinutes($time));
84
+        $output->writeln('=============== Time taken to batch '.$now->diffInMinutes($time));
85 85
 
86 86
     }
87 87
 
88
-    protected function processSheet($file){
88
+    protected function processSheet($file) {
89 89
         $this->startTime = Carbon::now()->tz('Asia/Colombo');
90 90
         $user = User::find($file['security_user_id']);
91 91
         $output = new \Symfony\Component\Console\Output\ConsoleOutput();
@@ -95,8 +95,8 @@  discard block
 block discarded – undo
95 95
             Mail::to($user->email)->send(new TerminatedReport($file));
96 96
             DB::table('uploads')
97 97
                 ->where('id', $file['id'])
98
-                ->update(['is_processed' => 3, 'is_email_sent' => 1,'updated_at' => now()]);
99
-        } else {
98
+                ->update(['is_processed' => 3, 'is_email_sent' => 1, 'updated_at' => now()]);
99
+        }else {
100 100
             exit();
101 101
         }
102 102
     }
Please login to merge, or discard this patch.
Braces   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -50,14 +50,14 @@
 block discarded – undo
50 50
                     unset($files);
51 51
                     exit();
52 52
 
53
-                }else{
53
+                } else{
54 54
                     $output = new \Symfony\Component\Console\Output\ConsoleOutput();
55 55
                     $output->writeln('No files found,Waiting for files');
56 56
                     exit();
57 57
 
58 58
                 }
59 59
 
60
-            }catch (Exception $e){
60
+            } catch (Exception $e){
61 61
                 $output = new \Symfony\Component\Console\Output\ConsoleOutput();
62 62
                 $output->writeln($e);
63 63
                 sleep(300);
Please login to merge, or discard this patch.
app/Console/Commands/RunAddApprovedStudents.php 3 patches
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -78,41 +78,41 @@
 block discarded – undo
78 78
             $this->count += 1;
79 79
             $this->student = $student ;
80 80
             try{
81
-               Institution_student::create([
82
-                   'student_status_id' => 1,
83
-                   'student_id' => $student['student_id'],
84
-                   'education_grade_id' => $student['education_grade_id'],
85
-                   'academic_period_id' => $student['academic_period_id'],
86
-                   'start_date' => $student['start_date'],
87
-                   'start_year' => \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $student['start_date'])->year , // $student['start_date']->format('Y'),
88
-                   'end_date' => $student['end_date'],
89
-                   'end_year' =>  \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $student['end_date'])->year , //$student['end_date']->format('Y'),
90
-                   'institution_id' => $student['institution_id'],
91
-                   'admission_id' => $student['admission_id'],
92
-                   'created_user_id' => $student['created_user_id'],
93
-               ]);
94
-
95
-               if(!is_null($student['institution_class_id'])){
96
-                   Institution_class_student::create([
97
-                       'student_id' => $student['student_id'],
98
-                       'institution_class_id' => $student['institution_class_id'],
99
-                       'education_grade_id' =>  $student['education_grade_id'],
100
-                       'academic_period_id' => $student['academic_period_id'],
101
-                       'institution_id' =>$student['institution_id'],
102
-                       'student_status_id' => 1,
103
-                       'created_user_id' => $student['created_user_id'],
104
-                   ]);
105
-               }
81
+                Institution_student::create([
82
+                    'student_status_id' => 1,
83
+                    'student_id' => $student['student_id'],
84
+                    'education_grade_id' => $student['education_grade_id'],
85
+                    'academic_period_id' => $student['academic_period_id'],
86
+                    'start_date' => $student['start_date'],
87
+                    'start_year' => \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $student['start_date'])->year , // $student['start_date']->format('Y'),
88
+                    'end_date' => $student['end_date'],
89
+                    'end_year' =>  \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $student['end_date'])->year , //$student['end_date']->format('Y'),
90
+                    'institution_id' => $student['institution_id'],
91
+                    'admission_id' => $student['admission_id'],
92
+                    'created_user_id' => $student['created_user_id'],
93
+                ]);
94
+
95
+                if(!is_null($student['institution_class_id'])){
96
+                    Institution_class_student::create([
97
+                        'student_id' => $student['student_id'],
98
+                        'institution_class_id' => $student['institution_class_id'],
99
+                        'education_grade_id' =>  $student['education_grade_id'],
100
+                        'academic_period_id' => $student['academic_period_id'],
101
+                        'institution_id' =>$student['institution_id'],
102
+                        'student_status_id' => 1,
103
+                        'created_user_id' => $student['created_user_id'],
104
+                    ]);
105
+                }
106 106
                 $output->writeln('
107 107
         ####################################################
108 108
            Total number of students updated : '.$this->count.'
109 109
         #                                                  #
110 110
         ####################################################' );
111 111
 //        $output->writeln();
112
-           }catch (\Exception $e){
112
+            }catch (\Exception $e){
113 113
 //               echo $e->getMessage();
114
-               $output->writeln( $e->getMessage());
115
-           }
114
+                $output->writeln( $e->getMessage());
115
+            }
116 116
         }
117 117
     }
118 118
 
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -51,48 +51,48 @@  discard block
 block discarded – undo
51 51
             'id' => $this->argument('institution')
52 52
         ])->first();
53 53
 
54
-        if(!is_null($institution)){
54
+        if (!is_null($institution)) {
55 55
             try {
56
-                $this->info('adding missing students to the admission ' . $institution->name);
56
+                $this->info('adding missing students to the admission '.$institution->name);
57 57
                 $allApprovedStudents = Institution_student_admission::where([
58 58
                     'status_id' => 124,
59 59
                     'institution_id' => $institution->id
60 60
                 ])->get()->toArray();
61 61
                 $allApprovedStudents = array_chunk($allApprovedStudents, 50);
62 62
                 array_walk($allApprovedStudents, array($this, 'addStudents'));
63
-            } catch (\Exception $e) {
63
+            }catch (\Exception $e) {
64 64
                 Log::error($e);
65 65
             }
66 66
         }
67 67
     }
68 68
 
69
-    protected function addStudents($students){
70
-        array_walk($students,array($this,'addStudent'));
69
+    protected function addStudents($students) {
70
+        array_walk($students, array($this, 'addStudent'));
71 71
     }
72 72
 
73
-    protected function addStudent($student){
73
+    protected function addStudent($student) {
74 74
 //        dd(Institution_class_student::isDuplicated($student));
75 75
         $output = new \Symfony\Component\Console\Output\ConsoleOutput();
76 76
         sleep(1);
77
-        if(!(Institution_class_student::isDuplicated($student) > 0)){
77
+        if (!(Institution_class_student::isDuplicated($student) > 0)) {
78 78
             $this->count += 1;
79
-            $this->student = $student ;
80
-            try{
79
+            $this->student = $student;
80
+            try {
81 81
                Institution_student::create([
82 82
                    'student_status_id' => 1,
83 83
                    'student_id' => $student['student_id'],
84 84
                    'education_grade_id' => $student['education_grade_id'],
85 85
                    'academic_period_id' => $student['academic_period_id'],
86 86
                    'start_date' => $student['start_date'],
87
-                   'start_year' => \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $student['start_date'])->year , // $student['start_date']->format('Y'),
87
+                   'start_year' => \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $student['start_date'])->year, // $student['start_date']->format('Y'),
88 88
                    'end_date' => $student['end_date'],
89
-                   'end_year' =>  \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $student['end_date'])->year , //$student['end_date']->format('Y'),
89
+                   'end_year' =>  \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $student['end_date'])->year, //$student['end_date']->format('Y'),
90 90
                    'institution_id' => $student['institution_id'],
91 91
                    'admission_id' => $student['admission_id'],
92 92
                    'created_user_id' => $student['created_user_id'],
93 93
                ]);
94 94
 
95
-               if(!is_null($student['institution_class_id'])){
95
+               if (!is_null($student['institution_class_id'])) {
96 96
                    Institution_class_student::create([
97 97
                        'student_id' => $student['student_id'],
98 98
                        'institution_class_id' => $student['institution_class_id'],
@@ -109,23 +109,23 @@  discard block
 block discarded – undo
109 109
         #                                                  #
110 110
         ####################################################' );
111 111
 //        $output->writeln();
112
-           }catch (\Exception $e){
112
+           }catch (\Exception $e) {
113 113
 //               echo $e->getMessage();
114
-               $output->writeln( $e->getMessage());
114
+               $output->writeln($e->getMessage());
115 115
            }
116 116
         }
117 117
     }
118 118
 
119 119
 
120
-    protected  function  setSubjects($student){
120
+    protected  function  setSubjects($student) {
121 121
         $allSubjects = Institution_class_subject::getMandetorySubjects($student['institution_class_id']);
122 122
 
123 123
         if (!empty($allSubjects)) {
124 124
             $allSubjects = unique_multidim_array($allSubjects, 'institution_subject_id');
125 125
             $this->student = $student;
126
-            $allSubjects = array_map(array($this,'setStudentSubjects'),$allSubjects);
126
+            $allSubjects = array_map(array($this, 'setStudentSubjects'), $allSubjects);
127 127
             $allSubjects = unique_multidim_array($allSubjects, 'education_subject_id');
128
-            array_walk($allSubjects,array($this,'insertSubject'));
128
+            array_walk($allSubjects, array($this, 'insertSubject'));
129 129
         }
130 130
 
131 131
         unset($allSubjects);
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
     }
134 134
 
135 135
 
136
-    protected function setStudentSubjects($subject){
136
+    protected function setStudentSubjects($subject) {
137 137
         return [
138 138
             'id' => (string) Uuid::generate(4),
139 139
             'student_id' => $this->student->student_id,
@@ -149,8 +149,8 @@  discard block
 block discarded – undo
149 149
         ];
150 150
     }
151 151
 
152
-    protected function insertSubject($subject){
153
-        if(!Institution_subject_student::isDuplicated($subject)){
152
+    protected function insertSubject($subject) {
153
+        if (!Institution_subject_student::isDuplicated($subject)) {
154 154
             Institution_subject_student::updateOrInsert($subject);
155 155
         }
156 156
     }
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -109,7 +109,7 @@
 block discarded – undo
109 109
         #                                                  #
110 110
         ####################################################' );
111 111
 //        $output->writeln();
112
-           }catch (\Exception $e){
112
+           } catch (\Exception $e){
113 113
 //               echo $e->getMessage();
114 114
                $output->writeln( $e->getMessage());
115 115
            }
Please login to merge, or discard this patch.
app/Console/Commands/callAddApprovedStudents.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -39,17 +39,17 @@
 block discarded – undo
39 39
      */
40 40
     public function handle()
41 41
     {
42
-        ini_set('memory_limit','2048');
42
+        ini_set('memory_limit', '2048');
43 43
         $institutions = $this->instituions->all()->chunk(50)->toArray();
44
-        array_walk($institutions,array($this,'addInstitutionStudents'));
44
+        array_walk($institutions, array($this, 'addInstitutionStudents'));
45 45
     }
46 46
 
47
-    protected function addInstitutionStudents($chunk){
48
-        array_walk($chunk,array($this,'callFunction'));
47
+    protected function addInstitutionStudents($chunk) {
48
+        array_walk($chunk, array($this, 'callFunction'));
49 49
 
50 50
     }
51 51
 
52
-    protected function callFunction($institution){
53
-        $this->call('admission:students',['institution' => $institution['code']]);
52
+    protected function callFunction($institution) {
53
+        $this->call('admission:students', ['institution' => $institution['code']]);
54 54
     }
55 55
 }
Please login to merge, or discard this patch.
app/Console/Commands/CloneConfigData.php 3 patches
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -76,9 +76,9 @@  discard block
 block discarded – undo
76 76
         $this->end_time = microtime(TRUE);
77 77
 
78 78
 
79
-       $this->output->writeln('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$');
80
-       $this->output->writeln('The cook took ' . ($this->end_time - $this->start_time) . ' seconds to complete');
81
-       $this->output->writeln('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$');
79
+        $this->output->writeln('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$');
80
+        $this->output->writeln('The cook took ' . ($this->end_time - $this->start_time) . ' seconds to complete');
81
+        $this->output->writeln('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$');
82 82
 
83 83
     }
84 84
 
@@ -113,13 +113,13 @@  discard block
 block discarded – undo
113 113
                     $this->output->writeln('updating from '. $shiftId);
114 114
 
115 115
                 }catch (\Exception $e){
116
-                     Log::error($e->getMessage(),[$e]);
116
+                        Log::error($e->getMessage(),[$e]);
117 117
                 }
118 118
             }
119 119
 //            DB::commit();
120 120
         }catch (\Exception $e){
121 121
 //            DB::rollBack();
122
-             Log::error($e->getMessage(),[$e]);
122
+                Log::error($e->getMessage(),[$e]);
123 123
         }
124 124
     }
125 125
 
@@ -130,16 +130,16 @@  discard block
 block discarded – undo
130 130
      * @param $academicPeriod
131 131
      */
132 132
     public function insertInstitutionSubjects($subjects, $count,$academicPeriod){
133
-       try{
134
-           $subjects['academic_period_id'] = $academicPeriod->id;
135
-           $subjects['created'] = now();
136
-           unset($subjects['total_male_students']);
137
-           unset($subjects['total_female_students']);
138
-           unset($subjects['id']);
139
-           $classSubject = Institution_subject::create($subjects);
140
-       }catch (\Exception $e){
133
+        try{
134
+            $subjects['academic_period_id'] = $academicPeriod->id;
135
+            $subjects['created'] = now();
136
+            unset($subjects['total_male_students']);
137
+            unset($subjects['total_female_students']);
138
+            unset($subjects['id']);
139
+            $classSubject = Institution_subject::create($subjects);
140
+        }catch (\Exception $e){
141 141
             Log::error($e->getMessage(),[$e]);
142
-       }
142
+        }
143 143
     }
144 144
 
145 145
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
                 $this->insertInstitutionClassSubjects($institutionSubjects,$class);
182 182
 //                array_walk($classSubjects,array($this,'insertInstitutionClassSubjects'),$params);
183 183
             }catch (\Exception $e){
184
-                 Log::error($e->getMessage(),[$e]);
184
+                    Log::error($e->getMessage(),[$e]);
185 185
             }
186 186
     }
187 187
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
                 array_walk($subjects,array($this,'insertClassSubjects'),$class);
192 192
                 $this->output->writeln('updating subjects '. $class->name);
193 193
             }catch (\Exception $e){
194
-                 Log::error($e->getMessage(),[$e]);
194
+                    Log::error($e->getMessage(),[$e]);
195 195
             }
196 196
         };
197 197
     }
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
                 $this->institution_class_subjects->create($subjectobj);
210 210
             }
211 211
         }catch (\Exception $e){
212
-             Log::error($e->getMessage(),[$e]);
212
+                Log::error($e->getMessage(),[$e]);
213 213
         }
214 214
     }
215 215
 
Please login to merge, or discard this patch.
Spacing   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -48,8 +48,8 @@  discard block
 block discarded – undo
48 48
         $this->academic_period = new Academic_period();
49 49
         $this->institution_classes = new Institution_class();
50 50
         $this->institution_class_subjects = new Institution_class_subject();
51
-        $this->institution_subjects =  new Institution_subject();
52
-        $this->education_grade_subjects =  new Education_grades_subject();
51
+        $this->institution_subjects = new Institution_subject();
52
+        $this->education_grade_subjects = new Education_grades_subject();
53 53
         $this->output = new \Symfony\Component\Console\Output\ConsoleOutput();
54 54
     }
55 55
 
@@ -72,33 +72,33 @@  discard block
 block discarded – undo
72 72
             'previous_academic_period' => $previousAcademicPeriod
73 73
         ];
74 74
         // dd($shift);
75
-        array_walk($shift,array($this,'process'),$params);
75
+        array_walk($shift, array($this, 'process'), $params);
76 76
         $this->end_time = microtime(TRUE);
77 77
 
78 78
 
79 79
        $this->output->writeln('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$');
80
-       $this->output->writeln('The cook took ' . ($this->end_time - $this->start_time) . ' seconds to complete');
80
+       $this->output->writeln('The cook took '.($this->end_time - $this->start_time).' seconds to complete');
81 81
        $this->output->writeln('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$');
82 82
 
83 83
     }
84 84
 
85
-    public function array_walk($shift,$count,$params){
86
-        array_walk($shift,array($this,'process'),$params);
85
+    public function array_walk($shift, $count, $params) {
86
+        array_walk($shift, array($this, 'process'), $params);
87 87
     }
88 88
 
89
-    public function process($shift,$count,$params){
89
+    public function process($shift, $count, $params) {
90 90
         $year = $params['year'];
91 91
         $academicPeriod = $params['academic_period'];
92 92
         $previousAcademicPeriod = $params['previous_academic_period'];
93 93
 //        DB::beginTransaction();
94
-        try{
94
+        try {
95 95
             $shiftId = $this->updateShifts($year, $shift);
96 96
             $institutionClasses = $this->institution_classes->getShiftClasses($shift['id']);
97 97
             $institutionSubjects = $this->education_grade_subjects->getInstitutionSubjects($shift['institution_id']);
98
-            array_walk($institutionSubjects , array($this,'insertInstitutionSubjects'),$academicPeriod);
99
-            if (!empty($institutionClasses) && !is_null($shiftId) && !is_null($academicPeriod) ) {
98
+            array_walk($institutionSubjects, array($this, 'insertInstitutionSubjects'), $academicPeriod);
99
+            if (!empty($institutionClasses) && !is_null($shiftId) && !is_null($academicPeriod)) {
100 100
 
101
-                $newInstitutionClasses = $this->generateNewClass($institutionClasses,$shiftId,$academicPeriod->id);
101
+                $newInstitutionClasses = $this->generateNewClass($institutionClasses, $shiftId, $academicPeriod->id);
102 102
 
103 103
                 $params = [
104 104
                     'previous_academic_period_id' => $previousAcademicPeriod->id,
@@ -106,20 +106,20 @@  discard block
 block discarded – undo
106 106
                     'shift_id' =>$shiftId
107 107
                 ];
108 108
 
109
-                try{
110
-                    array_walk($newInstitutionClasses,array($this,'insertInstitutionClasses'),$params);
109
+                try {
110
+                    array_walk($newInstitutionClasses, array($this, 'insertInstitutionClasses'), $params);
111 111
                     $newInstitutionClasses = $this->institution_classes->getShiftClasses($shiftId);
112 112
                     $this->output->writeln('##########################################################################################################################');
113
-                    $this->output->writeln('updating from '. $shiftId);
113
+                    $this->output->writeln('updating from '.$shiftId);
114 114
 
115
-                }catch (\Exception $e){
116
-                     Log::error($e->getMessage(),[$e]);
115
+                }catch (\Exception $e) {
116
+                     Log::error($e->getMessage(), [$e]);
117 117
                 }
118 118
             }
119 119
 //            DB::commit();
120
-        }catch (\Exception $e){
120
+        }catch (\Exception $e) {
121 121
 //            DB::rollBack();
122
-             Log::error($e->getMessage(),[$e]);
122
+             Log::error($e->getMessage(), [$e]);
123 123
         }
124 124
     }
125 125
 
@@ -129,31 +129,31 @@  discard block
 block discarded – undo
129 129
      * @param $count
130 130
      * @param $academicPeriod
131 131
      */
132
-    public function insertInstitutionSubjects($subjects, $count,$academicPeriod){
133
-       try{
132
+    public function insertInstitutionSubjects($subjects, $count, $academicPeriod) {
133
+       try {
134 134
            $subjects['academic_period_id'] = $academicPeriod->id;
135 135
            $subjects['created'] = now();
136 136
            unset($subjects['total_male_students']);
137 137
            unset($subjects['total_female_students']);
138 138
            unset($subjects['id']);
139 139
            $classSubject = Institution_subject::create($subjects);
140
-       }catch (\Exception $e){
141
-            Log::error($e->getMessage(),[$e]);
140
+       }catch (\Exception $e) {
141
+            Log::error($e->getMessage(), [$e]);
142 142
        }
143 143
     }
144 144
 
145 145
 
146
-    public function  insertInstitutionClasses($class,$count,$param){
147
-            try{
146
+    public function  insertInstitutionClasses($class, $count, $param) {
147
+            try {
148 148
 
149 149
                 $academicPeriod = $param['academic_period_id'];
150 150
                 $educationGrdae = $class['education_grade_id'];
151 151
 
152 152
                 $classId = $class['id'];
153 153
                 unset($class['id']);
154
-                $institutionSubjects = Institution_subject::query()->where('education_grade_id',$class['education_grade_id'])
155
-                    ->where('institution_id',$class['institution_id'])
156
-                    ->where('academic_period_id',$academicPeriod)->get()->toArray();
154
+                $institutionSubjects = Institution_subject::query()->where('education_grade_id', $class['education_grade_id'])
155
+                    ->where('institution_id', $class['institution_id'])
156
+                    ->where('academic_period_id', $academicPeriod)->get()->toArray();
157 157
                 $params = [
158 158
                     'class'=>$class,
159 159
                     'subjects'=>$institutionSubjects,
@@ -166,38 +166,38 @@  discard block
 block discarded – undo
166 166
                 $class['no_of_students'] = $noOfStudents;
167 167
                 $class['created'] = now();
168 168
                 $class['institution_shift_id'] = $param['shift_id'];
169
-                $this->output->writeln('Create class:'. $class['name']);
169
+                $this->output->writeln('Create class:'.$class['name']);
170 170
                 $class = Institution_class::create($class);
171 171
                 $institutionClassGrdaeObj['institution_class_id'] = $class->id;
172 172
                 $institutionClassGrdaeObj['education_grade_id'] = $educationGrdae;
173 173
                 Institution_class_grade::create($institutionClassGrdaeObj);
174
-                $institutionSubjects = Institution_subject::query()->where('education_grade_id',$educationGrdae)
175
-                    ->where('institution_id',$class->institution_id)
176
-                    ->where('academic_period_id',$academicPeriod)
174
+                $institutionSubjects = Institution_subject::query()->where('education_grade_id', $educationGrdae)
175
+                    ->where('institution_id', $class->institution_id)
176
+                    ->where('academic_period_id', $academicPeriod)
177 177
                     ->groupBy('education_subject_id')
178 178
                     ->get()
179 179
                     ->toArray();
180 180
                 $params['class'] = $class;
181
-                $this->insertInstitutionClassSubjects($institutionSubjects,$class);
181
+                $this->insertInstitutionClassSubjects($institutionSubjects, $class);
182 182
 //                array_walk($classSubjects,array($this,'insertInstitutionClassSubjects'),$params);
183
-            }catch (\Exception $e){
184
-                 Log::error($e->getMessage(),[$e]);
183
+            }catch (\Exception $e) {
184
+                 Log::error($e->getMessage(), [$e]);
185 185
             }
186 186
     }
187 187
 
188
-    public function insertInstitutionClassSubjects($subjects,$class){
189
-        if(!empty($subjects)){
190
-            try{
191
-                array_walk($subjects,array($this,'insertClassSubjects'),$class);
192
-                $this->output->writeln('updating subjects '. $class->name);
193
-            }catch (\Exception $e){
194
-                 Log::error($e->getMessage(),[$e]);
188
+    public function insertInstitutionClassSubjects($subjects, $class) {
189
+        if (!empty($subjects)) {
190
+            try {
191
+                array_walk($subjects, array($this, 'insertClassSubjects'), $class);
192
+                $this->output->writeln('updating subjects '.$class->name);
193
+            }catch (\Exception $e) {
194
+                 Log::error($e->getMessage(), [$e]);
195 195
             }
196 196
         };
197 197
     }
198 198
 
199
-    public function insertClassSubjects($subject,$count,$newClassId){
200
-        try{
199
+    public function insertClassSubjects($subject, $count, $newClassId) {
200
+        try {
201 201
             $subjectobj['status'] = 1;
202 202
             $subjectobj['created_user_id'] = 1;
203 203
             $subjectobj['created'] = now();
@@ -205,11 +205,11 @@  discard block
 block discarded – undo
205 205
             $subjectobj['institution_class_id'] = $newClassId->id;
206 206
             $subjectobj['institution_subject_id'] = $subject['id'];
207 207
 
208
-            if(!$this->institution_class_subjects->isDuplicated($subjectobj)){
208
+            if (!$this->institution_class_subjects->isDuplicated($subjectobj)) {
209 209
                 $this->institution_class_subjects->create($subjectobj);
210 210
             }
211
-        }catch (\Exception $e){
212
-             Log::error($e->getMessage(),[$e]);
211
+        }catch (\Exception $e) {
212
+             Log::error($e->getMessage(), [$e]);
213 213
         }
214 214
     }
215 215
 
@@ -221,15 +221,15 @@  discard block
 block discarded – undo
221 221
      * @param $academicPeriod
222 222
      * @return array
223 223
      */
224
-    public function generateNewClass($classes,$shiftId,$academicPeriod){
224
+    public function generateNewClass($classes, $shiftId, $academicPeriod) {
225 225
         $newClasses = [];
226
-        foreach ( $classes as $class) {
226
+        foreach ($classes as $class) {
227 227
             $noOfStudents = $class['no_of_students'] == 0 ? 40 : $class['no_of_students'];
228 228
             $class['academic_period_id'] = $academicPeriod;
229 229
             $class['no_of_students'] = $noOfStudents;
230 230
             $class['created'] = now();
231 231
             $class['institution_shift_id'] = $shiftId;
232
-            array_push($newClasses,$class);
232
+            array_push($newClasses, $class);
233 233
         }
234 234
         return $newClasses;
235 235
     }
@@ -240,11 +240,11 @@  discard block
 block discarded – undo
240 240
      * @param $shift
241 241
      * @return mixed
242 242
      */
243
-    public function updateShifts($year,$shift){
243
+    public function updateShifts($year, $shift) {
244 244
         $academicPeriod = $this->academic_period->getAcademicPeriod($year);
245
-        $this->shifts->where('id',$shift['id'])->update(['cloned' => '2020']);
245
+        $this->shifts->where('id', $shift['id'])->update(['cloned' => '2020']);
246 246
         $shift['academic_period_id'] = $academicPeriod->id;
247 247
         $exist = $this->shifts->shiftExists($shift);
248
-        return $this->shifts->create((array)$shift)->id;
248
+        return $this->shifts->create((array) $shift)->id;
249 249
     }
250 250
 }
Please login to merge, or discard this patch.
Braces   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -112,12 +112,12 @@  discard block
 block discarded – undo
112 112
                     $this->output->writeln('##########################################################################################################################');
113 113
                     $this->output->writeln('updating from '. $shiftId);
114 114
 
115
-                }catch (\Exception $e){
115
+                } catch (\Exception $e){
116 116
                      Log::error($e->getMessage(),[$e]);
117 117
                 }
118 118
             }
119 119
 //            DB::commit();
120
-        }catch (\Exception $e){
120
+        } catch (\Exception $e){
121 121
 //            DB::rollBack();
122 122
              Log::error($e->getMessage(),[$e]);
123 123
         }
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
            unset($subjects['total_female_students']);
138 138
            unset($subjects['id']);
139 139
            $classSubject = Institution_subject::create($subjects);
140
-       }catch (\Exception $e){
140
+       } catch (\Exception $e){
141 141
             Log::error($e->getMessage(),[$e]);
142 142
        }
143 143
     }
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
                 $params['class'] = $class;
181 181
                 $this->insertInstitutionClassSubjects($institutionSubjects,$class);
182 182
 //                array_walk($classSubjects,array($this,'insertInstitutionClassSubjects'),$params);
183
-            }catch (\Exception $e){
183
+            } catch (\Exception $e){
184 184
                  Log::error($e->getMessage(),[$e]);
185 185
             }
186 186
     }
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
             try{
191 191
                 array_walk($subjects,array($this,'insertClassSubjects'),$class);
192 192
                 $this->output->writeln('updating subjects '. $class->name);
193
-            }catch (\Exception $e){
193
+            } catch (\Exception $e){
194 194
                  Log::error($e->getMessage(),[$e]);
195 195
             }
196 196
         };
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
             if(!$this->institution_class_subjects->isDuplicated($subjectobj)){
209 209
                 $this->institution_class_subjects->create($subjectobj);
210 210
             }
211
-        }catch (\Exception $e){
211
+        } catch (\Exception $e){
212 212
              Log::error($e->getMessage(),[$e]);
213 213
         }
214 214
     }
Please login to merge, or discard this patch.
app/Console/Commands/ImportStudents.php 3 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -286,8 +286,8 @@  discard block
 block discarded – undo
286 286
 
287 287
 
288 288
     protected function getSheetCount($file){
289
-       $objPHPExcel = $this->setReader($file);
290
-       return $objPHPExcel->getSheetCount();
289
+        $objPHPExcel = $this->setReader($file);
290
+        return $objPHPExcel->getSheetCount();
291 291
     }
292 292
 
293 293
 
@@ -298,8 +298,8 @@  discard block
 block discarded – undo
298 298
      * @param $column
299 299
      */
300 300
     protected function import($file, $sheet, $column){
301
-             try {
302
-                 ini_set('memory_limit', '2048M');
301
+                try {
302
+                    ini_set('memory_limit', '2048M');
303 303
                 $this->getFileSize($file);
304 304
                 $user = User::find($file['security_user_id']);
305 305
                 $excelFile = '/sis-bulk-data-files/' . $file['filename'];
@@ -360,23 +360,23 @@  discard block
 block discarded – undo
360 360
                         break;
361 361
                 }
362 362
             }catch (\Maatwebsite\Excel\Validators\ValidationException $e) {
363
-                 $this->output->writeln( $e->getMessage());
364
-                 if($sheet == 1){
365
-                     self::writeErrors($e,$file,'Insert Students');
366
-                     DB::table('uploads')
367
-                         ->where('id', $file['id'])
368
-                         ->update(['insert' => 2,'updated_at' => now()]);
363
+                    $this->output->writeln( $e->getMessage());
364
+                    if($sheet == 1){
365
+                        self::writeErrors($e,$file,'Insert Students');
366
+                        DB::table('uploads')
367
+                            ->where('id', $file['id'])
368
+                            ->update(['insert' => 2,'updated_at' => now()]);
369 369
                     $this->processFailedEmail($file,$user,'Fresh Student Data Upload:Failed');
370
-                 }else if($sheet == 2){
371
-                     self::writeErrors($e,$file,'Update Students');
372
-                     DB::table('uploads')
373
-                         ->where('id', $file['id'])
374
-                         ->update(['update' => 2,'updated_at' => now()]);
370
+                    }else if($sheet == 2){
371
+                        self::writeErrors($e,$file,'Update Students');
372
+                        DB::table('uploads')
373
+                            ->where('id', $file['id'])
374
+                            ->update(['update' => 2,'updated_at' => now()]);
375 375
                     $this->processFailedEmail($file,$user, 'Existing Student Data Update:Failed');
376
-                 }
377
-                 DB::table('uploads')
378
-                     ->where('id',  $file['id'])
379
-                     ->update(['is_processed' =>2 , 'updated_at' => now()]);
376
+                    }
377
+                    DB::table('uploads')
378
+                        ->where('id',  $file['id'])
379
+                        ->update(['is_processed' =>2 , 'updated_at' => now()]);
380 380
 
381 381
             }
382 382
 
Please login to merge, or discard this patch.
Spacing   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
      */
48 48
     public function __construct()
49 49
     {
50
-        $this->output =  new \Symfony\Component\Console\Output\ConsoleOutput();
50
+        $this->output = new \Symfony\Component\Console\Output\ConsoleOutput();
51 51
         parent::__construct();
52 52
     }
53 53
 
@@ -62,64 +62,64 @@  discard block
 block discarded – undo
62 62
 //        if(empty($files)){
63 63
 //            $files = $this->getTerminatedFiles();
64 64
 //        }
65
-        while ($this->checkTime()){
66
-            if($this->checkTime()){
65
+        while ($this->checkTime()) {
66
+            if ($this->checkTime()) {
67 67
                 try {
68
-                    if(!empty($files)){
68
+                    if (!empty($files)) {
69 69
                         $this->process($files);
70 70
                         unset($files);
71 71
                         exit();
72 72
 
73
-                    }else{
73
+                    }else {
74 74
                         $output = new \Symfony\Component\Console\Output\ConsoleOutput();
75 75
                         $this->output->writeln('No files found,Waiting for files');
76 76
                         exit();
77 77
 
78 78
                     }
79 79
 
80
-                }catch (Exception $e){
80
+                }catch (Exception $e) {
81 81
                     $output = new \Symfony\Component\Console\Output\ConsoleOutput();
82 82
                     $this->output->writeln($e);
83 83
                     sleep(300);
84 84
                     $this->handle();
85 85
 
86 86
                 }
87
-            }else{
87
+            }else {
88 88
                 exit();
89 89
             }
90 90
         }
91 91
     }
92 92
 
93 93
 
94
-    protected function  process($files){
94
+    protected function  process($files) {
95 95
         $time = Carbon::now()->tz('Asia/Colombo');
96 96
 //        array_walk($files, array($this,'processSheet'));
97 97
         $node = $this->argument('node');
98 98
         $files[0]['node'] = $node;
99 99
         $this->processSheet($files[0]);
100 100
         $now = Carbon::now()->tz('Asia/Colombo');
101
-        $this->output->writeln('=============== Time taken to batch ' .$now->diffInMinutes($time));
101
+        $this->output->writeln('=============== Time taken to batch '.$now->diffInMinutes($time));
102 102
 
103 103
     }
104 104
 
105
-    protected function getTerminatedFiles(){
105
+    protected function getTerminatedFiles() {
106 106
         $files = Upload::where('is_processed', '=', 3)
107 107
             ->where('updated_at', '<=', Carbon::now()->tz('Asia/Colombo')->subHours(3))
108 108
             ->limit(1)
109
-            ->orderBy('updated_at','desc')
109
+            ->orderBy('updated_at', 'desc')
110 110
             ->get()->toArray();
111
-        if(!empty($files)){
111
+        if (!empty($files)) {
112 112
             $this->output->writeln('******************* Processing a terminated file **********************');
113 113
             DB::beginTransaction();
114 114
             DB::table('uploads')
115 115
                 ->where('id', $files[0]['id'])
116
-                ->update(['is_processed' => 4,'updated_at' => now()]);
116
+                ->update(['is_processed' => 4, 'updated_at' => now()]);
117 117
             DB::commit();
118 118
         }
119 119
         return $files;
120 120
     }
121 121
 
122
-    protected function getFiles(){
122
+    protected function getFiles() {
123 123
         $files = Upload::where('is_processed', '=', 0)
124 124
             ->select('uploads.id', 'uploads.security_user_id', 'uploads.institution_class_id', 'uploads.model',
125 125
                 'uploads.filename', 'uploads.is_processed', 'uploads.deleted_at', 'uploads.created_at',
@@ -133,85 +133,85 @@  discard block
 block discarded – undo
133 133
             ->limit(1)
134 134
             ->get()->toArray();
135 135
         $node = $this->argument('node');
136
-        if(!empty($files)){
136
+        if (!empty($files)) {
137 137
             DB::beginTransaction();
138 138
             DB::table('uploads')
139 139
                 ->where('id', $files[0]['id'])
140
-                ->update(['is_processed' => 3,'updated_at' => now(),'node' => $node]);
140
+                ->update(['is_processed' => 3, 'updated_at' => now(), 'node' => $node]);
141 141
             DB::commit();
142 142
         }
143 143
         return $files;
144 144
     }
145 145
 
146
-    protected function checkTime(){
146
+    protected function checkTime() {
147 147
         $time = Carbon::now()->tz('Asia/Colombo');
148
-        $morning = Carbon::create($time->year, $time->month, $time->day, env('CRON_START_TIME',0), 29, 0)->tz('Asia/Colombo')->setHour(0); //set time to 05:59
148
+        $morning = Carbon::create($time->year, $time->month, $time->day, env('CRON_START_TIME', 0), 29, 0)->tz('Asia/Colombo')->setHour(0); //set time to 05:59
149 149
 
150
-        $evening = Carbon::create($time->year, $time->month, $time->day, env('CRON_END_TIME',0), 30, 0)->tz('Asia/Colombo')->setHour(23); //set time to 18:00
150
+        $evening = Carbon::create($time->year, $time->month, $time->day, env('CRON_END_TIME', 0), 30, 0)->tz('Asia/Colombo')->setHour(23); //set time to 18:00
151 151
 
152
-        $check = $time->between($morning,$evening, true);
152
+        $check = $time->between($morning, $evening, true);
153 153
         return true;
154 154
     }
155 155
 
156
-    public function processSuccessEmail($file,$user,$subject) {
156
+    public function processSuccessEmail($file, $user, $subject) {
157 157
         $file['subject'] = $subject;
158 158
         $this->output->writeln('Processing the file: '.$file['filename']);
159 159
         try {
160 160
             Mail::to($user->email)->send(new StudentImportSuccess($file));
161 161
             DB::table('uploads')
162 162
                     ->where('id', $file['id'])
163
-                    ->update(['is_processed' => 1, 'is_email_sent' => 1,'updated_at' => now()]);
164
-        } catch (\Exception $ex) {
165
-            $this->output->writeln( $ex->getMessage());
163
+                    ->update(['is_processed' => 1, 'is_email_sent' => 1, 'updated_at' => now()]);
164
+        }catch (\Exception $ex) {
165
+            $this->output->writeln($ex->getMessage());
166 166
             DB::table('uploads')
167 167
                     ->where('id', $file['id'])
168
-                    ->update(['is_processed' => 1, 'is_email_sent' => 2,'updated_at' => now()]);
168
+                    ->update(['is_processed' => 1, 'is_email_sent' => 2, 'updated_at' => now()]);
169 169
         }
170 170
     }
171 171
 
172
-    public function processFailedEmail($file,$user,$subject) {
172
+    public function processFailedEmail($file, $user, $subject) {
173 173
         $file['subject'] = $subject;
174 174
         try {
175 175
             Mail::to($user->email)->send(new StudentImportFailure($file));
176 176
             DB::table('uploads')
177 177
                     ->where('id', $file['id'])
178
-                    ->update(['is_processed' => 2, 'is_email_sent' => 1,'updated_at' => now()]);
179
-        } catch (\Exception $ex) {
180
-            $this->output->writeln( $ex->getMessage());
178
+                    ->update(['is_processed' => 2, 'is_email_sent' => 1, 'updated_at' => now()]);
179
+        }catch (\Exception $ex) {
180
+            $this->output->writeln($ex->getMessage());
181 181
             DB::table('uploads')
182 182
                     ->where('id', $file['id'])
183
-                    ->update(['is_processed' => 2, 'is_email_sent' => 2,'updated_at' => now()]);
183
+                    ->update(['is_processed' => 2, 'is_email_sent' => 2, 'updated_at' => now()]);
184 184
         }
185 185
     }
186 186
 
187
-    public function processEmptyEmail($file,$user,$subject) {
187
+    public function processEmptyEmail($file, $user, $subject) {
188 188
         $file['subject'] = $subject;
189 189
         try {
190 190
             Mail::to($user->email)->send(new EmptyFile($file));
191 191
             DB::table('uploads')
192 192
                 ->where('id', $file['id'])
193
-                ->update(['is_processed' => 2, 'is_email_sent' => 1,'updated_at' => now()]);
194
-        } catch (\Exception $ex) {
195
-            $this->output->writeln( $ex->getMessage());
193
+                ->update(['is_processed' => 2, 'is_email_sent' => 1, 'updated_at' => now()]);
194
+        }catch (\Exception $ex) {
195
+            $this->output->writeln($ex->getMessage());
196 196
             DB::table('uploads')
197 197
                 ->where('id', $file['id'])
198
-                ->update(['is_processed' => 2, 'is_email_sent' => 2,'updated_at' => now()]);
198
+                ->update(['is_processed' => 2, 'is_email_sent' => 2, 'updated_at' => now()]);
199 199
         }
200 200
     }
201 201
 
202
-    protected function checkNode($file){
202
+    protected function checkNode($file) {
203 203
         $node = $this->argument('node');
204
-        if($node == $file['node']){
204
+        if ($node == $file['node']) {
205 205
             $output = new \Symfony\Component\Console\Output\ConsoleOutput();
206
-            $this->output->writeln('Processing from:' . $node);
206
+            $this->output->writeln('Processing from:'.$node);
207 207
             return true;
208
-        }else{
208
+        }else {
209 209
             exit;
210 210
             return false;
211 211
         }
212 212
     }
213 213
 
214
-    protected function processSheet($file){
214
+    protected function processSheet($file) {
215 215
         $this->startTime = Carbon::now()->tz('Asia/Colombo');
216 216
         $user = User::find($file['security_user_id']);
217 217
         $this->checkNode($file);
@@ -219,39 +219,39 @@  discard block
 block discarded – undo
219 219
         $this->output->writeln('Processing the file: '.$file['filename']);
220 220
         if ($this->checkTime()) {
221 221
             try {
222
-                $this->import($file,1,'C');
222
+                $this->import($file, 1, 'C');
223 223
                 sleep(10);
224
-                $this->import($file,2,'B');
224
+                $this->import($file, 2, 'B');
225 225
 
226
-            } catch (\Maatwebsite\Excel\Validators\ValidationException $e) {
227
-                $this->output->writeln( $e->getMessage());
226
+            }catch (\Maatwebsite\Excel\Validators\ValidationException $e) {
227
+                $this->output->writeln($e->getMessage());
228 228
                 try {
229 229
                     Mail::to($user->email)->send(new IncorrectTemplate($file));
230 230
                     DB::table('uploads')
231 231
                             ->where('id', $file['id'])
232
-                            ->update(['is_processed' => 2, 'is_email_sent' => 1,'updated_at' => now()]);
233
-                } catch (\Exception $ex) {
234
-                    $this->output->writeln( $e->getMessage());
232
+                            ->update(['is_processed' => 2, 'is_email_sent' => 1, 'updated_at' => now()]);
233
+                }catch (\Exception $ex) {
234
+                    $this->output->writeln($e->getMessage());
235 235
                     $this->handle();
236 236
                     DB::table('uploads')
237 237
                             ->where('id', $file['id'])
238
-                            ->update(['is_processed' => 2, 'is_email_sent' => 2 ,'updated_at' => now()]);
238
+                            ->update(['is_processed' => 2, 'is_email_sent' => 2, 'updated_at' => now()]);
239 239
                 }
240 240
             }
241
-        } else {
241
+        }else {
242 242
             exit();
243 243
         }
244 244
     }
245 245
 
246
-    protected function getType($file){
247
-        $file =  storage_path() . '/app/sis-bulk-data-files/'.$file;
248
-        $inputFileType =  \PhpOffice\PhpSpreadsheet\IOFactory::identify($file);
246
+    protected function getType($file) {
247
+        $file = storage_path().'/app/sis-bulk-data-files/'.$file;
248
+        $inputFileType = \PhpOffice\PhpSpreadsheet\IOFactory::identify($file);
249 249
         return $inputFileType;
250 250
     }
251 251
 
252 252
 
253
-    protected function getSheetWriter($file,$reader){
254
-        switch ($this->getType($file['filename'])){
253
+    protected function getSheetWriter($file, $reader) {
254
+        switch ($this->getType($file['filename'])) {
255 255
             case 'Xlsx':
256 256
                 return new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($reader);
257 257
                 break;
@@ -267,8 +267,8 @@  discard block
 block discarded – undo
267 267
         }
268 268
     }
269 269
 
270
-    protected function getSheetType($file){
271
-        switch ($this->getType($file)){
270
+    protected function getSheetType($file) {
271
+        switch ($this->getType($file)) {
272 272
             case 'Xlsx':
273 273
                 return \Maatwebsite\Excel\Excel::XLSX;
274 274
                 break;
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
     }
286 286
 
287 287
 
288
-    protected function getSheetCount($file){
288
+    protected function getSheetCount($file) {
289 289
        $objPHPExcel = $this->setReader($file);
290 290
        return $objPHPExcel->getSheetCount();
291 291
     }
@@ -297,205 +297,205 @@  discard block
 block discarded – undo
297 297
      * @param $sheet
298 298
      * @param $column
299 299
      */
300
-    protected function import($file, $sheet, $column){
300
+    protected function import($file, $sheet, $column) {
301 301
              try {
302 302
                  ini_set('memory_limit', '2048M');
303 303
                 $this->getFileSize($file);
304 304
                 $user = User::find($file['security_user_id']);
305
-                $excelFile = '/sis-bulk-data-files/' . $file['filename'];
306
-                $this->higestRow = $this->getHigestRow($file, $sheet,$column);
307
-                switch ($sheet){
305
+                $excelFile = '/sis-bulk-data-files/'.$file['filename'];
306
+                $this->higestRow = $this->getHigestRow($file, $sheet, $column);
307
+                switch ($sheet) {
308 308
                     case 1;
309
-                        $this->output->writeln( 'Trying to insert Students');
310
-                        if (($this->getSheetName($file,'Insert Students')) && $this->higestRow > 0)  { //
309
+                        $this->output->writeln('Trying to insert Students');
310
+                        if (($this->getSheetName($file, 'Insert Students')) && $this->higestRow > 0) { //
311 311
                             $import = new UsersImport($file);
312
-                            $import->import($excelFile,'local',$this->getSheetType($file['filename']));
312
+                            $import->import($excelFile, 'local', $this->getSheetType($file['filename']));
313 313
 //                            Excel::import($import, $excelFile, 'local');
314 314
                             DB::table('uploads')
315 315
                                 ->where('id', $file['id'])
316
-                                ->update(['insert' => 1,'is_processed' => 1,'updated_at' => now()]);
317
-                            if($import->failures()->count() > 0){
318
-                                self::writeErrors($import,$file,'Insert Students');
316
+                                ->update(['insert' => 1, 'is_processed' => 1, 'updated_at' => now()]);
317
+                            if ($import->failures()->count() > 0) {
318
+                                self::writeErrors($import, $file, 'Insert Students');
319 319
                                 DB::table('uploads')
320 320
                                     ->where('id', $file['id'])
321
-                                    ->update(['insert' => 3,'updated_at' => now()]);
322
-                                $this->processFailedEmail($file,$user,'Fresh Student Data Upload:Partial Success ');
323
-                                $this->stdOut('Insert Students',$this->higestRow);
324
-                            }else{
325
-                                $this->processSuccessEmail($file,$user,'Fresh Student Data Upload:Success ');
326
-                                $this->stdOut('Insert Students',$this->higestRow);
321
+                                    ->update(['insert' => 3, 'updated_at' => now()]);
322
+                                $this->processFailedEmail($file, $user, 'Fresh Student Data Upload:Partial Success ');
323
+                                $this->stdOut('Insert Students', $this->higestRow);
324
+                            }else {
325
+                                $this->processSuccessEmail($file, $user, 'Fresh Student Data Upload:Success ');
326
+                                $this->stdOut('Insert Students', $this->higestRow);
327 327
                             }
328
-                        }else if(($this->getSheetName($file,'Insert Students')) && $this->higestRow > 0) {
328
+                        }else if (($this->getSheetName($file, 'Insert Students')) && $this->higestRow > 0) {
329 329
                             DB::table('uploads')
330 330
                                 ->where('id', $file['id'])
331 331
                                 ->update(['is_processed' => 2]);
332
-                            $this->processEmptyEmail($file,$user, 'Fresh Student Data Upload ');
332
+                            $this->processEmptyEmail($file, $user, 'Fresh Student Data Upload ');
333 333
                         }
334 334
                         break;
335 335
                     case 2;
336
-                        $this->output->writeln( 'Trying to update Students');
337
-                        if (($this->getSheetName($file,'Update Students')) && $this->higestRow > 0) {
336
+                        $this->output->writeln('Trying to update Students');
337
+                        if (($this->getSheetName($file, 'Update Students')) && $this->higestRow > 0) {
338 338
                             $import = new StudentUpdate($file);
339
-                            $import->import($excelFile,'local',$this->getSheetType($file['filename']));
339
+                            $import->import($excelFile, 'local', $this->getSheetType($file['filename']));
340 340
                             DB::table('uploads')
341 341
                                 ->where('id', $file['id'])
342
-                                ->update(['update' => 1,'is_processed' => 1,'updated_at' => now()]);
343
-                            if($import->failures()->count() > 0){
344
-                                self::writeErrors($import,$file,'Update Students');
342
+                                ->update(['update' => 1, 'is_processed' => 1, 'updated_at' => now()]);
343
+                            if ($import->failures()->count() > 0) {
344
+                                self::writeErrors($import, $file, 'Update Students');
345 345
                                 DB::table('uploads')
346 346
                                     ->where('id', $file['id'])
347
-                                    ->update(['update' => 3,'is_processed' => 1,'updated_at' => now()]);
348
-                                $this->processFailedEmail($file,$user,'Existing Student Data Update:Partial Success ');
349
-                                $this->stdOut('Update Students',$this->higestRow);
350
-                            }else{
351
-                                $this->processSuccessEmail($file,$user, 'Existing Student Data Update:Success ');
352
-                                $this->stdOut('Update Students',$this->higestRow);
347
+                                    ->update(['update' => 3, 'is_processed' => 1, 'updated_at' => now()]);
348
+                                $this->processFailedEmail($file, $user, 'Existing Student Data Update:Partial Success ');
349
+                                $this->stdOut('Update Students', $this->higestRow);
350
+                            }else {
351
+                                $this->processSuccessEmail($file, $user, 'Existing Student Data Update:Success ');
352
+                                $this->stdOut('Update Students', $this->higestRow);
353 353
                             }
354
-                        }else if(($this->getSheetName($file,'Update Students')) && $this->higestRow == 0) {
354
+                        }else if (($this->getSheetName($file, 'Update Students')) && $this->higestRow == 0) {
355 355
                             DB::table('uploads')
356 356
                                 ->where('id', $file['id'])
357
-                                ->update(['is_processed' => 2,'updated_at' => now()]);
358
-                            $this->processEmptyEmail($file,$user, 'Existing Student Data Update');
357
+                                ->update(['is_processed' => 2, 'updated_at' => now()]);
358
+                            $this->processEmptyEmail($file, $user, 'Existing Student Data Update');
359 359
                         }
360 360
                         break;
361 361
                 }
362 362
             }catch (\Maatwebsite\Excel\Validators\ValidationException $e) {
363
-                 $this->output->writeln( $e->getMessage());
364
-                 if($sheet == 1){
365
-                     self::writeErrors($e,$file,'Insert Students');
363
+                 $this->output->writeln($e->getMessage());
364
+                 if ($sheet == 1) {
365
+                     self::writeErrors($e, $file, 'Insert Students');
366 366
                      DB::table('uploads')
367 367
                          ->where('id', $file['id'])
368
-                         ->update(['insert' => 2,'updated_at' => now()]);
369
-                    $this->processFailedEmail($file,$user,'Fresh Student Data Upload:Failed');
370
-                 }else if($sheet == 2){
371
-                     self::writeErrors($e,$file,'Update Students');
368
+                         ->update(['insert' => 2, 'updated_at' => now()]);
369
+                    $this->processFailedEmail($file, $user, 'Fresh Student Data Upload:Failed');
370
+                 }else if ($sheet == 2) {
371
+                     self::writeErrors($e, $file, 'Update Students');
372 372
                      DB::table('uploads')
373 373
                          ->where('id', $file['id'])
374
-                         ->update(['update' => 2,'updated_at' => now()]);
375
-                    $this->processFailedEmail($file,$user, 'Existing Student Data Update:Failed');
374
+                         ->update(['update' => 2, 'updated_at' => now()]);
375
+                    $this->processFailedEmail($file, $user, 'Existing Student Data Update:Failed');
376 376
                  }
377 377
                  DB::table('uploads')
378
-                     ->where('id',  $file['id'])
379
-                     ->update(['is_processed' =>2 , 'updated_at' => now()]);
378
+                     ->where('id', $file['id'])
379
+                     ->update(['is_processed' =>2, 'updated_at' => now()]);
380 380
 
381 381
             }
382 382
 
383 383
     }
384 384
 
385
-    protected function processErrors($failure){
386
-            $error_mesg = implode(',',$failure->errors());
385
+    protected function processErrors($failure) {
386
+            $error_mesg = implode(',', $failure->errors());
387 387
             $failure = [
388 388
                 'row'=> $failure->row(),
389
-                'errors' => [ $error_mesg],
389
+                'errors' => [$error_mesg],
390 390
                 'attribute' => $failure->attribute()
391 391
             ];
392 392
             return $failure;
393 393
 
394 394
     }
395 395
 
396
-    protected function  getFileSize($file){
397
-        $excelFile =  '/sis-bulk-data-files/' . $file['filename'];
396
+    protected function  getFileSize($file) {
397
+        $excelFile = '/sis-bulk-data-files/'.$file['filename'];
398 398
         $size = Storage::disk('local')->size($excelFile);
399 399
         $user = User::find($file['security_user_id']);
400
-        if( $size > 0){
400
+        if ($size > 0) {
401 401
             return true;
402
-        }else{
402
+        }else {
403 403
             DB::table('uploads')
404
-                ->where('id',  $file['id'])
405
-                ->update(['is_processed' =>2 , 'updated_at' => now()]);
406
-            $this->stdOut('No valid data found :Please re-upload the file',0);
407
-            $this->processEmptyEmail($file,$user, 'No valid data found :Please re-upload the file');
404
+                ->where('id', $file['id'])
405
+                ->update(['is_processed' =>2, 'updated_at' => now()]);
406
+            $this->stdOut('No valid data found :Please re-upload the file', 0);
407
+            $this->processEmptyEmail($file, $user, 'No valid data found :Please re-upload the file');
408 408
         }
409 409
     }
410 410
 
411
-    protected function setReader($file){
412
-        try{
413
-            $excelFile =  '/sis-bulk-data-files/processed/' . $file['filename'];
411
+    protected function setReader($file) {
412
+        try {
413
+            $excelFile = '/sis-bulk-data-files/processed/'.$file['filename'];
414 414
             $exists = Storage::disk('local')->exists($excelFile);
415
-            if(!$exists){
415
+            if (!$exists) {
416 416
 
417
-                $excelFile =  "/sis-bulk-data-files/" . $file['filename'];
417
+                $excelFile = "/sis-bulk-data-files/".$file['filename'];
418 418
             }
419
-            $excelFile = storage_path()."/app" . $excelFile;
419
+            $excelFile = storage_path()."/app".$excelFile;
420 420
             $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($this->getType($file['filename']));
421
-            $objPHPExcel =  $reader->load($excelFile);
421
+            $objPHPExcel = $reader->load($excelFile);
422 422
             return $objPHPExcel;
423
-        }catch (Exception $e){
424
-            $this->output->writeln( $e->getMessage());
423
+        }catch (Exception $e) {
424
+            $this->output->writeln($e->getMessage());
425 425
             $user = User::find($file['security_user_id']);
426 426
             DB::table('uploads')
427
-                ->where('id',  $file['id'])
428
-                ->update(['is_processed' =>2 , 'updated_at' => now()]);
429
-            $this->stdOut('No valid data found :Please re-upload the file',0);
430
-            $this->processEmptyEmail($file,$user, 'No valid data found :Please re-upload the file');
427
+                ->where('id', $file['id'])
428
+                ->update(['is_processed' =>2, 'updated_at' => now()]);
429
+            $this->stdOut('No valid data found :Please re-upload the file', 0);
430
+            $this->processEmptyEmail($file, $user, 'No valid data found :Please re-upload the file');
431 431
         }
432 432
     }
433 433
 
434
-    protected function  getSheetName($file,$sheet){
435
-        try{;
434
+    protected function  getSheetName($file, $sheet) {
435
+        try {;
436 436
             $objPHPExcel = $this->setReader($file);
437
-            return $objPHPExcel->getSheetByName($sheet)  !== null;
438
-        }catch (Exception $e){
439
-            $this->output->writeln( $e->getMessage());
437
+            return $objPHPExcel->getSheetByName($sheet) !== null;
438
+        }catch (Exception $e) {
439
+            $this->output->writeln($e->getMessage());
440 440
             $user = User::find($file['security_user_id']);
441 441
             DB::table('uploads')
442
-                ->where('id',  $file['id'])
443
-                ->update(['is_processed' =>2 , 'updated_at' => now()]);
444
-            $this->stdOut('No valid data found :Please re-upload the file',0);
445
-            $this->processEmptyEmail($file,$user, 'No valid data found :Please re-upload the file');
442
+                ->where('id', $file['id'])
443
+                ->update(['is_processed' =>2, 'updated_at' => now()]);
444
+            $this->stdOut('No valid data found :Please re-upload the file', 0);
445
+            $this->processEmptyEmail($file, $user, 'No valid data found :Please re-upload the file');
446 446
         }
447 447
     }
448 448
 
449
-    protected function getHigestRow($file,$sheet,$column){
450
-        try{
449
+    protected function getHigestRow($file, $sheet, $column) {
450
+        try {
451 451
             $reader = $this->setReader($file);
452 452
             $reader->setActiveSheetIndex($sheet);
453 453
             $higestRow = 0;
454
-            $highestRow =  $reader->getActiveSheet()->getHighestRow($column);
454
+            $highestRow = $reader->getActiveSheet()->getHighestRow($column);
455 455
             for ($row = 3; $row <= $highestRow; $row++) {
456 456
                 $rowData = $reader->getActiveSheet()->getCell($column.$row)->getValue();
457 457
                 if (empty($rowData) || $rowData == null) {
458 458
                     continue;
459
-                } else {
459
+                }else {
460 460
                     $higestRow += 1;
461 461
                 }
462 462
             }
463 463
             return $higestRow;
464
-        }catch(\Exception $e){
465
-            $this->output->writeln( $e->getMessage());
464
+        }catch (\Exception $e) {
465
+            $this->output->writeln($e->getMessage());
466 466
             $user = User::find($file['security_user_id']);
467 467
             DB::beginTransaction();
468 468
             DB::table('uploads')
469 469
                 ->where('id', $file['id'])
470
-                ->update(['is_processed' => 2,'updated_at' => now()]);
470
+                ->update(['is_processed' => 2, 'updated_at' => now()]);
471 471
             DB::commit();
472
-            $this->processEmptyEmail($file,$user, 'No valid data found');
472
+            $this->processEmptyEmail($file, $user, 'No valid data found');
473 473
             exit();
474 474
         }
475 475
     }
476 476
 
477
-    protected function stdOut($title,$rows){
478
-        $this->output->writeln(   $title. ' Process completed at . '.' '. now());
477
+    protected function stdOut($title, $rows) {
478
+        $this->output->writeln($title.' Process completed at . '.' '.now());
479 479
         $now = Carbon::now()->tz('Asia/Colombo');
480
-        $this->output->writeln('Total Processed lines: ' . $rows);
481
-        $this->output->writeln( 'Time taken to process           : '.   $now->diffInSeconds($this->startTime) .' Seconds');
480
+        $this->output->writeln('Total Processed lines: '.$rows);
481
+        $this->output->writeln('Time taken to process           : '.$now->diffInSeconds($this->startTime).' Seconds');
482 482
         $this->output->writeln('--------------------------------------------------------------------------------------------------------------------------');
483 483
     }
484 484
 
485 485
 
486 486
 
487
-    protected function removeRows($row,$count,$params){
487
+    protected function removeRows($row, $count, $params) {
488 488
         $reader = $params['reader'];
489 489
         $sheet = $reader->getActiveSheet();
490
-        if(!in_array($row,$params['rows'])){
490
+        if (!in_array($row, $params['rows'])) {
491 491
             $output = new \Symfony\Component\Console\Output\ConsoleOutput();
492
-            $this->output->writeln(    ' removing row . '.' '. $row);
492
+            $this->output->writeln(' removing row . '.' '.$row);
493 493
             $reader->getActiveSheet()->getCellCollection()->removeRow($row);
494 494
         }
495 495
     }
496 496
 
497 497
 
498
-    protected function writeErrors($e,$file,$sheet){
498
+    protected function writeErrors($e, $file, $sheet) {
499 499
         try {
500 500
             ini_set('memory_limit', '2048M');
501 501
             $baseMemory = memory_get_usage();
@@ -510,39 +510,39 @@  discard block
 block discarded – undo
510 510
             $reader = $this->setReader($file);
511 511
             $reader->setActiveSheetIndexByName($sheet);
512 512
 
513
-            $failures = gettype($failures) == 'object' ? array_map(array($this,'processErrors'),iterator_to_array($failures)) : array_map(array($this,'processErrors'),($failures));
514
-            if(count($failures) > 0){
515
-                $rows = array_map('rows',$failures);
513
+            $failures = gettype($failures) == 'object' ? array_map(array($this, 'processErrors'), iterator_to_array($failures)) : array_map(array($this, 'processErrors'), ($failures));
514
+            if (count($failures) > 0) {
515
+                $rows = array_map('rows', $failures);
516 516
                 $rows = array_unique($rows);
517
-                $rowIndex =   range(3,$this->higestRow+2);
517
+                $rowIndex = range(3, $this->higestRow + 2);
518 518
                 $params = [
519 519
                     'rows' =>$rows,
520 520
                     'reader' => $reader
521 521
                 ];
522
-                array_walk($failures , 'append_errors_to_excel',$reader);
523
-                array_walk($rowIndex , array($this,'removeRows'),$params);
524
-                $objWriter = $this->getSheetWriter($file,$reader);
522
+                array_walk($failures, 'append_errors_to_excel', $reader);
523
+                array_walk($rowIndex, array($this, 'removeRows'), $params);
524
+                $objWriter = $this->getSheetWriter($file, $reader);
525 525
                 Storage::disk('local')->makeDirectory('sis-bulk-data-files/processed');
526
-                $objWriter->save(storage_path() . '/app/sis-bulk-data-files/processed/' . $file['filename']);
526
+                $objWriter->save(storage_path().'/app/sis-bulk-data-files/processed/'.$file['filename']);
527 527
                 $now = Carbon::now()->tz('Asia/Colombo');
528
-                $this->output->writeln(  $reader->getActiveSheet()->getTitle() . ' Process completed at . '.' '. now());
528
+                $this->output->writeln($reader->getActiveSheet()->getTitle().' Process completed at . '.' '.now());
529 529
                 $this->output->writeln('memory usage for the processes : '.(memory_get_usage() - $baseMemory));
530
-                $this->output->writeln( 'Time taken to process           : '.   $now->diffInSeconds($this->startTime) .' Seconds');
530
+                $this->output->writeln('Time taken to process           : '.$now->diffInSeconds($this->startTime).' Seconds');
531 531
                 $this->output->writeln(' errors reported               : '.count($failures));
532 532
                 $this->output->writeln('--------------------------------------------------------------------------------------------------------------------------');
533 533
                 unset($objWriter);
534 534
                 unset($failures);
535 535
             }
536 536
 
537
-        }catch (Eception $e){
538
-            $this->output->writeln( $e->getMessage());
537
+        }catch (Eception $e) {
538
+            $this->output->writeln($e->getMessage());
539 539
             $user = User::find($file['security_user_id']);
540 540
             DB::beginTransaction();
541 541
             DB::table('uploads')
542 542
                 ->where('id', $file['id'])
543
-                ->update(['is_processed' => 2,'updated_at' => now()]);
543
+                ->update(['is_processed' => 2, 'updated_at' => now()]);
544 544
             DB::commit();
545
-            $this->processEmptyEmail($file,$user, 'No valid data found');
545
+            $this->processEmptyEmail($file, $user, 'No valid data found');
546 546
             exit();
547 547
         }
548 548
     }
Please login to merge, or discard this patch.
Braces   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -70,21 +70,21 @@  discard block
 block discarded – undo
70 70
                         unset($files);
71 71
                         exit();
72 72
 
73
-                    }else{
73
+                    } else{
74 74
                         $output = new \Symfony\Component\Console\Output\ConsoleOutput();
75 75
                         $this->output->writeln('No files found,Waiting for files');
76 76
                         exit();
77 77
 
78 78
                     }
79 79
 
80
-                }catch (Exception $e){
80
+                } catch (Exception $e){
81 81
                     $output = new \Symfony\Component\Console\Output\ConsoleOutput();
82 82
                     $this->output->writeln($e);
83 83
                     sleep(300);
84 84
                     $this->handle();
85 85
 
86 86
                 }
87
-            }else{
87
+            } else{
88 88
                 exit();
89 89
             }
90 90
         }
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
             $output = new \Symfony\Component\Console\Output\ConsoleOutput();
206 206
             $this->output->writeln('Processing from:' . $node);
207 207
             return true;
208
-        }else{
208
+        } else{
209 209
             exit;
210 210
             return false;
211 211
         }
@@ -321,11 +321,11 @@  discard block
 block discarded – undo
321 321
                                     ->update(['insert' => 3,'updated_at' => now()]);
322 322
                                 $this->processFailedEmail($file,$user,'Fresh Student Data Upload:Partial Success ');
323 323
                                 $this->stdOut('Insert Students',$this->higestRow);
324
-                            }else{
324
+                            } else{
325 325
                                 $this->processSuccessEmail($file,$user,'Fresh Student Data Upload:Success ');
326 326
                                 $this->stdOut('Insert Students',$this->higestRow);
327 327
                             }
328
-                        }else if(($this->getSheetName($file,'Insert Students')) && $this->higestRow > 0) {
328
+                        } else if(($this->getSheetName($file,'Insert Students')) && $this->higestRow > 0) {
329 329
                             DB::table('uploads')
330 330
                                 ->where('id', $file['id'])
331 331
                                 ->update(['is_processed' => 2]);
@@ -347,11 +347,11 @@  discard block
 block discarded – undo
347 347
                                     ->update(['update' => 3,'is_processed' => 1,'updated_at' => now()]);
348 348
                                 $this->processFailedEmail($file,$user,'Existing Student Data Update:Partial Success ');
349 349
                                 $this->stdOut('Update Students',$this->higestRow);
350
-                            }else{
350
+                            } else{
351 351
                                 $this->processSuccessEmail($file,$user, 'Existing Student Data Update:Success ');
352 352
                                 $this->stdOut('Update Students',$this->higestRow);
353 353
                             }
354
-                        }else if(($this->getSheetName($file,'Update Students')) && $this->higestRow == 0) {
354
+                        } else if(($this->getSheetName($file,'Update Students')) && $this->higestRow == 0) {
355 355
                             DB::table('uploads')
356 356
                                 ->where('id', $file['id'])
357 357
                                 ->update(['is_processed' => 2,'updated_at' => now()]);
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
                         }
360 360
                         break;
361 361
                 }
362
-            }catch (\Maatwebsite\Excel\Validators\ValidationException $e) {
362
+            } catch (\Maatwebsite\Excel\Validators\ValidationException $e) {
363 363
                  $this->output->writeln( $e->getMessage());
364 364
                  if($sheet == 1){
365 365
                      self::writeErrors($e,$file,'Insert Students');
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
                          ->where('id', $file['id'])
368 368
                          ->update(['insert' => 2,'updated_at' => now()]);
369 369
                     $this->processFailedEmail($file,$user,'Fresh Student Data Upload:Failed');
370
-                 }else if($sheet == 2){
370
+                 } else if($sheet == 2){
371 371
                      self::writeErrors($e,$file,'Update Students');
372 372
                      DB::table('uploads')
373 373
                          ->where('id', $file['id'])
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
         $user = User::find($file['security_user_id']);
400 400
         if( $size > 0){
401 401
             return true;
402
-        }else{
402
+        } else{
403 403
             DB::table('uploads')
404 404
                 ->where('id',  $file['id'])
405 405
                 ->update(['is_processed' =>2 , 'updated_at' => now()]);
@@ -420,7 +420,7 @@  discard block
 block discarded – undo
420 420
             $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($this->getType($file['filename']));
421 421
             $objPHPExcel =  $reader->load($excelFile);
422 422
             return $objPHPExcel;
423
-        }catch (Exception $e){
423
+        } catch (Exception $e){
424 424
             $this->output->writeln( $e->getMessage());
425 425
             $user = User::find($file['security_user_id']);
426 426
             DB::table('uploads')
@@ -435,7 +435,7 @@  discard block
 block discarded – undo
435 435
         try{;
436 436
             $objPHPExcel = $this->setReader($file);
437 437
             return $objPHPExcel->getSheetByName($sheet)  !== null;
438
-        }catch (Exception $e){
438
+        } catch (Exception $e){
439 439
             $this->output->writeln( $e->getMessage());
440 440
             $user = User::find($file['security_user_id']);
441 441
             DB::table('uploads')
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
                 }
462 462
             }
463 463
             return $higestRow;
464
-        }catch(\Exception $e){
464
+        } catch(\Exception $e){
465 465
             $this->output->writeln( $e->getMessage());
466 466
             $user = User::find($file['security_user_id']);
467 467
             DB::beginTransaction();
@@ -534,7 +534,7 @@  discard block
 block discarded – undo
534 534
                 unset($failures);
535 535
             }
536 536
 
537
-        }catch (Eception $e){
537
+        } catch (Eception $e){
538 538
             $this->output->writeln( $e->getMessage());
539 539
             $user = User::find($file['security_user_id']);
540 540
             DB::beginTransaction();
Please login to merge, or discard this patch.