1 | <?php |
||
2 | |||
3 | namespace App\Console\Commands; |
||
4 | |||
5 | use App\Models\Academic_period; |
||
6 | use Illuminate\Console\Command; |
||
7 | use App\Models\Institution_grade; |
||
8 | use Illuminate\Support\Facades\DB; |
||
9 | |||
10 | class CallPromotionCommand extends Command |
||
11 | { |
||
12 | /** |
||
13 | * The name and signature of the console command. |
||
14 | * |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $signature = 'promote:run {year} {mode} {limit}'; |
||
18 | |||
19 | /** |
||
20 | * The console command description. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $description = 'Command description'; |
||
25 | |||
26 | /** |
||
27 | * Create a new command instance. |
||
28 | * |
||
29 | * @return void |
||
30 | */ |
||
31 | public function __construct() |
||
32 | { |
||
33 | parent::__construct(); |
||
34 | $this->instituion_grade = new Institution_grade(); |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
35 | $this->academic_period = new Academic_period(); |
||
0 ignored issues
–
show
|
|||
36 | } |
||
37 | |||
38 | /** |
||
39 | * Execute the console command. |
||
40 | * |
||
41 | * @return mixed |
||
42 | */ |
||
43 | public function handle() |
||
44 | { |
||
45 | DB::statement("SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));"); |
||
46 | $year = $this->argument('year'); |
||
47 | $limit = $this->argument('limit'); |
||
48 | $mode = $this->argument('mode'); |
||
49 | $academicPeriod = $this->academic_period->getAcademicPeriod($year); |
||
50 | $previousAcademicPeriodYear = $academicPeriod->order; |
||
0 ignored issues
–
show
|
|||
51 | $previousAcademicPeriod = Academic_period::where('order',$previousAcademicPeriodYear+1)->first(); |
||
52 | $institutions = $this->instituion_grade->getInstitutionGradeList($previousAcademicPeriod->code,$limit,$mode); |
||
0 ignored issues
–
show
|
|||
53 | $params = [ |
||
54 | 'year' => $year, |
||
55 | 'mode'=> $mode |
||
56 | ]; |
||
57 | if(in_array($mode,['AL','1-5','SP','6-11'])){ |
||
58 | array_walk($institutions,array($this,'callPromotion'),$params); |
||
59 | }else{ |
||
60 | die('The give mode not support'); |
||
0 ignored issues
–
show
|
|||
61 | } |
||
62 | |||
63 | } |
||
64 | |||
65 | protected function callPromotion($institution,$count,$params){ |
||
66 | $this->call('promote:students',['year' => $params['year'],'institution' => $institution['code'],'mode' => $params['mode'] ]); |
||
67 | } |
||
68 | } |
||
69 |