Add warning when editing question added from question pool #2565

pull/2818/head
Angel Fernando Quiroz Campos 6 years ago
parent 8efd8cbdda
commit 59ffa7c5d4
  1. 10
      main/exercise/admin.php
  2. 22
      main/exercise/question.class.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 '<div class="alert alert-info">';
echo sprintf(
get_lang('XQuestionsWithTotalScoreY'),

@ -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;
}
}

Loading…
Cancel
Save