@@ -46,28 +46,9 @@ public function get_all_links()
46
46
47
47
$ sessionId = $ this ->get_session_id ();
48
48
$ session = api_get_session_entity ($ sessionId );
49
- /*
50
- if (empty($session_id)) {
51
- $session_condition = api_get_session_condition(0, true);
52
- } else {
53
- $session_condition = api_get_session_condition($session_id, true, true);
54
- }
55
- $sql = "SELECT id, url, title FROM $tbl_grade_links
56
- WHERE c_id = {$this->course_id} AND filetype='folder' AND active = 1 $session_condition ";*/
57
-
58
- //Only show works from the session
59
- //AND has_properties != ''
60
49
$ repo = Container::getStudentPublicationRepository ();
61
50
$ qb = $ repo ->findAllByCourse (api_get_course_entity ($ this ->course_id ), $ session , null , 1 , 'folder ' );
62
51
$ links = $ qb ->getQuery ()->getResult ();
63
-
64
- /*$links = Container::getStudentPublicationRepository()
65
- ->findBy([
66
- 'cId' => $this->course_id,
67
- 'active' => true,
68
- 'filetype' => 'folder',
69
- 'session' => $session,
70
- ]);*/
71
52
$ cats = [];
72
53
foreach ($ links as $ data ) {
73
54
$ work_name = $ data ->getTitle ();
@@ -93,10 +74,8 @@ public function has_results()
93
74
$ id = $ studentPublication ->getIid ();
94
75
$ session = api_get_session_entity ($ this ->get_session_id ());
95
76
$ results = Container::getStudentPublicationRepository ()
96
- ->findBy ([
97
- 'parentId ' => $ id ,
98
- 'session ' => $ session ,
99
- ]);
77
+ ->getStudentAssignments ($ studentPublication , api_get_course_entity ($ this ->course_id ), $ session );
78
+
100
79
101
80
return 0 !== count ($ results );
102
81
}
@@ -109,76 +88,30 @@ public function has_results()
109
88
public function calc_score ($ studentId = null , $ type = null )
110
89
{
111
90
$ studentId = (int ) $ studentId ;
112
- $ em = Database::getManager ();
113
91
$ assignment = $ this ->getStudentPublication ();
114
92
115
93
if (empty ($ assignment )) {
116
94
return [];
117
95
}
118
96
$ session = api_get_session_entity ($ this ->get_session_id ());
97
+ $ course = api_get_course_entity ($ this ->course_id );
119
98
120
- // @todo check session id / course id access
121
- /*$id = $studentPublication->getIid();
122
- $assignment = Container::getStudentPublicationRepository()
123
- ->findOneBy([
124
- 'cId' => $this->course_id,
125
- 'iid' => $id,
126
- 'session' => $session,
127
- ])
128
- ;
129
- $parentId = !$assignment ? 0 : $assignment->getId();
130
- */
131
-
132
- $ parentId = $ assignment ->getIid ();
133
-
134
- if (empty ($ session )) {
135
- $ dql = 'SELECT a FROM ChamiloCourseBundle:CStudentPublication a
136
- WHERE
137
- a.active = :active AND
138
- a.publicationParent = :parent AND
139
- a.session is null AND
140
- a.qualificatorId <> 0
141
- ' ;
142
- $ params = [
143
- 'parent ' => $ parentId ,
144
- 'active ' => true ,
145
- ];
146
- } else {
147
- $ dql = 'SELECT a FROM ChamiloCourseBundle:CStudentPublication a
148
- WHERE
149
- a.active = :active AND
150
- a.publicationParent = :parent AND
151
- a.session = :session AND
152
- a.qualificatorId <> 0
153
- ' ;
154
-
155
- $ params = [
156
- 'parent ' => $ parentId ,
157
- 'session ' => $ session ,
158
- 'active ' => true ,
159
- ];
160
- }
161
-
162
- if (!empty ($ studentId )) {
163
- $ dql .= ' AND a.userId = :student ' ;
164
- $ params ['student ' ] = $ studentId ;
165
- }
99
+ $ qb = Container::getStudentPublicationRepository ()
100
+ ->getStudentAssignments ($ assignment , $ course , $ session , null , $ studentId ? api_get_user_entity ($ studentId ) : null );
166
101
167
102
$ order = api_get_setting ('student_publication_to_take_in_gradebook ' );
168
103
169
104
switch ($ order ) {
170
105
case 'last ' :
171
- // latest attempt
172
- $ dql .= ' ORDER BY a.sentDate DESC ' ;
106
+ $ qb ->orderBy ('resource.sentDate ' , 'DESC ' );
173
107
break ;
174
108
case 'first ' :
175
109
default :
176
- // first attempt
177
- $ dql .= ' ORDER BY a.iid ' ;
110
+ $ qb ->orderBy ('resource.iid ' , 'ASC ' );
178
111
break ;
179
112
}
180
113
181
- $ scores = $ em -> createQuery ( $ dql )->execute ( $ params );
114
+ $ scores = $ qb -> getQuery ( )->getResult ( );
182
115
183
116
// for 1 student
184
117
if (!empty ($ studentId )) {
@@ -196,16 +129,16 @@ public function calc_score($studentId = null, $type = null)
196
129
];
197
130
}
198
131
199
- $ students = []; // user list, needed to make sure we only
200
- // take first attempts into account
132
+ // multiple students
133
+ $ students = [];
201
134
$ rescount = 0 ;
202
135
$ sum = 0 ;
203
136
$ bestResult = 0 ;
204
137
$ weight = 0 ;
205
138
$ sumResult = 0 ;
206
139
207
140
foreach ($ scores as $ data ) {
208
- if (!( array_key_exists ($ data ->getUserId (), $ students) )) {
141
+ if (!array_key_exists ($ data ->getUserId (), $ students )) {
209
142
if (0 != $ assignment ->getQualification ()) {
210
143
$ students [$ data ->getUserId ()] = $ data ->getQualification ();
211
144
$ rescount ++;
@@ -227,16 +160,12 @@ public function calc_score($studentId = null, $type = null)
227
160
switch ($ type ) {
228
161
case 'best ' :
229
162
return [$ bestResult , $ weight ];
230
- break ;
231
163
case 'average ' :
232
164
return [$ sumResult / $ rescount , $ weight ];
233
- break ;
234
165
case 'ranking ' :
235
166
return AbstractLink::getCurrentUserRanking ($ studentId , $ students );
236
- break ;
237
167
default :
238
168
return [$ sum , $ rescount ];
239
- break ;
240
169
}
241
170
}
242
171
0 commit comments