Test Setup Failed
Push — master ( b3ebe3...77c0d5 )
by Mohamed
13:31 queued 07:23
created

StudentUpdate   D

Complexity

Total Complexity 59

Size/Duplication

Total Lines 410
Duplicated Lines 0 %

Importance

Changes 4
Bugs 4 Features 0
Metric Value
eloc 288
c 4
b 4
f 0
dl 0
loc 410
rs 4.08
wmc 59

6 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 46 1
A getStudentSubjects() 0 3 1
A insertSubject() 0 3 2
F model() 0 313 52
A sheets() 0 3 1
A registerEvents() 0 17 2

How to fix   Complexity   

Complex Class

Complex classes like StudentUpdate often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use StudentUpdate, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace App\Imports;
4
5
use App\Models\User;
6
use function foo\func;
7
use App\Models\Nationality;
8
use App\Rules\admissionAge;
9
use App\Models\User_contact;
10
use App\Models\Identity_type;
11
use App\Models\Security_user;
12
use App\Models\User_identity;
13
use App\Models\Import_mapping;
14
use App\Models\Security_group;
15
use App\Models\User_body_mass;
16
use App\Models\Academic_period;
17
use App\Models\Student_guardian;
18
use App\Models\User_nationality;
19
use App\Models\Institution_class;
20
use App\Models\User_special_need;
21
use App\Mail\StudentCountExceeded;
22
use App\Mail\StudentImportSuccess;
23
use Illuminate\Support\Facades\DB;
24
use App\Models\Area_administrative;
25
use App\Models\Institution_student;
26
use App\Models\Institution_subject;
27
use App\Models\Workflow_transition;
28
use Illuminate\Support\Facades\Log;
29
use Illuminate\Support\Facades\Mail;
30
use App\Models\Institution_class_grade;
31
use App\Models\Special_need_difficulty;
32
use Illuminate\Support\Facades\Request;
33
use Maatwebsite\Excel\Concerns\ToModel;
34
use App\Models\Education_grades_subject;
35
use App\Models\Institution_class_student;
36
use App\Models\Institution_class_subject;
37
use Illuminate\Support\Facades\Validator;
38
use Maatwebsite\Excel\Concerns\WithLimit;
39
use Maatwebsite\Excel\Events\BeforeSheet;
40
use Maatwebsite\Excel\Validators\Failure;
41
use Maatwebsite\Excel\Concerns\Importable;
42
use Maatwebsite\Excel\Concerns\WithEvents;
43
use Maatwebsite\Excel\Events\BeforeImport;
44
use App\Models\Institution_subject_student;
45
use Maatwebsite\Excel\Concerns\SkipsErrors;
46
use Maatwebsite\Excel\Concerns\WithMapping;
47
use Maatwebsite\Excel\Concerns\SkipsOnError;
48
use Maatwebsite\Excel\Concerns\WithStartRow;
49
use App\Models\Institution_student_admission;
50
use Maatwebsite\Excel\Concerns\SkipsFailures;
51
use Maatwebsite\Excel\Concerns\SkipsOnFailure;
52
use Maatwebsite\Excel\Concerns\WithHeadingRow;
53
use Maatwebsite\Excel\Concerns\WithValidation;
54
use Maatwebsite\Excel\Concerns\WithBatchInserts;
55
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
56
use Maatwebsite\Excel\Concerns\RegistersEventListeners;
57
58
class StudentUpdate extends Import implements  ToModel, WithStartRow, WithHeadingRow, WithMultipleSheets, WithEvents, WithMapping, WithLimit, WithBatchInserts, WithValidation , SkipsOnFailure , SkipsOnError{
59
60
    use Importable,
0 ignored issues
show
introduced by
The trait Maatwebsite\Excel\Concerns\Importable requires some properties which are not provided by App\Imports\StudentUpdate: $disk, $readerType, $filePath
Loading history...
61
        RegistersEventListeners,
62
        SkipsFailures,
63
        SkipsErrors;
64
65
66
    public function sheets(): array {
67
        return [
68
            'Update Students' => $this
69
        ];
70
    }
71
72
    public function registerEvents(): array {
73
        // TODO: Implement registerEvents() method.
74
        return [
75
            BeforeSheet::class => function(BeforeSheet $event) {
76
                $this->sheetNames[] = $event->getSheet()->getTitle();
0 ignored issues
show
Bug Best Practice introduced by
The property sheetNames does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
77
                $this->worksheet = $event->getSheet();
0 ignored issues
show
Bug Best Practice introduced by
The property worksheet does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
78
                $worksheet = $event->getSheet();
79
                $this->highestRow = $worksheet->getHighestDataRow('B');
0 ignored issues
show
Bug Best Practice introduced by
The property highestRow does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
80
            },
81
            BeforeImport::class => function (BeforeImport $event) {
82
                $event->getReader()->getDelegate()->setActiveSheetIndex(2);
83
                $this->highestRow = ($event->getReader()->getDelegate()->getActiveSheet()->getHighestDataRow('B'));
0 ignored issues
show
Bug Best Practice introduced by
The property highestRow does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
84
                if ($this->highestRow < 3) {
85
                    $error = \Illuminate\Validation\ValidationException::withMessages([]);
86
                    $failure = new Failure(3, 'remark', [0 => 'No enough rows!'], [null]);
87
                    $failures = [0 => $failure];
88
                    throw new \Maatwebsite\Excel\Validators\ValidationException($error, $failures);
89
                }
90
            }
91
        ];
92
    }
93
94
95
    public function model(array $row) {
96
97
        try {
98
            $institutionClass = Institution_class::find($this->file['institution_class_id']);
99
            $institution = $institutionClass->institution_id;
0 ignored issues
show
Bug introduced by
The property institution_id does not exist on App\Models\Institution_class. Did you mean institution?
Loading history...
100
101
102
            if (!array_filter($row)) {
103
                return nulll;
0 ignored issues
show
Bug introduced by
The constant App\Imports\nulll was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
104
            }
105
106
            if (!empty($institutionClass)) {
107
                $mandatorySubject = Institution_class_subject::getMandetorySubjects($this->file['institution_class_id']);
108
                $subjects = getMatchingKeys($row);
109
                $genderId = null;
110
                switch ($row['gender_mf']) {
111
                    case 'M':
112
                        $row['gender_mf'] = 1;
113
                        $this->maleStudentsCount += 1;
114
                        break;
115
                    case 'F':
116
                        $row['gender_mf'] = 2;
117
                        $this->femaleStudentsCount += 1;
118
                        break;
119
                }
120
121
                $BirthArea = Area_administrative::where('name', 'like', '%' . $row['birth_registrar_office_as_in_birth_certificate'] . '%')->first();
122
                $nationalityId = Nationality::where('name', 'like', '%' . $row['nationality'] . '%')->first();
123
                $identityType = Identity_type::where('national_code', 'like', '%' . $row['identity_type'] . '%')->first();
124
                $academicPeriod = Academic_period::where('name', '=', $row['academic_period'])->first();
125
126
127
                $date = $row['date_of_birth_yyyy_mm_dd'];
128
129
                $identityType = $identityType !== null ? $identityType->id : null;
130
                $nationalityId = $nationalityId !== null ? $nationalityId->id : null;
131
132
                $BirthArea = $BirthArea !== null ? $BirthArea->id : null;
133
                $identityNUmber = $row['identity_number'];
134
135
                //create students data
136
                \Log::debug('Security_user');
137
138
                $studentInfo = Security_user::where('openemis_no', '=', $row['student_id'])->first();
139
                Security_user::where('openemis_no', $studentInfo['openemis_no'])
140
                        ->update([
141
                            'first_name' => $row['full_name'] ? $row['full_name'] : $studentInfo['first_name'], // here we save full name in the column of first name. re reduce breaks of the system.
142
                            'last_name' => $row['full_name'] ? genNameWithInitials($row['full_name']) : genNameWithInitials($studentInfo['first_name']),
143
                            'gender_id' => $genderId ? $genderId : $studentInfo['gender_id'],
0 ignored issues
show
introduced by
$genderId is of type null, thus it always evaluated to false.
Loading history...
144
                            'date_of_birth' => $date ? $date : $studentInfo['date_of_birth'],
145
                            'address' => $row['address'] ? $row['address'] : $studentInfo['address'],
146
                            'birthplace_area_id' => $row['birth_registrar_office_as_in_birth_certificate'] ? $BirthArea : $studentInfo['birthplace_area_id'],
147
                            'nationality_id' => $row['nationality'] ? $nationalityId : $studentInfo['nationality_id'],
148
                            'identity_type_id' => $row['identity_type'] ? $identityType : $studentInfo['identity_type_id'],
149
                            'identity_number' => $row['identity_number'] ? $identityNUmber : $studentInfo['identity_number'],
150
                            'is_student' => 1,
151
                            'modified' => now(),
152
                            'modified_user_id' => $this->file['security_user_id']
153
                            ]);
154
155
                $student = Institution_class_student::where('student_id', '=', $studentInfo->id)->first();
156
157
                if(!empty($row['admission_no']) && !empty($academicPeriod)){
158
                    Institution_student::where('student_id','=',$studentInfo->id)
159
                    ->where('institution_id','=', $institution)
160
                    ->where('academic_period_id','=',$academicPeriod->id)
161
                    ->update(['admission_id'=> $row['admission_no']]);
162
                }
163
                
164
                if (!empty($row['special_need'])) {
165
166
                    $specialNeed = Special_need_difficulty::where('name', '=', $row['special_need'])->first();
167
                    $data = [
168
                        'special_need_date' => now(),
169
                        'security_user_id' => $student->student_id,
0 ignored issues
show
Bug introduced by
The property student_id does not exist on App\Models\Institution_class_student. Did you mean student?
Loading history...
170
                        'special_need_type_id' => 1,
171
                        'special_need_difficulty_id' => $specialNeed->id,
172
                        'created_user_id' => $this->file['security_user_id']
173
                    ];
174
175
                    $check = User_special_need::isDuplicated($data);
176
                    if ($check) {
177
                        User_special_need::create($data);
178
                    }
179
                }
180
181
182
183
                if (!empty($row['bmi_height']) && (!empty($row['bmi_weight']))) {
184
185
                    // convert Meeter to CM
186
                    $hight = $row['bmi_height'] / 100;
187
188
                    //calculate BMI
189
                    $bodyMass = ($row['bmi_weight']) / pow($hight, 2);
190
191
                    $bmiAcademic = Academic_period::where('name', '=', $row['bmi_academic_period'])->first();
192
                    $count = User_body_mass::where('academic_period_id' ,'=',$bmiAcademic->id )
193
                            ->where('security_user_id','=',$student->student_id)->count();
194
195
                    \Log::debug('User_body_mass');
196
                    if(!($count > 0)){
197
                        User_body_mass::create([
198
                            'height' => $row['bmi_height'],
199
                            'weight' => $row['bmi_weight'],
200
                            'date' => $row['bmi_date_yyyy_mm_dd'],
201
                            'body_mass_index' => $bodyMass,
202
                            'academic_period_id' => $bmiAcademic->id,
203
                            'security_user_id' => $student->student_id,
204
                            'created_user_id' => $this->file['security_user_id']
205
                        ]);
206
                    }
207
                }
208
209
                if (!empty($row['fathers_full_name']) && ($row['fathers_date_of_birth_yyyy_mm_dd'] !== null)) {
210
                    $AddressArea = Area_administrative::where('name', 'like', '%' . $row['fathers_address_area'] . '%')->first();
211
                    $nationalityId = Nationality::where('name', 'like', '%' . $row['fathers_nationality'] . '%')->first();
212
                    $identityType = Identity_type::where('national_code', 'like', '%' . $row['fathers_identity_type'] . '%')->first();
213
                    $openemisFather =  $this->uniqueUid::getUniqueAlphanumeric();
214
215
                    $identityType = ($identityType !== null) ? $identityType->id : null;
216
                    $nationalityId = $nationalityId !== null ? $nationalityId->id : null;
217
218
                    $father = null;
219
                    if (!empty($row['fathers_identity_number'])) {
220
                        $father = Security_user::where('identity_type_id', '=', $nationalityId)
221
                                        ->where('identity_number', '=', $row['fathers_identity_number'])->first();
222
                    }
223
224
225
                    if ($father === null) {
226
                        $data = [
227
                            'username' => str_replace('-','',$openemisFather),
228
                            'openemis_no' => $openemisFather,
229
                            'first_name' => $row['fathers_full_name'], // here we save full name in the column of first name. re reduce breaks of the system.
230
                            'last_name' => genNameWithInitials($row['fathers_full_name']),
231
                            'gender_id' => 1,
232
                            'date_of_birth' => $row['fathers_date_of_birth_yyyy_mm_dd'],
233
                            'address' => $row['fathers_address'],
234
                            'address_area_id' => $AddressArea->id,
235
                            'nationality_id' => $nationalityId,
236
                            'identity_type_id' => $identityType,
237
                            'identity_number' => $row['fathers_identity_number'],
238
                            'is_guardian' => 1,
239
                            'created_user_id' => $this->file['security_user_id']
240
                        ];
241
                        $father = Security_user::create($data);
242
                             
243
                        $father['guardian_relation_id'] = 1;
244
                        if (array_key_exists('fathers_phone', $row)) {
245
                            $father['contact'] = $row['fathers_phone'];
246
                            User_contact::createOrUpdate($father,$this->file['security_user_id']);
247
                        }
248
                        Student_guardian::createStudentGuardian($student, $father, $this->file['security_user_id']);
249
                    } else {
250
                        Security_user::where('id', '=', $father->id)
251
                                ->update(['is_guardian' => 1]);
252
                        $father['guardian_relation_id'] = 1;
253
                        if (array_key_exists('fathers_phone', $row)) {
254
                            $father['contact'] = $row['fathers_phone'];
255
                            User_contact::createOrUpdate($father,$this->file['security_user_id']);
256
                        }
257
                        Student_guardian::createStudentGuardian($student, $father, $this->file['security_user_id']);
258
                    }
259
                }
260
261
                if (!empty($row['mothers_full_name']) && ($row['mothers_date_of_birth_yyyy_mm_dd'] !== null)) {
262
                    $AddressArea = Area_administrative::where('name', 'like', '%' . $row['mothers_address_area'] . '%')->first();
263
                    $nationalityId = Nationality::where('name', 'like', '%' . $row['mothers_nationality'] . '%')->first();
264
                    $identityType = Identity_type::where('national_code', 'like', '%' . $row['mothers_identity_type'] . '%')->first();
265
                    $openemisMother = $this->uniqueUid::getUniqueAlphanumeric();
266
267
                    $identityType = $identityType !== null ? $identityType->id : null;
268
                    $nationalityId = $nationalityId !== null ? $nationalityId->id : null;
269
270
                    $mother = null;
271
272
                    if (!empty($row['mothers_identity_number'])) {
273
                        $mother = Security_user::where('identity_type_id', '=', $nationalityId)
274
                                        ->where('identity_number', '=', $row['mothers_identity_number'])->first();
275
                    }
276
277
                    if ($mother === null) {
278
                        $mother = Security_user::create([
279
                                    'username' => str_replace('-','',$openemisMother),
280
                                    'openemis_no' => $openemisMother,
281
                                    'first_name' => $row['mothers_full_name'], // here we save full name in the column of first name. re reduce breaks of the system.
282
                                    'last_name' => genNameWithInitials($row['mothers_full_name']),
283
                                    'gender_id' => 2,
284
                                    'date_of_birth' => $row['mothers_date_of_birth_yyyy_mm_dd'],
285
                                    'address' => $row['mothers_address'],
286
                                    'address_area_id' => $AddressArea->id,
287
                                    'nationality_id' => $nationalityId,
288
                                    'identity_type_id' => $identityType,
289
                                    'identity_number' => $row['mothers_identity_number'],
290
                                    'is_guardian' => 1,
291
                                    'created_user_id' => $this->file['security_user_id']
292
                        ]);
293
294
                        $mother['guardian_relation_id'] = 2;
295
                        if (array_key_exists('mothers_phone', $row)) {
296
                            $mother['contact'] = $row['mothers_phone'];
297
                            User_contact::createOrUpdate($mother,$this->file['security_user_id']);
298
                        }   
299
                        Student_guardian::createStudentGuardian($student, $mother, $this->file['security_user_id']);
300
                    } else {
301
                        Security_user::where('id', '=', $mother->id)
302
                                ->update(['is_guardian' => 1]);
303
                        $mother['guardian_relation_id'] = 2;
304
                        if (array_key_exists('mothers_phone', $row)) {
305
                            $mother['contact'] = $row['mothers_phone'];
306
                            User_contact::createOrUpdate($mother,$this->file['security_user_id']);
307
                        }
308
                        Student_guardian::createStudentGuardian($student, $mother, $this->file['security_user_id']);
309
                    }
310
                }
311
312
313
                if (!empty($row['guardians_full_name']) && ($row['guardians_date_of_birth_yyyy_mm_dd'] !== null)) {
314
                    $genderId = $row['guardians_gender_mf'] == 'M' ? 1 : 2;
315
                    $AddressArea = Area_administrative::where('name', 'like', '%' . $row['guardians_address_area'] . '%')->first();
316
                    $nationalityId = Nationality::where('name', 'like', '%' . $row['guardians_nationality'] . '%')->first();
317
                    $identityType = Identity_type::where('national_code', 'like', '%' . $row['guardians_identity_type'] . '%')->first();
318
                    $openemisGuardian = $this->uniqueUid::getUniqueAlphanumeric();
319
320
                    $identityType = $identityType !== null ? $identityType->id : null;
321
                    $nationalityId = $nationalityId !== null ? $nationalityId->id : null;
322
323
                    $guardian = null;
324
325
                    if (!empty($row['guardians_identity_number'])) {
326
                        $guardian = Security_user::where('identity_type_id', '=', $nationalityId)
327
                                        ->where('identity_number', '=', $row['guardians_identity_number'])->first();
328
                    }
329
330
                    if ($guardian === null) {
331
                        $guardian = Security_user::create([
332
                                    'username' => str_replace('-','',$openemisGuardian),
333
                                    'openemis_no' => $openemisGuardian,
334
                                    'first_name' => $row['guardians_full_name'], // here we save full name in the column of first name. re reduce breaks of the system.
335
                                    'last_name' => genNameWithInitials($row['guardians_full_name']),
336
                                    'gender_id' => $genderId,
337
                                    'date_of_birth' => $row['guardians_date_of_birth_yyyy_mm_dd'],
338
                                    'address' => $row['guardians_address'],
339
                                    'address_area_id' => $AddressArea->id,
340
//                            'birthplace_area_id' => $BirthArea->id,
341
                                    'nationality_id' => $nationalityId,
342
                                    'identity_type_id' => $identityType,
343
                                    'identity_number' => $row['guardians_identity_number'],
344
                                    'is_guardian' => 1,
345
                                    'created_user_id' => $this->file['security_user_id']
346
                        ]);
347
348
                        $guardian['guardian_relation_id'] = 3;
349
                        if (array_key_exists('guardians_phone', $row)) {
350
                            $guardian['contact'] = $row['guardians_phone'];
351
                            User_contact::createOrUpdate($guardian,$this->file['security_user_id']);
352
                        }  
353
                        Student_guardian::createStudentGuardian($student, $guardian, $this->file['security_user_id']);
354
                    } else {
355
                        Security_user::where('id', '=', $guardian->id)
356
                                ->update(['is_guardian' => 1]);
357
                        $guardian['guardian_relation_id'] = 3;
358
                        if (array_key_exists('guardians_phone', $row)) {
359
                            $guardian['contact'] = $row['guardians_phone'];
360
                            User_contact::createOrUpdate($guardian,$this->file['security_user_id']);
361
                        } 
362
                        Student_guardian::createStudentGuardian($student, $guardian, $this->file['security_user_id']);
363
                    }
364
                }
365
366
                $optionalSubjects =  Institution_class_subject::getStudentOptionalSubject($subjects, $student, $row, $institution);
367
368
                $allSubjects = array_merge_recursive($optionalSubjects, $mandatorySubject);
369
                // $stundetSubjects = $this->getStudentSubjects($student);
370
                // $allSubjects = array_merge_recursive($newSubjects, $stundetSubjects);
371
372
                if (!empty($allSubjects)) {
373
                    $allSubjects = unique_multidim_array($allSubjects, 'institution_subject_id');
374
                    $this->student = $student;
0 ignored issues
show
Bug Best Practice introduced by
The property student does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
375
                    $allSubjects = array_map(array($this,'setStudentSubjects'),$allSubjects);
376
                    // $allSubjects = array_unique($allSubjects,SORT_REGULAR);
377
                    $allSubjects = unique_multidim_array($allSubjects, 'education_subject_id');
378
                    array_walk($allSubjects,array($this,'insertSubject'));
379
                    // Institution_subject_student::insert((array) $allSubjects);
380
//                    array_walk($allSubjects, array($this, 'updateSubjectCount'));
381
                }
382
383
                unset($allSubjects);
384
385
                $totalStudents = Institution_class_student::getStudentsCount($this->file['institution_class_id']);
386
387
                if ($totalStudents['total'] > $institutionClass->no_of_students) {
0 ignored issues
show
Bug introduced by
The property no_of_students does not seem to exist on App\Models\Institution_class. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
388
                    $error = \Illuminate\Validation\ValidationException::withMessages([]);
389
                    $failure = new Failure(3, 'rows', [3 => 'Class student count exceeded! Max number of students is ' . $institutionClass->no_of_students], [null]);
390
                    $failures = [0 => $failure];
391
                    throw new \Maatwebsite\Excel\Validators\ValidationException($error, $failures);
392
                    Log::info('email-sent', [$this->file]);
0 ignored issues
show
Unused Code introduced by
Illuminate\Support\Facad...t', array($this->file)) is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
393
                }
394
395
396
                Institution_class::where('id', '=', $institutionClass->id)
397
                        ->update([
398
                            'total_male_students' => $totalStudents['total_male_students'],
399
                            'total_female_students' => $totalStudents['total_female_students']]);
400
            }
401
        } catch (\Maatwebsite\Excel\Validators\ValidationException $e) {
402
            $error = \Illuminate\Validation\ValidationException::withMessages([]);
403
            $failures = $e->failures();
404
            throw new \Maatwebsite\Excel\Validators\ValidationException($error, $failures);
405
            Log::info('email-sent', [$e]);
406
        }
407
        unset($row);
408
    }
409
410
    public function getStudentSubjects($student) {
411
        return Institution_subject_student::where('student_id', '=', $student->student_id)
412
                        ->where('institution_class_id', '=', $student->institution_class_id)->get()->toArray();
413
    }
414
415
    protected function insertSubject($subject){
416
        if(!Institution_subject_student::isDuplicated($subject))
417
                Institution_subject_student::updateOrInsert($subject);
418
    }
419
420
421
422
    public function rules(): array {
423
424
        return [
425
            '*.student_id' => 'required|exists:security_users,openemis_no|is_student_in_class:'.$this->file['institution_class_id'],
426
            '*.full_name' => 'nullable|regex:/^[\pL\s\-]+$/u|max:100',
427
            '*.gender_mf' => 'nullable|in:M,F',
428
            '*.date_of_birth_yyyy_mm_dd' => 'date|nullable',
429
            '*.address' => 'nullable',
430
            '*.birth_registrar_office_as_in_birth_certificate' => 'nullable|exists:area_administratives,name|required_if:identity_type,BC|birth_place',
431
            '*.birth_divisional_secretariat' => 'nullable|exists:area_administratives,name|required_with:birth_registrar_office_as_in_birth_certificate',
432
            '*.nationality' => 'nullable',
433
            '*.identity_type' => 'required_with:identity_number',
434
//            '*.identity_number' => 'user_unique:identity_number',
435
            '*.academic_period' => 'required_with:*.admission_no|nullable|exists:academic_periods,name',
436
            '*.education_grade' => 'nullable|exists:education_grades,code',
437
            '*.option_*' => 'nullable|exists:education_subjects,name',
438
            '*.bmi_height' => 'required_with:*.bmi_weight|nullable|numeric|max:200|min:60',
439
            '*.bmi_weight' => 'required_with:*.bmi_height|nullable|numeric|max:200|min:10',
440
            '*.bmi_date_yyyy_mm_dd' => 'required_with:*.bmi_height|nullable|date',
441
            '*.bmi_academic_period' => 'required_with:*.bmi_weight|nullable|exists:academic_periods,name',
442
            '*.admission_no' => 'nullable|max:12|min:4|regex:/^[A-Za-z0-9\/]+$/',
443
            '*.start_date_yyyy_mm_dd' => 'nullable|date',
444
            '*.special_need_type' => 'nullable',
445
            '*.special_need' => 'nullable|exists:special_need_difficulties,name|required_if:special_need_type,Differantly Able',
446
            '*.fathers_full_name' => 'nullable|regex:/^[\pL\s\-]+$/u',
447
            '*.fathers_date_of_birth_yyyy_mm_dd' => 'nullable|required_with:*.fathers_full_name',
448
            '*.fathers_address' => 'required_with:*.fathers_full_name',
449
            '*.fathers_address_area' => 'required_with:*.fathers_full_name|nullable|exists:area_administratives,name',
450
            '*.fathers_nationality' => 'required_with:*.fathers_full_name',
451
            '*.fathers_identity_type' => 'required_with:*.fathers_identity_number',
452
            '*.fathers_identity_number' => 'nullable|required_with:*.fathers_identity_type|nic:fathers_identity_number',
453
            '*.mothers_full_name' => 'nullable|regex:/^[\pL\s\-]+$/u',
454
            '*.mothers_date_of_birth_yyyy_mm_dd' => 'nullable|required_with:*.mothers_full_name',
455
            '*.mothers_address' => 'required_with:*.mothers_full_name',
456
            '*.mothers_address_area' => 'required_with:*.mothers_full_name|nullable|exists:area_administratives,name',
457
            '*.mothers_nationality' => "required_with:*.mothers_full_name",
458
            '*.mothers_identity_type' => "required_with:*.mothers_identity_number",
459
            '*.mothers_identity_number' => 'nullable|required_with:*.mothers_identity_type|nic:mothers_identity_number',
460
            '*.guardians_full_name' => 'nullable|regex:/^[\pL\s\-]+$/u',
461
            '*.guardians_gender_mf' => 'required_with:*.guardians_full_name',
462
            '*.guardians_date_of_birth_yyyy_mm_dd' => 'nullable|required_with:*.guardians_full_name',
463
            '*.guardians_address' => 'required_with:*.guardians_full_name',
464
            '*.guardians_address_area' => 'required_with:*.guardians_full_name|nullable|exists:area_administratives,name',
465
            '*.guardians_nationality' => 'required_with:*.guardians_full_name',
466
            '*.guardians_identity_type' => 'required_with:*.guardians_identity_number',
467
            '*.guardians_identity_number' => 'nullable|required_with:*.guardians_identity_type|nic:guardians_identity_number',
468
        ];
469
    }
470
471
}
472