Institution_subject   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Importance

Changes 2
Bugs 2 Features 0
Metric Value
eloc 31
c 2
b 2
f 0
dl 0
loc 87
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A institutionOptionalGradeSubject() 0 2 1
A institutionGradeSubject() 0 2 1
A institutionClassSubject() 0 2 1
A institutionMandatoryGradeSubject() 0 2 1
A getStudentsCount() 0 21 1
A getInstitutionSubjects() 0 7 1
1
<?php
2
3
namespace App\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class Institution_subject extends Base_Model  {
8
9
    /**
10
     * The database table used by the model.
11
     *
12
     * @var string
13
     */
14
    protected $table = 'institution_subjects';
15
16
    /**
17
     * Attributes that should be mass-assignable.
18
     *
19
     * @var array
20
     */
21
    protected $fillable = ['name', 'no_of_seats', 'total_male_students', 'total_female_students', 'institution_id', 'education_grade_id', 'education_subject_id', 'academic_period_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', 'modified', 'created'];
43
44
45
    public  function institutionGradeSubject(){
46
        return $this->belongsTo('App\Models\Education_grades_subject','education_subject_id','education_subject_id');
47
    }
48
49
    public  function institutionOptionalGradeSubject(){
50
        return $this->belongsTo('App\Models\Education_grades_subject','education_grade_id','education_grade_id');
51
    }
52
53
    public  function institutionMandatoryGradeSubject(){
54
        return $this->belongsTo('App\Models\Education_grades_subject','education_grade_id','education_grade_id');
55
    }
56
57
58
    public  function institutionClassSubject(){
59
        return $this->hasMany('App\Models\Institution_class_subject','institution_class_id','id');
60
    }
61
62
63
64
    public function getInstitutionSubjects($institution_id,$academic_period_id){
65
        $query =  self::query()->where('institution_id',$institution_id)
66
            ->where('academic_period_id',$academic_period_id)
67
            ->join('education_grades_subjects','institution_subjects.education_subject_id','education_grades_subjects.id')
68
            ->join('education_grades', 'education_grades_subjects.education_grade_id', 'education_grades.id')
69
            ->groupBy('education_grades_subjects.id');
70
        return $query->get()->toArray();
71
    }
72
73
    public  static function getStudentsCount($institution_subject_id)
74
    {
75
        $total_male_students = self::with(['student' => function ($query) {
76
            $query->where('student.gender_id', '=', 1);
77
        }])->whereHas('student', function ($query) {
78
            $query->where('gender_id', '=', 1);
79
        })->where('institution_subject_id', '=', $institution_subject_id)->count();
80
81
        $total_female_students = self::with(['student' => function ($query) {
82
            $query->where('student.gender_id', '=', 2);
83
        }])->whereHas('student', function ($query) {
84
            $query->where('gender_id', '=', 2);
85
        })->where('institution_subject_id', '=', $institution_subject_id)->count();
86
87
        $totalStudents = $total_female_students + $total_male_students;
88
89
90
        return [
91
            'total' => $totalStudents,
92
            'total_female_students' => $total_female_students,
93
            'total_male_students' => $total_male_students
94
        ];
95
    }
96
97
98
}
99