1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Models; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
class Institution_grade extends Base_Model |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* The database table used by the model. |
13
|
|
|
* |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected $table = 'institution_grades'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Attributes that should be mass-assignable. |
20
|
|
|
* |
21
|
|
|
* @var array |
22
|
|
|
*/ |
23
|
|
|
protected $fillable = ['education_grade_id', 'start_date', 'start_year', 'end_date', 'end_year', 'institution_id', 'modified_user_id', 'modified', 'created_user_id', 'created', 'promoted']; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The attributes excluded from the model's JSON form. |
27
|
|
|
* |
28
|
|
|
* @var array |
29
|
|
|
*/ |
30
|
|
|
protected $hidden = []; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* The attributes that should be casted to native types. |
34
|
|
|
* |
35
|
|
|
* @var array |
36
|
|
|
*/ |
37
|
|
|
protected $casts = []; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* The attributes that should be mutated to dates. |
41
|
|
|
* |
42
|
|
|
* @var array |
43
|
|
|
*/ |
44
|
|
|
protected $dates = ['start_date', 'end_date', 'modified', 'created']; |
45
|
|
|
|
46
|
|
|
public function isPool($grade) |
47
|
|
|
{ |
48
|
|
|
$classes = Institution_class_grade::query()->where('education_grade_id', '=', $grade->education_grade_id) |
|
|
|
|
49
|
|
|
->where('institution_id', '=', $grade->institution_id)->get(); |
50
|
|
|
return true; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param $id |
55
|
|
|
*/ |
56
|
|
|
public function getNumberOfParallelClasses($id) |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
$this->hasMany('App\Models\Institution_class_grade', 'education_grade_id', 'education_grade_id')->count(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* get parallel class information of a grade |
63
|
|
|
* |
64
|
|
|
* @param $id |
65
|
|
|
* @param $institutionId |
66
|
|
|
* @param $educationGradeId |
67
|
|
|
* @param $academicPeriodId |
68
|
|
|
* @return |null |
|
|
|
|
69
|
|
|
*/ |
70
|
|
|
public function getParallelClasses($id, $institutionId, $educationGradeId, $academicPeriodId) |
71
|
|
|
{ |
72
|
|
|
$data = self::find($id)->select('institution_grades.id as insGrade', 'institution_classes.id', 'institution_classes.name', 'institution_grades.education_grade_id') |
73
|
|
|
->join('institution_classes', function ($join) use ($educationGradeId, $academicPeriodId) { |
74
|
|
|
$join->on('institution_classes.institution_id', '=', 'institution_grades.institution_id') |
75
|
|
|
->where('institution_classes.academic_period_id', $academicPeriodId) |
76
|
|
|
->join('institution_class_grades', function ($join) use ($educationGradeId) { |
77
|
|
|
$join->on('institution_class_grades.institution_class_id', '=', 'institution_classes.id') |
78
|
|
|
->where('institution_class_grades.education_grade_id', $educationGradeId); |
79
|
|
|
}) |
80
|
|
|
->groupBy('institution_classes.id'); |
81
|
|
|
}) |
82
|
|
|
->where('institution_grades.education_grade_id', $educationGradeId) |
83
|
|
|
->where('institution_grades.institution_id', $institutionId) |
84
|
|
|
->groupBy('institution_classes.id') |
85
|
|
|
->get(); |
86
|
|
|
return $data; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* update processed grade |
92
|
|
|
* |
93
|
|
|
* @param $year |
94
|
|
|
* @param $id |
95
|
|
|
*/ |
96
|
|
|
public function updatePromoted($year, $id) |
97
|
|
|
{ |
98
|
|
|
self::where('id', $id)->update(['promoted' => $year]); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* get grade of an institution |
103
|
|
|
* |
104
|
|
|
* @param $institutionId |
105
|
|
|
* @param $gradeId |
106
|
|
|
* @return mixed |
107
|
|
|
*/ |
108
|
|
|
public function getInstitutionGrade($institutionId, $gradeId) |
109
|
|
|
{ |
110
|
|
|
return self::where('education_grade_id', $gradeId) |
111
|
|
|
->where('institution_id', $institutionId)->get()->first(); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param $year |
116
|
|
|
* @param null $institution |
|
|
|
|
117
|
|
|
* @return mixed |
118
|
|
|
*/ |
119
|
|
|
public function getInstitutionGradeToPromoted($year, $institution = null, $mode) |
120
|
|
|
{ |
121
|
|
|
$data = array(); |
|
|
|
|
122
|
|
|
$query = self::query() |
123
|
|
|
->select('education_grades.name', 'institutions.code', 'institutions.name as institution_name', 'institution_grades.id', 'institution_grades.institution_id', 'institution_grades.education_grade_id') |
124
|
|
|
->where('promoted', '=', $year) |
125
|
|
|
->join('education_grades', 'institution_grades.education_grade_id', '=', 'education_grades.id') |
126
|
|
|
->join('institutions', function ($join) use ($year, $institution) { |
|
|
|
|
127
|
|
|
$join->on('institutions.id', '=', 'institution_grades.institution_id') |
128
|
|
|
->where('institutions.code', '=', $institution); |
129
|
|
|
}) |
130
|
|
|
->join('education_programmes', 'education_grades.education_programme_id', 'education_programmes.id'); |
131
|
|
|
switch ($mode) { |
132
|
|
|
case '1-5': |
133
|
|
|
$query->where('education_programmes.education_cycle_id', 1); |
134
|
|
|
break; |
135
|
|
|
case '6-11': |
136
|
|
|
$query->whereIn('education_programmes.education_cycle_id', [2, 3]); |
137
|
|
|
break; |
138
|
|
|
case 'AL': |
139
|
|
|
$query->where('education_programmes.education_cycle_id', 4); |
140
|
|
|
break; |
141
|
|
|
case 'SP': |
142
|
|
|
$query->where('education_programmes.education_cycle_id', 7); |
143
|
|
|
break; |
144
|
|
|
} |
145
|
|
|
$data = $query->groupBy('institution_grades.id') |
146
|
|
|
->get()->toArray(); |
147
|
|
|
return $data; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @param $year |
152
|
|
|
* @return mixed |
153
|
|
|
*/ |
154
|
|
|
public function getInstitutionGradeList($year, $limit) |
155
|
|
|
{ |
156
|
|
|
return self::query() |
157
|
|
|
->select('education_grades.name', 'institutions.code', 'institutions.name as institution_name', 'institution_grades.id', 'institution_grades.institution_id', 'institution_grades.education_grade_id') |
158
|
|
|
->where('promoted', '=', $year) |
159
|
|
|
->join('education_grades', 'institution_grades.education_grade_id', '=', 'education_grades.id') |
160
|
|
|
->join('institutions', function ($join) use ($year) { |
|
|
|
|
161
|
|
|
$join->on('institutions.id', '=', 'institution_grades.institution_id'); |
162
|
|
|
}) |
163
|
|
|
->orderBy('institution_id') |
164
|
|
|
->groupBy('institutions.id') |
165
|
|
|
->limit($limit) |
166
|
|
|
->get() |
167
|
|
|
->toArray(); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
public function getGradeSubjects($institutionId){ |
171
|
|
|
return self::query() |
172
|
|
|
->select('institution_grades.institution_id','education_grades_subjects.education_grade_id','education_grades_subjects.education_subject_id','education_subjects.name') |
173
|
|
|
->where('institution_grades.institution_id',$institutionId) |
174
|
|
|
->join('education_grades', 'institution_grades.education_grade_id', 'education_grades.id') |
175
|
|
|
->join('education_grades_subjects','education_grades.id','education_grades_subjects.education_grade_id') |
176
|
|
|
->join('education_subjects','education_grades_subjects.education_subject_id','education_subjects.id') |
177
|
|
|
->groupBy('education_grades_subjects.id') |
178
|
|
|
->get() |
179
|
|
|
->toArray(); |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
|