Skip to content

Exercise: Use c_quiz_rel_question.destination for success/failure navigation - refs #6180 #6184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions assets/js/legacy/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,21 @@ document.addEventListener("DOMContentLoaded", function () {
}
})
})

window.SendEx = function (num) {
const params = new URLSearchParams(window.location.search)
const exerciseId = params.get("exerciseId") || 0
const learnpathId = params.get("learnpath_id") || 0
const learnpathItemId = params.get("learnpath_item_id") || 0
const exeId = window?.exeId || ""

let url = ""

if (parseInt(num) === -1) {
url = `exercise_result.php?${params.toString()}&exe_id=${exeId}&take_session=1&exerciseId=${exerciseId}&num=${num}&learnpath_item_id=${learnpathItemId}&learnpath_id=${learnpathId}`
} else {
url = `exercise_submit.php?${params.toString()}&tryagain=1&exerciseId=${exerciseId}&num=${num}&learnpath_item_id=${learnpathItemId}&learnpath_id=${learnpathId}`
}

window.location.href = url
}
17 changes: 3 additions & 14 deletions public/main/exercise/answer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ public function read()
$this->position[$i] = $object->position;
$this->hotspot_coordinates[$i] = $object->hotspot_coordinates;
$this->hotspot_type[$i] = $object->hotspot_type;
$this->destination[$i] = $object->destination;
$i++;
}
$this->nbrAnswers = $i - 1;
Expand Down Expand Up @@ -268,7 +267,6 @@ public function readOrderedBy($field, $order = 'ASC')
$this->position[$i] = $object->position;
$this->hotspot_coordinates[$i] = $object->hotspot_coordinates;
$this->hotspot_type[$i] = $object->hotspot_type;
$this->destination[$i] = $object->destination;
$this->autoId[$i] = $object->iid;
$this->iid[$i] = $object->iid;
$i++;
Expand Down Expand Up @@ -437,7 +435,6 @@ public function getAnswersList($decode = false)
'hotspot_coord' => $this->hotspot_coordinates[$i],
'hotspot_type' => $this->hotspot_type[$i],
'correct' => $this->correct[$i],
'destination' => $this->destination[$i],
];
}
}
Expand Down Expand Up @@ -604,7 +601,6 @@ public function createAnswer(
$this->new_position[$id] = $position;
$this->new_hotspot_coordinates[$id] = $new_hotspot_coordinates;
$this->new_hotspot_type[$id] = $new_hotspot_type;
$this->new_destination[$id] = $destination;
}

/**
Expand Down Expand Up @@ -646,7 +642,6 @@ public function updateAnswers(
->setCorrect((int) $correct)
->setPonderation($weighting)
->setPosition($position)
->setDestination($destination)
->setHotspotCoordinates($hotSpotCoordinates)
->setHotspotType($hotSpotType)
;
Expand Down Expand Up @@ -686,8 +681,6 @@ public function save()
$position = isset($this->new_position[$i]) ? $this->new_position[$i] : null;
$hotspot_coordinates = isset($this->new_hotspot_coordinates[$i]) ? $this->new_hotspot_coordinates[$i] : null;
$hotspot_type = isset($this->new_hotspot_type[$i]) ? $this->new_hotspot_type[$i] : null;
$destination = isset($this->new_destination[$i]) ? $this->new_destination[$i] : null;
//$autoId = $this->selectAutoId($i);
$iid = isset($this->iid[$i]) ? $this->iid[$i] : 0;

if (!isset($this->position[$i])) {
Expand All @@ -700,8 +693,7 @@ public function save()
->setPonderation(!is_null($weighting) ? $weighting : 0.0)
->setPosition($position)
->setHotspotCoordinates($hotspot_coordinates)
->setHotspotType($hotspot_type)
->setDestination($destination);
->setHotspotType($hotspot_type);

$em->persist($quizAnswer);
$em->flush();
Expand Down Expand Up @@ -737,7 +729,7 @@ public function save()
$this->new_correct[$i],
$this->new_weighting[$i],
$this->new_position[$i],
$this->new_destination[$i],
null,
$this->new_hotspot_coordinates[$i],
$this->new_hotspot_type[$i]
);
Expand Down Expand Up @@ -805,7 +797,6 @@ public function save()
$this->hotspot_coordinates = $this->new_hotspot_coordinates;
$this->hotspot_type = $this->new_hotspot_type;
$this->nbrAnswers = $this->new_nbrAnswers;
$this->destination = $this->new_destination;

$this->cancel();
}
Expand Down Expand Up @@ -879,7 +870,6 @@ public function duplicate(Question $newQuestion, $courseInfo = null)
'position' => $this->position[$i],
'hotspot_coordinates' => $this->hotspot_coordinates[$i],
'hotspot_type' => $this->hotspot_type[$i],
'destination' => $this->destination[$i],
];
$temp[$answer['position']] = $answer;
$allAnswers[$this->id[$i]] = $this->answer[$i];
Expand Down Expand Up @@ -957,8 +947,7 @@ public function duplicate(Question $newQuestion, $courseInfo = null)
->setPonderation($this->weighting[$i])
->setPosition($this->position[$i])
->setHotspotCoordinates($this->hotspot_coordinates[$i])
->setHotspotType($this->hotspot_type[$i])
->setDestination($this->destination[$i]);
->setHotspotType($this->hotspot_type[$i]);

$em->persist($quizAnswer);
$em->flush();
Expand Down
27 changes: 16 additions & 11 deletions public/main/exercise/exercise.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -4851,13 +4851,16 @@ public function manage_answer(
$resq = Database::query($query);
$row = Database::fetch_assoc($resq);

$choice = $row['hotspot_correct'];
$user_answer = $row['hotspot_coordinate'];
if ($row && isset($row['hotspot_correct'], $row['hotspot_coordinate'])) {
$choice = $row['hotspot_correct'];
$user_answer = $row['hotspot_coordinate'];
$coords = explode('/', $user_answer);
} else {
$choice = '';
$user_answer = '';
$coords = [];
}

// THIS is very important otherwise the poly_compile will throw an error!!
// round-up the coordinates
$coords = explode('/', $user_answer);
$coords = array_filter($coords);
$user_array = '';
foreach ($coords as $coord) {
[$x, $y] = explode(';', $coord);
Expand All @@ -4870,7 +4873,7 @@ public function manage_answer(
$newquestionList[] = $questionId;
}

if (1 === $answerId) {
if (1 === $answerId && isset($choice[$answerId])) {
$studentChoice = $choice[$answerId];
$questionScore += $answerWeighting;
}
Expand Down Expand Up @@ -5055,7 +5058,7 @@ public function manage_answer(
$studentChoice,
$answerComment
);*/
} elseif (HOT_SPOT_DELINEATION == $answerType) {
} elseif (HOT_SPOT_DELINEATION == $answerType && isset($_SESSION['exerciseResultCoordinates'][$questionId])) {
$user_answer = $_SESSION['exerciseResultCoordinates'][$questionId];

// Round-up the coordinates
Expand Down Expand Up @@ -5739,9 +5742,11 @@ public function manage_answer(
echo $message;

$_SESSION['hotspot_delineation_result'][$this->getId()][$questionId][0] = $message;
$_SESSION['hotspot_delineation_result'][$this->getId()][$questionId][1] = $_SESSION['exerciseResultCoordinates'][$questionId];
if (isset($_SESSION['exerciseResultCoordinates'][$questionId])) {
$_SESSION['hotspot_delineation_result'][$this->getId()][$questionId][1] = $_SESSION['exerciseResultCoordinates'][$questionId];
}
} else {
echo $hotspot_delineation_result[0];
echo $hotspot_delineation_result[0] ?? '';
}

// Save the score attempts
Expand All @@ -5761,7 +5766,7 @@ public function manage_answer(
$quesId,
1,
$hotspotValue,
$exerciseResultCoordinates[$quesId],
$exerciseResultCoordinates[$quesId] ?? '',
false,
0,
$learnpath_id,
Expand Down
Loading
Loading