@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | use Maatwebsite\Excel\Concerns\WithMultipleSheets; |
56 | 56 | use Maatwebsite\Excel\Concerns\RegistersEventListeners; |
57 | 57 | |
58 | -class StudentUpdate extends Import implements ToModel, WithStartRow, WithHeadingRow, WithMultipleSheets, WithEvents, WithMapping, WithLimit, WithBatchInserts, WithValidation , SkipsOnFailure , SkipsOnError{ |
|
58 | +class StudentUpdate extends Import implements ToModel, WithStartRow, WithHeadingRow, WithMultipleSheets, WithEvents, WithMapping, WithLimit, WithBatchInserts, WithValidation, SkipsOnFailure, SkipsOnError{ |
|
59 | 59 | |
60 | 60 | use Importable, |
61 | 61 | RegistersEventListeners, |
@@ -89,30 +89,30 @@ discard block |
||
89 | 89 | $institution = $institutionClass->institution_id; |
90 | 90 | if (!empty($institutionClass)) { |
91 | 91 | $this->setGender($row); |
92 | - $studentInfo = Security_user::createOrUpdateStudentProfile($row,'update',$this->file); |
|
92 | + $studentInfo = Security_user::createOrUpdateStudentProfile($row, 'update', $this->file); |
|
93 | 93 | $student = Institution_class_student::where('student_id', '=', $studentInfo->id)->first(); |
94 | - if(!empty($row['admission_no'])){ |
|
95 | - Institution_student::where('student_id','=',$studentInfo->id) |
|
96 | - ->where('institution_id','=', $institution) |
|
94 | + if (!empty($row['admission_no'])) { |
|
95 | + Institution_student::where('student_id', '=', $studentInfo->id) |
|
96 | + ->where('institution_id', '=', $institution) |
|
97 | 97 | ->update(['admission_id'=> $row['admission_no']]); |
98 | 98 | } |
99 | - User_special_need::createOrUpdate($studentInfo->id,$row,$this->file); |
|
100 | - User_body_mass::createOrUpdate($studentInfo->id,$row,$this->file); |
|
99 | + User_special_need::createOrUpdate($studentInfo->id, $row, $this->file); |
|
100 | + User_body_mass::createOrUpdate($studentInfo->id, $row, $this->file); |
|
101 | 101 | |
102 | - $this->createOrUpdateGuardian($row,$student,'father'); |
|
103 | - $this->createOrUpdateGuardian($row,$student,'mother'); |
|
104 | - $this->createOrUpdateGuardian($row,$student,'guardian'); |
|
102 | + $this->createOrUpdateGuardian($row, $student, 'father'); |
|
103 | + $this->createOrUpdateGuardian($row, $student, 'mother'); |
|
104 | + $this->createOrUpdateGuardian($row, $student, 'guardian'); |
|
105 | 105 | |
106 | 106 | $studentInfo['student_id'] = $studentInfo->id; |
107 | 107 | Institution_student::updateStudentArea($studentInfo->toArray()); |
108 | - $this->insertOrUpdateSubjects($row,$student,$institution); |
|
108 | + $this->insertOrUpdateSubjects($row, $student, $institution); |
|
109 | 109 | $totalStudents = Institution_class_student::getStudentsCount($this->file['institution_class_id']); |
110 | 110 | Institution_class::where('id', '=', $institutionClass->id) |
111 | 111 | ->update([ |
112 | 112 | 'total_male_students' => $totalStudents['total_male_students'], |
113 | 113 | 'total_female_students' => $totalStudents['total_female_students']]); |
114 | 114 | } |
115 | - } catch (\Maatwebsite\Excel\Validators\ValidationException $e) { |
|
115 | + }catch (\Maatwebsite\Excel\Validators\ValidationException $e) { |
|
116 | 116 | $error = \Illuminate\Validation\ValidationException::withMessages([]); |
117 | 117 | $failures = $e->failures(); |
118 | 118 | throw new \Maatwebsite\Excel\Validators\ValidationException($error, $failures); |
@@ -1,22 +1,22 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -function get_l_name($name){ |
|
3 | +function get_l_name($name) { |
|
4 | 4 | $name = trim($name); |
5 | - $last_name = (strpos($name,' ') === false) ? '' : preg_replace('#.*\s([\w-]*)$#', '$1', $name); |
|
5 | + $last_name = (strpos($name, ' ') === false) ? '' : preg_replace('#.*\s([\w-]*)$#', '$1', $name); |
|
6 | 6 | return $last_name; |
7 | 7 | } |
8 | 8 | |
9 | 9 | // Gen name with initials with help of fullname |
10 | -function genNameWithInitials($fullname = null){ |
|
10 | +function genNameWithInitials($fullname = null) { |
|
11 | 11 | $names = explode(' ', $fullname); |
12 | - $length = count($names); |
|
12 | + $length = count($names); |
|
13 | 13 | $Initials = ''; |
14 | - if($length > 1){ |
|
15 | - for ($i = 0; ($length-1) > $i; $i++) { |
|
16 | - $Initials = $Initials . '' . mb_substr($names[$i], 0, 1, "UTF-8"); |
|
14 | + if ($length > 1) { |
|
15 | + for ($i = 0; ($length - 1) > $i; $i++) { |
|
16 | + $Initials = $Initials.''.mb_substr($names[$i], 0, 1, "UTF-8"); |
|
17 | 17 | } |
18 | - $nameWithInitials = $Initials . ' ' . $names[$length - 1]; |
|
19 | - }else{ |
|
18 | + $nameWithInitials = $Initials.' '.$names[$length - 1]; |
|
19 | + }else { |
|
20 | 20 | $nameWithInitials = $fullname; |
21 | 21 | } |
22 | 22 | return $nameWithInitials; |
@@ -35,10 +35,10 @@ discard block |
||
35 | 35 | } |
36 | 36 | |
37 | 37 | |
38 | -function getMatchingKeys($array){ |
|
38 | +function getMatchingKeys($array) { |
|
39 | 39 | $keys = []; |
40 | - foreach ($array as $key => $value){ |
|
41 | - if(strstr($key , 'option')) |
|
40 | + foreach ($array as $key => $value) { |
|
41 | + if (strstr($key, 'option')) |
|
42 | 42 | $keys[] = $key; |
43 | 43 | } |
44 | 44 | return $keys; |
@@ -48,12 +48,12 @@ discard block |
||
48 | 48 | return (bool) preg_match('/^[0-9a-f]{40}$/i', $str); |
49 | 49 | } |
50 | 50 | |
51 | -function isEmpty($value){ |
|
51 | +function isEmpty($value) { |
|
52 | 52 | return $value['institution_optional_subject'] !== null; |
53 | 53 | } |
54 | 54 | |
55 | 55 | function isEmptyRow($row) { |
56 | - foreach($row as $cell){ |
|
56 | + foreach ($row as $cell) { |
|
57 | 57 | if (null !== $cell) return false; |
58 | 58 | } |
59 | 59 | return true; |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | $i = 0; |
65 | 65 | $key_array = array(); |
66 | 66 | |
67 | - foreach($array as $val) { |
|
67 | + foreach ($array as $val) { |
|
68 | 68 | if (!in_array($val[$key], $key_array)) { |
69 | 69 | $key_array[$i] = $val[$key]; |
70 | 70 | $temp_array[$i] = $val; |
@@ -76,10 +76,10 @@ discard block |
||
76 | 76 | |
77 | 77 | |
78 | 78 | |
79 | -function merge_two_arrays($array1,$array2) { |
|
79 | +function merge_two_arrays($array1, $array2) { |
|
80 | 80 | |
81 | 81 | $data = array(); |
82 | - $arrayAB = array_merge($array1,$array2); |
|
82 | + $arrayAB = array_merge($array1, $array2); |
|
83 | 83 | |
84 | 84 | foreach ($arrayAB as $value) { |
85 | 85 | dd($arrayAB); |
@@ -87,25 +87,25 @@ discard block |
||
87 | 87 | if (!isset($data[$id])) { |
88 | 88 | $data[$id] = array(); |
89 | 89 | } |
90 | - $data[$id] = array_merge($data[$id],$value); |
|
90 | + $data[$id] = array_merge($data[$id], $value); |
|
91 | 91 | } |
92 | 92 | return $data; |
93 | 93 | } |
94 | 94 | |
95 | -function array_value_recursive($key, array $arr){ |
|
95 | +function array_value_recursive($key, array $arr) { |
|
96 | 96 | $val = array(); |
97 | 97 | array_walk_recursive($arr, function($v, $k) use($key, &$val){ |
98 | - if($k == $key) array_push($val, $v); |
|
98 | + if ($k == $key) array_push($val, $v); |
|
99 | 99 | }); |
100 | 100 | return count($val) > 1 ? $val : array_pop($val); |
101 | 101 | } |
102 | 102 | |
103 | 103 | |
104 | -function merge_error_by_row($errors,$key){ |
|
104 | +function merge_error_by_row($errors, $key) { |
|
105 | 105 | $temp_array = array(); |
106 | 106 | $i = 0; |
107 | 107 | |
108 | - foreach($errors as $keys => $val) { |
|
108 | + foreach ($errors as $keys => $val) { |
|
109 | 109 | if (!in_array($val[$key], $temp_array)) { |
110 | 110 | $temp_array[$keys]['errors'][] = $val; |
111 | 111 | } |
@@ -121,17 +121,17 @@ discard block |
||
121 | 121 | * bind error messages to the excel file |
122 | 122 | */ |
123 | 123 | |
124 | -function append_errors_to_excel($error, $count, $reader){ |
|
124 | +function append_errors_to_excel($error, $count, $reader) { |
|
125 | 125 | $active_sheet = $reader->getActiveSheet(); |
126 | 126 | $prev_value = $active_sheet->getCell('A'.$error['row'])->getValue(); |
127 | - $active_sheet->setCellValue('A'. ($error['row']) , $prev_value.','.implode(',',$error['errors'])); |
|
128 | - $active_sheet->getStyle('A'. ($error['row']))->getAlignment()->setWrapText(true); |
|
127 | + $active_sheet->setCellValue('A'.($error['row']), $prev_value.','.implode(',', $error['errors'])); |
|
128 | + $active_sheet->getStyle('A'.($error['row']))->getAlignment()->setWrapText(true); |
|
129 | 129 | $columns = Illuminate\Support\Facades\Config::get('excel.columns'); |
130 | 130 | |
131 | - $column = array_keys($columns,$error['attribute']); |
|
132 | - if(!empty($column)){ |
|
133 | - $column = $column[0]+1; |
|
134 | - $selectedCells = $active_sheet->setSelectedCellByColumnAndRow($column,$error['row']); |
|
131 | + $column = array_keys($columns, $error['attribute']); |
|
132 | + if (!empty($column)) { |
|
133 | + $column = $column[0] + 1; |
|
134 | + $selectedCells = $active_sheet->setSelectedCellByColumnAndRow($column, $error['row']); |
|
135 | 135 | $active_cell = ($selectedCells->getActiveCell()); |
136 | 136 | |
137 | 137 | $active_sheet->getStyle($active_cell) |
@@ -143,23 +143,23 @@ discard block |
||
143 | 143 | } |
144 | 144 | } |
145 | 145 | |
146 | -function rows($error){ |
|
146 | +function rows($error) { |
|
147 | 147 | return $error['row']; |
148 | 148 | } |
149 | 149 | |
150 | -function rowIndex($row){ |
|
150 | +function rowIndex($row) { |
|
151 | 151 | return $row->getRowIndex(); |
152 | 152 | } |
153 | 153 | |
154 | -function removeRows($row,$param){ |
|
155 | - if(in_array($row,$param['rows'])){ |
|
154 | +function removeRows($row, $param) { |
|
155 | + if (in_array($row, $param['rows'])) { |
|
156 | 156 | $param['reader']->getActiveSheet()->removeRow($row); |
157 | 157 | } |
158 | 158 | } |
159 | 159 | |
160 | -function colorizeCell($column,$error,$active_sheet){ |
|
161 | - $column = array_keys($column,$error['attribute']); |
|
162 | - $selectedCells = $active_sheet->setSelectedCellByColumnAndRow($column,$error['row']); |
|
160 | +function colorizeCell($column, $error, $active_sheet) { |
|
161 | + $column = array_keys($column, $error['attribute']); |
|
162 | + $selectedCells = $active_sheet->setSelectedCellByColumnAndRow($column, $error['row']); |
|
163 | 163 | $active_cell = ($selectedCells->getActiveCell()); |
164 | 164 | |
165 | 165 | $active_sheet->getStyle($active_cell) |
@@ -171,45 +171,45 @@ discard block |
||
171 | 171 | } |
172 | 172 | |
173 | 173 | |
174 | -function errors_unique_array($item,$key){ |
|
174 | +function errors_unique_array($item, $key) { |
|
175 | 175 | |
176 | - $search = array_filter($item,function ($data) use ($item){ |
|
177 | - return isset($data['row']) && ($data['row'] == $item->row()); |
|
176 | + $search = array_filter($item, function($data) use ($item){ |
|
177 | + return isset($data['row']) && ($data['row'] == $item->row()); |
|
178 | 178 | }); |
179 | 179 | |
180 | - if($search){ |
|
181 | - array_push($search[0]['errors'],implode(',',$item->errors())); |
|
180 | + if ($search) { |
|
181 | + array_push($search[0]['errors'], implode(',', $item->errors())); |
|
182 | 182 | $errors = $search; |
183 | 183 | } |
184 | 184 | |
185 | 185 | return $errors; |
186 | 186 | } |
187 | 187 | |
188 | -function sig_handler($signo){ |
|
188 | +function sig_handler($signo) { |
|
189 | 189 | global $child; |
190 | - switch($signo){ |
|
190 | + switch ($signo) { |
|
191 | 191 | case 'SIFCLD': |
192 | 192 | } |
193 | 193 | |
194 | 194 | } |
195 | -function processParallel($func ,array $arr, $procs = 4,$params =[]) |
|
195 | +function processParallel($func, array $arr, $procs = 4, $params = []) |
|
196 | 196 | { |
197 | 197 | // Break array up into $procs chunks. |
198 | - $chunks = array_chunk($arr, ceil((count($arr) / $procs))); |
|
198 | + $chunks = array_chunk($arr, ceil((count($arr)/$procs))); |
|
199 | 199 | $pid = -1; |
200 | 200 | $children = array(); |
201 | 201 | foreach ($chunks as $items) { |
202 | 202 | $pid = pcntl_fork(); |
203 | 203 | if ($pid === -1) { |
204 | 204 | die('could not fork'); |
205 | - } else if ($pid === 0) { |
|
205 | + }else if ($pid === 0) { |
|
206 | 206 | // We are the child process. Pass a chunk of items to process. |
207 | - echo('['.getmypid().']This Process executed at'.date("F d, Y h:i:s A")."\n") ; |
|
208 | - array_walk($items, $func,$params); |
|
207 | + echo('['.getmypid().']This Process executed at'.date("F d, Y h:i:s A")."\n"); |
|
208 | + array_walk($items, $func, $params); |
|
209 | 209 | exit(0); |
210 | - } else { |
|
210 | + }else { |
|
211 | 211 | // We are the parent. |
212 | - echo('['.getmypid().']This Process executed at'.date("F d, Y h:i:s A")."\n") ; |
|
212 | + echo('['.getmypid().']This Process executed at'.date("F d, Y h:i:s A")."\n"); |
|
213 | 213 | $children[] = $pid; |
214 | 214 | } |
215 | 215 | } |