1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Console\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use App\Models\Institution_class_student; |
7
|
|
|
use App\Models\Institution_class_subject; |
8
|
|
|
use App\Models\Institution_student_admission; |
9
|
|
|
use App\Models\Institution_student; |
10
|
|
|
use App\Models\Institution; |
11
|
|
|
use Illuminate\Support\Facades\Log; |
12
|
|
|
|
13
|
|
|
class RunAddStudentsToInstitutions extends Command |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* The name and signature of the console command. |
17
|
|
|
* |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $signature = 'admission:students {institution}'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* The console command description. |
24
|
|
|
* |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $description = 'Add approved students data to indtitution_student table'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Create a new command instance. |
31
|
|
|
* |
32
|
|
|
* @return void |
33
|
|
|
*/ |
34
|
|
|
public function __construct() |
35
|
|
|
{ |
36
|
|
|
parent::__construct(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Execute the console command. |
41
|
|
|
* |
42
|
|
|
* @return mixed |
43
|
|
|
*/ |
44
|
|
|
public function handle() |
45
|
|
|
{ |
46
|
|
|
// dd('test'); |
47
|
|
|
$institution = Institution::where([ |
48
|
|
|
'id' => $this->argument('institution') |
49
|
|
|
])->first(); |
50
|
|
|
|
51
|
|
|
if(!is_null($institution)){ |
52
|
|
|
|
53
|
|
|
// dd($institution); |
54
|
|
|
try { |
55
|
|
|
$this->info('adding missing students to the institution ' . $institution->name); |
|
|
|
|
56
|
|
|
$approvedstudent = Institution_student_admission::select('institution_student_admission.*')->join('institutions', 'institution_id', '=', 'institutions.id')->leftJoin('institution_students', 'student_id', '=', 'institution_students.student_id')->where([ |
57
|
|
|
// 'status_id' => 121,122,123,124, // |
58
|
|
|
'institution_id' => $institution->id |
59
|
|
|
])->get()->toArray(); |
60
|
|
|
dd($approvedstudent); |
61
|
|
|
$approvedstudent = array_chunk($approvedstudent, 50); |
62
|
|
|
array_walk($approvedstudent, array($this, 'addStudents')); |
63
|
|
|
}catch (\Exception $e) { |
64
|
|
|
Log::error($e); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
protected function addStudents($approvedstudent){ |
71
|
|
|
array_walk($approvedstudent,array($this,'addStudent')); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
protected function addStudent($approvedstudent){ |
75
|
|
|
$output = new \Symfony\Component\Console\Output\ConsoleOutput(); |
76
|
|
|
Log::info($approvedstudent); |
77
|
|
|
|
78
|
|
|
sleep(1); |
79
|
|
|
if(!(Institution_student::isDuplicated($approvedstudent) > 0)){ |
80
|
|
|
$this->count += 1; |
|
|
|
|
81
|
|
|
$this->student = $approvedstudent ; |
|
|
|
|
82
|
|
|
try{ |
83
|
|
|
Institution_student::insert([ |
84
|
|
|
'student_status_id' => 1, |
85
|
|
|
'student_id' => $approvedstudent['student_id'], |
86
|
|
|
'education_grade_id' => $approvedstudent['education_grade_id'], |
87
|
|
|
'academic_period_id' => $approvedstudent['academic_period_id'], |
88
|
|
|
'start_date' => $approvedstudent['start_date'], |
89
|
|
|
'start_year' => \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $approvedstudent['start_date'])->year , // $approvedstudent['start_date']->format('Y'), |
90
|
|
|
'end_date' => $approvedstudent['end_date'], |
91
|
|
|
'end_year' => \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $approvedstudent['end_date'])->year , //$approvedstudent['end_date']->format('Y'), |
92
|
|
|
'institution_id' => $approvedstudent['institution_id'], |
93
|
|
|
'admission_id' => $approvedstudent['admission_id'], |
94
|
|
|
'created_user_id' => $approvedstudent['created_user_id'], |
95
|
|
|
]); |
96
|
|
|
|
97
|
|
|
if(!is_null($approvedstudent['institution_class_id'])){ |
98
|
|
|
Institution_class_student::insert([ |
99
|
|
|
'student_id' => $approvedstudent['student_id'], |
100
|
|
|
'institution_class_id' => $approvedstudent['institution_class_id'], |
101
|
|
|
'education_grade_id' => $approvedstudent['education_grade_id'], |
102
|
|
|
'academic_period_id' => $approvedstudent['academic_period_id'], |
103
|
|
|
'institution_id' =>$approvedstudent['institution_id'], |
104
|
|
|
'student_status_id' => 1, |
105
|
|
|
'created_user_id' => $approvedstudent['created_user_id'], |
106
|
|
|
]); |
107
|
|
|
} |
108
|
|
|
$output->writeln(' |
109
|
|
|
#################################################### |
110
|
|
|
Total number of students updated : '.$this->count.' |
111
|
|
|
# # |
112
|
|
|
####################################################' ); |
113
|
|
|
// $output->writeln(); |
114
|
|
|
}catch (\Exception $e){ |
115
|
|
|
// echo $e->getMessage(); |
116
|
|
|
$output->writeln( $e->getMessage()); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.