Test Setup Failed
Pull Request — master (#266)
by Mohamed
07:49
created
app/Mail/StudentImportSuccess.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@
 block discarded – undo
45 45
     public function build()
46 46
     {
47 47
         return $this->view('emails.mail')
48
-                ->from($this->from_address,$this->from_name)
48
+                ->from($this->from_address, $this->from_name)
49 49
                 ->to($this->user->email)
50 50
             ->subject($this->subject)
51 51
             ->with($this->with);
Please login to merge, or discard this patch.
app/Providers/ValidatorExtended.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -100,58 +100,58 @@
 block discarded – undo
100 100
     protected function validateBirthPlace($attribute, $value, $perameters, $validator) {
101 101
         foreach ($validator->getData() as $data) {
102 102
             if ($data['identity_type'] == 'BC' && key_exists('birth_divisional_secretariat', $data)) {
103
-                $BirthDivision = Area_administrative::where('name', '=',  '%'.$data['birth_divisional_secretariat'].'%')->where('area_administrative_level_id', '=', 5); //
104
-                if ($BirthDivision->count() > 0 ) {
105
-                    $BirthArea = Area_administrative::where('name', '=', '%'. $value.'%') //$data['birth_registrar_office_as_in_birth_certificate']
103
+                $BirthDivision = Area_administrative::where('name', '=', '%'.$data['birth_divisional_secretariat'].'%')->where('area_administrative_level_id', '=', 5); //
104
+                if ($BirthDivision->count() > 0) {
105
+                    $BirthArea = Area_administrative::where('name', '=', '%'.$value.'%') //$data['birth_registrar_office_as_in_birth_certificate']
106 106
                                     ->where('parent_id', '=', $BirthDivision->first()->id)->count();
107
-                    return $BirthArea  > 0;
107
+                    return $BirthArea > 0;
108 108
                 } elseif (key_exists('birth_divisional_secretariat', $data) && (!key_exists('birth_registrar_office_as_in_birth_certificate', $data))) {
109 109
                     $this->_custom_messages['birth_place'] = 'birth_registrar_office_as_in_birth_certificate required with BC';
110 110
                     $this->_set_custom_stuff();
111 111
                     return false;
112
-                } else {
112
+                }else {
113 113
                     return true;
114 114
                 }
115
-            } else {
115
+            }else {
116 116
                 return true;
117 117
             }
118 118
         }
119 119
     }
120 120
 
121 121
     protected function validateIsStudentInClass($attribute, $value, $perameters, $validator) {
122
-        $student =  Security_user::where('openemis_no', '=', $value);
123
-        if($student->count() > 0){
122
+        $student = Security_user::where('openemis_no', '=', $value);
123
+        if ($student->count() > 0) {
124 124
             $student = $student->first()->toArray();
125
-            $check =  Institution_class_student::where('student_id', '=', $student['id'])->where('institution_class_id','=',$perameters[0])->count();
126
-            if($check == 1){
125
+            $check = Institution_class_student::where('student_id', '=', $student['id'])->where('institution_class_id', '=', $perameters[0])->count();
126
+            if ($check == 1) {
127 127
                 return true;
128
-            } else{
128
+            }else {
129 129
                 return false;
130 130
             }
131
-        } else{
131
+        }else {
132 132
             return false;
133 133
         }
134 134
 
135 135
     }
136
-    protected function validateNic($attribute, $value, $perameters, $validator){
136
+    protected function validateNic($attribute, $value, $perameters, $validator) {
137 137
         $valid = preg_match('/^([0-9]{9}[VX]|[0-9]{12})$/i', $value);
138
-        if(!$valid){
139
-                $this->_custom_messages['nic'] = $attribute. ' is not valid,  Please check the NIC number';
138
+        if (!$valid) {
139
+                $this->_custom_messages['nic'] = $attribute.' is not valid,  Please check the NIC number';
140 140
                 $this->_set_custom_stuff();
141 141
                 return false;
142
-        }else{
142
+        }else {
143 143
             return true;
144 144
         }
145 145
     }
146 146
 
147 147
     protected function validateUserUnique($attribute, $value, $perameters, $validator) {
148 148
         foreach ($validator->getData() as $data) {
149
-            $identityType = Identity_type::where('national_code', 'like', '%' . $data['identity_type'] . '%')->first();
149
+            $identityType = Identity_type::where('national_code', 'like', '%'.$data['identity_type'].'%')->first();
150 150
             if ($identityType !== null && ($value !== null)) {
151 151
                 if ($identityType->national_code === 'BC') {
152
-                    return $this->checkUnique($value, $data,$identityType);
152
+                    return $this->checkUnique($value, $data, $identityType);
153 153
                 } elseif ($identityType->national_code === 'NIC') {
154
-                    return $this->checkUnique($value, $data,$identityType);
154
+                    return $this->checkUnique($value, $data, $identityType);
155 155
                 }
156 156
             } elseif (($value == null) || $value == "") {
157 157
                 return true;
Please login to merge, or discard this patch.
app/Providers/AppServiceProvider.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@
 block discarded – undo
28 28
         public function boot()
29 29
         {
30 30
             //
31
-            if((\App::environment('dev')) |  (\App::environment('stage')) | (\App::environment('prod'))) {
31
+            if ((\App::environment('dev')) | (\App::environment('stage')) | (\App::environment('prod'))) {
32 32
                 URL::forceScheme('https');
33 33
             }
34 34
         }
Please login to merge, or discard this patch.
app/Providers/ValidationExtensionServiceProvider.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -10,10 +10,10 @@
 block discarded – undo
10 10
     public function register() {}
11 11
 
12 12
     public function boot() {
13
-        $this->app->validator->resolver( function( $translator, $data, $rules,
14
-                                                    $messages = array(), $customAttributes = array() ) {
15
-            return new ValidatorExtended( $translator, $data, $rules, $messages,
16
-                $customAttributes );
13
+        $this->app->validator->resolver(function($translator, $data, $rules,
14
+                                                    $messages = array(), $customAttributes = array()) {
15
+            return new ValidatorExtended($translator, $data, $rules, $messages,
16
+                $customAttributes);
17 17
         } );
18 18
     }
19 19
 }
Please login to merge, or discard this patch.
app/Console/Commands/RunAddApprovedStudents.php 1 patch
Spacing   +17 added lines, -17 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);
Please login to merge, or discard this patch.
app/Console/Commands/CloneConfigData.php 1 patch
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -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
 
Please login to merge, or discard this patch.
app/Console/Commands/ImportStudents.php 1 patch
Spacing   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -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();
Please login to merge, or discard this patch.
app/Console/Commands/PromoteStudents.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -204,19 +204,19 @@
 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
             }
Please login to merge, or discard this patch.
app/Models/Institution_subject_student.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -69,31 +69,31 @@
 block discarded – undo
69 69
      *
70 70
      *
71 71
      */
72
-    public static function  isDuplicated($inputs){
72
+    public static function  isDuplicated($inputs) {
73 73
 
74
-        $exists = self::where('student_id','=',$inputs['student_id'])
75
-            ->where('institution_subject_id','=',$inputs['institution_subject_id'])
76
-            ->where('education_subject_id','=',$inputs['education_subject_id'])->count();
74
+        $exists = self::where('student_id', '=', $inputs['student_id'])
75
+            ->where('institution_subject_id', '=', $inputs['institution_subject_id'])
76
+            ->where('education_subject_id', '=', $inputs['education_subject_id'])->count();
77 77
 
78 78
 
79 79
         return $exists ? true :false;
80 80
     }
81 81
 
82 82
     
83
-        public function student(){
84
-        return $this->belongsTo('App\Models\Security_user','student_id');
83
+        public function student() {
84
+        return $this->belongsTo('App\Models\Security_user', 'student_id');
85 85
     }
86 86
     
87
-    public static function getStudentsCount(){
87
+    public static function getStudentsCount() {
88 88
             $total_male_students = self::with(['student' => function($query) {
89 89
                         $query->where('student.gender_id', '=', 1);
90
-                    }])->whereHas('student', function ($query) {
90
+                    }])->whereHas('student', function($query) {
91 91
                     $query->where('gender_id', '=', 1);
92 92
                 })->where('institution_subject_id', '=', $institution_subject_id)->count();
93 93
 
94 94
         $total_female_students = self::with(['student' => function($query) {
95 95
                         $query->where('student.gender_id', '=', 2);
96
-                    }])->whereHas('student', function ($query) {
96
+                    }])->whereHas('student', function($query) {
97 97
                     $query->where('gender_id', '=', 2);
98 98
                 })->where('institution_subject_id', '=', $institution_subject_id)->count();
99 99
 
Please login to merge, or discard this patch.