|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
6
|
|
|
|
|
7
|
|
|
class Education_grade extends Model { |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* The database table used by the model. |
|
11
|
|
|
* |
|
12
|
|
|
* @var string |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $table = 'education_grades'; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Attributes that should be mass-assignable. |
|
18
|
|
|
* |
|
19
|
|
|
* @var array |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $fillable = ['code', 'name', 'admission_age', 'order', 'visible', 'education_stage_id', 'education_programme_id', 'modified_user_id', 'modified', 'created_user_id', 'created']; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* The attributes excluded from the model's JSON form. |
|
25
|
|
|
* |
|
26
|
|
|
* @var array |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $hidden = []; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* The attributes that should be casted to native types. |
|
32
|
|
|
* |
|
33
|
|
|
* @var array |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $casts = []; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* The attributes that should be mutated to dates. |
|
39
|
|
|
* |
|
40
|
|
|
* @var array |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $dates = ['modified', 'created']; |
|
43
|
|
|
|
|
44
|
|
|
public function getNextGrade($gradeId,$getNextProgrammeGrades = false, $firstGradeOnly = false){ |
|
|
|
|
|
|
45
|
|
|
if (!empty($gradeId)) { |
|
46
|
|
|
$gradeObj = $this->find($gradeId); |
|
47
|
|
|
$programmeId = $gradeObj->education_programme_id; |
|
|
|
|
|
|
48
|
|
|
$order = $gradeObj->order; |
|
|
|
|
|
|
49
|
|
|
$gradeOptions = self::where( 'education_programme_id',$programmeId |
|
50
|
|
|
)->where('order',$order+1)->get()->first(); |
|
51
|
|
|
$nextProgramme = self::getNextProgrammeList($programmeId); |
|
|
|
|
|
|
52
|
|
|
if(is_null($gradeOptions) && !is_null($nextProgramme)){ |
|
53
|
|
|
$programmeId = $nextProgramme->next_programme_id; |
|
54
|
|
|
$gradeOptions = self::where( 'education_programme_id',$programmeId |
|
55
|
|
|
) |
|
56
|
|
|
->orderBy('order') |
|
57
|
|
|
->get()->first(); |
|
58
|
|
|
} |
|
59
|
|
|
// Default is to get the list of grades with the next programme grades |
|
60
|
|
|
// if ($getNextProgrammeGrades) { |
|
61
|
|
|
// if ($firstGradeOnly) { |
|
62
|
|
|
// $nextProgrammesGradesOptions = $this->getNextProgrammeFirstGradeList($programmeId); |
|
63
|
|
|
// } else { |
|
64
|
|
|
// $nextProgrammesGradesOptions = $this->getNextGradeList($programmeId); |
|
65
|
|
|
// } |
|
66
|
|
|
// $results = array_merge($gradeOptions,$nextProgrammesGradesOptions); |
|
67
|
|
|
// } else { |
|
68
|
|
|
// $results = $gradeOptions; |
|
69
|
|
|
// } |
|
70
|
|
|
return $gradeOptions; |
|
71
|
|
|
} else { |
|
72
|
|
|
return null; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function getNextProgrammeFirstGradeList($id) { |
|
77
|
|
|
$nextProgrammeList = self::getNextProgrammeList($id); |
|
|
|
|
|
|
78
|
|
|
if (!empty($nextProgrammeList)) { |
|
79
|
|
|
$results = []; |
|
80
|
|
|
|
|
81
|
|
|
foreach ($nextProgrammeList as $nextProgrammeId) { |
|
82
|
|
|
$nextProgrammeGradeResults = self:: |
|
83
|
|
|
where('education_programme_id',$nextProgrammeId->next_programme_id)->get()->toArray(); |
|
84
|
|
|
|
|
85
|
|
|
$results = $results + [key($nextProgrammeGradeResults) => current($nextProgrammeGradeResults)]; |
|
86
|
|
|
} |
|
87
|
|
|
} else { |
|
88
|
|
|
$results = []; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
return (object)$results; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Function to get the list of the next education grade base on a given education programme id |
|
97
|
|
|
* |
|
98
|
|
|
* @param $id Education programme id |
|
99
|
|
|
* @return array List of next education grades id |
|
100
|
|
|
*/ |
|
101
|
|
|
public function getNextGradeList($id) { |
|
102
|
|
|
|
|
103
|
|
|
$nextProgrammeList = $this->getNextProgrammeList($id); |
|
104
|
|
|
if (!empty($nextProgrammeList)) { |
|
105
|
|
|
$results = self::whereIn('education_programme_id',$nextProgrammeList) |
|
106
|
|
|
->get()->toArray(); |
|
107
|
|
|
} else { |
|
108
|
|
|
$results = []; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
return $results; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Function to get the list of the next programme base on a given programme id |
|
116
|
|
|
* |
|
117
|
|
|
* @param $id Education programme id |
|
118
|
|
|
* @return array List of next education programmes id |
|
119
|
|
|
*/ |
|
120
|
|
|
public function getNextProgrammeList($id) { |
|
121
|
|
|
return Education_programmes_next_programme::where('education_programme_id',$id) |
|
|
|
|
|
|
122
|
|
|
->get()->first(); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
} |
|
127
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.