From 59ffa7c5d44224567d1a9b77da036db0ebb684cf Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Fri, 21 Dec 2018 11:53:26 -0500 Subject: [PATCH] Add warning when editing question added from question pool #2565 --- main/exercise/admin.php | 10 ++++++++++ main/exercise/question.class.php | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/main/exercise/admin.php b/main/exercise/admin.php index 14bc37cce0..c458b720c7 100755 --- a/main/exercise/admin.php +++ b/main/exercise/admin.php @@ -366,6 +366,16 @@ if ($inATest) { if ($objExercise->added_in_lp()) { echo Display::return_message(get_lang('AddedToLPCannotBeAccessed'), 'warning'); } + + if ($editQuestion && $objQuestion->existsInAnotherExercises()) { + echo Display::return_message( + Display::returnFontAwesomeIcon('exclamation-triangle"') + .get_lang('ThisQuestionExistsInAnotherExercisesWarning'), + 'warning', + false + ); + } + echo '
'; echo sprintf( get_lang('XQuestionsWithTotalScoreY'), diff --git a/main/exercise/question.class.php b/main/exercise/question.class.php index 13901524f5..28bb422829 100755 --- a/main/exercise/question.class.php +++ b/main/exercise/question.class.php @@ -2373,4 +2373,26 @@ abstract class Question return false; } + + /** + * Check if this question exists in another exercise. + * + * @throws \Doctrine\ORM\Query\QueryException + * + * @return mixed + */ + public function existsInAnotherExercises() + { + $em = Database::getManager(); + + $count = $em + ->createQuery(' + SELECT COUNT(qq.iid) FROM ChamiloCourseBundle:CQuizRelQuestion qq + WHERE qq.questionId = :id + ') + ->setParameters(['id' => (int) $this->id]) + ->getSingleScalarResult(); + + return $count > 1; + } }