Issues (367)

app/Models/Institution_grade.php (7 issues)

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)
0 ignored issues
show
The assignment to $classes is dead and can be removed.
Loading history...
49
            ->where('institution_id', '=', $grade->institution_id)->get();
50
        return true;
51
    }
52
53
    /**
54
     * @param $id
55
     */
56
    public function getNumberOfParallelClasses($id)
0 ignored issues
show
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

56
    public function getNumberOfParallelClasses(/** @scrutinizer ignore-unused */ $id)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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
0 ignored issues
show
Documentation Bug introduced by
The doc comment |null at position 0 could not be parsed: Unknown type name '|' at position 0 in |null.
Loading history...
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
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $institution is correct as it would always require null to be passed?
Loading history...
117
     * @return mixed
118
     */
119
    public function getInstitutionGradeToPromoted($year, $institution = null, $mode)
120
    {
121
        $data = array();
0 ignored issues
show
The assignment to $data is dead and can be removed.
Loading history...
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) {
0 ignored issues
show
The import $year is not used and could be removed.

This check looks for imports that have been defined, but are not used in the scope.

Loading history...
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
                $query->whereNotIn('education_grades.id',[29,34]);
138
                break;
139
            case 'AL':
140
                $query->where('education_programmes.education_cycle_id', 4);
141
                break; 
142
            case 'SP':
143
                $query->where('education_programmes.education_cycle_id', 7);
144
                break;
145
        }
146
        $data = $query->groupBy('institution_grades.id')
147
            ->get()->toArray();
148
        return $data;
149
    }
150
151
    /**
152
     * @param $year
153
     * @return mixed
154
     */
155
    public function getInstitutionGradeList($year, $limit,$mode)
156
    {
157
        $query = $this->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) {
0 ignored issues
show
The import $year is not used and could be removed.

This check looks for imports that have been defined, but are not used in the scope.

Loading history...
161
                $join->on('institutions.id', '=', 'institution_grades.institution_id');
162
            })
163
            ->join('education_programmes', 'education_grades.education_programme_id', 'education_programmes.id');
164
            switch ($mode) {
165
                case '1-5':
166
                    $query->whereIn('education_programmes.education_cycle_id', [1,2]);
167
                    break;
168
                case '6-11':
169
                    $query->whereIn('education_programmes.education_cycle_id', [2,3,4]);
170
                    break;
171
                case 'AL':
172
                    $query->where('education_programmes.education_cycle_id', 4);
173
                    break; 
174
                case 'SP':
175
                    $query->where('education_programmes.education_cycle_id', 7);
176
                    break;
177
            }
178
            $data = $query->groupBy('institutions.id')
179
                ->limit($limit)
180
                ->get()->toArray();
181
            return $data;
182
    }
183
184
    public function getGradeSubjects($institutionId){
185
        return self::query()
186
        ->select('institution_grades.institution_id','education_grades_subjects.education_grade_id','education_grades_subjects.education_subject_id','education_subjects.name')
187
        ->where('institution_grades.institution_id',$institutionId)
188
        ->join('education_grades', 'institution_grades.education_grade_id', 'education_grades.id')
189
        ->join('education_grades_subjects','education_grades.id','education_grades_subjects.education_grade_id')
190
        ->join('education_subjects','education_grades_subjects.education_subject_id','education_subjects.id')
191
        ->groupBy('education_grades_subjects.id')
192
        ->get()
193
        ->toArray();
194
    }
195
}
196