1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Models; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
6
|
|
|
|
7
|
|
|
class Institution_class extends Base_Model |
8
|
|
|
{ |
9
|
|
|
|
10
|
|
|
public const CREATED_AT = 'created'; |
11
|
|
|
public const UPDATED_AT = 'modified'; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* The database table used by the model. |
17
|
|
|
* |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $table = 'institution_classes'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Attributes that should be mass-assignable. |
24
|
|
|
* |
25
|
|
|
* @var array |
26
|
|
|
*/ |
27
|
|
|
protected $fillable = ['name', 'no_of_students', 'class_number', 'total_male_students', 'total_female_students', 'staff_id', 'secondary_staff_id', 'institution_shift_id', 'institution_id', 'academic_period_id', 'modified_user_id', 'modified', 'created_user_id', 'created']; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* The attributes excluded from the model's JSON form. |
31
|
|
|
* |
32
|
|
|
* @var array |
33
|
|
|
*/ |
34
|
|
|
protected $hidden = []; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* The attributes that should be casted to native types. |
38
|
|
|
* |
39
|
|
|
* @var array |
40
|
|
|
*/ |
41
|
|
|
protected $casts = []; |
42
|
|
|
|
43
|
|
|
// protected |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* The attributes that should be mutated to dates. |
47
|
|
|
* |
48
|
|
|
* @var array |
49
|
|
|
*/ |
50
|
|
|
protected $dates = ['modified', 'created']; |
51
|
|
|
|
52
|
|
|
public function class_teacher() |
53
|
|
|
{ |
54
|
|
|
return $this->belongsTo('App\Models\Security_group_user', 'staff_id', 'security_user_id'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function institution() |
58
|
|
|
{ |
59
|
|
|
return $this->belongsTo('App\Models\Institution', 'institution_id'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
public function getShiftClasses($shift, $al) |
64
|
|
|
{ |
65
|
|
|
$query = self::query() |
66
|
|
|
->select( |
67
|
|
|
'institution_classes.id', |
68
|
|
|
'institution_classes.institution_id', |
69
|
|
|
'institution_classes.institution_shift_id', |
70
|
|
|
'institution_classes.name', |
71
|
|
|
'institution_classes.no_of_students', |
72
|
|
|
'institution_classes.class_number', |
73
|
|
|
'institution_class_grades.education_grade_id', |
74
|
|
|
'institution_classes.created_user_id' |
75
|
|
|
|
76
|
|
|
) |
77
|
|
|
->join('institution_class_grades', 'institution_classes.id', 'institution_class_grades.institution_class_id') |
78
|
|
|
->join('education_grades','institution_class_grades.education_grade_id','education_grades.id') |
79
|
|
|
->join('education_programmes', 'education_grades.education_programme_id', 'education_programmes.id') |
80
|
|
|
->join('education_cycles', 'education_programmes.education_cycle_id','education_cycles.id') |
81
|
|
|
->groupBy('institution_classes.id'); |
82
|
|
|
|
83
|
|
|
if ($al == true) { |
84
|
|
|
$query->where('education_programmes.education_cycle_id', 4) |
85
|
|
|
->where('institution_id', $shift['institution_id']); |
86
|
|
|
$data = $query |
87
|
|
|
->groupBy('institution_classes.id') |
88
|
|
|
->get()->toArray(); |
89
|
|
|
return $data; |
90
|
|
|
} else { |
91
|
|
|
$query->where('education_programmes.education_cycle_id','<>',4) |
92
|
|
|
->where('institution_shift_id', $shift['id']); |
93
|
|
|
$data = $query |
94
|
|
|
->groupBy('institution_classes.id') |
95
|
|
|
->get()->toArray(); |
96
|
|
|
return $data; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public static function getGradeClasses($education_grade_id,$institution_id){ |
101
|
|
|
return self::query() |
102
|
|
|
->select('institution_classes.id','institution_classes.institution_id','institution_classes.institution_shift_id', |
103
|
|
|
'institution_classes.name','institution_classes.no_of_students','institution_classes.class_number','institution_class_grades.education_grade_id') |
104
|
|
|
->where('institution_class_grades.education_grade_id',$education_grade_id) |
105
|
|
|
->where('institution_classes.institution_id',$institution_id) |
106
|
|
|
->join('institution_class_grades','institution_classes.id','institution_class_grades.institution_class_id') |
107
|
|
|
->get()->toArray(); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function updateClassCount($institutionClass) |
111
|
|
|
{ |
112
|
|
|
$studentCount = Institution_class_student::getStudentsCount($institutionClass['institution_class_id']); |
113
|
|
|
Institution_class::where(['id' => $institutionClass['institution_class_id']]) |
114
|
|
|
->update([ |
115
|
|
|
'total_male_students' => $studentCount['total_male_students'], |
116
|
|
|
'total_female_students' => $studentCount['total_female_students'] |
117
|
|
|
]); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
} |
121
|
|
|
|