moe-lk /
bulk-upload
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Console\Commands; |
||
| 4 | |||
| 5 | use App\Models\Institution; |
||
| 6 | use Illuminate\Console\Command; |
||
| 7 | use App\Models\Institution_class; |
||
| 8 | use Illuminate\Support\Facades\DB; |
||
| 9 | use App\Models\Institution_student; |
||
| 10 | use App\Models\Institution_class_student; |
||
| 11 | use App\Models\Institution_student_admission; |
||
| 12 | use App\Models\Security_user; |
||
| 13 | use Carbon\Carbon; |
||
| 14 | |||
| 15 | class UpdateClassEntriyWithZeroId extends Command |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * The name and signature of the console command. |
||
| 19 | * |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | protected $signature = 'update:zero_id_class {from} {max} {code}'; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * The console command description. |
||
| 26 | * |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | protected $description = 'update student class reference'; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Create a new command instance. |
||
| 33 | * |
||
| 34 | * @return void |
||
| 35 | */ |
||
| 36 | public function __construct() |
||
| 37 | { |
||
| 38 | $this->class = new Institution_class; |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 39 | $this->output = new \Symfony\Component\Console\Output\ConsoleOutput(); |
||
|
0 ignored issues
–
show
It seems like
new Symfony\Component\Co...\Output\ConsoleOutput() of type Symfony\Component\Console\Output\ConsoleOutput is incompatible with the declared type Illuminate\Console\OutputStyle of property $output.
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property. Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.. Loading history...
|
|||
| 40 | parent::__construct(); |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Execute the console command. |
||
| 45 | * |
||
| 46 | * @return mixed |
||
| 47 | */ |
||
| 48 | public function handle() |
||
| 49 | { |
||
| 50 | DB::statement("SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));"); |
||
| 51 | |||
| 52 | if ($this->argument('code') !== 'All') { |
||
| 53 | $institutions = Institution::where('code', $this->argument('code'))->get()->toArray(); |
||
| 54 | processParallel(array($this,'processInstitution'),$institutions,$this->argument('max')); |
||
| 55 | } else { |
||
| 56 | $institutions = Institution::where('institution_status_id', 1)->get()->toArray(); |
||
| 57 | processParallel(array($this,'processInstitution'),$institutions,$this->argument('max')); |
||
| 58 | } |
||
| 59 | } |
||
| 60 | |||
| 61 | public function processInstitution($institution) |
||
| 62 | { |
||
| 63 | $students = Institution_student::withTrashed()->where('updated_from', $this->argument('from')) |
||
| 64 | ->join('institutions', 'institutions.id', 'institution_students.institution_id') |
||
| 65 | ->where('institutions.id', $institution['id']) |
||
| 66 | ->get()->toArray(); |
||
| 67 | if (count($students) > 0) { |
||
| 68 | array_walk($students,array($this, 'process')); |
||
| 69 | $this->output->writeln("institution :" .$institution['code']. ' cleaned'); |
||
| 70 | } else { |
||
| 71 | $this->output->writeln("all records are cleaned at :".$institution['code'] ); |
||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 75 | public function process($student) |
||
| 76 | { |
||
| 77 | try{ |
||
| 78 | $wrongStudentsClass = Institution_class_student::where('institution_id', $student['institution_id']) |
||
| 79 | ->whereRaw('institution_class_id not in (select id from institution_classes where institution_id ='.$student['institution_id'].' )') |
||
| 80 | ->orWhere('institution_class_id', 0) |
||
| 81 | ->where('student_id', $student['student_id']) |
||
| 82 | ->get()->toArray(); |
||
| 83 | |||
| 84 | if (count($wrongStudentsClass) > 0) { |
||
| 85 | Institution_class_student::where('student_id', $student['student_id'])->forceDelete(); |
||
| 86 | Institution_student_admission::where('student_id', $student['student_id'])->forceDelete(); |
||
| 87 | Institution_student::where('student_id', $student['student_id'])->forceDelete(); |
||
| 88 | |||
| 89 | array_walk($wrongStudentsClass, array($this->class, 'updateClassCount')); |
||
| 90 | |||
| 91 | $institutionClass = Institution_class::getGradeClasses($student['education_grade_id'], $student['institution_id']); |
||
| 92 | |||
| 93 | if (count($institutionClass) == 1) { |
||
| 94 | $start_date = new Carbon($student['start_date']); |
||
| 95 | $end_date = new Carbon($student['end_date']); |
||
| 96 | Institution_student_admission::create( |
||
| 97 | [ |
||
| 98 | 'student_id' => $student['student_id'], |
||
| 99 | 'institution_class_id' => $institutionClass[0]['id'], |
||
| 100 | 'start_date' => $student['start_date'], |
||
| 101 | 'start_year' => $start_date->format('Y'), |
||
| 102 | 'end_date' => $student['start_date'], |
||
| 103 | 'end_year' => $end_date->format('Y'), |
||
| 104 | 'education_grade_id' => $student['education_grade_id'], |
||
| 105 | 'institution_id' => $student['institution_id'], |
||
| 106 | 'status_id' => 124, |
||
| 107 | 'academic_period_id' => $student['academic_period_id'], |
||
| 108 | 'created_user_id' => $student['created_user_id'], |
||
| 109 | 'updated_from' => $student['updated_from'] |
||
| 110 | ] |
||
| 111 | ); |
||
| 112 | $institutionClassStudent = [ |
||
| 113 | 'student_id' => $student['student_id'], |
||
| 114 | 'institution_class_id' => $institutionClass[0]['id'], |
||
| 115 | 'education_grade_id' => $student['education_grade_id'], |
||
| 116 | 'institution_id' => $student['institution_id'], |
||
| 117 | 'status_id' => 124, |
||
| 118 | 'academic_period_id' => $student['academic_period_id'], |
||
| 119 | 'student_status_id' => 1, |
||
| 120 | 'created_user_id' => $student['created_user_id'], |
||
| 121 | 'updated_from' => $student['updated_from'] |
||
| 122 | ]; |
||
| 123 | Institution_class_student::create($institutionClassStudent); |
||
| 124 | Institution_student::create([ |
||
| 125 | 'student_id' => $student['student_id'], |
||
| 126 | 'student_status_id' => 1, |
||
| 127 | 'education_grade_id' => $student['education_grade_id'], |
||
| 128 | 'institution_id' => $student['institution_id'], |
||
| 129 | 'academic_period_id' => $student['academic_period_id'], |
||
| 130 | 'created_user_id' => $student['created_user_id'], |
||
| 131 | 'start_date' => $student['start_date'], |
||
| 132 | 'start_year' => $start_date->format('Y'), |
||
| 133 | 'end_date' => $student['start_date'], |
||
| 134 | 'end_year' => $end_date->format('Y'), |
||
| 135 | 'taking_g5_exam' => $student['updated_from'] == 'doe' ? true : false, |
||
| 136 | 'income_at_g5' => $student['income_at_g5'], |
||
| 137 | 'updated_from' => $student['updated_from'], |
||
| 138 | 'exam_center_for_special_education_g5' => $student['exam_center_for_special_education_g5'], |
||
| 139 | 'modified_user_id' => $student['modified_user_id'], |
||
| 140 | ]); |
||
| 141 | $institutionClassStudent = [$institutionClassStudent]; |
||
| 142 | array_walk($institutionClassStudent, array($this->class, 'updateClassCount')); |
||
| 143 | $this->output->writeln("student record :".$student['student_id'] ); |
||
| 144 | } |
||
| 145 | } |
||
| 146 | }catch(\Exception $e){ |
||
| 147 | dd($e); |
||
| 148 | } |
||
| 149 | } |
||
| 150 | } |
||
| 151 |