moe-lk /
bulk-upload
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace App\Console\Commands; |
||||
| 4 | |||||
| 5 | use App\Models\Unprocessed_students; |
||||
| 6 | use Illuminate\Console\Command; |
||||
| 7 | use App\Models\Institution_class_student; |
||||
| 8 | use App\Models\Institution_class_subject; |
||||
| 9 | use App\Models\Institution_student_admission; |
||||
| 10 | use App\Models\Institution_student; |
||||
| 11 | use App\Models\Institution; |
||||
| 12 | use Illuminate\Support\Facades\Log; |
||||
| 13 | use Webpatser\Uuid\Uuid; |
||||
| 14 | |||||
| 15 | |||||
| 16 | class RunAddApprovedStudents extends Command |
||||
| 17 | { |
||||
| 18 | /** |
||||
| 19 | * The name and signature of the console command. |
||||
| 20 | * |
||||
| 21 | * @var string |
||||
| 22 | */ |
||||
| 23 | protected $signature = 'admission:students {institution}'; |
||||
| 24 | |||||
| 25 | /** |
||||
| 26 | * The console command description. |
||||
| 27 | * |
||||
| 28 | * @var string |
||||
| 29 | */ |
||||
| 30 | protected $description = 'Provide the institution cencus id for process add mission students'; |
||||
| 31 | |||||
| 32 | public $count = 0; |
||||
| 33 | /** |
||||
| 34 | * Create a new command instance. |
||||
| 35 | * |
||||
| 36 | * @return void |
||||
| 37 | */ |
||||
| 38 | public function __construct() |
||||
| 39 | { |
||||
| 40 | parent::__construct(); |
||||
| 41 | } |
||||
| 42 | |||||
| 43 | /** |
||||
| 44 | * Execute the console command. |
||||
| 45 | * |
||||
| 46 | * @return mixed |
||||
| 47 | */ |
||||
| 48 | public function handle() |
||||
| 49 | { |
||||
| 50 | $institution = Institution::where([ |
||||
| 51 | 'id' => $this->argument('institution') |
||||
| 52 | ])->first(); |
||||
| 53 | |||||
| 54 | if(!is_null($institution)){ |
||||
| 55 | try { |
||||
| 56 | $this->info('adding missing students to the admission ' . $institution->name); |
||||
|
0 ignored issues
–
show
|
|||||
| 57 | $allApprovedStudents = Institution_student_admission::where([ |
||||
| 58 | 'status_id' => 124, |
||||
| 59 | 'institution_id' => $institution->id |
||||
| 60 | ])->get()->toArray(); |
||||
| 61 | $allApprovedStudents = array_chunk($allApprovedStudents, 50); |
||||
| 62 | array_walk($allApprovedStudents, array($this, 'addStudents')); |
||||
| 63 | } catch (\Exception $e) { |
||||
| 64 | Log::error($e); |
||||
| 65 | } |
||||
| 66 | } |
||||
| 67 | } |
||||
| 68 | |||||
| 69 | protected function addStudents($students){ |
||||
| 70 | array_walk($students,array($this,'addStudent')); |
||||
| 71 | } |
||||
| 72 | |||||
| 73 | protected function addStudent($student){ |
||||
| 74 | // dd(Institution_class_student::isDuplicated($student)); |
||||
| 75 | $output = new \Symfony\Component\Console\Output\ConsoleOutput(); |
||||
| 76 | sleep(1); |
||||
| 77 | if(!(Institution_class_student::isDuplicated($student) > 0)){ |
||||
| 78 | $this->count += 1; |
||||
| 79 | $this->student = $student ; |
||||
|
0 ignored issues
–
show
|
|||||
| 80 | try{ |
||||
| 81 | Institution_student::create([ |
||||
| 82 | 'student_status_id' => 1, |
||||
| 83 | 'student_id' => $student['student_id'], |
||||
| 84 | 'education_grade_id' => $student['education_grade_id'], |
||||
| 85 | 'academic_period_id' => $student['academic_period_id'], |
||||
| 86 | 'start_date' => $student['start_date'], |
||||
| 87 | 'start_year' => \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $student['start_date'])->year , // $student['start_date']->format('Y'), |
||||
| 88 | 'end_date' => $student['end_date'], |
||||
| 89 | 'end_year' => \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $student['end_date'])->year , //$student['end_date']->format('Y'), |
||||
| 90 | 'institution_id' => $student['institution_id'], |
||||
| 91 | 'admission_id' => $student['admission_id'], |
||||
| 92 | 'created_user_id' => $student['created_user_id'], |
||||
| 93 | ]); |
||||
| 94 | |||||
| 95 | if(!is_null($student['institution_class_id'])){ |
||||
| 96 | Institution_class_student::create([ |
||||
| 97 | 'student_id' => $student['student_id'], |
||||
| 98 | 'institution_class_id' => $student['institution_class_id'], |
||||
| 99 | 'education_grade_id' => $student['education_grade_id'], |
||||
| 100 | 'academic_period_id' => $student['academic_period_id'], |
||||
| 101 | 'institution_id' =>$student['institution_id'], |
||||
| 102 | 'student_status_id' => 1, |
||||
| 103 | 'created_user_id' => $student['created_user_id'], |
||||
| 104 | ]); |
||||
| 105 | } |
||||
| 106 | $output->writeln(' |
||||
| 107 | #################################################### |
||||
| 108 | Total number of students updated : '.$this->count.' |
||||
| 109 | # # |
||||
| 110 | ####################################################' ); |
||||
| 111 | // $output->writeln(); |
||||
| 112 | }catch (\Exception $e){ |
||||
| 113 | // echo $e->getMessage(); |
||||
| 114 | $output->writeln( $e->getMessage()); |
||||
| 115 | } |
||||
| 116 | } |
||||
| 117 | } |
||||
| 118 | |||||
| 119 | |||||
| 120 | protected function setSubjects($student){ |
||||
| 121 | $allSubjects = Institution_class_subject::getMandetorySubjects($student['institution_class_id']); |
||||
| 122 | |||||
| 123 | if (!empty($allSubjects)) { |
||||
| 124 | $allSubjects = unique_multidim_array($allSubjects, 'institution_subject_id'); |
||||
|
0 ignored issues
–
show
It seems like
$allSubjects can also be of type Illuminate\Database\Eloquent\Builder; however, parameter $array of unique_multidim_array() does only seem to accept array, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 125 | $this->student = $student; |
||||
|
0 ignored issues
–
show
|
|||||
| 126 | $allSubjects = array_map(array($this,'setStudentSubjects'),$allSubjects); |
||||
| 127 | $allSubjects = unique_multidim_array($allSubjects, 'education_subject_id'); |
||||
| 128 | array_walk($allSubjects,array($this,'insertSubject')); |
||||
| 129 | } |
||||
| 130 | |||||
| 131 | unset($allSubjects); |
||||
| 132 | |||||
| 133 | } |
||||
| 134 | |||||
| 135 | |||||
| 136 | protected function setStudentSubjects($subject){ |
||||
| 137 | return [ |
||||
| 138 | 'id' => (string) Uuid::generate(4), |
||||
| 139 | 'student_id' => $this->student->student_id, |
||||
| 140 | 'institution_class_id' => $this->student->institution_class_id, |
||||
| 141 | 'institution_subject_id' => $subject['institution_subject_id'], |
||||
| 142 | 'institution_id' => $this->student->institution_id, |
||||
| 143 | 'academic_period_id' => $this->student->academic_period_id, |
||||
| 144 | 'education_subject_id' => $subject['institution_subject']['education_subject_id'], |
||||
| 145 | 'education_grade_id' => $this->student->education_grade_id, |
||||
| 146 | 'student_status_id' => 1, |
||||
| 147 | 'created_user_id' => $this->file['security_user_id'], |
||||
|
0 ignored issues
–
show
|
|||||
| 148 | 'created' => now() |
||||
| 149 | ]; |
||||
| 150 | } |
||||
| 151 | |||||
| 152 | protected function insertSubject($subject){ |
||||
| 153 | if(!Institution_subject_student::isDuplicated($subject)){ |
||||
|
0 ignored issues
–
show
The type
App\Console\Commands\Institution_subject_student was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 154 | Institution_subject_student::updateOrInsert($subject); |
||||
| 155 | } |
||||
| 156 | } |
||||
| 157 | |||||
| 158 | } |
||||
| 159 |
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.