Test Setup Failed
Pull Request — master (#620)
by Mohamed
08:18
created

Institution_grade::getGradeSubjects()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 2 Features 0
Metric Value
cc 1
eloc 9
c 2
b 2
f 0
nc 1
nop 1
dl 0
loc 10
rs 9.9666
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
Unused Code introduced by
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
Unused Code introduced by
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
Unused Code introduced by
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
Unused Code introduced by
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
                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) {
0 ignored issues
show
Unused Code introduced by
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
            ->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