FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Module-Note/models/Student.php at master · BHafsa/Module-Note · GitHub
BHafsa
/
Module-Note
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Module-Note
/
models
/
Student.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
203 lines (182 loc) · 5.79 KB
Breadcrumbs
Module-Note
/
models
/
Student.php
Copy path
File metadata and controls
203 lines (182 loc) · 5.79 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php
namespace
humhub
\
modules
\
note
\
models
;
use
Yii
;
/**
* This is the model class for table "student".
*
* @property integer $student_id
* @property string $registration_number
* @property string $date_of_birth
* @property string $place_of_birth
* @property string $admission_date
* @property integer $class_group_id
* @property integer $user_id
*/
class
Student
extends
\
yii
\
db
\ActiveRecord
{
/**
* @inheritdoc
*/
public
static
function
tableName
()
{
return
'
student
'
;
}
/**
* @inheritdoc
*/
public
function
rules
()
{
return
[
[[
'
registration_number
'
,
'
date_of_birth
'
,
'
place_of_birth
'
,
'
class_group_id
'
,
'
user_id
'
],
'
required
'
],
[[
'
date_of_birth
'
,
'
admission_date
'
],
'
safe
'
],
[[
'
class_group_id
'
,
'
user_id
'
],
'
integer
'
],
[[
'
registration_number
'
,
'
place_of_birth
'
],
'
string
'
,
'
max
'
=>
15
],
[[
'
registration_number
'
],
'
unique
'
],
];
}
/**
* @inheritdoc
*/
public
function
attributeLabels
()
{
return
[
'
student_id
'
=>
'
Student ID
'
,
'
registration_number
'
=>
'
Registration Number
'
,
'
date_of_birth
'
=>
'
Date Of Birth
'
,
'
place_of_birth
'
=>
'
Place Of Birth
'
,
'
admission_date
'
=>
'
Admission Date
'
,
'
class_group_id
'
=>
'
Class Group ID
'
,
'
user_id
'
=>
'
User ID
'
,
];
}
/**
* @return \yii\db\ActiveQuery
*/
public
function
getClassGroup
()
{
return
$
this
->
hasOne
(ClassGroup::
className
(), [
'
class_group_id
'
=>
'
class_group_id
'
]);
}
/**
* @return \yii\db\ActiveQuery
*/
public
function
getUser
()
{
return
$
this
->
hasOne
(User::
className
(), [
'
id
'
=>
'
user_id
'
]);
}
/**
* @return array|ActiveRecord[]
*/
public
function
getSchoolYears
()
{
return
GradeReport::
find
()->
asArray
()
->
select
([
'
date
'
])
->
where
([
'
student_id
'
=>
$
this
->
student_id
])
->
groupBy
(
'
date
'
)
->
all
();
}
public
function
getYear
()
{
return
$
this
->
classGroup
->
level
->
year
;
}
public
function
getOption
()
{
return
$
this
->
classGroup
->
level
->
option
;
}
/**
* @param $schoolYear
* @param string $semester
* @return array
*/
public
function
getCourses
(
$
schoolYear
,
$
semester
=
''
)
{
return
$
this
->
getCoursesQuery
(
$
schoolYear
,
$
semester
)->
all
();
}
public
function
calculateSemesterScore
(
$
schoolYear
,
$
semester
=
''
)
{
return
round
(
$
this
->
getCoursesQuery
(
$
schoolYear
,
$
semester
)
->
select
(
'
sum(value * coefficient) / sum(coefficient) as score
'
)
->
createCommand
()->
queryScalar
(),
2
);
}
public
function
calculateGeneralScore
(
$
schoolYear
)
{
return
round
((
$
this
->
calculateSemesterScore
(
$
schoolYear
,
0
) +
$
this
->
calculateSemesterScore
(
$
schoolYear
,
1
)) /
2
,
2
);
}
/**
* @param $schoolYear
* @return array|Student[]
*/
public
function
getClassStudents
(
$
schoolYear
)
{
return
$
this
->
getClassQuery
(
$
schoolYear
)->
all
();
}
public
function
getRank
(
$
schoolYear
)
{
$
classStudents
=
$
this
->
getClassStudents
(
$
schoolYear
);
$
generalScore
=
$
this
->
calculateGeneralScore
(
$
schoolYear
);
$
rank
=
1
;
foreach
(
$
classStudents
as
$
student
) {
if
(
$
student
->
calculateGeneralScore
(
$
schoolYear
) >
$
generalScore
) {
$
rank
++;
}
}
return
$
rank
;
}
public
function
getClassCount
(
$
schoolYear
)
{
return
self
::
find
()->
select
(
'
count(*)
'
)
->
from
(
'
(
'
.
$
this
->
getClassQuery
(
$
schoolYear
)->
createCommand
()->
sql
.
'
) x
'
)
->
createCommand
()->
queryScalar
();
}
/**
* @param $schoolYear
* @param string $semester
* @return \yii\db\ActiveQuery
*/
private
function
getCoursesQuery
(
$
schoolYear
,
$
semester
=
''
)
{
return
EducationalUnit::
find
()
->
select
([
'
nature
'
,
'
code
'
,
'
semester
'
,
'
designation
'
,
'
coefficient
'
,
'
value
'
])
->
asArray
()
->
join
(
'
JOIN
'
,
Course::
tableName
(),
EducationalUnit::
tableName
() .
'
.educational_unit_id=
'
. Course::
tableName
() .
'
.educational_unit_id
'
)->
join
(
'
JOIN
'
,
GradeReport::
tableName
(),
[
'
AND
'
,
GradeReport::
tableName
() .
'
.student_id=
'
.
$
this
->
student_id
,
GradeReport::
tableName
() .
'
.course_id=
'
. Course::
tableName
() .
'
.course_id
'
,
GradeReport::
tableName
() .
'
.date=
'
.
$
schoolYear
]
)->
join
(
'
JOIN
'
,
Grade::
tableName
(),
GradeReport::
tableName
() .
'
.grade_id=
'
. Grade::
tableName
() .
'
.grade_id
'
)->
andFilterWhere
([
'
semester
'
=>
$
semester
]);
}
private
function
getClassQuery
(
$
schoolYear
)
{
return
Student::
find
()
->
join
(
'
JOIN
'
,
ClassGroup::
tableName
(),
Student::
tableName
() .
'
.class_group_id=
'
. ClassGroup::
tableName
() .
'
.class_group_id
'
)->
join
(
'
JOIN
'
,
Level::
tableName
(),
[
'
AND
'
,
Level::
tableName
() .
'
.level_id=
'
. ClassGroup::
tableName
() .
'
.level_id
'
,
Level::
tableName
() .
'
.year=
'
.
"
'
"
.
$
this
->
year
.
"
'
"
,
]
)->
join
(
'
JOIN
'
,
GradeReport::
tableName
(),
[
'
AND
'
,
GradeReport::
tableName
() .
'
.student_id=
'
. Student::
tableName
() .
'
.student_id
'
,
GradeReport::
tableName
() .
'
.date=
'
.
$
schoolYear
,
]
)->
groupBy
(Student::
tableName
() .
'
.student_id
'
);
}
}
Back
|
FazBrowse Home
|
New Git URL