Skip to content

Commit 51d3169

Browse files
Merge pull request #7055 from christianbeeznest/GH-7054
Gradebook: Improve item display and reporting - refs #7054
2 parents 16cab1a + f927204 commit 51d3169

File tree

8 files changed

+58
-123
lines changed

8 files changed

+58
-123
lines changed

public/main/gradebook/gradebook_add_link.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
$tbl_link = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
1818

1919
$session_id = api_get_session_id();
20+
$courseRealId = (int) $course_info['real_id'];
2021
$typeSelected = isset($_GET['typeselected']) ? (int) $_GET['typeselected'] : null;
2122

2223
if (0 == $session_id) {
@@ -100,9 +101,7 @@
100101
(isset($addvalues['select_link']) && "" != $addvalues['select_link'])
101102
) {
102103
$sql1 = 'SELECT title from '.$tbl_forum_thread.'
103-
WHERE
104-
c_id = '.$course_info['real_id'].' AND
105-
iid = '.$addvalues['select_link'];
104+
WHERE iid = '.$addvalues['select_link'];
106105
$res1 = Database::query($sql1);
107106
$rowtit = Database::fetch_row($res1);
108107
$course_id = api_get_course_id();
@@ -119,9 +118,7 @@
119118
thread_qualify_max= "'.api_float_val($addvalues['weight']).'",
120119
thread_weight= "'.api_float_val($addvalues['weight']).'",
121120
thread_title_qualify = "'.$rowtit[0].'"
122-
WHERE
123-
iid ='.$addvalues['select_link'].' AND
124-
c_id = '.$course_info['real_id'].' ';
121+
WHERE iid ='.$addvalues['select_link'];
125122
Database::query($sql);
126123
}
127124
}

public/main/gradebook/gradebook_edit_all.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
foreach ($links as &$row) {
114114
$item_weight = $row['weight'];
115115
$sql = 'SELECT * FROM '.GradebookUtils::get_table_type_course($row['type']).'
116-
WHERE c_id = '.$course_id.' AND '.$table_evaluated[$row['type']][2].' = '.$row['ref_id'];
116+
WHERE '.$table_evaluated[$row['type']][2].' = '.$row['ref_id'];
117117

118118
$result = Database::query($sql);
119119
$resource_name = Database::fetch_array($result);

public/main/gradebook/lib/GradebookUtils.php

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,10 @@ public static function get_table_type_course($type)
533533
{
534534
global $table_evaluated;
535535

536+
if (!isset($table_evaluated[$type][0])) {
537+
throw new \InvalidArgumentException('Unknown evaluated type: '.$type);
538+
}
539+
536540
return Database::get_course_table($table_evaluated[$type][0]);
537541
}
538542

@@ -674,18 +678,24 @@ public static function get_list_users_certificates($cat_id = null, $userList = [
674678
{
675679
$table_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
676680
$table_user = Database::get_main_table(TABLE_MAIN_USER);
677-
$sql = 'SELECT DISTINCT u.id as user_id, u.lastname, u.firstname, u.username, gc.created_at
678-
FROM '.$table_user.' u
679-
INNER JOIN '.$table_certificate.' gc
680-
ON u.id = gc.user_id ';
681+
682+
$sql = 'SELECT DISTINCT u.id AS user_id, u.lastname, u.firstname, u.username, gc.created_at
683+
FROM '.$table_user.' u
684+
INNER JOIN '.$table_certificate.' gc ON u.id = gc.user_id';
685+
686+
$where = [];
687+
681688
if (!is_null($cat_id) && $cat_id > 0) {
682-
$sql .= ' WHERE cat_id='.intval($cat_id);
689+
$where[] = 'gc.cat_id = '.(int) $cat_id;
683690
}
684691
if (!empty($userList)) {
685-
$userList = array_map('intval', $userList);
686-
$userListCondition = implode("','", $userList);
687-
$sql .= " AND u.id IN ('$userListCondition')";
692+
$ids = array_map('intval', $userList);
693+
$where[] = 'u.id IN ('.implode(',', $ids).')';
694+
}
695+
if ($where) {
696+
$sql .= ' WHERE '.implode(' AND ', $where);
688697
}
698+
689699
$sql .= ' ORDER BY '.(api_sort_by_first_name() ? 'u.firstname' : 'u.lastname');
690700
$rs = Database::query($sql);
691701

@@ -1210,39 +1220,31 @@ public static function get_all_users($evals = [], $links = []): array
12101220
*/
12111221
public static function find_students($mask = '')
12121222
{
1213-
// students shouldn't be here // don't search if mask empty
1214-
if (!api_is_allowed_to_edit() || empty($mask)) {
1223+
if (!api_is_allowed_to_edit() || $mask === '') {
12151224
return null;
12161225
}
1226+
12171227
$mask = Database::escape_string($mask);
12181228
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
1219-
$tbl_cru = Database::get_main_table(TABLE_MAIN_COURSE_USER);
1220-
$sql = 'SELECT DISTINCT user.id as user_id, user.lastname, user.firstname, user.email, user.official_code
1221-
FROM '.$tbl_user.' user';
1222-
if (!api_is_platform_admin()) {
1223-
$sql .= ', '.$tbl_cru.' cru';
1224-
}
1229+
$tbl_cru = Database::get_main_table(TABLE_MAIN_COURSE_USER);
12251230

1226-
$sql .= ' WHERE user.status = '.STUDENT;
1227-
$sql .= ' AND (user.lastname LIKE '."'%".$mask."%'";
1228-
$sql .= ' OR user.firstname LIKE '."'%".$mask."%')";
1231+
$sql = 'SELECT DISTINCT user.id AS user_id, user.lastname, user.firstname, user.email, user.official_code
1232+
FROM '.$tbl_user.' user';
12291233

12301234
if (!api_is_platform_admin()) {
1231-
$sql .= ' AND user.id = cru.user_id AND
1232-
cru.relation_type <> '.COURSE_RELATION_TYPE_RRHH.' AND
1233-
cru.c_id in (
1234-
SELECT c_id FROM '.$tbl_cru.'
1235-
WHERE
1236-
user_id = '.api_get_user_id().' AND
1237-
status = '.COURSEMANAGER.'
1238-
)
1239-
';
1235+
$sql .= ' INNER JOIN '.$tbl_cru.' cru ON (cru.user_id = user.id)
1236+
AND cru.relation_type <> '.COURSE_RELATION_TYPE_RRHH.'
1237+
AND cru.c_id IN (
1238+
SELECT c_id FROM '.$tbl_cru.'
1239+
WHERE user_id = '.api_get_user_id().' AND status = '.COURSEMANAGER.'
1240+
)';
12401241
}
12411242

1242-
$sql .= ' ORDER BY lastname, firstname';
1243-
if (api_is_western_name_order()) {
1244-
$sql .= ' ORDER BY firstname, lastname';
1245-
}
1243+
$sql .= ' WHERE user.status = '.STUDENT.'
1244+
AND (user.lastname LIKE \'%'.$mask.'%\' OR user.firstname LIKE \'%'.$mask.'%\')';
1245+
1246+
$orderBy = api_is_western_name_order() ? 'firstname, lastname' : 'lastname, firstname';
1247+
$sql .= ' ORDER BY '.$orderBy;
12461248

12471249
$result = Database::query($sql);
12481250

@@ -1281,14 +1283,13 @@ public static function updateLinkWeight($linkId, $name, $weight)
12811283
$row_attendance = Database::fetch_array($rs_attendance);
12821284
$sql = 'UPDATE '.$tbl_attendance.' SET
12831285
attendance_weight ='.api_float_val($weight).'
1284-
WHERE c_id = '.$course_id.' AND id = '.intval($row_attendance['ref_id']);
1286+
WHERE id = '.intval($row_attendance['ref_id']);
12851287
Database::query($sql);
12861288
}
12871289
// Update weight into forum thread
12881290
$sql = 'UPDATE '.$tbl_forum_thread.' SET
12891291
thread_weight = '.api_float_val($weight).'
12901292
WHERE
1291-
c_id = '.$course_id.' AND
12921293
iid = (
12931294
SELECT ref_id FROM '.$table_link.'
12941295
WHERE id='.$linkId.' AND type='.LINK_FORUM_THREAD.'
@@ -1300,15 +1301,14 @@ public static function updateLinkWeight($linkId, $name, $weight)
13001301
->createQuery('
13011302
UPDATE ChamiloCourseBundle:CStudentPublication w
13021303
SET w.weight = :final_weight
1303-
WHERE w.cId = :course
1304-
AND w.iid = (
1304+
WHERE
1305+
w.iid = (
13051306
SELECT l.refId FROM ChamiloCoreBundle:GradebookLink l
13061307
WHERE l.id = :link AND l.type = :type
13071308
)
13081309
')
13091310
->execute([
13101311
'final_weight' => $weight,
1311-
'course' => $course_id,
13121312
'link' => $linkId,
13131313
'type' => LINK_STUDENTPUBLICATION,
13141314
]);

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

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,6 @@ public function get_all_links(): array
5353
$qb = $repo->getResourcesByCourse(api_get_course_entity($this->course_id), api_get_session_entity($sessionId));
5454
$qb->andWhere('resource.active = 1');
5555
$links = $qb->getQuery()->getResult();
56-
57-
/*$tbl_attendance = $this->get_attendance_table();
58-
$sql = 'SELECT att.iid, att.title, att.attendance_qualify_title
59-
FROM '.$tbl_attendance.' att
60-
WHERE
61-
att.c_id = '.$this->course_id.' AND
62-
att.active = 1 AND
63-
att.session_id = '.$sessionId;
64-
$result = Database::query($sql);*/
6556
$cats = [];
6657
/** @var CAttendance $link */
6758
foreach ($links as $link) {
@@ -86,9 +77,7 @@ public function has_results(): bool
8677
$sessionId = $this->get_session_id();
8778

8879
$sql = 'SELECT count(*) AS number FROM '.$tbl_attendance_result."
89-
WHERE
90-
session_id = $sessionId AND
91-
attendance_id = ".$this->get_ref_id();
80+
WHERE attendance_id = ".$this->get_ref_id();
9281
$result = Database::query($sql);
9382
$number = Database::fetch_row($result);
9483

@@ -109,8 +98,7 @@ public function calc_score(?int $studentId = null, ?string $type = null): array
10998
// get attendance qualify max
11099
$sql = 'SELECT attendance_qualify_max
111100
FROM '.$this->get_attendance_table().'
112-
WHERE
113-
iid = '.$this->get_ref_id();
101+
WHERE iid = '.$this->get_ref_id();
114102
$query = Database::query($sql);
115103
$attendance = Database::fetch_assoc($query);
116104

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ public function get_view_url($stud_id)
2929
// with the same title as the evaluation name
3030

3131
$eval = $this->get_evaluation();
32-
$sql = 'SELECT filename FROM '.$this->get_dropbox_table().'
33-
WHERE
34-
c_id = '.$this->course_id.' AND
35-
uploader_id = '.intval($stud_id)." AND
32+
$sql = 'SELECT filename FROM '.$this->get_dropbox_table().'
33+
WHERE
34+
uploader_id = '.intval($stud_id)." AND
3635
title = '".Database::escape_string($eval->get_name())."'";
3736

3837
$result = Database::query($sql);

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,7 @@ public function calc_score($studentId = null, $type = null)
267267
$sql = "SELECT * FROM $tblHp hp
268268
INNER JOIN $tblDoc doc
269269
ON (hp.title = doc.path)
270-
WHERE
271-
hp.c_id = $courseId AND
272-
doc.iid = $exerciseId";
270+
WHERE doc.iid = $exerciseId";
273271

274272
if (!empty($studentId)) {
275273
$sql .= " AND hp.exe_user_id = $studentId ";

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

Lines changed: 10 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -52,28 +52,13 @@ public function get_all_links()
5252

5353
$tbl_grade_links = Database::get_course_table(TABLE_FORUM_THREAD);
5454
$sessionId = $this->get_session_id();
55-
56-
if ($sessionId) {
57-
$session_condition = 'tl.session_id='.$sessionId;
58-
} else {
59-
$session_condition = '(tl.session_id = 0 OR tl.session_id IS NULL)';
60-
}
61-
6255
$repo = Container::getForumThreadRepository();
6356
$course = api_get_course_entity($this->course_id);
6457
$session = api_get_session_entity($sessionId);
6558

6659
$qb = $repo->findAllByCourse($course, $session);
6760
/** @var CForumThread[] $threads */
6861
$threads = $qb->getQuery()->getResult();
69-
70-
/*$sql = 'SELECT tl.iid as thread_id, tl.thread_title, tl.thread_title_qualify
71-
FROM '.$tbl_grade_links.' tl
72-
WHERE
73-
tl.c_id = '.$this->course_id.' AND
74-
'.$session_condition.'
75-
';
76-
$result = Database::query($sql);*/
7762
$cats = [];
7863
foreach ($threads as $thread) {
7964
$title = $thread->getTitle();
@@ -97,10 +82,7 @@ public function has_results()
9782
$table = Database::get_course_table(TABLE_FORUM_POST);
9883

9984
$sql = "SELECT count(*) AS number FROM $table
100-
WHERE
101-
c_id = ".$this->course_id." AND
102-
iid = '".$this->get_ref_id()."'
103-
";
85+
WHERE iid = '".$this->get_ref_id();
10486
$result = Database::query($sql);
10587
$number = Database::fetch_row($result);
10688

@@ -126,21 +108,13 @@ public function calc_score($studentId = null, $type = null)
126108
);
127109

128110
$sql = 'SELECT thread_qualify_max
129-
FROM '.Database::get_course_table(TABLE_FORUM_THREAD)."
130-
WHERE
131-
c_id = ".$this->course_id." AND
132-
iid = '".$this->get_ref_id()."'
133-
$sessionCondition
134-
";
111+
FROM '.Database::get_course_table(TABLE_FORUM_THREAD).'
112+
WHERE iid = '.$this->get_ref_id();
135113
$query = Database::query($sql);
136114
$assignment = Database::fetch_array($query);
137115

138116
$sql = "SELECT * FROM $thread_qualify
139-
WHERE
140-
c_id = ".$this->course_id." AND
141-
iid = ".$this->get_ref_id()."
142-
$sessionCondition
143-
";
117+
WHERE iid = ".$this->get_ref_id();
144118
if (isset($studentId)) {
145119
$sql .= ' AND user_id = '.intval($studentId);
146120
}
@@ -270,10 +244,7 @@ public function is_valid_link()
270244
{
271245
$sessionId = $this->get_session_id();
272246
$sql = 'SELECT count(iid) FROM '.$this->get_forum_thread_table().'
273-
WHERE
274-
c_id = '.$this->course_id.' AND
275-
iid = '.$this->get_ref_id().' AND
276-
session_id='.$sessionId;
247+
WHERE iid = '.$this->get_ref_id();
277248
$result = Database::query($sql);
278249
$number = Database::fetch_row($result);
279250

@@ -283,11 +254,8 @@ public function is_valid_link()
283254
public function get_link()
284255
{
285256
$sessionId = $this->get_session_id();
286-
$sql = 'SELECT * FROM '.$this->get_forum_thread_table()."
287-
WHERE
288-
c_id = {$this->course_id} AND
289-
iid = '".$this->get_ref_id()."' AND
290-
session_id = $sessionId ";
257+
$sql = 'SELECT * FROM '.$this->get_forum_thread_table().'
258+
WHERE iid = '.$this->get_ref_id();
291259
$result = Database::query($sql);
292260
$row = Database::fetch_assoc($result);
293261

@@ -315,7 +283,7 @@ public function save_linked_data()
315283
if (!empty($ref_id)) {
316284
$sql = 'UPDATE '.$this->get_forum_thread_table().' SET
317285
thread_weight='.api_float_val($weight).'
318-
WHERE c_id = '.$this->course_id.' AND iid = '.$ref_id;
286+
WHERE iid = '.$ref_id;
319287
Database::query($sql);
320288
}
321289
}
@@ -329,7 +297,7 @@ public function delete_linked_data()
329297
thread_qualify_max = 0,
330298
thread_weight = 0,
331299
thread_title_qualify = ""
332-
WHERE c_id = '.$this->course_id.' AND iid = '.$ref_id;
300+
WHERE iid = '.$ref_id;
333301
Database::query($sql);
334302
}
335303
}
@@ -344,19 +312,9 @@ private function get_forum_thread_table()
344312

345313
private function getThreadData()
346314
{
347-
$sessionId = $this->get_session_id();
348-
if ($sessionId) {
349-
$session_condition = 'session_id = '.$sessionId;
350-
} else {
351-
$session_condition = '(session_id = 0 OR session_id IS NULL)';
352-
}
353-
354315
if (!isset($this->exercise_data)) {
355316
$sql = 'SELECT * FROM '.$this->get_forum_thread_table().'
356-
WHERE
357-
c_id = '.$this->course_id.' AND
358-
iid = '.$this->get_ref_id().' AND
359-
'.$session_condition;
317+
WHERE iid = '.$this->get_ref_id();
360318
$query = Database::query($sql);
361319
$this->exercise_data = Database::fetch_array($query);
362320
}

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,9 @@ public function calc_score($studentId = null, $type = null)
8080
{
8181
$tbl_stats = Database::get_course_table(TABLE_LP_VIEW);
8282
$session_id = $this->get_session_id();
83-
if (empty($session_id)) {
84-
$session_id = api_get_session_id();
85-
}
8683

8784
$sql = "SELECT * FROM $tbl_stats
88-
WHERE
89-
lp_id = ".$this->get_ref_id()." AND
90-
session_id = $session_id ";
85+
WHERE lp_id = ".$this->get_ref_id();
9186

9287
if (isset($studentId)) {
9388
$sql .= ' AND user_id = '.intval($studentId);

0 commit comments

Comments
 (0)