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. 8
      main/gradebook/exercise_jump.php
  3. 3
      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,10 +55,8 @@ 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 ($count == 1) {
// If the exercise was added once redirect to the LP // If the exercise was added once redirect to the LP
$firstLp = current($exercise->lpList); $firstLp = $exercise->getLpBySession($session_id);
if (isset($firstLp['lp_id'])) { if (isset($firstLp['lp_id'])) {
$url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq().'&' $url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq().'&'
.http_build_query( .http_build_query(
@ -69,10 +67,6 @@ if (!empty($doExerciseUrl)) {
] ]
); );
} }
} 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 {
$url = api_get_path(WEB_CODE_PATH).'exercise/overview.php?'.http_build_query( $url = api_get_path(WEB_CODE_PATH).'exercise/overview.php?'.http_build_query(

@ -274,8 +274,7 @@ 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'];
} }

Loading…
Cancel
Save