From 22df8947ddbb816038e9c838e598f2dcc4d3633d Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Mon, 3 Jun 2013 14:43:25 +0200 Subject: [PATCH] Fixing exercise order when adding a test, renaming function names --- .../classes/CourseRestorer.class.php | 4 +- main/exercice/exercice.php | 43 +++++++---------- main/exercice/exercise.class.php | 46 +++++++++++++------ 3 files changed, 51 insertions(+), 42 deletions(-) diff --git a/main/coursecopy/classes/CourseRestorer.class.php b/main/coursecopy/classes/CourseRestorer.class.php index b87b6db22c..213fa9f1ca 100644 --- a/main/coursecopy/classes/CourseRestorer.class.php +++ b/main/coursecopy/classes/CourseRestorer.class.php @@ -1506,7 +1506,7 @@ class CourseRestorer $exercise->read($new_id); if ($new_id != -1) { - $exercise->add_exercise_to_order_table(); + $exercise->addExerciseToOrderTable(); } $this->course->resources[RESOURCE_QUIZ][$id]->obj->destination_id = $new_id; @@ -2657,4 +2657,4 @@ class CourseRestorer return $array; } } -} \ No newline at end of file +} diff --git a/main/exercice/exercice.php b/main/exercice/exercice.php index 0ddd15ff3c..d7be89dcb0 100644 --- a/main/exercice/exercice.php +++ b/main/exercice/exercice.php @@ -204,7 +204,7 @@ if ($is_allowedToEdit) { if ($objExerciseTmp->read($exerciseId)) { if ($check) { switch ($choice) { - case 'delete' : // deletes an exercise + case 'delete': // deletes an exercise if ($exercise_action_locked == false) { $objExerciseTmp->delete(); require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php'; @@ -220,7 +220,7 @@ if ($is_allowedToEdit) { Display :: display_confirmation_message(get_lang('ExerciseDeleted')); } break; - case 'enable' : // enables an exercise + case 'enable': // enables an exercise $objExerciseTmp->enable(); $objExerciseTmp->save(); api_item_property_update( @@ -233,7 +233,7 @@ if ($is_allowedToEdit) { // "WHAT'S NEW" notification: update table item_property (previously last_tooledit) Display :: display_confirmation_message(get_lang('VisibilityChanged')); break; - case 'disable' : // disables an exercise + case 'disable': // disables an exercise $objExerciseTmp->disable(); $objExerciseTmp->save(); api_item_property_update( @@ -245,17 +245,17 @@ if ($is_allowedToEdit) { ); Display :: display_confirmation_message(get_lang('VisibilityChanged')); break; - case 'disable_results' : //disable the results for the learners + case 'disable_results': //disable the results for the learners $objExerciseTmp->disable_results(); $objExerciseTmp->save(); Display :: display_confirmation_message(get_lang('ResultsDisabled')); break; - case 'enable_results' : //disable the results for the learners + case 'enable_results': //disable the results for the learners $objExerciseTmp->enable_results(); $objExerciseTmp->save(); Display :: display_confirmation_message(get_lang('ResultsEnabled')); break; - case 'clean_results' : //clean student results + case 'clean_results': //clean student results if ($exercise_action_locked == false) { $quantity_results_deleted = $objExerciseTmp->clean_results(); Display :: display_confirmation_message( @@ -263,7 +263,7 @@ if ($is_allowedToEdit) { ); } break; - case 'copy_exercise' : + case 'copy_exercise': $objExerciseTmp->copy_exercise(); Display :: display_confirmation_message(get_lang('ExerciseCopied')); break; @@ -281,7 +281,7 @@ if ($is_allowedToEdit) { if (!empty($hpchoice)) { switch ($hpchoice) { - case 'delete' : // deletes an exercise + case 'delete': // deletes an exercise $imgparams = array(); $imgcount = 0; GetImgParams($file, $documentPath, $imgparams, $imgcount); @@ -294,7 +294,7 @@ if ($is_allowedToEdit) { if (FileManager::my_delete($documentPath.$file)) { FileManager::update_db_info("delete", $file); } - // hotpotatoes folder may contains several tests so don't delete folder if not empty : http://support.chamilo.org/issues/2165 + // hotpotatoes folder may contains several tests so don't delete folder if not empty : #2165 if (!(strstr($uploadPath, DIR_HOTPOTATOES) && !FileManager::folder_is_empty( $documentPath.$uploadPath."/".$fld."/" )) @@ -302,27 +302,21 @@ if ($is_allowedToEdit) { FileManager::my_delete($documentPath.$uploadPath."/".$fld."/"); } break; - case 'enable' : // enables an exercise + case 'enable': // enables an exercise $newVisibilityStatus = "1"; //"visible" - $query = "SELECT id FROM $TBL_DOCUMENT WHERE c_id = $course_id AND path='".Database :: escape_string( - $file - )."'"; + $query = "SELECT id FROM $TBL_DOCUMENT WHERE c_id = $course_id AND path='".Database :: escape_string($file)."'"; $res = Database::query($query); $row = Database :: fetch_array($res, 'ASSOC'); api_item_property_update($_course, TOOL_DOCUMENT, $row['id'], 'visible', $_user['user_id']); - //$dialogBox = get_lang('ViMod'); - break; - case 'disable' : // disables an exercise + case 'disable': // disables an exercise $newVisibilityStatus = "0"; //"invisible" - $query = "SELECT id FROM $TBL_DOCUMENT WHERE c_id = $course_id AND path='".Database :: escape_string( - $file - )."'"; + $query = "SELECT id FROM $TBL_DOCUMENT WHERE c_id = $course_id AND path='".Database :: escape_string($file)."'"; $res = Database::query($query); $row = Database :: fetch_array($res, 'ASSOC'); api_item_property_update($_course, TOOL_DOCUMENT, $row['id'], 'invisible', $_user['user_id']); break; - default : + default: break; } } @@ -347,7 +341,6 @@ $courseId = api_get_course_int_id(); $session_id = api_get_session_id(); $condition_session = api_get_session_condition($session_id, true, true); - // Only for administrators if ($is_allowedToEdit) { $total_sql = "SELECT count(iid) as count FROM $TBL_EXERCICES WHERE c_id = $course_id AND active<>'-1' $condition_session "; @@ -372,11 +365,9 @@ if (Database :: num_rows($result_total)) { $total_exercises = $result_total['count']; } -//get HotPotatoes files (active and inactive) +// Get HotPotatoes files (active and inactive) if ($is_allowedToEdit) { - $sql = "SELECT * FROM $TBL_DOCUMENT WHERE c_id = $course_id AND path LIKE '".Database :: escape_string( - $uploadPath - )."/%/%'"; + $sql = "SELECT * FROM $TBL_DOCUMENT WHERE c_id = $course_id AND path LIKE '".Database :: escape_string($uploadPath)."/%/%'"; $res = Database::query($sql); $hp_count = Database :: num_rows($res); } else { @@ -737,7 +728,7 @@ if (!empty($exercise_list)) { }*/ $number_of_questions = $exercise_obj->getQuestionCount(); - if ($row['random'] > 0 || $row['random'] != -1) { + if ($row['random'] > 0 && $row['random'] != -1) { $number_of_questions = $number_of_questions.' ('.$row['random'].' '.get_lang('Random').') '; } diff --git a/main/exercice/exercise.class.php b/main/exercice/exercise.class.php index ff533066cb..b34976833b 100644 --- a/main/exercice/exercise.class.php +++ b/main/exercice/exercise.class.php @@ -115,10 +115,11 @@ class Exercise } /** - * Reads exercise informations from the data base + * Reads exercise information from the database * * @author Olivier Brouckaert * @param int $id - exercise ID + * @param parse exercise question list * @return boolean - true if exercise exists, otherwise false */ public function read($id, $parseQuestionList = true) @@ -1258,7 +1259,7 @@ class Exercise Database::query($sql); $this->id = Database::insert_id(); - $this->add_exercise_to_order_table(); + $this->addExerciseToOrderTable(); // insert into the item_property table api_item_property_update($this->course, TOOL_QUIZ, $this->id, 'QuizAdded', api_get_user_id()); @@ -2122,7 +2123,7 @@ class Exercise } } - function search_engine_delete() + public function search_engine_delete() { // remove from search engine if enabled if (api_get_setting('search_enabled') == 'true' && extension_loaded('xapian')) { @@ -2161,7 +2162,7 @@ class Exercise } } - function selectExpiredTime() + public function selectExpiredTime() { return $this->expired_time; } @@ -2172,7 +2173,7 @@ class Exercise * Works with exercises in sessions * @return int quantity of user's exercises deleted */ - function clean_results() + public function clean_results() { $table_track_e_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); $table_track_e_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); @@ -2209,7 +2210,11 @@ class Exercise return $i; } - function get_last_exercise_order() + /** + * Gets the latest exercise order + * @return int + */ + public function getLastExerciseOrder() { $table = Database::get_course_table(TABLE_QUIZ_ORDER); $course_id = intval($this->course_id); @@ -2224,10 +2229,18 @@ class Exercise return 0; } - function get_exercise_order() + /** + * Get exercise order + * @return mixed + */ + public function getExerciseOrder() { $table = Database::get_course_table(TABLE_QUIZ_ORDER); - $sql = "SELECT exercise_order FROM $table WHERE exercise_id = {$this->id}"; + $courseId = $this->course_id; + $sessionId = api_get_session_id(); + + $sql = "SELECT exercise_order FROM $table + WHERE exercise_id = {$this->id} AND c_id = $courseId AND session_id = $sessionId "; $result = Database::query($sql); if (Database::num_rows($result)) { $row = Database::fetch_array($result); @@ -2237,10 +2250,13 @@ class Exercise return false; } - function add_exercise_to_order_table() + /** + * Add the exercise to the exercise order table + */ + public function addExerciseToOrderTable() { $table = Database::get_course_table(TABLE_QUIZ_ORDER); - $last_order = $this->get_last_exercise_order(); + $last_order = $this->getLastExerciseOrder(); $course_id = $this->course_id; if ($last_order == 0) { @@ -2254,7 +2270,7 @@ class Exercise ) ); } else { - $current_exercise_order = $this->get_exercise_order(); + $current_exercise_order = $this->getExerciseOrder(); if ($current_exercise_order == false) { Database::insert( $table, @@ -2269,11 +2285,11 @@ class Exercise } } - function update_exercise_list_order($new_exercise_list, $course_id, $session_id) + public function update_exercise_list_order($new_exercise_list, $course_id, $session_id) { $table = Database::get_course_table(TABLE_QUIZ_ORDER); $counter = 1; - //Drop all + // Drop all $session_id = intval($session_id); $course_id = intval($course_id); @@ -5220,7 +5236,9 @@ class Exercise $table_exercise_order = Database::get_course_table(TABLE_QUIZ_ORDER); $course_id = api_get_course_int_id(); $session_id = api_get_session_id(); - $sql = "SELECT exercise_id, exercise_order FROM $table_exercise_order WHERE c_id = $course_id AND session_id = $session_id ORDER BY exercise_order"; + $sql = "SELECT exercise_id, exercise_order FROM $table_exercise_order + WHERE c_id = $course_id AND session_id = $session_id ORDER BY exercise_order"; + $result = Database::query($sql); $list = array(); if (Database::num_rows($result)) {