1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Models; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
6
|
|
|
use Webpatser\Uuid\Uuid; |
7
|
|
|
|
8
|
|
|
class Institution_class_subject extends Base_Model { |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* The database table used by the model. |
12
|
|
|
* |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
protected $table = 'institution_class_subjects'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Attributes that should be mass-assignable. |
19
|
|
|
* |
20
|
|
|
* @var array |
21
|
|
|
*/ |
22
|
|
|
protected $fillable = ['status', 'institution_class_id', 'institution_subject_id', 'modified_user_id', 'modified', 'created_user_id', 'created']; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The attributes excluded from the model's JSON form. |
26
|
|
|
* |
27
|
|
|
* @var array |
28
|
|
|
*/ |
29
|
|
|
protected $hidden = []; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The attributes that should be casted to native types. |
33
|
|
|
* |
34
|
|
|
* @var array |
35
|
|
|
*/ |
36
|
|
|
protected $casts = []; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* The attributes that should be mutated to dates. |
40
|
|
|
* |
41
|
|
|
* @var array |
42
|
|
|
*/ |
43
|
|
|
protected $dates = ['modified', 'created']; |
44
|
|
|
|
45
|
|
|
public function institutionMandatorySubject(){ |
46
|
|
|
return $this->belongsTo('App\Models\Institution_subject','institution_subject_id','id') |
47
|
|
|
->with('institutionGradeSubject') |
48
|
|
|
->whereHas('institutionGradeSubject', function ($query) { |
49
|
|
|
$query->where('auto_allocation',1); |
50
|
|
|
}); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function institutionOptionalSubject(){ |
54
|
|
|
return $this->belongsTo('App\Models\Institution_subject','institution_subject_id','id') |
55
|
|
|
->with('institutionGradeSubject') |
56
|
|
|
->whereHas('institutionGradeSubject', function ($query) { |
57
|
|
|
$query->where('auto_allocation',0); |
58
|
|
|
}); |
59
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public static function boot() |
63
|
|
|
{ |
64
|
|
|
parent::boot(); |
65
|
|
|
self::creating(function ($model) { |
66
|
|
|
$model->id = (string) Uuid::generate(4); |
67
|
|
|
}); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function institutionSubject(){ |
71
|
|
|
return $this->belongsTo('App\Models\Institution_subject','institution_subject_id','id') |
72
|
|
|
->with('institutionGradeSubject'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
public static function getMandatorySubjects($institutionClass){ |
77
|
|
|
$institutionGrade = Institution_class_grade::where('institution_class_id', '=', $institutionClass)->first(); |
78
|
|
|
$mandatorySubject = Institution_class_subject::with(['institutionSubject']) |
79
|
|
|
->whereHas('institutionSubject', function ($query) use ($institutionGrade) { |
80
|
|
|
$query->whereHas('institutionGradeSubject',function($query){ |
81
|
|
|
$query->where('auto_allocation',1); |
82
|
|
|
})->where('education_grade_id', $institutionGrade->education_grade_id); |
|
|
|
|
83
|
|
|
}) |
84
|
|
|
->where('institution_class_id', '=', $institutionClass) |
85
|
|
|
->get()->toArray(); |
86
|
|
|
return $mandatorySubject; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public static function getAllSubjects($institutionClass){ |
90
|
|
|
$allSubjects = Institution_class_subject::with(['institutionSubject']) |
91
|
|
|
->whereHas('institutionSubject', function ($query) use ($institutionClass) { |
92
|
|
|
$query->whereHas('institutionGradeSubject')->where('education_grade_id', $institutionClass['education_grade_id']); |
93
|
|
|
}) |
94
|
|
|
->where('institution_class_id', '=', $institutionClass['id']) |
95
|
|
|
->get()->toArray(); |
96
|
|
|
return $allSubjects; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public static function getStudentOptionalSubject($subjects, $student, $row, $institution) { |
|
|
|
|
100
|
|
|
$data = []; |
101
|
|
|
foreach ($subjects as $subject) { |
102
|
|
|
$subjectId = Institution_class_subject::with(['institutionSubject']) |
103
|
|
|
->whereHas('institutionSubject', function ($query) use ($row, $subject, $student) { |
104
|
|
|
$query->whereHas('institutionGradeSubject',function($query){ |
105
|
|
|
$query->where('auto_allocation',0); |
106
|
|
|
}) |
107
|
|
|
->where('name', '=', $row[$subject]) |
108
|
|
|
->where('education_grade_id', '=', $student->education_grade_id); |
109
|
|
|
}) |
110
|
|
|
->where('institution_class_id', '=', $student->institution_class_id) |
111
|
|
|
->get()->toArray(); |
112
|
|
|
if (!empty($subjectId)) |
113
|
|
|
$data[] = $subjectId[0]; |
114
|
|
|
} |
115
|
|
|
return $data; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function getInstitutionClassSubjects($academicPeriodId,$classIds){ |
|
|
|
|
119
|
|
|
return self::query() |
120
|
|
|
->whereIn('institution_class_id',$classIds) |
121
|
|
|
->get() |
122
|
|
|
->toArray(); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function isDuplicated($subject){ |
126
|
|
|
return self::query()->where('institution_subject_id',$subject['institution_subject_id']) |
127
|
|
|
->where('institution_class_id',$subject['institution_class_id'])->get()->toArray(); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.