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);
$tableLpItem = Database::get_course_table(TABLE_LP_ITEM);
$tblLp = Database::get_course_table(TABLE_LP_MAIN);
$id = (int) $id;
if (empty($this->course_id)) {
@ -218,12 +219,13 @@ class Exercise
$this->showPreviousButton = $object->show_previous_button == 1 ? true : false;
}
$sql = "SELECT lp_id, max_score
FROM $tableLpItem
$sql = "SELECT lpi.lp_id, lpi.max_score, lp.session_id
FROM $tableLpItem lpi
INNER JOIN $tblLp lp ON (lpi.lp_id = lp.iid AND lpi.c_id = lp.c_id)
WHERE
c_id = {$this->course_id} AND
item_type = '".TOOL_QUIZ."' AND
path = '".$id."'";
lpi.c_id = {$this->course_id} AND
lpi.item_type = '".TOOL_QUIZ."' AND
lpi.path = '$id'";
$result = Database::query($sql);
if (Database::num_rows($result) > 0) {
@ -8327,7 +8329,7 @@ class Exercise
$lpId = null;
if (!empty($this->lpList)) {
// Taking only the first LP
$lpId = current($this->lpList);
$lpId = $this->getLpBySession($sessionId);
$lpId = $lpId['lp_id'];
}
@ -10225,4 +10227,28 @@ class Exercise
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 ($exercise->exercise_was_added_in_lp) {
if (!empty($exercise->lpList)) {
$count = count($exercise->lpList);
if ($count == 1) {
// If the exercise was added once redirect to the LP
$firstLp = current($exercise->lpList);
if (isset($firstLp['lp_id'])) {
$url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq().'&'
.http_build_query(
[
'lp_id' => $firstLp['lp_id'],
'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';
// If the exercise was added once redirect to the LP
$firstLp = $exercise->getLpBySession($session_id);
if (isset($firstLp['lp_id'])) {
$url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq().'&'
.http_build_query(
[
'lp_id' => $firstLp['lp_id'],
'action' => 'view',
'isStudentView' => 'true',
]
);
}
}
} else {

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

Loading…
Cancel
Save