diff --git a/main/exercice/admin.php b/main/exercice/admin.php index 342eca1f90..a4ff6dfde4 100644 --- a/main/exercice/admin.php +++ b/main/exercice/admin.php @@ -141,7 +141,6 @@ $aType = array( ); $fastEdition = api_get_course_setting('allow_fast_exercise_edition') == 1 ? true : false; -//$fastEdition = true; if ($fastEdition) { $htmlHeadXtra[] = api_get_jqgrid_js(); @@ -329,8 +328,42 @@ function multiple_answer_true_false_onchange(variable) { } document.getElementById(weight_id).value = array_result[result]; } +$(function() { + + $( "#dialog:ui-dialog" ).dialog( "destroy" ); + $( "#dialog-confirm" ).dialog({ + autoOpen: false, + show: "blind", + resizable: false, + height:150, + modal: false + }); + + + $(".opener").click(function() { + var targetUrl = $(this).attr("href"); + $( "#dialog-confirm" ).dialog({ + modal: true, + buttons: { + "'.get_lang("Yes").'": function() { + location.href = targetUrl; + $( this ).dialog( "close" ); + }, + "'.get_lang("No").'": function() { + $( this ).dialog( "close" ); + } + } + }); + $( "#dialog-confirm" ).dialog("open"); + return false; + }); +}); + + '; + + $htmlHeadXtra[] = ''; $htmlHeadXtra[] = ''; $htmlHeadXtra[] = ''; @@ -561,6 +594,17 @@ if ($newQuestion || $editQuestion) { // Create/Edit question. require 'question_admin.inc.php'; } +/* +$q = new \Entity\CQuizQuestion(); +$q->setQuestion('test'); +$q->setCId(1); +$q->setPonderation(1); +$q->setPosition(1); +$q->setType(1); +$q->setLevel(1); +$q->setParentId(1); +$app['orm.em']->persist($q); +$app['orm.em']->flush();*/ if (isset($_GET['hotspotadmin'])) { if (!is_object($objQuestion)) { @@ -577,7 +621,6 @@ if (!$newQuestion && !$modifyQuestion && !$editQuestion && !isset($_GET['hotspot if ($objExercise->randomByCat == EXERCISE_CATEGORY_RANDOM_SHUFFLED || EXERCISE_CATEGORY_RANDOM_ORDERED) { Display::display_normal_message(get_lang('AllQuestionsMustHaveACategory')); } - // Question list (drag n drop view) if ($fastEdition) { require 'question_list_pagination_admin.inc.php'; diff --git a/main/exercice/exercise.class.php b/main/exercice/exercise.class.php index 71487f88ae..92b225ef91 100644 --- a/main/exercice/exercise.class.php +++ b/main/exercice/exercise.class.php @@ -491,7 +491,7 @@ class Exercise $question_media = null; if (!empty($objQuestionTmp->parent_id)) { $objQuestionMedia = Question::read($objQuestionTmp->parent_id); - $question_media = Display::label($objQuestionMedia->question, 'info'); + $question_media = Question::getMediaLabel($objQuestionMedia->question); } $questionType = Display::tag('div', Display::return_icon($typeImg, $typeExpl, array(), ICON_SIZE_MEDIUM).$question_media); diff --git a/main/exercice/media_question.class.php b/main/exercice/media_question.class.php index de6e7a9c16..92c04c104e 100644 --- a/main/exercice/media_question.class.php +++ b/main/exercice/media_question.class.php @@ -5,34 +5,39 @@ class MediaQuestion extends Question { static $typePicture = 'looknfeel.png'; static $explanationLangVar = 'MediaQuestion'; - - function __construct(){ + + function __construct() + { parent::question(); - $this->type = MEDIA_QUESTION; + $this->type = MEDIA_QUESTION; } - - function processAnswersCreation($form) { - $params = $form->getSubmitValues(); - $this->save_media($params); + + function processAnswersCreation($form) + { + $params = $form->getSubmitValues(); + $this->saveMedia($params); } - - function save_media($params) { - $table_question = Database::get_course_table(TABLE_QUIZ_QUESTION); + + function saveMedia($params) + { + $table_question = Database::get_course_table(TABLE_QUIZ_QUESTION); $new_params = array( - 'c_id' => $this->course['real_id'], + 'c_id' => $this->course['real_id'], 'question' => $params['questionName'], 'description' => $params['questionDescription'], 'parent_id' => 0, 'type' => MEDIA_QUESTION ); - if (isset($params['id'])) { - Database::update($table_question, $new_params, array('iid = ? and c_id = ?' => array($params['id'], $this->course['real_id']))); + + if (isset($this->id) && !empty($this->id)) { + Database::update($table_question, $new_params, array('iid = ? and c_id = ?' => array($this->id, $this->course['real_id']))); } else { return Database::insert($table_question, $new_params); } } - - function createAnswersForm ($form) { + + function createAnswersForm ($form) + { $form->addElement('button', 'submitQuestion', get_lang('Save')); } -} \ No newline at end of file +} diff --git a/main/exercice/question.class.php b/main/exercice/question.class.php index 1fe0514fe7..5b0a6b32bb 100644 --- a/main/exercice/question.class.php +++ b/main/exercice/question.class.php @@ -1127,40 +1127,50 @@ abstract class Question $id = $this->id; + if ($this->type == MEDIA_QUESTION) { + // Removing media for attached questions + + $sql = "UPDATE $TBL_QUESTIONS SET parent_id = '' WHERE parent_id = $id"; + Database::query($sql); + + $sql = "DELETE FROM $TBL_QUESTIONS WHERE c_id = $course_id AND iid='".Database::escape_string($id)."'"; + Database::query($sql); + return true; + } + // if the question must be removed from all exercises if (!$deleteFromEx) { + //update the question_order of each question to avoid inconsistencies - $sql = "SELECT exercice_id, question_order FROM $TBL_EXERCICE_QUESTION WHERE c_id = $course_id AND question_id='".Database::escape_string( - $id - )."'"; + $sql = "SELECT exercice_id, question_order FROM $TBL_EXERCICE_QUESTION + WHERE c_id = $course_id AND question_id='".Database::escape_string($id)."'"; $res = Database::query($sql); + if (Database::num_rows($res) > 0) { while ($row = Database::fetch_array($res)) { if (!empty($row['question_order'])) { $sql = "UPDATE $TBL_EXERCICE_QUESTION - SET question_order = question_order-1 - WHERE c_id = $course_id AND exercice_id='".Database::escape_string( - $row['exercice_id'] - )."' AND question_order > ".$row['question_order']; + SET question_order = question_order - 1 + WHERE c_id = $course_id AND + exercice_id='".Database::escape_string($row['exercice_id'])."' AND + question_order > ".$row['question_order']; Database::query($sql); } } } - $sql = "DELETE FROM $TBL_EXERCICE_QUESTION WHERE c_id = $course_id AND question_id='".Database::escape_string( - $id - )."'"; + + $sql = "DELETE FROM $TBL_EXERCICE_QUESTION WHERE c_id = $course_id AND question_id='".Database::escape_string($id)."'"; Database::query($sql); - $sql = "DELETE FROM $TBL_QUESTIONS WHERE c_id = $course_id AND id='".Database::escape_string($id)."'"; + $sql = "DELETE FROM $TBL_QUESTIONS WHERE c_id = $course_id AND iid='".Database::escape_string($id)."'"; Database::query($sql); $sql = "DELETE FROM $TBL_REPONSES WHERE question_id='".Database::escape_string($id)."'"; Database::query($sql); // remove the category of this question in the question_rel_category table - $sql = "DELETE FROM $TBL_QUIZ_QUESTION_REL_CATEGORY WHERE c_id = $course_id AND question_id='".Database::escape_string( - $id - )."' AND c_id=".api_get_course_int_id(); + $sql = "DELETE FROM $TBL_QUIZ_QUESTION_REL_CATEGORY + WHERE c_id = $course_id AND question_id='".Database::escape_string($id)."' AND c_id=".api_get_course_int_id(); Database::query($sql); api_item_property_update($this->course, TOOL_QUIZ, $id, 'QuizQuestionDeleted', api_get_user_id()); @@ -1176,6 +1186,7 @@ abstract class Question $this->search_engine_edit($deleteFromEx, false, true); } api_item_property_update($this->course, TOOL_QUIZ, $id, 'QuizQuestionDeleted', api_get_user_id()); + } } @@ -1571,7 +1582,7 @@ abstract class Question $this->updateLevel($form->getSubmitValue('questionLevel')); $this->updateCategory($form->getSubmitValue('questionCategory')); - //Save normal question if NOT media + // Save normal question if NOT media if ($this->type != MEDIA_QUESTION) { $this->save($objExercise->id); @@ -1951,15 +1962,18 @@ abstract class Question public static function getMediaLabels() { - // Shows media questions $courseMedias = Question::prepare_course_media_select(api_get_course_int_id()); $labels = null; if (!empty($courseMedias)) { $labels .= get_lang('MediaQuestion').' '; foreach ($courseMedias as $mediaId => $media) { + + $editLink = ''.Display::return_icon('edit.png',get_lang('Modify'), array(), ICON_SIZE_SMALL).''; + $deleteLink = ''.Display::return_icon('delete.png',get_lang('Delete'), array(), ICON_SIZE_SMALL).''; + if (!empty($mediaId)) { - $labels .= Display::label($media).' '; + $labels .= self::getMediaLabel($media).''.$editLink.$deleteLink.' '; } } } @@ -2064,7 +2078,13 @@ abstract class Question return $questions[0]['total_rows']; } } + return $questions; + } + static function getMediaLabel($title) + { + return Display::label($title, 'warning'); } + } diff --git a/main/exercice/question_list_admin.inc.php b/main/exercice/question_list_admin.inc.php index e2d12cf82e..804f4a7e4e 100644 --- a/main/exercice/question_list_admin.inc.php +++ b/main/exercice/question_list_admin.inc.php @@ -45,34 +45,6 @@ $ajax_url = api_get_path(WEB_AJAX_PATH)."exercise.ajax.php?".api_get_cidreq()."& + +
" style="display:none;"> +

+ + +

+
+ '; -echo Display::grid_html('question_list'); \ No newline at end of file +echo Question::getMediaLabels(); + +echo '
'; +echo Display::grid_html('question_list'); diff --git a/main/exercice/testcategory.class.php b/main/exercice/testcategory.class.php index 317db5b28e..055c8aa8c7 100644 --- a/main/exercice/testcategory.class.php +++ b/main/exercice/testcategory.class.php @@ -67,7 +67,8 @@ class Testcategory * @assert () === false */ - public function getCategory($id) { + public function getCategory($id) + { $t_cattable = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY); $in_id = Database::escape_string($id); $sql = "SELECT * FROM $t_cattable WHERE iid = $id "; @@ -134,11 +135,7 @@ class Testcategory } else { return false; } - /*$sql = "INSERT INTO $t_cattable (c_id, title, description, parent_id) VALUES ('$course_id', '$v_name', '$v_description', '$parent_id')"; - Database::query($sql);*/ - //return Database::insert_id(); } else { - return false; } } @@ -228,14 +225,6 @@ class Testcategory $repo->removeFromTree($category); $app['orm.em']->clear(); // clear cached nodes return true; - - /*$sql = "DELETE FROM $t_cattable WHERE iid = $v_id"; - Database::query($sql); - if (Database::affected_rows() <= 0) { - return false; - } else { - return true; - }*/ } @@ -432,7 +421,7 @@ class Testcategory if (Database::num_rows($res) > 0) { while ($row = Database::fetch_array($res)) { $cat = new Testcategory($row['iid']); - $result[] = $cat->parent_path; + $result[] = array('title' => $cat->parent_path); } } @@ -593,8 +582,11 @@ class Testcategory foreach ($categories as $cat_id) { $cat = new Testcategory($cat_id); if (!empty($cat->id)) { - $result[$cat->id] = $cat->name; - } + $result[$cat->id] = array( + 'title' => $cat->name, + 'parent_id' => $cat->parent_id + ); + } } return $result; } @@ -840,16 +832,22 @@ class Testcategory * @param array $all_categories * @return null|string */ - public static function return_category_labels($category_list, $all_categories) { + public static function return_category_labels($category_list, $all_categories) + { $category_list_to_render = array(); foreach ($category_list as $category_id) { $category_name = null; if (!isset($all_categories[$category_id])) { $category_name = get_lang('Untitled'); + $parentId = null; } else { - $category_name = Text::cut($all_categories[$category_id], 15); + $parentId = $all_categories[$category_id]['parent_id']; + $category_name = Text::cut($all_categories[$category_id]['title'], 15); } - $category_list_to_render[] = $category_name; + $category_list_to_render[] = array( + 'title' => $category_name, + 'parent_id' => $parentId + ); } $html = self::draw_category_label($category_list_to_render, 'label'); return $html; @@ -862,10 +860,18 @@ class Testcategory */ public static function draw_category_label($category_list, $type = 'label') { $new_category_list = array(); - foreach ($category_list as $category_name) { + foreach ($category_list as $category) { + $category_name = $category['title']; + switch ($type) { case 'label': - $new_category_list[] = Display::label($category_name, 'info'); + // Global cat + $parentId = isset($category['parent_id']) ? $category['parent_id'] : null; + if (empty($parentId)) { + $new_category_list[] = Display::label($category_name, 'info'); + } else { + $new_category_list[] = Display::label($category_name, 'success'); + } break; case 'header': $new_category_list[] = $category_name;