Quiz: Get the first LP found matching the session ID - refs BT#17140

pull/3223/head
Angel Fernando Quiroz Campos 5 years ago
parent 1d8820f670
commit 85bb9800bc
  1. 38
      main/exercise/exercise.class.php
  2. 28
      main/gradebook/exercise_jump.php
  3. 27
      main/gradebook/lib/be/exerciselink.class.php

@ -160,6 +160,7 @@ class Exercise
{ {
$table = Database::get_course_table(TABLE_QUIZ_TEST); $table = Database::get_course_table(TABLE_QUIZ_TEST);
$tableLpItem = Database::get_course_table(TABLE_LP_ITEM); $tableLpItem = Database::get_course_table(TABLE_LP_ITEM);
$tblLp = Database::get_course_table(TABLE_LP_MAIN);
$id = (int) $id; $id = (int) $id;
if (empty($this->course_id)) { if (empty($this->course_id)) {
@ -218,12 +219,13 @@ class Exercise
$this->showPreviousButton = $object->show_previous_button == 1 ? true : false; $this->showPreviousButton = $object->show_previous_button == 1 ? true : false;
} }
$sql = "SELECT lp_id, max_score $sql = "SELECT lpi.lp_id, lpi.max_score, lp.session_id
FROM $tableLpItem FROM $tableLpItem lpi
INNER JOIN $tblLp lp ON (lpi.lp_id = lp.iid AND lpi.c_id = lp.c_id)
WHERE WHERE
c_id = {$this->course_id} AND lpi.c_id = {$this->course_id} AND
item_type = '".TOOL_QUIZ."' AND lpi.item_type = '".TOOL_QUIZ."' AND
path = '".$id."'"; lpi.path = '$id'";
$result = Database::query($sql); $result = Database::query($sql);
if (Database::num_rows($result) > 0) { if (Database::num_rows($result) > 0) {
@ -8327,7 +8329,7 @@ class Exercise
$lpId = null; $lpId = null;
if (!empty($this->lpList)) { if (!empty($this->lpList)) {
// Taking only the first LP // Taking only the first LP
$lpId = current($this->lpList); $lpId = $this->getLpBySession($sessionId);
$lpId = $lpId['lp_id']; $lpId = $lpId['lp_id'];
} }
@ -10225,4 +10227,28 @@ class Exercise
return $group; return $group;
} }
/**
* Get the first LP found matching the session ID.
*
* @param int $sessionId
*
* @return array
*/
public function getLpBySession($sessionId)
{
if (empty($this->lpList)) {
return [];
}
$sessionId = (int) $sessionId;
foreach ($this->lpList as $lp) {
if ((int) $lp['session_id'] == $sessionId) {
return $lp;
}
}
return [];
}
} }

@ -55,23 +55,17 @@ if (!empty($doExerciseUrl)) {
if (!empty($exercise->id)) { if (!empty($exercise->id)) {
if ($exercise->exercise_was_added_in_lp) { if ($exercise->exercise_was_added_in_lp) {
if (!empty($exercise->lpList)) { if (!empty($exercise->lpList)) {
$count = count($exercise->lpList); // If the exercise was added once redirect to the LP
if ($count == 1) { $firstLp = $exercise->getLpBySession($session_id);
// If the exercise was added once redirect to the LP if (isset($firstLp['lp_id'])) {
$firstLp = current($exercise->lpList); $url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq().'&'
if (isset($firstLp['lp_id'])) { .http_build_query(
$url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq().'&' [
.http_build_query( 'lp_id' => $firstLp['lp_id'],
[ 'action' => 'view',
'lp_id' => $firstLp['lp_id'], 'isStudentView' => 'true',
'action' => 'view', ]
'isStudentView' => 'true', );
]
);
}
} else {
// If the exercise was added multiple times show the LP list
$url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq().'&action=list';
} }
} }
} else { } else {

@ -60,25 +60,25 @@ class ExerciseLink extends AbstractLink
$sql = 'SELECT iid, title FROM '.$exerciseTable.' $sql = 'SELECT iid, title FROM '.$exerciseTable.'
WHERE c_id = '.$this->course_id.' AND active=1 '.$session_condition; WHERE c_id = '.$this->course_id.' AND active=1 '.$session_condition;
$sqlLp = "SELECT e.iid, e.title $sqlLp = "SELECT e.iid, e.title
FROM $exerciseTable e FROM $exerciseTable e
INNER JOIN $lpItemTable i INNER JOIN $lpItemTable i
ON (e.c_id = i.c_id AND e.id = i.path) ON (e.c_id = i.c_id AND e.id = i.path)
WHERE WHERE
e.c_id = $this->course_id AND e.c_id = $this->course_id AND
active = 0 AND active = 0 AND
item_type = 'quiz' item_type = 'quiz'
$session_condition"; $session_condition";
$sql2 = "SELECT d.path as path, d.comment as comment, ip.visibility as visibility, d.id $sql2 = "SELECT d.path as path, d.comment as comment, ip.visibility as visibility, d.id
FROM $TBL_DOCUMENT d FROM $TBL_DOCUMENT d
INNER JOIN $tableItemProperty ip INNER JOIN $tableItemProperty ip
ON (d.id = ip.ref AND d.c_id = ip.c_id) ON (d.id = ip.ref AND d.c_id = ip.c_id)
WHERE WHERE
d.c_id = $this->course_id AND d.c_id = $this->course_id AND
ip.c_id = $this->course_id AND ip.c_id = $this->course_id AND
ip.tool = '".TOOL_DOCUMENT."' AND ip.tool = '".TOOL_DOCUMENT."' AND
(d.path LIKE '%htm%') AND (d.path LIKE '%htm%') AND
(d.path LIKE '%HotPotatoes_files%') AND (d.path LIKE '%HotPotatoes_files%') AND
d.path LIKE '".Database::escape_string($uploadPath.'/%/%')."' AND d.path LIKE '".Database::escape_string($uploadPath.'/%/%')."' AND
ip.visibility = '1' ip.visibility = '1'
@ -151,7 +151,7 @@ class ExerciseLink extends AbstractLink
$tbl_stats = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES); $tbl_stats = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
$sessionId = $this->get_session_id(); $sessionId = $this->get_session_id();
$course_id = api_get_course_int_id($this->get_course_code()); $course_id = api_get_course_int_id($this->get_course_code());
$sql = "SELECT count(exe_id) AS number $sql = "SELECT count(exe_id) AS number
FROM $tbl_stats FROM $tbl_stats
WHERE WHERE
session_id = $sessionId AND session_id = $sessionId AND
@ -274,12 +274,11 @@ class ExerciseLink extends AbstractLink
} else { } else {
$lpId = null; $lpId = null;
if (!empty($exercise->lpList)) { if (!empty($exercise->lpList)) {
// Taking only the first LP $lpId = $exercise->getLpBySession($sessionId);
$lpId = current($exercise->lpList);
$lpId = $lpId['lp_id']; $lpId = $lpId['lp_id'];
} }
$sql = "SELECT * $sql = "SELECT *
FROM $tblStats FROM $tblStats
WHERE WHERE
exe_exo_id = $exerciseId AND exe_exo_id = $exerciseId AND
@ -294,11 +293,11 @@ class ExerciseLink extends AbstractLink
} }
$sql .= ' ORDER BY exe_id DESC'; $sql .= ' ORDER BY exe_id DESC';
} else { } else {
$sql = "SELECT * FROM $tblHp hp $sql = "SELECT * FROM $tblHp hp
INNER JOIN $tblDoc doc INNER JOIN $tblDoc doc
ON (hp.exe_name = doc.path AND doc.c_id = hp.c_id) ON (hp.exe_name = doc.path AND doc.c_id = hp.c_id)
WHERE WHERE
hp.c_id = $courseId AND hp.c_id = $courseId AND
doc.id = $exerciseId"; doc.id = $exerciseId";
if (!empty($stud_id)) { if (!empty($stud_id)) {

Loading…
Cancel
Save