Skip to content

Commit 145daaf

Browse files
Gradebook: Fix session handling for surveys and student publications - refs BT#22564
1 parent 9254814 commit 145daaf

File tree

5 files changed

+148
-237
lines changed

5 files changed

+148
-237
lines changed

public/main/gradebook/lib/be/studentpublicationlink.class.php

+11-82
Original file line numberDiff line numberDiff line change
@@ -46,28 +46,9 @@ public function get_all_links()
4646

4747
$sessionId = $this->get_session_id();
4848
$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 != ''
6049
$repo = Container::getStudentPublicationRepository();
6150
$qb = $repo->findAllByCourse(api_get_course_entity($this->course_id), $session, null, 1, 'folder');
6251
$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-
]);*/
7152
$cats = [];
7253
foreach ($links as $data) {
7354
$work_name = $data->getTitle();
@@ -93,10 +74,8 @@ public function has_results()
9374
$id = $studentPublication->getIid();
9475
$session = api_get_session_entity($this->get_session_id());
9576
$results = Container::getStudentPublicationRepository()
96-
->findBy([
97-
'parentId' => $id,
98-
'session' => $session,
99-
]);
77+
->getStudentAssignments($studentPublication, api_get_course_entity($this->course_id), $session);
78+
10079

10180
return 0 !== count($results);
10281
}
@@ -109,76 +88,30 @@ public function has_results()
10988
public function calc_score($studentId = null, $type = null)
11089
{
11190
$studentId = (int) $studentId;
112-
$em = Database::getManager();
11391
$assignment = $this->getStudentPublication();
11492

11593
if (empty($assignment)) {
11694
return [];
11795
}
11896
$session = api_get_session_entity($this->get_session_id());
97+
$course = api_get_course_entity($this->course_id);
11998

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);
166101

167102
$order = api_get_setting('student_publication_to_take_in_gradebook');
168103

169104
switch ($order) {
170105
case 'last':
171-
// latest attempt
172-
$dql .= ' ORDER BY a.sentDate DESC';
106+
$qb->orderBy('resource.sentDate', 'DESC');
173107
break;
174108
case 'first':
175109
default:
176-
// first attempt
177-
$dql .= ' ORDER BY a.iid';
110+
$qb->orderBy('resource.iid', 'ASC');
178111
break;
179112
}
180113

181-
$scores = $em->createQuery($dql)->execute($params);
114+
$scores = $qb->getQuery()->getResult();
182115

183116
// for 1 student
184117
if (!empty($studentId)) {
@@ -196,16 +129,16 @@ public function calc_score($studentId = null, $type = null)
196129
];
197130
}
198131

199-
$students = []; // user list, needed to make sure we only
200-
// take first attempts into account
132+
// multiple students
133+
$students = [];
201134
$rescount = 0;
202135
$sum = 0;
203136
$bestResult = 0;
204137
$weight = 0;
205138
$sumResult = 0;
206139

207140
foreach ($scores as $data) {
208-
if (!(array_key_exists($data->getUserId(), $students))) {
141+
if (!array_key_exists($data->getUserId(), $students)) {
209142
if (0 != $assignment->getQualification()) {
210143
$students[$data->getUserId()] = $data->getQualification();
211144
$rescount++;
@@ -227,16 +160,12 @@ public function calc_score($studentId = null, $type = null)
227160
switch ($type) {
228161
case 'best':
229162
return [$bestResult, $weight];
230-
break;
231163
case 'average':
232164
return [$sumResult / $rescount, $weight];
233-
break;
234165
case 'ranking':
235166
return AbstractLink::getCurrentUserRanking($studentId, $students);
236-
break;
237167
default:
238168
return [$sum, $rescount];
239-
break;
240169
}
241170
}
242171

0 commit comments

Comments
 (0)