Skip to content
Permalink
Browse files

Allow edit questions that are not inside an exercise see BT#15534

  • Loading branch information...
jmontoyaa committed Apr 16, 2019
1 parent dbe48db commit f8d91f9c2dc5502b90088a706a50cb2f8b6a066d
@@ -54,6 +54,9 @@
$questions = $repo->matching($criteria);
if (empty($id)) {
$id = '';
}
$params = [
'id' => $id,
'title' => $title,
@@ -127,7 +130,6 @@
$url.http_build_query([
'cidReq' => $courseCode,
'id_session' => $exercise->sessionId,
'myid' => 1,
'exerciseId' => $exerciseId,
'type' => $question->getType(),
'editQuestion' => $question->getId(),
@@ -136,10 +138,14 @@
}
$question->questionData .= '<br />'.$exerciseData;
} else {
$question->questionData .= get_lang('Course').': '.Display::url(
$courseInfo['name'],
$exerciseUrl.http_build_query([
$question->questionData = Display::url(
Display::return_icon('edit.png', get_lang('Edit')),
$url.http_build_query([
'cidReq' => $courseCode,
'id_session' => $exercise->sessionId,
'exerciseId' => $exerciseId,
'type' => $question->getType(),
'editQuestion' => $question->getId(),
])
);
}
@@ -155,10 +155,8 @@ public function createForm(&$form, $exercise)
}
// hidden values
$my_id = isset($_REQUEST['myid']) ? intval($_REQUEST['myid']) : null;
$form->addElement('hidden', 'myid', $my_id);
$form->addRule('questionName', get_lang('GiveQuestion'), 'required');
$isContent = isset($_REQUEST['isContent']) ? intval($_REQUEST['isContent']) : null;
$isContent = isset($_REQUEST['isContent']) ? (int) $_REQUEST['isContent'] : null;
// default values
$defaults = [];
@@ -172,12 +170,8 @@ public function createForm(&$form, $exercise)
$form->setDefaults($defaults);
}
if (!empty($_REQUEST['myid'])) {
if (!isset($_GET['newQuestion']) || $isContent) {
$form->setDefaults($defaults);
} else {
if ($isContent == 1) {
$form->setDefaults($defaults);
}
}
}
@@ -301,7 +301,7 @@
}
// if the question is duplicated, disable the link of tool name
if ($modifyIn == 'thisExercise') {
if ($modifyIn === 'thisExercise') {
if ($buttonBack) {
$modifyIn = 'allExercises';
}
@@ -330,12 +330,12 @@
if ($inATest) {
echo '<div class="actions">';
if (isset($_GET['hotspotadmin']) || isset($_GET['newQuestion']) || isset($_GET['myid'])) {
if (isset($_GET['hotspotadmin']) || isset($_GET['newQuestion'])) {
echo '<a href="'.api_get_path(WEB_CODE_PATH).'exercise/admin.php?exerciseId='.$exerciseId.'&'.api_get_cidreq().'">'.
Display::return_icon('back.png', get_lang('GoBackToQuestionList'), '', ICON_SIZE_MEDIUM).'</a>';
}
if (!isset($_GET['hotspotadmin']) && !isset($_GET['newQuestion']) && !isset($_GET['myid']) && !isset($_GET['editQuestion'])) {
if (!isset($_GET['hotspotadmin']) && !isset($_GET['newQuestion']) && !isset($_GET['editQuestion'])) {
echo '<a href="'.api_get_path(WEB_CODE_PATH).'exercise/exercise.php?'.api_get_cidreq().'">'.
Display::return_icon('back.png', get_lang('BackToExercisesList'), '', ICON_SIZE_MEDIUM).'</a>';
}
@@ -1720,23 +1720,37 @@ public function save($type_e = '')
/**
* Updates question position.
*
* @return bool
*
*/
public function update_question_positions()
{
$table = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
//Fixes #3483 when updating order
$question_list = $this->selectQuestionList(true);
if (!empty($question_list)) {
foreach ($question_list as $position => $questionId) {
// Fixes #3483 when updating order
$questionList = $this->selectQuestionList(true);
$this->id = (int) $this->id;
if (empty($this->id)) {
return false;
}
if (!empty($questionList)) {
foreach ($questionList as $position => $questionId) {
$position = (int) $position;
$questionId = (int) $questionId;
$sql = "UPDATE $table SET
question_order ='".intval($position)."'
question_order ='".$position."'
WHERE
c_id = ".$this->course_id." AND
question_id = ".intval($questionId)." AND
exercice_id=".intval($this->id);
question_id = ".$questionId." AND
exercice_id=".$this->id;
Database::query($sql);
}
}
return true;
}
/**
@@ -188,7 +188,7 @@ public function createAnswersForm($form)
*/
public function processAnswersCreation($form, $exercise)
{
$questionWeighting = $nbrGoodAnswers = 0;
$questionWeighting = 0;
$objAnswer = new Answer($this->id);
$nb_answers = $form->getSubmitValue('nb_answers');
@@ -182,7 +182,7 @@ public function createAnswersForm($form)
*/
public function processAnswersCreation($form, $exercise)
{
$questionWeighting = $nbrGoodAnswers = 0;
$questionWeighting = 0;
$objAnswer = new Answer($this->id);
$nb_answers = $form->getSubmitValue('nb_answers');
@@ -239,7 +239,7 @@ public function createAnswersForm($form)
*/
public function processAnswersCreation($form, $exercise)
{
$questionWeighting = $nbrGoodAnswers = 0;
$questionWeighting = 0;
$objAnswer = new Answer($this->id);
$nb_answers = $form->getSubmitValue('nb_answers');
$course_id = api_get_course_int_id();
@@ -952,6 +952,7 @@ public function save($exercise)
if ($exercise->questionFeedbackEnabled) {
$params['feedback'] = $this->feedback;
}
Database::update(
$TBL_QUESTIONS,
$params,
@@ -974,24 +975,17 @@ public function save($exercise)
api_get_user_id()
);
}
if (api_get_setting('search_enabled') == 'true') {
if ($exerciseId != 0) {
$this->search_engine_edit($exerciseId);
} else {
/**
* actually there is *not* an user interface for
* creating questions without a relation with an exercise.
*/
}
if (api_get_setting('search_enabled') === 'true') {
$this->search_engine_edit($exerciseId);
}
} else {
// creates a new question
// Creates a new question
$sql = "SELECT max(position)
FROM $TBL_QUESTIONS as question,
$TBL_EXERCISE_QUESTION as test_question
WHERE
question.id = test_question.question_id AND
test_question.exercice_id = ".intval($exerciseId)." AND
test_question.exercice_id = ".$exerciseId." AND
question.c_id = $c_id AND
test_question.c_id = $c_id ";
$result = Database::query($sql);
@@ -1087,33 +1081,33 @@ public function save($exercise)
}
}
if (api_get_setting('search_enabled') == 'true') {
if ($exerciseId != 0) {
$this->search_engine_edit($exerciseId, true);
} else {
/**
* actually there is *not* an user interface for
* creating questions without a relation with an exercise.
*/
}
if (api_get_setting('search_enabled') === 'true') {
$this->search_engine_edit($exerciseId, true);
}
}
}
// if the question is created in an exercise
if ($exerciseId) {
if (!empty($exerciseId)) {
// adds the exercise into the exercise list of this question
$this->addToList($exerciseId, true);
}
}
/**
* @param int $exerciseId
* @param bool $addQs
* @param bool $rmQs
*/
public function search_engine_edit(
$exerciseId,
$addQs = false,
$rmQs = false
) {
// update search engine and its values table if enabled
if (api_get_setting('search_enabled') == 'true' && extension_loaded('xapian')) {
if (!empty($exerciseId) && api_get_setting('search_enabled') == 'true' &&
extension_loaded('xapian')
) {
$course_id = api_get_course_id();
// get search_did
$tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
@@ -1260,17 +1254,19 @@ public function search_engine_edit(
public function addToList($exerciseId, $fromSave = false)
{
$exerciseRelQuestionTable = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$id = $this->id;
$id = (int) $this->id;
$exerciseId = (int) $exerciseId;
// checks if the exercise ID is not in the list
if (!in_array($exerciseId, $this->exerciseList)) {
if (!empty($exerciseId) && !in_array($exerciseId, $this->exerciseList)) {
$this->exerciseList[] = $exerciseId;
$courseId = isset($this->course['real_id']) ? $this->course['real_id'] : 0;
$newExercise = new Exercise($courseId);
$newExercise->read($exerciseId, false);
$count = $newExercise->getQuestionCount();
$count++;
$sql = "INSERT INTO $exerciseRelQuestionTable (c_id, question_id, exercice_id, question_order)
VALUES ({$this->course['real_id']}, ".intval($id).", ".intval($exerciseId).", '$count')";
VALUES ({$this->course['real_id']}, ".$id.", ".$exerciseId.", '$count')";
Database::query($sql);
// we do not want to reindex if we had just saved adnd indexed the question
@@ -1606,10 +1602,10 @@ public function createForm(&$form, $exercise)
$form->addRule('questionName', get_lang('GiveQuestion'), 'required');
// default content
$isContent = isset($_REQUEST['isContent']) ? intval($_REQUEST['isContent']) : null;
$isContent = isset($_REQUEST['isContent']) ? (int) $_REQUEST['isContent'] : null;
// Question type
$answerType = isset($_REQUEST['answerType']) ? intval($_REQUEST['answerType']) : null;
$answerType = isset($_REQUEST['answerType']) ? (int) $_REQUEST['answerType'] : null;
$form->addElement('hidden', 'answerType', $answerType);
// html editor
@@ -1632,10 +1628,6 @@ public function createForm(&$form, $exercise)
$editorConfig
);
// hidden values
$my_id = isset($_REQUEST['myid']) ? intval($_REQUEST['myid']) : null;
$form->addElement('hidden', 'myid', $my_id);
if ($this->type != MEDIA_QUESTION) {
// Advanced parameters
$select_level = self::get_default_levels();
@@ -1746,13 +1738,17 @@ public function createForm(&$form, $exercise)
$form->setDefaults($defaults);
}
if (!empty($_REQUEST['myid'])) {
if (!isset($_GET['newQuestion']) || $isContent) {
$form->setDefaults($defaults);
}
/*if (!empty($_REQUEST['myid'])) {
$form->setDefaults($defaults);
} else {
if ($isContent == 1) {
$form->setDefaults($defaults);
}
}
}*/
}
/**
@@ -13,10 +13,10 @@
*/
if (isset($_GET['editQuestion'])) {
$objQuestion = Question::read($_GET['editQuestion']);
$action = api_get_self().'?'.api_get_cidreq()."&myid=1&modifyQuestion=".$modifyQuestion."&editQuestion=".$objQuestion->id.'&page='.$page;
$action = api_get_self().'?'.api_get_cidreq().'&modifyQuestion='.$modifyQuestion.'&editQuestion='.$objQuestion->id.'&page='.$page;
} else {
$objQuestion = Question::getInstance($_REQUEST['answerType']);
$action = api_get_self().'?'.api_get_cidreq()."&modifyQuestion=".$modifyQuestion."&newQuestion=".$newQuestion;
$action = api_get_self().'?'.api_get_cidreq().'&modifyQuestion='.$modifyQuestion.'&newQuestion='.$newQuestion;
}
if (is_object($objQuestion)) {
@@ -50,7 +50,7 @@
$objQuestion->createAnswersForm($form);
// this variable $show_quiz_edition comes from admin.php blocks the exercise/quiz modifications
if ($objExercise->edit_exercise_in_lp == false) {
if (!empty($objExercise->id) && $objExercise->edit_exercise_in_lp == false) {
$form->freeze();
}
@@ -65,6 +65,12 @@
$objQuestion->type != HOT_SPOT_DELINEATION
) {
if (isset($_GET['editQuestion'])) {
if (empty($exerciseId)) {
Display::addFlash(Display::return_message(get_lang('ItemUpdated')));
$url = 'admin.php?exerciseId='.$exerciseId.'&'.api_get_cidreq().'&editQuestion='.$objQuestion->id;
echo '<script type="text/javascript">window.location.href="'.$url.'"</script>';
exit;
}
echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&'.api_get_cidreq().'&page='.$page.'&message=ItemUpdated"</script>';
} else {
// New question
@@ -254,7 +254,6 @@
api_get_self().'?'.api_get_cidreq().'&'
.http_build_query([
'type' => $objQuestionTmp->selectType(),
'myid' => 1,
'editQuestion' => $id,
'page' => $page,
]),

0 comments on commit f8d91f9

Please sign in to comment.
You can’t perform that action at this time.