Skip to content

Commit

Permalink
Improve question search see BT#15534
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed May 8, 2019
1 parent 58c0fe3 commit f7bfb84
Show file tree
Hide file tree
Showing 6 changed files with 354 additions and 292 deletions.
25 changes: 24 additions & 1 deletion main/admin/questions.php
@@ -1,6 +1,7 @@
<?php
/* For licensing terms, see /license.txt */

use Chamilo\CourseBundle\Entity\CQuiz;
use Chamilo\CourseBundle\Entity\CQuizQuestion;
use ChamiloSession as Session;
use Doctrine\Common\Collections\Criteria;
Expand Down Expand Up @@ -93,10 +94,11 @@
return $render;
};

/** @var CQuizQuestion $question */
if ($pagination) {
$url = api_get_path(WEB_CODE_PATH).'exercise/admin.php?';
$exerciseUrl = api_get_path(WEB_CODE_PATH).'exercise/exercise.php?';

/** @var CQuizQuestion $question */
foreach ($pagination as $question) {
$courseId = $question->getCId();
$courseInfo = api_get_course_info_by_id($courseId);
Expand Down Expand Up @@ -124,6 +126,7 @@
$exerciseData = '';
$exerciseId = 0;
if (!empty($questionObject->exerciseList)) {
// Question exists in a valid exercise
$exerciseData .= get_lang('Exercises').'<br />';
foreach ($questionObject->exerciseList as $exerciseId) {
$exercise = new Exercise();
Expand All @@ -143,6 +146,7 @@
}
$question->questionData .= '<br />'.$exerciseData;
} else {
// Question exists but it's orphan or it belongs to a deleted exercise
$question->questionData = Display::url(
Display::return_icon('edit.png', get_lang('Edit')),
$url.http_build_query([
Expand All @@ -153,6 +157,25 @@
'editQuestion' => $question->getId(),
])
);

// This means the question is added in a deleted exercise
if ($questionObject->getCountExercise() > 0) {
$exerciseList = $questionObject->getExerciseListWhereQuestionExists();
if (!empty($exerciseList)) {
$question->questionData .= '<br />'.get_lang('Exercises').'<br />';
/** @var CQuiz $exercise */
foreach ($exerciseList as $exercise) {
$question->questionData .= $exercise->getTitle();
if ($exercise->getActive() == -1) {
$question->questionData .= '- ('.get_lang('ExerciseDeleted').') ';
}
$question->questionData .= '<br />';
}
}
} else {
// This question is orphan :(
$question->questionData .= '&nbsp;'.get_lang('OrphanQuestion').'<br />';
}
}
ob_end_clean();
}
Expand Down
2 changes: 1 addition & 1 deletion main/exercise/admin.php
Expand Up @@ -367,7 +367,7 @@
if ($objExercise->added_in_lp()) {
echo Display::return_message(get_lang('AddedToLPCannotBeAccessed'), 'warning');
}
if ($editQuestion && $objQuestion->existsInAnotherExercises()) {
if ($editQuestion && $objQuestion->existsInAnotherExercise()) {
echo Display::return_message(
Display::returnFontAwesomeIcon('exclamation-triangle"')
.get_lang('ThisQuestionExistsInAnotherExercisesWarning'),
Expand Down
40 changes: 38 additions & 2 deletions main/exercise/question.class.php
Expand Up @@ -2396,7 +2396,19 @@ public function returnFormatFeedback()
*
* @return mixed
*/
public function existsInAnotherExercises()
public function existsInAnotherExercise()
{
$count = $this->getCountExercise();

return $count > 1;
}

/**
* @return int
*
* @throws \Doctrine\ORM\Query\QueryException
*/
public function getCountExercise()
{
$em = Database::getManager();

Expand All @@ -2408,7 +2420,31 @@ public function existsInAnotherExercises()
->setParameters(['id' => (int) $this->id])
->getSingleScalarResult();

return $count > 1;
return (int) $count;
}

/**
* Check if this question exists in another exercise.
*
* @throws \Doctrine\ORM\Query\QueryException
*
* @return mixed
*/
public function getExerciseListWhereQuestionExists()
{
$em = Database::getManager();

$result = $em
->createQuery('
SELECT e
FROM ChamiloCourseBundle:CQuizRelQuestion qq
JOIN ChamiloCourseBundle:CQuiz e
WHERE e.iid = qq.exerciceId AND qq.questionId = :id
')
->setParameters(['id' => (int) $this->id])
->getResult();

return $result;
}

/**
Expand Down
1 change: 1 addition & 0 deletions main/inc/ajax/model.ajax.php
Expand Up @@ -1298,6 +1298,7 @@ function getWhereClause($col, $oper, $val)
$columns = array_merge(['official_code'], $columns);
}
}

$result = ExerciseLib::get_exam_results_data(
$start,
$limit,
Expand Down

0 comments on commit f7bfb84

Please sign in to comment.