Skip to content

Commit f4ff246

Browse files
committed
Fixed attach interface
There were some logic issues in how exams were attached. It now reads this correctly
1 parent d5ca082 commit f4ff246

2 files changed

Lines changed: 31 additions & 16 deletions

File tree

Controller/AdminController.php

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -301,23 +301,36 @@ public function attachAction(Request $request) : JsonResponse {
301301

302302
//get rid of the old exam if there is one.
303303
$old_exam = $repo->get_exam($art_id);
304-
$reponse = "";
305-
if ($old_exam) {
306-
$old_exam->setQuickcheckrefid(-1); //no article attached
307-
}
308-
if (isset($attach)) {
309-
if (!isset($art_id) || !isset($exam)) {
310-
throw new NotFoundHttpException($this->trans('An article id or exam id are missing'));
304+
$response = "";
305+
$already_attached = false;
306+
if (null !== $old_exam) {
307+
if(($old_exam->getId() == $exam) && $attach) {
308+
$response = "<p>That exam is already attached.</p>";
309+
$already_attached = true;
310+
} else {
311+
$old_exam->setQuickcheckrefid(-1); //no article attached
312+
$response = "<p>" . $old_exam->getQuickcheckname() . " was removed from the page. </p>";
311313
}
312-
//modify the exam by grabbing it and then changing or adding the art_id
313-
$new_exam = $em->find('PaustianQuickcheckModule:QuickcheckExamEntity', $exam);
314-
if (null === $new_exam) {
315-
throw new \Doctrine\ORM\NoResultException($this->trans('An exam was not found, when it should have been.'));
314+
}
315+
if(!$already_attached){
316+
if (isset($attach)) {
317+
if (!isset($art_id) || !isset($exam)) {
318+
throw new NotFoundHttpException($this->trans('An article id or exam id are missing'));
319+
}
320+
//modify the exam by grabbing it and then changing or adding the art_id
321+
$new_exam = $em->find('PaustianQuickcheckModule:QuickcheckExamEntity', $exam);
322+
if (null === $new_exam) {
323+
throw new \Doctrine\ORM\NoResultException($this->trans('An exam was not found, when it should have been.'));
324+
}
325+
$new_exam->setQuickcheckrefid((int)$art_id);
326+
$response .= "<p>" . $new_exam->getQuickcheckname() ." exam was attached to the page. Reload the page to see it.</p>";
327+
} else {
328+
if(null !== $old_exam){
329+
$response = "<p>" . $old_exam->getQuickcheckname() ." exam was removed from the page. Reload the page to see it.</p>";
330+
} else {
331+
$response = "<p> There is no exam to remove. Get it together you loser.";
332+
}
316333
}
317-
$new_exam->setQuickcheckrefid((int)$art_id);
318-
$response = "<p>" . $new_exam->getQuickcheckname() ." exam was attached to the page. Reload the page to see it.</p>";
319-
} else {
320-
$response = "<p>" . $old_exam->getQuickcheckname() ." exam was removed from the page. Reload the page to see it.</p>";
321334
}
322335
$em->flush();
323336
//finally return to the page that called.

Resources/views/Hook/quickcheck.addquiz.html.twig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{{ pageAddAsset('javascript', zasset('jquery-ui/jquery-ui.js')) }}
2+
{{ pageAddAsset('stylesheet', asset('jquery-ui/themes/base/jquery-ui.min.css')) }}
13
{{ pageAddAsset('stylesheet', 'https://cdn.datatables.net/1.10.20/css/jquery.dataTables.css') }}
24
{{ pageAddAsset('javascript', 'https://cdn.datatables.net/1.10.20/js/jquery.dataTables.js') }}
35
{{ pageAddAsset('javascript', zasset('@PaustianQuickcheckModule:js/Paustian.Quickcheck.examtablesort.js')) }}
@@ -28,7 +30,7 @@
2830
</tbody>
2931
</table>
3032
</form>
31-
<button id="DialogButton"></button>
33+
3234
<div id="dialog" title="Attach/Remove Exam">
3335
<p id="dialog_text"></p>
3436
</div>

0 commit comments

Comments
 (0)