@@ -1,63 +1,62 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ |
| 3 | 3 | /** |
| 4 | - * PEAR::HTML_Table makes the design of HTML tables easy, flexible, reusable and |
|
| 5 | - * efficient. |
|
| 6 | - * |
|
| 7 | - * The PEAR::HTML_Table package provides methods for easy and efficient design |
|
| 8 | - * of HTML tables. |
|
| 9 | - * - Lots of customization options. |
|
| 10 | - * - Tables can be modified at any time. |
|
| 11 | - * - The logic is the same as standard HTML editors. |
|
| 12 | - * - Handles col and rowspans. |
|
| 13 | - * - PHP code is shorter, easier to read and to maintain. |
|
| 14 | - * - Tables options can be reused. |
|
| 15 | - * |
|
| 16 | - * For auto filling of data and such then check out |
|
| 17 | - * http://pear.php.net/package/HTML_Table_Matrix |
|
| 18 | - * |
|
| 19 | - * PHP versions 4 and 5 |
|
| 20 | - * |
|
| 21 | - * LICENSE: |
|
| 22 | - * |
|
| 23 | - * Copyright (c) 2005-2007, Adam Daniel <[email protected]>, |
|
| 24 | - * Bertrand Mansion <[email protected]>, |
|
| 25 | - * Mark Wiesemann <[email protected]> |
|
| 26 | - * All rights reserved. |
|
| 27 | - * |
|
| 28 | - * Redistribution and use in source and binary forms, with or without |
|
| 29 | - * modification, are permitted provided that the following conditions |
|
| 30 | - * are met: |
|
| 31 | - * |
|
| 32 | - * * Redistributions of source code must retain the above copyright |
|
| 33 | - * notice, this list of conditions and the following disclaimer. |
|
| 34 | - * * Redistributions in binary form must reproduce the above copyright |
|
| 35 | - * notice, this list of conditions and the following disclaimer in the |
|
| 36 | - * documentation and/or other materials provided with the distribution. |
|
| 37 | - * * The names of the authors may not be used to endorse or promote products |
|
| 38 | - * derived from this software without specific prior written permission. |
|
| 39 | - * |
|
| 40 | - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
|
| 41 | - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
|
| 42 | - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
| 43 | - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
|
| 44 | - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
| 45 | - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
| 46 | - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
| 47 | - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
| 48 | - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
| 49 | - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|
| 50 | - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
| 51 | - |
|
| 52 | - * |
|
| 53 | - * @category HTML |
|
| 54 | - * @package HTML_Table |
|
| 55 | - * @author Adam Daniel <[email protected]> |
|
| 56 | - * @author Bertrand Mansion <[email protected]> |
|
| 57 | - * @license http://www.opensource.org/licenses/bsd-license.php New BSD License |
|
| 58 | - * @version CVS: $Id: Table.php,v 1.39 2007/06/25 16:44:43 wiesemann Exp $ |
|
| 59 | - * @link http://pear.php.net/package/HTML_Table |
|
| 60 | - */ |
|
| 4 | + * PEAR::HTML_Table makes the design of HTML tables easy, flexible, reusable and |
|
| 5 | + * efficient. |
|
| 6 | + * |
|
| 7 | + * The PEAR::HTML_Table package provides methods for easy and efficient design |
|
| 8 | + * of HTML tables. |
|
| 9 | + * - Lots of customization options. |
|
| 10 | + * - Tables can be modified at any time. |
|
| 11 | + * - The logic is the same as standard HTML editors. |
|
| 12 | + * - Handles col and rowspans. |
|
| 13 | + * - PHP code is shorter, easier to read and to maintain. |
|
| 14 | + * - Tables options can be reused. |
|
| 15 | + * |
|
| 16 | + * For auto filling of data and such then check out |
|
| 17 | + * http://pear.php.net/package/HTML_Table_Matrix |
|
| 18 | + * |
|
| 19 | + * PHP versions 4 and 5 |
|
| 20 | + * |
|
| 21 | + * LICENSE: |
|
| 22 | + * |
|
| 23 | + * Copyright (c) 2005-2007, Adam Daniel <[email protected]>, |
|
| 24 | + * Bertrand Mansion <[email protected]>, |
|
| 25 | + * Mark Wiesemann <[email protected]> |
|
| 26 | + * All rights reserved. |
|
| 27 | + * |
|
| 28 | + * Redistribution and use in source and binary forms, with or without |
|
| 29 | + * modification, are permitted provided that the following conditions |
|
| 30 | + * are met: |
|
| 31 | + * |
|
| 32 | + * * Redistributions of source code must retain the above copyright |
|
| 33 | + * notice, this list of conditions and the following disclaimer. |
|
| 34 | + * * Redistributions in binary form must reproduce the above copyright |
|
| 35 | + * notice, this list of conditions and the following disclaimer in the |
|
| 36 | + * documentation and/or other materials provided with the distribution. |
|
| 37 | + * * The names of the authors may not be used to endorse or promote products |
|
| 38 | + * derived from this software without specific prior written permission. |
|
| 39 | + * |
|
| 40 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
|
| 41 | + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
|
| 42 | + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
| 43 | + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
|
| 44 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
| 45 | + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
| 46 | + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
| 47 | + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
| 48 | + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
| 49 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|
| 50 | + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
| 51 | + * |
|
| 52 | + * @category HTML |
|
| 53 | + * @package HTML_Table |
|
| 54 | + * @author Adam Daniel <[email protected]> |
|
| 55 | + * @author Bertrand Mansion <[email protected]> |
|
| 56 | + * @license http://www.opensource.org/licenses/bsd-license.php New BSD License |
|
| 57 | + * @version CVS: $Id: Table.php,v 1.39 2007/06/25 16:44:43 wiesemann Exp $ |
|
| 58 | + * @link http://pear.php.net/package/HTML_Table |
|
| 59 | + */ |
|
| 61 | 60 | |
| 62 | 61 | /** |
| 63 | 62 | * PEAR::HTML_Table makes the design of HTML tables easy, flexible, reusable and efficient. |
@@ -256,7 +255,7 @@ discard block |
||
| 256 | 255 | |
| 257 | 256 | $body = $this->_tbodyCount++; |
| 258 | 257 | $this->_tbodies[$body] = new HTML_Table_Storage($this->_tabOffset, |
| 259 | - $this->_useTGroups); |
|
| 258 | + $this->_useTGroups); |
|
| 260 | 259 | $this->_tbodies[$body]->setAutoFill($this->_autoFill); |
| 261 | 260 | $this->_tbodies[$body]->setAttributes($attributes); |
| 262 | 261 | return $body; |
@@ -308,7 +307,7 @@ discard block |
||
| 308 | 307 | if (isset($colgroup)) { |
| 309 | 308 | $attributes = $this->_parseAttributes($attributes); |
| 310 | 309 | $this->_colgroup[] = array('attr' => $attributes, |
| 311 | - 'contents' => $colgroup); |
|
| 310 | + 'contents' => $colgroup); |
|
| 312 | 311 | } else { |
| 313 | 312 | $this->_colgroup = array(); |
| 314 | 313 | } |
@@ -13,11 +13,11 @@ discard block |
||
| 13 | 13 | public $name; |
| 14 | 14 | public $description; |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Constructor of the class Category |
|
| 18 | - * If you give an in_id and no in_name, you get info concerning the category of id=in_id |
|
| 19 | - * otherwise, you've got an category objet avec your in_id, in_name, in_descr |
|
| 20 | - * |
|
| 16 | + /** |
|
| 17 | + * Constructor of the class Category |
|
| 18 | + * If you give an in_id and no in_name, you get info concerning the category of id=in_id |
|
| 19 | + * otherwise, you've got an category objet avec your in_id, in_name, in_descr |
|
| 20 | + * |
|
| 21 | 21 | * @param int $id |
| 22 | 22 | * @param string $name |
| 23 | 23 | * @param string $description |
@@ -61,9 +61,9 @@ discard block |
||
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - /** |
|
| 64 | + /** |
|
| 65 | 65 | * add TestCategory in the database if name doesn't already exists |
| 66 | - */ |
|
| 66 | + */ |
|
| 67 | 67 | public function addCategoryInBDD() |
| 68 | 68 | { |
| 69 | 69 | $table = Database :: get_course_table(TABLE_QUIZ_QUESTION_CATEGORY); |
@@ -108,12 +108,12 @@ discard block |
||
| 108 | 108 | |
| 109 | 109 | return false; |
| 110 | 110 | } |
| 111 | - } |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - /** |
|
| 113 | + /** |
|
| 114 | 114 | * Removes the category from the database |
| 115 | 115 | * if there were question in this category, the link between question and category is removed |
| 116 | - */ |
|
| 116 | + */ |
|
| 117 | 117 | public function removeCategory() |
| 118 | 118 | { |
| 119 | 119 | $table = Database :: get_course_table(TABLE_QUIZ_QUESTION_CATEGORY); |
@@ -143,11 +143,11 @@ discard block |
||
| 143 | 143 | |
| 144 | 144 | return true; |
| 145 | 145 | } |
| 146 | - } |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - /** |
|
| 148 | + /** |
|
| 149 | 149 | * Modify category name or description of category with id=in_id |
| 150 | - */ |
|
| 150 | + */ |
|
| 151 | 151 | public function modifyCategory() |
| 152 | 152 | { |
| 153 | 153 | $table = Database :: get_course_table(TABLE_QUIZ_QUESTION_CATEGORY); |
@@ -175,40 +175,40 @@ discard block |
||
| 175 | 175 | |
| 176 | 176 | return true; |
| 177 | 177 | } |
| 178 | - } |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - /** |
|
| 180 | + /** |
|
| 181 | 181 | * Gets the number of question of category id=in_id |
| 182 | - */ |
|
| 182 | + */ |
|
| 183 | 183 | public function getCategoryQuestionsNumber() |
| 184 | 184 | { |
| 185 | - $table = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); |
|
| 186 | - $in_id = intval($this->id); |
|
| 187 | - $sql = "SELECT count(*) AS nb |
|
| 185 | + $table = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); |
|
| 186 | + $in_id = intval($this->id); |
|
| 187 | + $sql = "SELECT count(*) AS nb |
|
| 188 | 188 | FROM $table |
| 189 | 189 | WHERE category_id=$in_id AND c_id=".api_get_course_int_id(); |
| 190 | - $res = Database::query($sql); |
|
| 191 | - $row = Database::fetch_array($res); |
|
| 190 | + $res = Database::query($sql); |
|
| 191 | + $row = Database::fetch_array($res); |
|
| 192 | 192 | |
| 193 | - return $row['nb']; |
|
| 194 | - } |
|
| 193 | + return $row['nb']; |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | 196 | /** |
| 197 | 197 | * @param string $in_color |
| 198 | 198 | */ |
| 199 | 199 | public function display($in_color="#E0EBF5") |
| 200 | 200 | { |
| 201 | - echo "<textarea style='background-color:$in_color; width:60%; height:100px;'>"; |
|
| 202 | - print_r($this); |
|
| 203 | - echo "</textarea>"; |
|
| 204 | - } |
|
| 201 | + echo "<textarea style='background-color:$in_color; width:60%; height:100px;'>"; |
|
| 202 | + print_r($this); |
|
| 203 | + echo "</textarea>"; |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | - /** |
|
| 206 | + /** |
|
| 207 | 207 | * Return an array of all Category objects in the database |
| 208 | - * If in_field=="" Return an array of all category objects in the database |
|
| 209 | - * Otherwise, return an array of all in_field value |
|
| 210 | - * in the database (in_field = id or name or description) |
|
| 211 | - */ |
|
| 208 | + * If in_field=="" Return an array of all category objects in the database |
|
| 209 | + * Otherwise, return an array of all in_field value |
|
| 210 | + * in the database (in_field = id or name or description) |
|
| 211 | + */ |
|
| 212 | 212 | public static function getCategoryListInfo($in_field = "", $courseId = "") |
| 213 | 213 | { |
| 214 | 214 | if (empty($courseId) || $courseId=="") { |
@@ -239,8 +239,8 @@ discard block |
||
| 239 | 239 | } |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | - return $tabres; |
|
| 243 | - } |
|
| 242 | + return $tabres; |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | 245 | /** |
| 246 | 246 | * Return the TestCategory id for question with question_id = $questionId |
@@ -251,246 +251,246 @@ discard block |
||
| 251 | 251 | * |
| 252 | 252 | * @return int |
| 253 | 253 | */ |
| 254 | - public static function getCategoryForQuestion($questionId, $courseId ="") |
|
| 254 | + public static function getCategoryForQuestion($questionId, $courseId ="") |
|
| 255 | 255 | { |
| 256 | - $result = 0; |
|
| 256 | + $result = 0; |
|
| 257 | 257 | if (empty($courseId) || $courseId == "") { |
| 258 | 258 | $courseId = api_get_course_int_id(); |
| 259 | 259 | } |
| 260 | - $table = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); |
|
| 260 | + $table = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); |
|
| 261 | 261 | $questionId = intval($questionId); |
| 262 | - $sql = "SELECT category_id |
|
| 262 | + $sql = "SELECT category_id |
|
| 263 | 263 | FROM $table |
| 264 | 264 | WHERE question_id = $questionId AND c_id = $courseId"; |
| 265 | - $res = Database::query($sql); |
|
| 266 | - if (Database::num_rows($res) > 0) { |
|
| 265 | + $res = Database::query($sql); |
|
| 266 | + if (Database::num_rows($res) > 0) { |
|
| 267 | 267 | $data = Database::fetch_array($res); |
| 268 | - $result = $data['category_id']; |
|
| 269 | - } |
|
| 268 | + $result = $data['category_id']; |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | - return $result; |
|
| 272 | - } |
|
| 271 | + return $result; |
|
| 272 | + } |
|
| 273 | 273 | |
| 274 | - /** |
|
| 275 | - * true if question id has a category |
|
| 276 | - */ |
|
| 277 | - public static function isQuestionHasCategory($questionId) |
|
| 274 | + /** |
|
| 275 | + * true if question id has a category |
|
| 276 | + */ |
|
| 277 | + public static function isQuestionHasCategory($questionId) |
|
| 278 | 278 | { |
| 279 | - if (TestCategory::getCategoryForQuestion($questionId) > 0) { |
|
| 280 | - return true; |
|
| 281 | - } |
|
| 282 | - return false; |
|
| 283 | - } |
|
| 279 | + if (TestCategory::getCategoryForQuestion($questionId) > 0) { |
|
| 280 | + return true; |
|
| 281 | + } |
|
| 282 | + return false; |
|
| 283 | + } |
|
| 284 | 284 | |
| 285 | - /** |
|
| 285 | + /** |
|
| 286 | 286 | Return the category name for question with question_id = $questionId |
| 287 | 287 | In this version, a question has only 1 category. |
| 288 | 288 | Return the category id, "" if none |
| 289 | - */ |
|
| 289 | + */ |
|
| 290 | 290 | public static function getCategoryNameForQuestion( |
| 291 | 291 | $questionId, |
| 292 | 292 | $courseId = "" |
| 293 | 293 | ) { |
| 294 | - if (empty($courseId) || $courseId=="") { |
|
| 295 | - $courseId = api_get_course_int_id(); |
|
| 296 | - } |
|
| 297 | - $catid = TestCategory::getCategoryForQuestion($questionId, $courseId); |
|
| 298 | - $result = ""; // result |
|
| 299 | - $table = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY); |
|
| 300 | - $catid = intval($catid); |
|
| 301 | - $sql = "SELECT title FROM $table |
|
| 294 | + if (empty($courseId) || $courseId=="") { |
|
| 295 | + $courseId = api_get_course_int_id(); |
|
| 296 | + } |
|
| 297 | + $catid = TestCategory::getCategoryForQuestion($questionId, $courseId); |
|
| 298 | + $result = ""; // result |
|
| 299 | + $table = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY); |
|
| 300 | + $catid = intval($catid); |
|
| 301 | + $sql = "SELECT title FROM $table |
|
| 302 | 302 | WHERE id = $catid AND c_id = $courseId"; |
| 303 | - $res = Database::query($sql); |
|
| 304 | - $data = Database::fetch_array($res); |
|
| 305 | - if (Database::num_rows($res) > 0) { |
|
| 306 | - $result = $data['title']; |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - return $result; |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - /** |
|
| 313 | - * Return the list of differents categories ID for a test in the current course |
|
| 314 | - * input : test_id |
|
| 315 | - * return : array of category id (integer) |
|
| 316 | - * hubert.borderiou 07-04-2011 |
|
| 317 | - * @param int $exerciseId |
|
| 318 | - */ |
|
| 319 | - public static function getListOfCategoriesIDForTest($exerciseId) |
|
| 303 | + $res = Database::query($sql); |
|
| 304 | + $data = Database::fetch_array($res); |
|
| 305 | + if (Database::num_rows($res) > 0) { |
|
| 306 | + $result = $data['title']; |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + return $result; |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + /** |
|
| 313 | + * Return the list of differents categories ID for a test in the current course |
|
| 314 | + * input : test_id |
|
| 315 | + * return : array of category id (integer) |
|
| 316 | + * hubert.borderiou 07-04-2011 |
|
| 317 | + * @param int $exerciseId |
|
| 318 | + */ |
|
| 319 | + public static function getListOfCategoriesIDForTest($exerciseId) |
|
| 320 | 320 | { |
| 321 | - // parcourir les questions d'un test, recup les categories uniques dans un tableau |
|
| 322 | - $exercise = new Exercise(); |
|
| 323 | - $exercise->read($exerciseId, false); |
|
| 324 | - $categoriesInExercise = $exercise->getQuestionWithCategories(); |
|
| 325 | - // the array given by selectQuestionList start at indice 1 and not at indice 0 !!! ??? |
|
| 326 | - $categories = array(); |
|
| 321 | + // parcourir les questions d'un test, recup les categories uniques dans un tableau |
|
| 322 | + $exercise = new Exercise(); |
|
| 323 | + $exercise->read($exerciseId, false); |
|
| 324 | + $categoriesInExercise = $exercise->getQuestionWithCategories(); |
|
| 325 | + // the array given by selectQuestionList start at indice 1 and not at indice 0 !!! ??? |
|
| 326 | + $categories = array(); |
|
| 327 | 327 | if (!empty($categoriesInExercise)) { |
| 328 | - foreach ($categoriesInExercise as $category) { |
|
| 329 | - //$category['id'] = $category['iid']; |
|
| 330 | - $categories[$category['id']] = $category; |
|
| 331 | - } |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - return $categories; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * @param Exercise $exercise_obj |
|
| 339 | - * @return array |
|
| 340 | - */ |
|
| 341 | - public static function getListOfCategoriesIDForTestObject(Exercise $exercise_obj) |
|
| 342 | - { |
|
| 343 | - // parcourir les questions d'un test, recup les categories uniques dans un tableau |
|
| 344 | - $categories_in_exercise = array(); |
|
| 345 | - // $question_list = $exercise_obj->getQuestionList(); |
|
| 346 | - $question_list = $exercise_obj->getQuestionOrderedListByName(); |
|
| 347 | - |
|
| 348 | - // the array given by selectQuestionList start at indice 1 and not at indice 0 !!! ??? |
|
| 349 | - foreach ($question_list as $questionInfo) { |
|
| 350 | - $question_id = $questionInfo['question_id']; |
|
| 351 | - $category_list = self::getCategoryForQuestion($question_id); |
|
| 352 | - if (is_numeric($category_list)) { |
|
| 353 | - $category_list = array($category_list); |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - if (!empty($category_list)) { |
|
| 357 | - $categories_in_exercise = array_merge($categories_in_exercise, $category_list); |
|
| 358 | - } |
|
| 359 | - } |
|
| 360 | - if (!empty($categories_in_exercise)) { |
|
| 361 | - $categories_in_exercise = array_unique(array_filter($categories_in_exercise)); |
|
| 362 | - } |
|
| 363 | - return $categories_in_exercise; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - /** |
|
| 367 | - * Return the list of differents categories NAME for a test |
|
| 368 | - * @param int exercise id |
|
| 369 | - * @param bool |
|
| 370 | - * @return array of string |
|
| 371 | - * |
|
| 328 | + foreach ($categoriesInExercise as $category) { |
|
| 329 | + //$category['id'] = $category['iid']; |
|
| 330 | + $categories[$category['id']] = $category; |
|
| 331 | + } |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + return $categories; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * @param Exercise $exercise_obj |
|
| 339 | + * @return array |
|
| 340 | + */ |
|
| 341 | + public static function getListOfCategoriesIDForTestObject(Exercise $exercise_obj) |
|
| 342 | + { |
|
| 343 | + // parcourir les questions d'un test, recup les categories uniques dans un tableau |
|
| 344 | + $categories_in_exercise = array(); |
|
| 345 | + // $question_list = $exercise_obj->getQuestionList(); |
|
| 346 | + $question_list = $exercise_obj->getQuestionOrderedListByName(); |
|
| 347 | + |
|
| 348 | + // the array given by selectQuestionList start at indice 1 and not at indice 0 !!! ??? |
|
| 349 | + foreach ($question_list as $questionInfo) { |
|
| 350 | + $question_id = $questionInfo['question_id']; |
|
| 351 | + $category_list = self::getCategoryForQuestion($question_id); |
|
| 352 | + if (is_numeric($category_list)) { |
|
| 353 | + $category_list = array($category_list); |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + if (!empty($category_list)) { |
|
| 357 | + $categories_in_exercise = array_merge($categories_in_exercise, $category_list); |
|
| 358 | + } |
|
| 359 | + } |
|
| 360 | + if (!empty($categories_in_exercise)) { |
|
| 361 | + $categories_in_exercise = array_unique(array_filter($categories_in_exercise)); |
|
| 362 | + } |
|
| 363 | + return $categories_in_exercise; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + /** |
|
| 367 | + * Return the list of differents categories NAME for a test |
|
| 368 | + * @param int exercise id |
|
| 369 | + * @param bool |
|
| 370 | + * @return array of string |
|
| 371 | + * |
|
| 372 | 372 | * @author function rewrote by jmontoya |
| 373 | - */ |
|
| 374 | - public static function getListOfCategoriesNameForTest($exercise_id, $grouped_by_category = true) |
|
| 373 | + */ |
|
| 374 | + public static function getListOfCategoriesNameForTest($exercise_id, $grouped_by_category = true) |
|
| 375 | 375 | { |
| 376 | - $result = array(); |
|
| 377 | - $categories = self::getListOfCategoriesIDForTest($exercise_id, $grouped_by_category); |
|
| 376 | + $result = array(); |
|
| 377 | + $categories = self::getListOfCategoriesIDForTest($exercise_id, $grouped_by_category); |
|
| 378 | 378 | |
| 379 | - foreach ($categories as $catInfo) { |
|
| 380 | - $categoryId = $catInfo['id']; |
|
| 381 | - if (!empty($categoryId)) { |
|
| 382 | - $result[$categoryId] = array( |
|
| 379 | + foreach ($categories as $catInfo) { |
|
| 380 | + $categoryId = $catInfo['id']; |
|
| 381 | + if (!empty($categoryId)) { |
|
| 382 | + $result[$categoryId] = array( |
|
| 383 | 383 | 'title' => $catInfo['title'], |
| 384 | 384 | //'parent_id' => $catInfo['parent_id'], |
| 385 | - 'parent_id' => '', |
|
| 385 | + 'parent_id' => '', |
|
| 386 | 386 | 'c_id' => $catInfo['c_id'] |
| 387 | 387 | ); |
| 388 | - } |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - return $result; |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - /** |
|
| 395 | - * @param Exercise $exercise_obj |
|
| 396 | - * @return array |
|
| 397 | - */ |
|
| 398 | - public static function getListOfCategoriesForTest(Exercise $exercise_obj) |
|
| 399 | - { |
|
| 400 | - $result = array(); |
|
| 401 | - $categories = self::getListOfCategoriesIDForTestObject($exercise_obj); |
|
| 402 | - foreach ($categories as $cat_id) { |
|
| 403 | - $cat = new TestCategory($cat_id); |
|
| 404 | - $cat = (array)$cat; |
|
| 405 | - $cat['iid'] = $cat['id']; |
|
| 406 | - $cat['title'] = $cat['name']; |
|
| 407 | - $result[$cat['id']] = $cat; |
|
| 408 | - } |
|
| 409 | - return $result; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * return the number of differents categories for a test |
|
| 414 | - * input : test_id |
|
| 415 | - * return : integer |
|
| 416 | - * hubert.borderiou 07-04-2011 |
|
| 417 | - */ |
|
| 418 | - public static function getNumberOfCategoriesForTest($id) |
|
| 388 | + } |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + return $result; |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + /** |
|
| 395 | + * @param Exercise $exercise_obj |
|
| 396 | + * @return array |
|
| 397 | + */ |
|
| 398 | + public static function getListOfCategoriesForTest(Exercise $exercise_obj) |
|
| 399 | + { |
|
| 400 | + $result = array(); |
|
| 401 | + $categories = self::getListOfCategoriesIDForTestObject($exercise_obj); |
|
| 402 | + foreach ($categories as $cat_id) { |
|
| 403 | + $cat = new TestCategory($cat_id); |
|
| 404 | + $cat = (array)$cat; |
|
| 405 | + $cat['iid'] = $cat['id']; |
|
| 406 | + $cat['title'] = $cat['name']; |
|
| 407 | + $result[$cat['id']] = $cat; |
|
| 408 | + } |
|
| 409 | + return $result; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * return the number of differents categories for a test |
|
| 414 | + * input : test_id |
|
| 415 | + * return : integer |
|
| 416 | + * hubert.borderiou 07-04-2011 |
|
| 417 | + */ |
|
| 418 | + public static function getNumberOfCategoriesForTest($id) |
|
| 419 | 419 | { |
| 420 | - return count(TestCategory::getListOfCategoriesIDForTest($id)); |
|
| 421 | - } |
|
| 420 | + return count(TestCategory::getListOfCategoriesIDForTest($id)); |
|
| 421 | + } |
|
| 422 | 422 | |
| 423 | - /** |
|
| 424 | - * return the number of question of a category id in a test |
|
| 425 | - * @param int $exerciseId |
|
| 423 | + /** |
|
| 424 | + * return the number of question of a category id in a test |
|
| 425 | + * @param int $exerciseId |
|
| 426 | 426 | * @param int $categoryId |
| 427 | 427 | * |
| 428 | - * @return integer |
|
| 428 | + * @return integer |
|
| 429 | 429 | * |
| 430 | - * @author hubert.borderiou 07-04-2011 |
|
| 431 | - */ |
|
| 432 | - public static function getNumberOfQuestionsInCategoryForTest($exerciseId, $categoryId) |
|
| 430 | + * @author hubert.borderiou 07-04-2011 |
|
| 431 | + */ |
|
| 432 | + public static function getNumberOfQuestionsInCategoryForTest($exerciseId, $categoryId) |
|
| 433 | 433 | { |
| 434 | - $nbCatResult = 0; |
|
| 435 | - $quiz = new Exercise(); |
|
| 436 | - $quiz->read($exerciseId); |
|
| 437 | - $tabQuestionList = $quiz->selectQuestionList(); |
|
| 438 | - // the array given by selectQuestionList start at indice 1 and not at indice 0 !!! ? ? ? |
|
| 439 | - for ($i=1; $i <= count($tabQuestionList); $i++) { |
|
| 440 | - if (TestCategory::getCategoryForQuestion($tabQuestionList[$i]) == $categoryId) { |
|
| 441 | - $nbCatResult++; |
|
| 442 | - } |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - return $nbCatResult; |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - /** |
|
| 449 | - * return the number of question for a test using random by category |
|
| 450 | - * input : test_id, number of random question (min 1) |
|
| 451 | - * hubert.borderiou 07-04-2011 |
|
| 452 | - * question without categories are not counted |
|
| 453 | - */ |
|
| 454 | - public static function getNumberOfQuestionRandomByCategory($exerciseId, $in_nbrandom) |
|
| 434 | + $nbCatResult = 0; |
|
| 435 | + $quiz = new Exercise(); |
|
| 436 | + $quiz->read($exerciseId); |
|
| 437 | + $tabQuestionList = $quiz->selectQuestionList(); |
|
| 438 | + // the array given by selectQuestionList start at indice 1 and not at indice 0 !!! ? ? ? |
|
| 439 | + for ($i=1; $i <= count($tabQuestionList); $i++) { |
|
| 440 | + if (TestCategory::getCategoryForQuestion($tabQuestionList[$i]) == $categoryId) { |
|
| 441 | + $nbCatResult++; |
|
| 442 | + } |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + return $nbCatResult; |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + /** |
|
| 449 | + * return the number of question for a test using random by category |
|
| 450 | + * input : test_id, number of random question (min 1) |
|
| 451 | + * hubert.borderiou 07-04-2011 |
|
| 452 | + * question without categories are not counted |
|
| 453 | + */ |
|
| 454 | + public static function getNumberOfQuestionRandomByCategory($exerciseId, $in_nbrandom) |
|
| 455 | 455 | { |
| 456 | - $nbquestionresult = 0; |
|
| 457 | - $tabcatid = TestCategory::getListOfCategoriesIDForTest($exerciseId); |
|
| 458 | - for ($i=0; $i < count($tabcatid); $i++) { |
|
| 459 | - if ($tabcatid[$i] > 0 && $tabcatid[$i] > 0) { // 0 = no category for this questio |
|
| 460 | - $nbQuestionInThisCat = TestCategory::getNumberOfQuestionsInCategoryForTest($exerciseId, $tabcatid[$i]); |
|
| 461 | - if ($nbQuestionInThisCat > $in_nbrandom) { |
|
| 462 | - $nbquestionresult += $in_nbrandom; |
|
| 463 | - } |
|
| 464 | - else { |
|
| 465 | - $nbquestionresult += $nbQuestionInThisCat; |
|
| 466 | - } |
|
| 467 | - } |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - return $nbquestionresult; |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - /** |
|
| 474 | - * Return an array (id=>name) |
|
| 475 | - * tabresult[0] = get_lang('NoCategory'); |
|
| 456 | + $nbquestionresult = 0; |
|
| 457 | + $tabcatid = TestCategory::getListOfCategoriesIDForTest($exerciseId); |
|
| 458 | + for ($i=0; $i < count($tabcatid); $i++) { |
|
| 459 | + if ($tabcatid[$i] > 0 && $tabcatid[$i] > 0) { // 0 = no category for this questio |
|
| 460 | + $nbQuestionInThisCat = TestCategory::getNumberOfQuestionsInCategoryForTest($exerciseId, $tabcatid[$i]); |
|
| 461 | + if ($nbQuestionInThisCat > $in_nbrandom) { |
|
| 462 | + $nbquestionresult += $in_nbrandom; |
|
| 463 | + } |
|
| 464 | + else { |
|
| 465 | + $nbquestionresult += $nbQuestionInThisCat; |
|
| 466 | + } |
|
| 467 | + } |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + return $nbquestionresult; |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + /** |
|
| 474 | + * Return an array (id=>name) |
|
| 475 | + * tabresult[0] = get_lang('NoCategory'); |
|
| 476 | 476 | * |
| 477 | 477 | * @param int $courseId |
| 478 | 478 | * |
| 479 | 479 | * @return array |
| 480 | - * |
|
| 481 | - */ |
|
| 480 | + * |
|
| 481 | + */ |
|
| 482 | 482 | public static function getCategoriesIdAndName($courseId = "") |
| 483 | 483 | { |
| 484 | - if (empty($courseId)) { |
|
| 485 | - $courseId = api_get_course_int_id(); |
|
| 486 | - } |
|
| 487 | - $tabcatobject = TestCategory::getCategoryListInfo("", $courseId); |
|
| 488 | - $tabresult = array("0"=>get_lang('NoCategorySelected')); |
|
| 489 | - for ($i=0; $i < count($tabcatobject); $i++) { |
|
| 490 | - $tabresult[$tabcatobject[$i]->id] = $tabcatobject[$i]->name; |
|
| 491 | - } |
|
| 492 | - return $tabresult; |
|
| 493 | - } |
|
| 484 | + if (empty($courseId)) { |
|
| 485 | + $courseId = api_get_course_int_id(); |
|
| 486 | + } |
|
| 487 | + $tabcatobject = TestCategory::getCategoryListInfo("", $courseId); |
|
| 488 | + $tabresult = array("0"=>get_lang('NoCategorySelected')); |
|
| 489 | + for ($i=0; $i < count($tabcatobject); $i++) { |
|
| 490 | + $tabresult[$tabcatobject[$i]->id] = $tabcatobject[$i]->name; |
|
| 491 | + } |
|
| 492 | + return $tabresult; |
|
| 493 | + } |
|
| 494 | 494 | |
| 495 | 495 | /** |
| 496 | 496 | * Returns an array of question ids for each category |
@@ -499,10 +499,10 @@ discard block |
||
| 499 | 499 | * @param int exercise |
| 500 | 500 | * @param array $check_in_question_list |
| 501 | 501 | * @param array $categoriesAddedInExercise |
| 502 | - * |
|
| 503 | - * @param int $exerciseId |
|
| 504 | - * @return array |
|
| 505 | - */ |
|
| 502 | + * |
|
| 503 | + * @param int $exerciseId |
|
| 504 | + * @return array |
|
| 505 | + */ |
|
| 506 | 506 | static function getQuestionsByCat( |
| 507 | 507 | $exerciseId, |
| 508 | 508 | $check_in_question_list = array(), |
@@ -580,28 +580,28 @@ discard block |
||
| 580 | 580 | } |
| 581 | 581 | |
| 582 | 582 | return $categories; |
| 583 | - } |
|
| 583 | + } |
|
| 584 | 584 | |
| 585 | - /** |
|
| 586 | - * return a tab of $in_number random elements of $in_tab |
|
| 587 | - */ |
|
| 585 | + /** |
|
| 586 | + * return a tab of $in_number random elements of $in_tab |
|
| 587 | + */ |
|
| 588 | 588 | public static function getNElementsFromArray($in_tab, $in_number) |
| 589 | 589 | { |
| 590 | - $tabres = $in_tab; |
|
| 591 | - shuffle($tabres); |
|
| 592 | - if ($in_number < count($tabres)) { |
|
| 593 | - $tabres = array_slice($tabres, 0, $in_number); |
|
| 594 | - } |
|
| 595 | - return $tabres; |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - /** |
|
| 599 | - * display the category |
|
| 600 | - */ |
|
| 601 | - public static function displayCategoryAndTitle($questionId, $in_display_category_name = 1) |
|
| 590 | + $tabres = $in_tab; |
|
| 591 | + shuffle($tabres); |
|
| 592 | + if ($in_number < count($tabres)) { |
|
| 593 | + $tabres = array_slice($tabres, 0, $in_number); |
|
| 594 | + } |
|
| 595 | + return $tabres; |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + /** |
|
| 599 | + * display the category |
|
| 600 | + */ |
|
| 601 | + public static function displayCategoryAndTitle($questionId, $in_display_category_name = 1) |
|
| 602 | 602 | { |
| 603 | 603 | echo self::returnCategoryAndTitle($questionId, $in_display_category_name); |
| 604 | - } |
|
| 604 | + } |
|
| 605 | 605 | |
| 606 | 606 | /** |
| 607 | 607 | * @param int $questionId |
@@ -617,98 +617,98 @@ discard block |
||
| 617 | 617 | $in_display_category_name = $objExercise->display_category_name; |
| 618 | 618 | } |
| 619 | 619 | $content = null; |
| 620 | - if (TestCategory::getCategoryNameForQuestion($questionId) != "" && ($in_display_category_name == 1 || !$is_student)) { |
|
| 620 | + if (TestCategory::getCategoryNameForQuestion($questionId) != "" && ($in_display_category_name == 1 || !$is_student)) { |
|
| 621 | 621 | $content .= '<div class="page-header">'; |
| 622 | 622 | $content .= '<h4>'.get_lang('Category').": ".TestCategory::getCategoryNameForQuestion($questionId).'</h4>'; |
| 623 | 623 | $content .= "</div>"; |
| 624 | - } |
|
| 624 | + } |
|
| 625 | 625 | return $content; |
| 626 | - } |
|
| 626 | + } |
|
| 627 | 627 | |
| 628 | 628 | /** |
| 629 | - * Display signs [+] and/or (>0) after question title if question has options |
|
| 630 | - * scoreAlwaysPositive and/or uncheckedMayScore |
|
| 631 | - */ |
|
| 629 | + * Display signs [+] and/or (>0) after question title if question has options |
|
| 630 | + * scoreAlwaysPositive and/or uncheckedMayScore |
|
| 631 | + */ |
|
| 632 | 632 | public function displayQuestionOption($in_objQuestion) |
| 633 | 633 | { |
| 634 | - if ($in_objQuestion->type == MULTIPLE_ANSWER && $in_objQuestion->scoreAlwaysPositive) { |
|
| 635 | - echo "<span style='font-size:75%'> (>0)</span>"; |
|
| 636 | - } |
|
| 637 | - if ($in_objQuestion->type == MULTIPLE_ANSWER && $in_objQuestion->uncheckedMayScore) { |
|
| 638 | - echo "<span style='font-size:75%'> [+]</span>"; |
|
| 639 | - } |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - /** |
|
| 643 | - * sortTabByBracketLabel ($tabCategoryQuestions) |
|
| 644 | - * key of $tabCategoryQuestions are the category id (0 for not in a category) |
|
| 645 | - * value is the array of question id of this category |
|
| 646 | - * Sort question by Category |
|
| 647 | - */ |
|
| 634 | + if ($in_objQuestion->type == MULTIPLE_ANSWER && $in_objQuestion->scoreAlwaysPositive) { |
|
| 635 | + echo "<span style='font-size:75%'> (>0)</span>"; |
|
| 636 | + } |
|
| 637 | + if ($in_objQuestion->type == MULTIPLE_ANSWER && $in_objQuestion->uncheckedMayScore) { |
|
| 638 | + echo "<span style='font-size:75%'> [+]</span>"; |
|
| 639 | + } |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + /** |
|
| 643 | + * sortTabByBracketLabel ($tabCategoryQuestions) |
|
| 644 | + * key of $tabCategoryQuestions are the category id (0 for not in a category) |
|
| 645 | + * value is the array of question id of this category |
|
| 646 | + * Sort question by Category |
|
| 647 | + */ |
|
| 648 | 648 | public static function sortTabByBracketLabel($in_tab) |
| 649 | 649 | { |
| 650 | - $tabResult = array(); |
|
| 651 | - $tabCatName = array(); // tab of category name |
|
| 652 | - while (list($cat_id, $tabquestion) = each($in_tab)) { |
|
| 653 | - $catTitle = new TestCategory($cat_id); |
|
| 654 | - $tabCatName[$cat_id] = $catTitle->name; |
|
| 655 | - } |
|
| 656 | - reset($in_tab); |
|
| 657 | - // sort table by value, keeping keys as they are |
|
| 658 | - asort($tabCatName); |
|
| 659 | - // keys of $tabCatName are keys order for $in_tab |
|
| 660 | - while (list($key, $val) = each($tabCatName)) { |
|
| 661 | - $tabResult[$key] = $in_tab[$key]; |
|
| 662 | - } |
|
| 663 | - return $tabResult; |
|
| 664 | - } |
|
| 650 | + $tabResult = array(); |
|
| 651 | + $tabCatName = array(); // tab of category name |
|
| 652 | + while (list($cat_id, $tabquestion) = each($in_tab)) { |
|
| 653 | + $catTitle = new TestCategory($cat_id); |
|
| 654 | + $tabCatName[$cat_id] = $catTitle->name; |
|
| 655 | + } |
|
| 656 | + reset($in_tab); |
|
| 657 | + // sort table by value, keeping keys as they are |
|
| 658 | + asort($tabCatName); |
|
| 659 | + // keys of $tabCatName are keys order for $in_tab |
|
| 660 | + while (list($key, $val) = each($tabCatName)) { |
|
| 661 | + $tabResult[$key] = $in_tab[$key]; |
|
| 662 | + } |
|
| 663 | + return $tabResult; |
|
| 664 | + } |
|
| 665 | 665 | |
| 666 | 666 | /** |
| 667 | - * return total score for test exe_id for all question in the category $in_cat_id for user |
|
| 668 | - * If no question for this category, return "" |
|
| 669 | - */ |
|
| 670 | - public static function getCatScoreForExeidForUserid($in_cat_id, $in_exe_id, $in_user_id) |
|
| 671 | - { |
|
| 672 | - $tbl_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); |
|
| 673 | - $tbl_question_rel_category = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); |
|
| 674 | - $in_cat_id = intval($in_cat_id); |
|
| 675 | - $in_exe_id = intval($in_exe_id); |
|
| 676 | - $in_user_id = intval($in_user_id); |
|
| 677 | - |
|
| 678 | - $query = "SELECT DISTINCT |
|
| 667 | + * return total score for test exe_id for all question in the category $in_cat_id for user |
|
| 668 | + * If no question for this category, return "" |
|
| 669 | + */ |
|
| 670 | + public static function getCatScoreForExeidForUserid($in_cat_id, $in_exe_id, $in_user_id) |
|
| 671 | + { |
|
| 672 | + $tbl_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); |
|
| 673 | + $tbl_question_rel_category = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); |
|
| 674 | + $in_cat_id = intval($in_cat_id); |
|
| 675 | + $in_exe_id = intval($in_exe_id); |
|
| 676 | + $in_user_id = intval($in_user_id); |
|
| 677 | + |
|
| 678 | + $query = "SELECT DISTINCT |
|
| 679 | 679 | marks, exe_id, user_id, ta.question_id, category_id |
| 680 | 680 | FROM $tbl_track_attempt ta , $tbl_question_rel_category qrc |
| 681 | 681 | WHERE |
| 682 | 682 | ta.question_id=qrc.question_id AND |
| 683 | 683 | qrc.category_id=$in_cat_id AND |
| 684 | 684 | exe_id=$in_exe_id AND user_id=$in_user_id"; |
| 685 | - $res = Database::query($query); |
|
| 686 | - $totalcatscore = ""; |
|
| 687 | - while ($data = Database::fetch_array($res)) { |
|
| 688 | - $totalcatscore += $data['marks']; |
|
| 689 | - } |
|
| 690 | - return $totalcatscore; |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - /** |
|
| 685 | + $res = Database::query($query); |
|
| 686 | + $totalcatscore = ""; |
|
| 687 | + while ($data = Database::fetch_array($res)) { |
|
| 688 | + $totalcatscore += $data['marks']; |
|
| 689 | + } |
|
| 690 | + return $totalcatscore; |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + /** |
|
| 694 | 694 | * return the number max of question in a category |
| 695 | 695 | * count the number of questions in all categories, and return the max |
| 696 | 696 | * @param int $exerciseId |
| 697 | 697 | * @author - hubert borderiou |
| 698 | - */ |
|
| 698 | + */ |
|
| 699 | 699 | public static function getNumberMaxQuestionByCat($exerciseId) |
| 700 | 700 | { |
| 701 | 701 | $res_num_max = 0; |
| 702 | 702 | // foreach question |
| 703 | - $tabcatid = TestCategory::getListOfCategoriesIDForTest($exerciseId); |
|
| 704 | - for ($i=0; $i < count($tabcatid); $i++) { |
|
| 705 | - if ($tabcatid[$i] > 0) { // 0 = no category for this question |
|
| 706 | - $nbQuestionInThisCat = TestCategory::getNumberOfQuestionsInCategoryForTest($exerciseId, $tabcatid[$i]); |
|
| 703 | + $tabcatid = TestCategory::getListOfCategoriesIDForTest($exerciseId); |
|
| 704 | + for ($i=0; $i < count($tabcatid); $i++) { |
|
| 705 | + if ($tabcatid[$i] > 0) { // 0 = no category for this question |
|
| 706 | + $nbQuestionInThisCat = TestCategory::getNumberOfQuestionsInCategoryForTest($exerciseId, $tabcatid[$i]); |
|
| 707 | 707 | if ($nbQuestionInThisCat > $res_num_max) { |
| 708 | 708 | $res_num_max = $nbQuestionInThisCat; |
| 709 | 709 | } |
| 710 | - } |
|
| 711 | - } |
|
| 710 | + } |
|
| 711 | + } |
|
| 712 | 712 | return $res_num_max; |
| 713 | 713 | } |
| 714 | 714 | |
@@ -768,34 +768,34 @@ discard block |
||
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | /** |
| 771 | - * @return array |
|
| 772 | - */ |
|
| 773 | - function get_all_categories() |
|
| 774 | - { |
|
| 775 | - $table = Database::get_course_table(TABLE_QUIZ_CATEGORY); |
|
| 776 | - $sql = "SELECT * FROM $table ORDER BY title ASC"; |
|
| 777 | - $res = Database::query($sql); |
|
| 778 | - while ($row = Database::fetch_array($res,'ASSOC')) { |
|
| 779 | - $array[] = $row; |
|
| 780 | - } |
|
| 781 | - return $array; |
|
| 782 | - } |
|
| 783 | - |
|
| 784 | - /** |
|
| 785 | - * @param Exercise $exercise |
|
| 786 | - * @param int $course_id |
|
| 787 | - * @param string $order |
|
| 788 | - * @param bool $shuffle |
|
| 789 | - * @param bool $excludeCategoryWithNoQuestions |
|
| 790 | - * @return array|bool |
|
| 791 | - */ |
|
| 792 | - public function getCategoryExerciseTree( |
|
| 793 | - $exercise, |
|
| 794 | - $course_id, |
|
| 795 | - $order = null, |
|
| 796 | - $shuffle = false, |
|
| 797 | - $excludeCategoryWithNoQuestions = true |
|
| 798 | - ) { |
|
| 771 | + * @return array |
|
| 772 | + */ |
|
| 773 | + function get_all_categories() |
|
| 774 | + { |
|
| 775 | + $table = Database::get_course_table(TABLE_QUIZ_CATEGORY); |
|
| 776 | + $sql = "SELECT * FROM $table ORDER BY title ASC"; |
|
| 777 | + $res = Database::query($sql); |
|
| 778 | + while ($row = Database::fetch_array($res,'ASSOC')) { |
|
| 779 | + $array[] = $row; |
|
| 780 | + } |
|
| 781 | + return $array; |
|
| 782 | + } |
|
| 783 | + |
|
| 784 | + /** |
|
| 785 | + * @param Exercise $exercise |
|
| 786 | + * @param int $course_id |
|
| 787 | + * @param string $order |
|
| 788 | + * @param bool $shuffle |
|
| 789 | + * @param bool $excludeCategoryWithNoQuestions |
|
| 790 | + * @return array|bool |
|
| 791 | + */ |
|
| 792 | + public function getCategoryExerciseTree( |
|
| 793 | + $exercise, |
|
| 794 | + $course_id, |
|
| 795 | + $order = null, |
|
| 796 | + $shuffle = false, |
|
| 797 | + $excludeCategoryWithNoQuestions = true |
|
| 798 | + ) { |
|
| 799 | 799 | if (empty($exercise)) { |
| 800 | 800 | return array(); |
| 801 | 801 | } |
@@ -805,165 +805,165 @@ discard block |
||
| 805 | 805 | } |
| 806 | 806 | |
| 807 | 807 | $course_id = intval($course_id); |
| 808 | - $table = Database::get_course_table(TABLE_QUIZ_REL_CATEGORY); |
|
| 808 | + $table = Database::get_course_table(TABLE_QUIZ_REL_CATEGORY); |
|
| 809 | 809 | $categoryTable = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY); |
| 810 | - $sql = "SELECT * FROM $table qc |
|
| 810 | + $sql = "SELECT * FROM $table qc |
|
| 811 | 811 | LEFT JOIN $categoryTable c |
| 812 | 812 | ON (qc.c_id = c.c_id AND c.id = qc.category_id) |
| 813 | 813 | WHERE qc.c_id = $course_id AND exercise_id = {$exercise->id} "; |
| 814 | 814 | |
| 815 | - if (!empty($order)) { |
|
| 816 | - $sql .= "ORDER BY $order"; |
|
| 817 | - } |
|
| 818 | - |
|
| 819 | - $categories = array(); |
|
| 820 | - |
|
| 821 | - $result = Database::query($sql); |
|
| 822 | - if (Database::num_rows($result)) { |
|
| 823 | - while ($row = Database::fetch_array($result, 'ASSOC')) { |
|
| 824 | - if ($excludeCategoryWithNoQuestions) { |
|
| 825 | - if ($row['count_questions'] == 0) { |
|
| 826 | - continue; |
|
| 827 | - } |
|
| 828 | - } |
|
| 829 | - if (empty($row['title']) && empty($row['category_id'])) { |
|
| 830 | - $row['title'] = get_lang('NoCategory'); |
|
| 831 | - } |
|
| 815 | + if (!empty($order)) { |
|
| 816 | + $sql .= "ORDER BY $order"; |
|
| 817 | + } |
|
| 818 | + |
|
| 819 | + $categories = array(); |
|
| 820 | + |
|
| 821 | + $result = Database::query($sql); |
|
| 822 | + if (Database::num_rows($result)) { |
|
| 823 | + while ($row = Database::fetch_array($result, 'ASSOC')) { |
|
| 824 | + if ($excludeCategoryWithNoQuestions) { |
|
| 825 | + if ($row['count_questions'] == 0) { |
|
| 826 | + continue; |
|
| 827 | + } |
|
| 828 | + } |
|
| 829 | + if (empty($row['title']) && empty($row['category_id'])) { |
|
| 830 | + $row['title'] = get_lang('NoCategory'); |
|
| 831 | + } |
|
| 832 | 832 | $categories[$row['category_id']] = $row; |
| 833 | - } |
|
| 834 | - } |
|
| 835 | - |
|
| 836 | - if ($shuffle) { |
|
| 837 | - shuffle_assoc($categories); |
|
| 838 | - } |
|
| 839 | - |
|
| 840 | - return $categories; |
|
| 841 | - } |
|
| 842 | - |
|
| 843 | - public function getForm(& $form, $action = 'new') |
|
| 844 | - { |
|
| 845 | - switch($action) { |
|
| 846 | - case 'new': |
|
| 847 | - $header = get_lang('AddACategory'); |
|
| 848 | - $submit = get_lang('AddTestCategory'); |
|
| 849 | - break; |
|
| 850 | - case 'edit': |
|
| 851 | - $header = get_lang('EditCategory'); |
|
| 852 | - $submit = get_lang('ModifyCategory'); |
|
| 853 | - break; |
|
| 854 | - } |
|
| 855 | - |
|
| 856 | - // settting the form elements |
|
| 857 | - $form->addElement('header', $header); |
|
| 858 | - $form->addElement('hidden', 'category_id'); |
|
| 859 | - $form->addElement('text', 'category_name', get_lang('CategoryName'), array('class' => 'span6')); |
|
| 860 | - $form->add_html_editor('category_description', get_lang('CategoryDescription'), false, false, array('ToolbarSet' => 'test_category', 'Width' => '90%', 'Height' => '200')); |
|
| 861 | - $category_parent_list = array(); |
|
| 862 | - |
|
| 863 | - $options = array( |
|
| 864 | - '1' => get_lang('Visible'), |
|
| 865 | - '0' => get_lang('Hidden') |
|
| 866 | - ); |
|
| 867 | - $form->addElement('select', 'visibility', get_lang('Visibility'), $options); |
|
| 868 | - $script = null; |
|
| 869 | - if (!empty($this->parent_id)) { |
|
| 870 | - $parent_cat = new TestCategory($this->parent_id); |
|
| 871 | - $category_parent_list = array($parent_cat->id => $parent_cat->name); |
|
| 872 | - $script .= '<script>$(function() { $("#parent_id").trigger("addItem",[{"title": "'.$parent_cat->name.'", "value": "'.$parent_cat->id.'"}]); });</script>'; |
|
| 873 | - } |
|
| 874 | - $form->addElement('html', $script); |
|
| 875 | - |
|
| 876 | - $form->addElement('select', 'parent_id', get_lang('Parent'), $category_parent_list, array('id' => 'parent_id')); |
|
| 877 | - $form->addElement('style_submit_button', 'SubmitNote', $submit, 'class="add"'); |
|
| 878 | - |
|
| 879 | - // setting the defaults |
|
| 880 | - $defaults = array(); |
|
| 881 | - $defaults["category_id"] = $this->id; |
|
| 882 | - $defaults["category_name"] = $this->name; |
|
| 883 | - $defaults["category_description"] = $this->description; |
|
| 884 | - $defaults["parent_id"] = $this->parent_id; |
|
| 885 | - $defaults["visibility"] = $this->visibility; |
|
| 886 | - $form->setDefaults($defaults); |
|
| 887 | - |
|
| 888 | - // setting the rules |
|
| 889 | - $form->addRule('category_name', get_lang('ThisFieldIsRequired'), 'required'); |
|
| 890 | - } |
|
| 891 | - |
|
| 892 | - /** |
|
| 893 | - * Returns the category form. |
|
| 894 | - * @param Exercise $exercise_obj |
|
| 895 | - * @return string |
|
| 896 | - */ |
|
| 897 | - public function returnCategoryForm(Exercise $exercise_obj) |
|
| 898 | - { |
|
| 899 | - $categories = $this->getListOfCategoriesForTest($exercise_obj); |
|
| 900 | - |
|
| 901 | - $saved_categories = $exercise_obj->get_categories_in_exercise(); |
|
| 902 | - $return = null; |
|
| 903 | - |
|
| 904 | - if (!empty($categories)) { |
|
| 905 | - $nbQuestionsTotal = $exercise_obj->getNumberQuestionExerciseCategory(); |
|
| 906 | - $exercise_obj->setCategoriesGrouping(true); |
|
| 907 | - $real_question_count = count($exercise_obj->getQuestionList()); |
|
| 908 | - |
|
| 909 | - $warning = null; |
|
| 910 | - if ($nbQuestionsTotal != $real_question_count) { |
|
| 911 | - $warning = Display::return_message(get_lang('CheckThatYouHaveEnoughQuestionsInYourCategories'), 'warning'); |
|
| 912 | - } |
|
| 913 | - |
|
| 914 | - $return .= $warning; |
|
| 915 | - $return .= '<table class="data_table">'; |
|
| 916 | - $return .= '<tr>'; |
|
| 917 | - $return .= '<th height="24">' . get_lang('Categories') . '</th>'; |
|
| 918 | - $return .= '<th width="70" height="24">' . get_lang('Number') . '</th></tr>'; |
|
| 919 | - |
|
| 920 | - $emptyCategory = array( |
|
| 921 | - 'id' => '0', |
|
| 922 | - 'name' => get_lang('NoCategory'), |
|
| 923 | - 'description' => '', |
|
| 924 | - 'iid' => '0', |
|
| 925 | - 'title' => get_lang('NoCategory') |
|
| 926 | - ); |
|
| 927 | - |
|
| 928 | - $categories[] = $emptyCategory; |
|
| 929 | - |
|
| 930 | - foreach ($categories as $category) { |
|
| 931 | - $cat_id = $category['iid']; |
|
| 932 | - $return .= '<tr>'; |
|
| 933 | - $return .= '<td>'; |
|
| 934 | - //$return .= Display::div(isset($category['parent_path']) ? $category['parent_path'] : ''); |
|
| 935 | - $return .= Display::div($category['name']); |
|
| 936 | - $return .= '</td>'; |
|
| 937 | - $return .= '<td>'; |
|
| 938 | - $value = isset($saved_categories) && isset($saved_categories[$cat_id]) ? $saved_categories[$cat_id]['count_questions'] : -1; |
|
| 939 | - $return .= '<input name="category['.$cat_id.']" value="' .$value.'" />'; |
|
| 940 | - $return .= '</td>'; |
|
| 941 | - $return .= '</tr>'; |
|
| 942 | - } |
|
| 943 | - |
|
| 944 | - $return .= '</table>'; |
|
| 945 | - $return .= get_lang('ZeroMeansNoQuestionWillBeSelectedMinusOneMeansThatAllQuestionsWillBeSelected'); |
|
| 946 | - return $return; |
|
| 947 | - } |
|
| 948 | - } |
|
| 949 | - |
|
| 950 | - /** |
|
| 951 | - * Sorts an array |
|
| 952 | - * @param $array |
|
| 953 | - * @return mixed |
|
| 954 | - */ |
|
| 955 | - public function sort_tree_array($array) |
|
| 956 | - { |
|
| 957 | - foreach ($array as $key => $row) { |
|
| 958 | - $parent[$key] = $row['parent_id']; |
|
| 959 | - } |
|
| 960 | - if (count($array) > 0) { |
|
| 961 | - array_multisort($parent, SORT_ASC, $array); |
|
| 962 | - } |
|
| 963 | - return $array; |
|
| 964 | - } |
|
| 965 | - |
|
| 966 | - /** |
|
| 833 | + } |
|
| 834 | + } |
|
| 835 | + |
|
| 836 | + if ($shuffle) { |
|
| 837 | + shuffle_assoc($categories); |
|
| 838 | + } |
|
| 839 | + |
|
| 840 | + return $categories; |
|
| 841 | + } |
|
| 842 | + |
|
| 843 | + public function getForm(& $form, $action = 'new') |
|
| 844 | + { |
|
| 845 | + switch($action) { |
|
| 846 | + case 'new': |
|
| 847 | + $header = get_lang('AddACategory'); |
|
| 848 | + $submit = get_lang('AddTestCategory'); |
|
| 849 | + break; |
|
| 850 | + case 'edit': |
|
| 851 | + $header = get_lang('EditCategory'); |
|
| 852 | + $submit = get_lang('ModifyCategory'); |
|
| 853 | + break; |
|
| 854 | + } |
|
| 855 | + |
|
| 856 | + // settting the form elements |
|
| 857 | + $form->addElement('header', $header); |
|
| 858 | + $form->addElement('hidden', 'category_id'); |
|
| 859 | + $form->addElement('text', 'category_name', get_lang('CategoryName'), array('class' => 'span6')); |
|
| 860 | + $form->add_html_editor('category_description', get_lang('CategoryDescription'), false, false, array('ToolbarSet' => 'test_category', 'Width' => '90%', 'Height' => '200')); |
|
| 861 | + $category_parent_list = array(); |
|
| 862 | + |
|
| 863 | + $options = array( |
|
| 864 | + '1' => get_lang('Visible'), |
|
| 865 | + '0' => get_lang('Hidden') |
|
| 866 | + ); |
|
| 867 | + $form->addElement('select', 'visibility', get_lang('Visibility'), $options); |
|
| 868 | + $script = null; |
|
| 869 | + if (!empty($this->parent_id)) { |
|
| 870 | + $parent_cat = new TestCategory($this->parent_id); |
|
| 871 | + $category_parent_list = array($parent_cat->id => $parent_cat->name); |
|
| 872 | + $script .= '<script>$(function() { $("#parent_id").trigger("addItem",[{"title": "'.$parent_cat->name.'", "value": "'.$parent_cat->id.'"}]); });</script>'; |
|
| 873 | + } |
|
| 874 | + $form->addElement('html', $script); |
|
| 875 | + |
|
| 876 | + $form->addElement('select', 'parent_id', get_lang('Parent'), $category_parent_list, array('id' => 'parent_id')); |
|
| 877 | + $form->addElement('style_submit_button', 'SubmitNote', $submit, 'class="add"'); |
|
| 878 | + |
|
| 879 | + // setting the defaults |
|
| 880 | + $defaults = array(); |
|
| 881 | + $defaults["category_id"] = $this->id; |
|
| 882 | + $defaults["category_name"] = $this->name; |
|
| 883 | + $defaults["category_description"] = $this->description; |
|
| 884 | + $defaults["parent_id"] = $this->parent_id; |
|
| 885 | + $defaults["visibility"] = $this->visibility; |
|
| 886 | + $form->setDefaults($defaults); |
|
| 887 | + |
|
| 888 | + // setting the rules |
|
| 889 | + $form->addRule('category_name', get_lang('ThisFieldIsRequired'), 'required'); |
|
| 890 | + } |
|
| 891 | + |
|
| 892 | + /** |
|
| 893 | + * Returns the category form. |
|
| 894 | + * @param Exercise $exercise_obj |
|
| 895 | + * @return string |
|
| 896 | + */ |
|
| 897 | + public function returnCategoryForm(Exercise $exercise_obj) |
|
| 898 | + { |
|
| 899 | + $categories = $this->getListOfCategoriesForTest($exercise_obj); |
|
| 900 | + |
|
| 901 | + $saved_categories = $exercise_obj->get_categories_in_exercise(); |
|
| 902 | + $return = null; |
|
| 903 | + |
|
| 904 | + if (!empty($categories)) { |
|
| 905 | + $nbQuestionsTotal = $exercise_obj->getNumberQuestionExerciseCategory(); |
|
| 906 | + $exercise_obj->setCategoriesGrouping(true); |
|
| 907 | + $real_question_count = count($exercise_obj->getQuestionList()); |
|
| 908 | + |
|
| 909 | + $warning = null; |
|
| 910 | + if ($nbQuestionsTotal != $real_question_count) { |
|
| 911 | + $warning = Display::return_message(get_lang('CheckThatYouHaveEnoughQuestionsInYourCategories'), 'warning'); |
|
| 912 | + } |
|
| 913 | + |
|
| 914 | + $return .= $warning; |
|
| 915 | + $return .= '<table class="data_table">'; |
|
| 916 | + $return .= '<tr>'; |
|
| 917 | + $return .= '<th height="24">' . get_lang('Categories') . '</th>'; |
|
| 918 | + $return .= '<th width="70" height="24">' . get_lang('Number') . '</th></tr>'; |
|
| 919 | + |
|
| 920 | + $emptyCategory = array( |
|
| 921 | + 'id' => '0', |
|
| 922 | + 'name' => get_lang('NoCategory'), |
|
| 923 | + 'description' => '', |
|
| 924 | + 'iid' => '0', |
|
| 925 | + 'title' => get_lang('NoCategory') |
|
| 926 | + ); |
|
| 927 | + |
|
| 928 | + $categories[] = $emptyCategory; |
|
| 929 | + |
|
| 930 | + foreach ($categories as $category) { |
|
| 931 | + $cat_id = $category['iid']; |
|
| 932 | + $return .= '<tr>'; |
|
| 933 | + $return .= '<td>'; |
|
| 934 | + //$return .= Display::div(isset($category['parent_path']) ? $category['parent_path'] : ''); |
|
| 935 | + $return .= Display::div($category['name']); |
|
| 936 | + $return .= '</td>'; |
|
| 937 | + $return .= '<td>'; |
|
| 938 | + $value = isset($saved_categories) && isset($saved_categories[$cat_id]) ? $saved_categories[$cat_id]['count_questions'] : -1; |
|
| 939 | + $return .= '<input name="category['.$cat_id.']" value="' .$value.'" />'; |
|
| 940 | + $return .= '</td>'; |
|
| 941 | + $return .= '</tr>'; |
|
| 942 | + } |
|
| 943 | + |
|
| 944 | + $return .= '</table>'; |
|
| 945 | + $return .= get_lang('ZeroMeansNoQuestionWillBeSelectedMinusOneMeansThatAllQuestionsWillBeSelected'); |
|
| 946 | + return $return; |
|
| 947 | + } |
|
| 948 | + } |
|
| 949 | + |
|
| 950 | + /** |
|
| 951 | + * Sorts an array |
|
| 952 | + * @param $array |
|
| 953 | + * @return mixed |
|
| 954 | + */ |
|
| 955 | + public function sort_tree_array($array) |
|
| 956 | + { |
|
| 957 | + foreach ($array as $key => $row) { |
|
| 958 | + $parent[$key] = $row['parent_id']; |
|
| 959 | + } |
|
| 960 | + if (count($array) > 0) { |
|
| 961 | + array_multisort($parent, SORT_ASC, $array); |
|
| 962 | + } |
|
| 963 | + return $array; |
|
| 964 | + } |
|
| 965 | + |
|
| 966 | + /** |
|
| 967 | 967 | * Return true if a category already exists with the same name |
| 968 | 968 | * @param string $in_name |
| 969 | 969 | * |
@@ -1010,8 +1010,8 @@ discard block |
||
| 1010 | 1010 | * @param int $categoryId |
| 1011 | 1011 | * @param int $questionId |
| 1012 | 1012 | * @param int $courseId |
| 1013 | - * |
|
| 1014 | - * @return int |
|
| 1013 | + * |
|
| 1014 | + * @return int |
|
| 1015 | 1015 | */ |
| 1016 | 1016 | public static function add_category_for_question_id($categoryId, $questionId, $courseId) |
| 1017 | 1017 | { |
@@ -1019,18 +1019,18 @@ discard block |
||
| 1019 | 1019 | // if question doesn't have a category |
| 1020 | 1020 | // @todo change for 1.10 when a question can have several categories |
| 1021 | 1021 | if (TestCategory::getCategoryForQuestion($questionId, $courseId) == 0 && |
| 1022 | - $questionId > 0 && |
|
| 1023 | - $courseId > 0 |
|
| 1022 | + $questionId > 0 && |
|
| 1023 | + $courseId > 0 |
|
| 1024 | 1024 | ) { |
| 1025 | 1025 | $sql = "INSERT INTO $table (c_id, question_id, category_id) |
| 1026 | 1026 | VALUES (".intval($courseId).", ".intval($questionId).", ".intval($categoryId).")"; |
| 1027 | 1027 | Database::query($sql); |
| 1028 | - $id = Database::insert_id(); |
|
| 1028 | + $id = Database::insert_id(); |
|
| 1029 | 1029 | |
| 1030 | - return $id; |
|
| 1030 | + return $id; |
|
| 1031 | 1031 | } |
| 1032 | 1032 | |
| 1033 | - return false; |
|
| 1033 | + return false; |
|
| 1034 | 1034 | } |
| 1035 | 1035 | |
| 1036 | 1036 | /** |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | if (!$objExercise->read($exerciseId) || |
| 117 | 117 | (!$objExercise->selectStatus() && !$is_allowedToEdit && $origin != 'learnpath') |
| 118 | 118 | ) { |
| 119 | - if ($debug) {error_log('1.1. Error while reading the exercise'); }; |
|
| 119 | + if ($debug) {error_log('1.1. Error while reading the exercise'); }; |
|
| 120 | 120 | unset ($objExercise); |
| 121 | 121 | $error = get_lang('ExerciseNotFound'); |
| 122 | 122 | } else { |
@@ -130,13 +130,13 @@ discard block |
||
| 130 | 130 | |
| 131 | 131 | //2. Checking if $objExercise is set |
| 132 | 132 | if (!isset($objExercise) && isset($exerciseInSession)) { |
| 133 | - if ($debug) { error_log('2. Loading $objExercise from session'); }; |
|
| 133 | + if ($debug) { error_log('2. Loading $objExercise from session'); }; |
|
| 134 | 134 | $objExercise = $exerciseInSession; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | //3. $objExercise is not set, then return to the exercise list |
| 138 | 138 | if (!is_object($objExercise)) { |
| 139 | - if ($debug) {error_log('3. $objExercise was not set, kill the script'); }; |
|
| 139 | + if ($debug) {error_log('3. $objExercise was not set, kill the script'); }; |
|
| 140 | 140 | header('Location: exercise.php'); |
| 141 | 141 | exit; |
| 142 | 142 | } |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | |
| 158 | 158 | $time_control = false; |
| 159 | 159 | if ($objExercise->expired_time != 0) { |
| 160 | - $time_control = true; |
|
| 160 | + $time_control = true; |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | // Generating the time control key for the user |
@@ -166,14 +166,14 @@ discard block |
||
| 166 | 166 | $_SESSION['duration_time'][$current_expired_time_key] = $current_timestamp; |
| 167 | 167 | |
| 168 | 168 | if ($time_control) { |
| 169 | - // Get the expired time of the current exercise in track_e_exercises |
|
| 170 | - $total_seconds = $objExercise->expired_time*60; |
|
| 169 | + // Get the expired time of the current exercise in track_e_exercises |
|
| 170 | + $total_seconds = $objExercise->expired_time*60; |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | $show_clock = true; |
| 174 | 174 | $user_id = api_get_user_id(); |
| 175 | 175 | if ($objExercise->selectAttempts() > 0) { |
| 176 | - $attempt_html = ''; |
|
| 176 | + $attempt_html = ''; |
|
| 177 | 177 | $attempt_count = Event::get_attempt_count( |
| 178 | 178 | $user_id, |
| 179 | 179 | $exerciseId, |
@@ -182,9 +182,9 @@ discard block |
||
| 182 | 182 | $learnpath_item_view_id |
| 183 | 183 | ); |
| 184 | 184 | |
| 185 | - if ($attempt_count >= $objExercise->selectAttempts()) { |
|
| 186 | - $show_clock = false; |
|
| 187 | - if (!api_is_allowed_to_edit(null,true)) { |
|
| 185 | + if ($attempt_count >= $objExercise->selectAttempts()) { |
|
| 186 | + $show_clock = false; |
|
| 187 | + if (!api_is_allowed_to_edit(null,true)) { |
|
| 188 | 188 | if ($objExercise->results_disabled == 0 && $origin != 'learnpath') { |
| 189 | 189 | |
| 190 | 190 | // Showing latest attempt according with task BT#1628 |
@@ -223,29 +223,29 @@ discard block |
||
| 223 | 223 | $attempt_html .= Display::div(get_lang('Score').' '.$marks, array('id'=>'question_question_titlescore')); |
| 224 | 224 | } |
| 225 | 225 | } |
| 226 | - $score = ExerciseLib::show_score($last_attempt_info['exe_result'], $last_attempt_info['exe_weighting']); |
|
| 227 | - $attempt_html .= Display::div(get_lang('YourTotalScore').' '.$score, array('id'=>'question_score')); |
|
| 228 | - } else { |
|
| 229 | - $attempt_html .= Display::return_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), 'warning', false); |
|
| 230 | - } |
|
| 231 | - } else { |
|
| 232 | - $attempt_html .= Display::return_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), 'warning', false); |
|
| 233 | - } |
|
| 234 | - } else { |
|
| 235 | - $attempt_html .= Display :: return_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), 'warning', false); |
|
| 236 | - } |
|
| 226 | + $score = ExerciseLib::show_score($last_attempt_info['exe_result'], $last_attempt_info['exe_weighting']); |
|
| 227 | + $attempt_html .= Display::div(get_lang('YourTotalScore').' '.$score, array('id'=>'question_score')); |
|
| 228 | + } else { |
|
| 229 | + $attempt_html .= Display::return_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), 'warning', false); |
|
| 230 | + } |
|
| 231 | + } else { |
|
| 232 | + $attempt_html .= Display::return_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), 'warning', false); |
|
| 233 | + } |
|
| 234 | + } else { |
|
| 235 | + $attempt_html .= Display :: return_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), 'warning', false); |
|
| 236 | + } |
|
| 237 | 237 | |
| 238 | - if ($origin == 'learnpath') { |
|
| 239 | - Display :: display_reduced_header(); |
|
| 240 | - } else { |
|
| 241 | - Display :: display_header($nameTools,'Exercises'); |
|
| 242 | - } |
|
| 238 | + if ($origin == 'learnpath') { |
|
| 239 | + Display :: display_reduced_header(); |
|
| 240 | + } else { |
|
| 241 | + Display :: display_header($nameTools,'Exercises'); |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | - echo $attempt_html; |
|
| 245 | - if ($origin != 'learnpath') |
|
| 246 | - Display :: display_footer(); |
|
| 247 | - exit; |
|
| 248 | - } |
|
| 244 | + echo $attempt_html; |
|
| 245 | + if ($origin != 'learnpath') |
|
| 246 | + Display :: display_footer(); |
|
| 247 | + exit; |
|
| 248 | + } |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | if ($debug) { |
@@ -296,26 +296,26 @@ discard block |
||
| 296 | 296 | |
| 297 | 297 | if (empty($exercise_stat_info)) { |
| 298 | 298 | if ($debug) error_log('5 $exercise_stat_info is empty '); |
| 299 | - $total_weight = 0; |
|
| 300 | - $questionList = $objExercise->get_validated_question_list(); |
|
| 301 | - foreach ($questionListUncompressed as $question_id) { |
|
| 302 | - $objQuestionTmp = Question::read($question_id); |
|
| 303 | - $total_weight += floatval($objQuestionTmp->weighting); |
|
| 304 | - } |
|
| 299 | + $total_weight = 0; |
|
| 300 | + $questionList = $objExercise->get_validated_question_list(); |
|
| 301 | + foreach ($questionListUncompressed as $question_id) { |
|
| 302 | + $objQuestionTmp = Question::read($question_id); |
|
| 303 | + $total_weight += floatval($objQuestionTmp->weighting); |
|
| 304 | + } |
|
| 305 | 305 | |
| 306 | - if ($time_control) { |
|
| 307 | - $expected_time = $current_timestamp + $total_seconds; |
|
| 306 | + if ($time_control) { |
|
| 307 | + $expected_time = $current_timestamp + $total_seconds; |
|
| 308 | 308 | |
| 309 | - if ($debug) error_log('5.1. $current_timestamp '.$current_timestamp); |
|
| 310 | - if ($debug) error_log('5.2. $expected_time '.$expected_time); |
|
| 309 | + if ($debug) error_log('5.1. $current_timestamp '.$current_timestamp); |
|
| 310 | + if ($debug) error_log('5.2. $expected_time '.$expected_time); |
|
| 311 | 311 | |
| 312 | - $clock_expired_time = api_get_utc_datetime($expected_time); |
|
| 313 | - if ($debug) error_log('5.3. $expected_time '.$clock_expired_time); |
|
| 312 | + $clock_expired_time = api_get_utc_datetime($expected_time); |
|
| 313 | + if ($debug) error_log('5.3. $expected_time '.$clock_expired_time); |
|
| 314 | 314 | |
| 315 | - //Sessions that contain the expired time |
|
| 316 | - $_SESSION['expired_time'][$current_expired_time_key] = $clock_expired_time; |
|
| 317 | - if ($debug) { error_log('5.4. Setting the $_SESSION[expired_time]: '.$_SESSION['expired_time'][$current_expired_time_key] ); }; |
|
| 318 | - } |
|
| 315 | + //Sessions that contain the expired time |
|
| 316 | + $_SESSION['expired_time'][$current_expired_time_key] = $clock_expired_time; |
|
| 317 | + if ($debug) { error_log('5.4. Setting the $_SESSION[expired_time]: '.$_SESSION['expired_time'][$current_expired_time_key] ); }; |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | 320 | $exe_id = $objExercise->save_stat_track_exercise_info( |
| 321 | 321 | $clock_expired_time, |
@@ -332,7 +332,7 @@ discard block |
||
| 332 | 332 | ); |
| 333 | 333 | if ($debug) error_log("5.5 exercise_stat_info[] exists getting exe_id $exe_id"); |
| 334 | 334 | } else { |
| 335 | - $exe_id = $exercise_stat_info['exe_id']; |
|
| 335 | + $exe_id = $exercise_stat_info['exe_id']; |
|
| 336 | 336 | // Remember last question id position. |
| 337 | 337 | $isFirstTime = Session::read('firstTime'); |
| 338 | 338 | if ($isFirstTime && $objExercise->type == ONE_PER_PAGE) { |
@@ -362,9 +362,9 @@ discard block |
||
| 362 | 362 | if ($debug) { error_log('6. $objExercise->get_stat_track_exercise_info function called:: '.print_r($exercise_stat_info, 1)); }; |
| 363 | 363 | |
| 364 | 364 | if (!empty($exercise_stat_info['questions_to_check'])) { |
| 365 | - $my_remind_list = $exercise_stat_info['questions_to_check']; |
|
| 366 | - $my_remind_list = explode(',', $my_remind_list); |
|
| 367 | - $my_remind_list = array_filter($my_remind_list); |
|
| 365 | + $my_remind_list = $exercise_stat_info['questions_to_check']; |
|
| 366 | + $my_remind_list = explode(',', $my_remind_list); |
|
| 367 | + $my_remind_list = array_filter($my_remind_list); |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | $params = "exe_id=$exe_id&exerciseId=$exerciseId&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&learnpath_item_view_id=$learnpath_item_view_id&".api_get_cidreq(); |
@@ -372,8 +372,8 @@ discard block |
||
| 372 | 372 | |
| 373 | 373 | if ($reminder == 2 && empty($my_remind_list)) { |
| 374 | 374 | if ($debug) { error_log("6.2 calling the exercise_reminder.php "); }; |
| 375 | - header('Location: exercise_reminder.php?'.$params); |
|
| 376 | - exit; |
|
| 375 | + header('Location: exercise_reminder.php?'.$params); |
|
| 376 | + exit; |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | /* |
@@ -381,56 +381,56 @@ discard block |
||
| 381 | 381 | * If the expired time is major that zero(0) then the expired time is compute on this time. |
| 382 | 382 | */ |
| 383 | 383 | if ($time_control) { |
| 384 | - if ($debug) error_log('7.1. Time control is enabled'); |
|
| 385 | - if ($debug) error_log('7.2. $current_expired_time_key '.$current_expired_time_key); |
|
| 386 | - if ($debug) error_log('7.3. $_SESSION[expired_time][$current_expired_time_key] '.$_SESSION['expired_time'][$current_expired_time_key]); |
|
| 384 | + if ($debug) error_log('7.1. Time control is enabled'); |
|
| 385 | + if ($debug) error_log('7.2. $current_expired_time_key '.$current_expired_time_key); |
|
| 386 | + if ($debug) error_log('7.3. $_SESSION[expired_time][$current_expired_time_key] '.$_SESSION['expired_time'][$current_expired_time_key]); |
|
| 387 | 387 | |
| 388 | 388 | if (!isset($_SESSION['expired_time'][$current_expired_time_key])) { |
| 389 | 389 | //Timer - Get expired_time for a student |
| 390 | 390 | if (!empty($exercise_stat_info)) { |
| 391 | - if ($debug) {error_log('7.4 Seems that the session ends and the user want to retake the exam'); }; |
|
| 392 | - $expired_time_of_this_attempt = $exercise_stat_info['expired_time_control']; |
|
| 393 | - if ($debug) {error_log('7.5 $expired_time_of_this_attempt: '.$expired_time_of_this_attempt); } |
|
| 394 | - // Get the last attempt of an exercise |
|
| 395 | - $last_attempt_date = Event::getLastAttemptDateOfExercise($exercise_stat_info['exe_id']); |
|
| 391 | + if ($debug) {error_log('7.4 Seems that the session ends and the user want to retake the exam'); }; |
|
| 392 | + $expired_time_of_this_attempt = $exercise_stat_info['expired_time_control']; |
|
| 393 | + if ($debug) {error_log('7.5 $expired_time_of_this_attempt: '.$expired_time_of_this_attempt); } |
|
| 394 | + // Get the last attempt of an exercise |
|
| 395 | + $last_attempt_date = Event::getLastAttemptDateOfExercise($exercise_stat_info['exe_id']); |
|
| 396 | 396 | |
| 397 | - /* This means that the user enters the exam but do not answer the |
|
| 397 | + /* This means that the user enters the exam but do not answer the |
|
| 398 | 398 | first question we get the date from the track_e_exercises not from |
| 399 | 399 | the track_et_attempt see #2069 */ |
| 400 | - if (empty($last_attempt_date)) { |
|
| 401 | - $diff = $current_timestamp - api_strtotime($exercise_stat_info['start_date'], 'UTC'); |
|
| 402 | - $last_attempt_date = api_get_utc_datetime(api_strtotime($exercise_stat_info['start_date'],'UTC') + $diff); |
|
| 403 | - } else { |
|
| 404 | - //Recalculate the time control due #2069 |
|
| 405 | - $diff = $current_timestamp - api_strtotime($last_attempt_date,'UTC'); |
|
| 406 | - $last_attempt_date = api_get_utc_datetime(api_strtotime($last_attempt_date,'UTC') + $diff); |
|
| 407 | - } |
|
| 408 | - if ($debug) {error_log('7.6. $last_attempt_date: '.$last_attempt_date); } |
|
| 409 | - |
|
| 410 | - //New expired time - it is due to the possible closure of session |
|
| 411 | - $new_expired_time_in_seconds = api_strtotime($expired_time_of_this_attempt, 'UTC') - api_strtotime($last_attempt_date,'UTC'); |
|
| 412 | - if ($debug) {error_log('7.7. $new_expired_time_in_seconds: '.$new_expired_time_in_seconds); } |
|
| 413 | - |
|
| 414 | - $expected_time = $current_timestamp + $new_expired_time_in_seconds; |
|
| 415 | - if ($debug) {error_log('7.8. $expected_time1: '.$expected_time); } |
|
| 416 | - |
|
| 417 | - $clock_expired_time = api_get_utc_datetime($expected_time); |
|
| 418 | - if ($debug) {error_log('7.9. $clock_expired_time: '.$clock_expired_time); } |
|
| 419 | - |
|
| 420 | - // First we update the attempt to today |
|
| 421 | - /* How the expired time is changed into "track_e_exercises" table, |
|
| 400 | + if (empty($last_attempt_date)) { |
|
| 401 | + $diff = $current_timestamp - api_strtotime($exercise_stat_info['start_date'], 'UTC'); |
|
| 402 | + $last_attempt_date = api_get_utc_datetime(api_strtotime($exercise_stat_info['start_date'],'UTC') + $diff); |
|
| 403 | + } else { |
|
| 404 | + //Recalculate the time control due #2069 |
|
| 405 | + $diff = $current_timestamp - api_strtotime($last_attempt_date,'UTC'); |
|
| 406 | + $last_attempt_date = api_get_utc_datetime(api_strtotime($last_attempt_date,'UTC') + $diff); |
|
| 407 | + } |
|
| 408 | + if ($debug) {error_log('7.6. $last_attempt_date: '.$last_attempt_date); } |
|
| 409 | + |
|
| 410 | + //New expired time - it is due to the possible closure of session |
|
| 411 | + $new_expired_time_in_seconds = api_strtotime($expired_time_of_this_attempt, 'UTC') - api_strtotime($last_attempt_date,'UTC'); |
|
| 412 | + if ($debug) {error_log('7.7. $new_expired_time_in_seconds: '.$new_expired_time_in_seconds); } |
|
| 413 | + |
|
| 414 | + $expected_time = $current_timestamp + $new_expired_time_in_seconds; |
|
| 415 | + if ($debug) {error_log('7.8. $expected_time1: '.$expected_time); } |
|
| 416 | + |
|
| 417 | + $clock_expired_time = api_get_utc_datetime($expected_time); |
|
| 418 | + if ($debug) {error_log('7.9. $clock_expired_time: '.$clock_expired_time); } |
|
| 419 | + |
|
| 420 | + // First we update the attempt to today |
|
| 421 | + /* How the expired time is changed into "track_e_exercises" table, |
|
| 422 | 422 | then the last attempt for this student should be changed too */ |
| 423 | - $sql = "UPDATE $exercise_attempt_table SET |
|
| 423 | + $sql = "UPDATE $exercise_attempt_table SET |
|
| 424 | 424 | tms = '".api_get_utc_datetime()."' |
| 425 | 425 | WHERE |
| 426 | 426 | exe_id = '".$exercise_stat_info['exe_id']."' AND |
| 427 | 427 | tms = '".$last_attempt_date."' "; |
| 428 | - if ($debug) {error_log('7.10. $sql: '.$sql); } |
|
| 429 | - Database::query($sql); |
|
| 428 | + if ($debug) {error_log('7.10. $sql: '.$sql); } |
|
| 429 | + Database::query($sql); |
|
| 430 | 430 | |
| 431 | - //Sessions that contain the expired time |
|
| 432 | - $_SESSION['expired_time'][$current_expired_time_key] = $clock_expired_time; |
|
| 433 | - if ($debug) {error_log('7.11. Setting the $_SESSION[expired_time]: '.$_SESSION['expired_time'][$current_expired_time_key] ); }; |
|
| 431 | + //Sessions that contain the expired time |
|
| 432 | + $_SESSION['expired_time'][$current_expired_time_key] = $clock_expired_time; |
|
| 433 | + if ($debug) {error_log('7.11. Setting the $_SESSION[expired_time]: '.$_SESSION['expired_time'][$current_expired_time_key] ); }; |
|
| 434 | 434 | } |
| 435 | 435 | } else { |
| 436 | 436 | $clock_expired_time = $_SESSION['expired_time'][$current_expired_time_key]; |
@@ -447,7 +447,7 @@ discard block |
||
| 447 | 447 | * for more details of how it works see this link : http://eric.garside.name/docs.html?p=epiclock |
| 448 | 448 | */ |
| 449 | 449 | if ($time_control) { //Sends the exercise form when the expired time is finished |
| 450 | - $htmlHeadXtra[] = $objExercise->show_time_control_js($time_left); |
|
| 450 | + $htmlHeadXtra[] = $objExercise->show_time_control_js($time_left); |
|
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | // if the user has submitted the form |
@@ -461,14 +461,14 @@ discard block |
||
| 461 | 461 | // selects the list of question ID |
| 462 | 462 | $questionList = $objExercise->get_validated_question_list(); |
| 463 | 463 | if ($objExercise->isRandom() && !empty($exercise_stat_info['data_tracking'])) { |
| 464 | - $questionList = explode(',', $exercise_stat_info['data_tracking']); |
|
| 464 | + $questionList = explode(',', $exercise_stat_info['data_tracking']); |
|
| 465 | 465 | } |
| 466 | 466 | Session::write('questionList', $questionList); |
| 467 | 467 | if ($debug > 0) { error_log('$_SESSION[questionList] was set'); } |
| 468 | 468 | } else { |
| 469 | - if (isset($objExercise) && isset($_SESSION['objExercise'])) { |
|
| 470 | - $questionList = $_SESSION['questionList']; |
|
| 471 | - } |
|
| 469 | + if (isset($objExercise) && isset($_SESSION['objExercise'])) { |
|
| 470 | + $questionList = $_SESSION['questionList']; |
|
| 471 | + } |
|
| 472 | 472 | } |
| 473 | 473 | |
| 474 | 474 | if ($debug) error_log('8. Question list loaded '.print_r($questionList, 1)); |
@@ -476,7 +476,7 @@ discard block |
||
| 476 | 476 | //Real question count |
| 477 | 477 | $question_count = 0; |
| 478 | 478 | if (!empty($questionList)) { |
| 479 | - $question_count = count($questionList); |
|
| 479 | + $question_count = count($questionList); |
|
| 480 | 480 | } |
| 481 | 481 | |
| 482 | 482 | if ($formSent && isset($_POST)) { |
@@ -518,11 +518,11 @@ discard block |
||
| 518 | 518 | //saving each question |
| 519 | 519 | if ($objExercise->feedback_type != EXERCISE_FEEDBACK_TYPE_DIRECT) { |
| 520 | 520 | $nro_question = $current_question; // - 1; |
| 521 | - $questionId = $key; |
|
| 521 | + $questionId = $key; |
|
| 522 | 522 | // gets the student choice for this question |
| 523 | 523 | $choice = $exerciseResult[$questionId]; |
| 524 | 524 | if (isset($exe_id)) { |
| 525 | - // Manage the question and answer attempts |
|
| 525 | + // Manage the question and answer attempts |
|
| 526 | 526 | if ($debug) { error_log('8.3. manage_answer exe_id: '.$exe_id.' - $questionId: '.$questionId.' Choice'.print_r($choice,1)); } |
| 527 | 527 | $objExercise->manage_answer( |
| 528 | 528 | $exe_id, |
@@ -611,58 +611,58 @@ discard block |
||
| 611 | 611 | } |
| 612 | 612 | |
| 613 | 613 | if ($question_count != 0) { |
| 614 | - if (($objExercise->type == ALL_ON_ONE_PAGE || |
|
| 614 | + if (($objExercise->type == ALL_ON_ONE_PAGE || |
|
| 615 | 615 | $current_question > $question_count) |
| 616 | 616 | ) { |
| 617 | - if (api_is_allowed_to_session_edit()) { |
|
| 618 | - // goes to the script that will show the result of the exercise |
|
| 619 | - if ($objExercise->type == ALL_ON_ONE_PAGE) { |
|
| 620 | - if ($debug) { error_log('12. Exercise ALL_ON_ONE_PAGE -> Redirecting to exercise_result.php'); } |
|
| 621 | - |
|
| 622 | - //We check if the user attempts before sending to the exercise_result.php |
|
| 623 | - if ($objExercise->selectAttempts() > 0) { |
|
| 624 | - $attempt_count = Event::get_attempt_count( |
|
| 617 | + if (api_is_allowed_to_session_edit()) { |
|
| 618 | + // goes to the script that will show the result of the exercise |
|
| 619 | + if ($objExercise->type == ALL_ON_ONE_PAGE) { |
|
| 620 | + if ($debug) { error_log('12. Exercise ALL_ON_ONE_PAGE -> Redirecting to exercise_result.php'); } |
|
| 621 | + |
|
| 622 | + //We check if the user attempts before sending to the exercise_result.php |
|
| 623 | + if ($objExercise->selectAttempts() > 0) { |
|
| 624 | + $attempt_count = Event::get_attempt_count( |
|
| 625 | 625 | api_get_user_id(), |
| 626 | 626 | $exerciseId, |
| 627 | 627 | $learnpath_id, |
| 628 | 628 | $learnpath_item_id, |
| 629 | 629 | $learnpath_item_view_id |
| 630 | 630 | ); |
| 631 | - if ($attempt_count >= $objExercise->selectAttempts()) { |
|
| 632 | - Display :: display_warning_message( |
|
| 631 | + if ($attempt_count >= $objExercise->selectAttempts()) { |
|
| 632 | + Display :: display_warning_message( |
|
| 633 | 633 | sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), |
| 634 | 634 | false |
| 635 | 635 | ); |
| 636 | - if ($origin != 'learnpath') { |
|
| 637 | - //so we are not in learnpath tool |
|
| 638 | - echo '</div>'; //End glossary div |
|
| 639 | - Display :: display_footer(); |
|
| 640 | - } else { |
|
| 641 | - echo '</body></html>'; |
|
| 642 | - } |
|
| 643 | - exit; |
|
| 644 | - } |
|
| 645 | - } |
|
| 646 | - } else { |
|
| 647 | - if ($objExercise->review_answers) { |
|
| 648 | - header('Location: exercise_reminder.php?'.$params); |
|
| 649 | - exit; |
|
| 650 | - } else { |
|
| 636 | + if ($origin != 'learnpath') { |
|
| 637 | + //so we are not in learnpath tool |
|
| 638 | + echo '</div>'; //End glossary div |
|
| 639 | + Display :: display_footer(); |
|
| 640 | + } else { |
|
| 641 | + echo '</body></html>'; |
|
| 642 | + } |
|
| 643 | + exit; |
|
| 644 | + } |
|
| 645 | + } |
|
| 646 | + } else { |
|
| 647 | + if ($objExercise->review_answers) { |
|
| 648 | + header('Location: exercise_reminder.php?'.$params); |
|
| 649 | + exit; |
|
| 650 | + } else { |
|
| 651 | 651 | header("Location: exercise_result.php?".api_get_cidreq()."&exe_id=$exe_id&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&learnpath_item_view_id=$learnpath_item_view_id"); |
| 652 | 652 | exit; |
| 653 | - } |
|
| 654 | - } |
|
| 655 | - } else { |
|
| 656 | - if ($debug) { error_log('Redirecting to exercise_submit.php'); } |
|
| 657 | - exit; |
|
| 658 | - } |
|
| 659 | - } |
|
| 653 | + } |
|
| 654 | + } |
|
| 655 | + } else { |
|
| 656 | + if ($debug) { error_log('Redirecting to exercise_submit.php'); } |
|
| 657 | + exit; |
|
| 658 | + } |
|
| 659 | + } |
|
| 660 | 660 | } else { |
| 661 | - $error = get_lang('ThereAreNoQuestionsForThisExercise'); |
|
| 662 | - // if we are in the case where user select random by category, but didn't choose the number of random question |
|
| 663 | - if ($objExercise->selectRandomByCat() > 0 && $objExercise->random <= 0) { |
|
| 664 | - $error .= "<br/>".get_lang('PleaseSelectSomeRandomQuestion'); |
|
| 665 | - } |
|
| 661 | + $error = get_lang('ThereAreNoQuestionsForThisExercise'); |
|
| 662 | + // if we are in the case where user select random by category, but didn't choose the number of random question |
|
| 663 | + if ($objExercise->selectRandomByCat() > 0 && $objExercise->random <= 0) { |
|
| 664 | + $error .= "<br/>".get_lang('PleaseSelectSomeRandomQuestion'); |
|
| 665 | + } |
|
| 666 | 666 | } |
| 667 | 667 | |
| 668 | 668 | if (!empty ($_GET['gradebook']) && $_GET['gradebook'] == 'view') { |
@@ -701,9 +701,9 @@ discard block |
||
| 701 | 701 | if (api_is_course_admin() && $origin != 'learnpath') { |
| 702 | 702 | echo '<div class="actions">'; |
| 703 | 703 | if ($show_quiz_edition == false) { |
| 704 | - echo '<a href="exercise_admin.php?' . api_get_cidreq() . '&modifyExercise=yes&exerciseId=' . $objExercise->id . '">'.Display :: return_icon('settings.png', get_lang('ModifyExercise'),'',ICON_SIZE_MEDIUM).'</a>'; |
|
| 704 | + echo '<a href="exercise_admin.php?' . api_get_cidreq() . '&modifyExercise=yes&exerciseId=' . $objExercise->id . '">'.Display :: return_icon('settings.png', get_lang('ModifyExercise'),'',ICON_SIZE_MEDIUM).'</a>'; |
|
| 705 | 705 | } else { |
| 706 | - echo '<a href="#">'.Display::return_icon('settings_na.png', get_lang('ModifyExercise'),'',ICON_SIZE_MEDIUM).'</a>'; |
|
| 706 | + echo '<a href="#">'.Display::return_icon('settings_na.png', get_lang('ModifyExercise'),'',ICON_SIZE_MEDIUM).'</a>'; |
|
| 707 | 707 | } |
| 708 | 708 | echo '</div>'; |
| 709 | 709 | } |
@@ -746,7 +746,7 @@ discard block |
||
| 746 | 746 | $message_warning = $permission_to_start ? get_lang('ReachedTimeLimit') : get_lang('ExerciseNoStartedYet'); |
| 747 | 747 | Display :: display_warning_message(sprintf($message_warning, $exercise_title, $objExercise->selectAttempts())); |
| 748 | 748 | if ($origin != 'learnpath') { |
| 749 | - Display :: display_footer(); |
|
| 749 | + Display :: display_footer(); |
|
| 750 | 750 | } |
| 751 | 751 | exit; |
| 752 | 752 | } else { |
@@ -761,7 +761,7 @@ discard block |
||
| 761 | 761 | if (isset($_custom['exercises_hidden_when_no_start_date']) && |
| 762 | 762 | $_custom['exercises_hidden_when_no_start_date'] |
| 763 | 763 | ) { |
| 764 | - if (empty($objExercise->start_time) || $objExercise->start_time == '0000-00-00 00:00:00') { |
|
| 764 | + if (empty($objExercise->start_time) || $objExercise->start_time == '0000-00-00 00:00:00') { |
|
| 765 | 765 | Display:: display_warning_message( |
| 766 | 766 | sprintf( |
| 767 | 767 | get_lang('ExerciseNoStartedYet'), |
@@ -769,20 +769,20 @@ discard block |
||
| 769 | 769 | $objExercise->selectAttempts() |
| 770 | 770 | ) |
| 771 | 771 | ); |
| 772 | - if ($origin != 'learnpath') { |
|
| 773 | - Display :: display_footer(); |
|
| 774 | - } |
|
| 775 | - } |
|
| 772 | + if ($origin != 'learnpath') { |
|
| 773 | + Display :: display_footer(); |
|
| 774 | + } |
|
| 775 | + } |
|
| 776 | 776 | } |
| 777 | 777 | |
| 778 | 778 | //Timer control |
| 779 | 779 | if ($time_control) { |
| 780 | 780 | echo $objExercise->return_time_left_div(); |
| 781 | - echo '<div style="display:none" class="warning-message" id="expired-message-id">'.get_lang('ExerciseExpiredTimeMessage').'</div>'; |
|
| 781 | + echo '<div style="display:none" class="warning-message" id="expired-message-id">'.get_lang('ExerciseExpiredTimeMessage').'</div>'; |
|
| 782 | 782 | } |
| 783 | 783 | |
| 784 | 784 | if ($origin != 'learnpath') { |
| 785 | - echo '<div id="highlight-plugin" class="glossary-content">'; |
|
| 785 | + echo '<div id="highlight-plugin" class="glossary-content">'; |
|
| 786 | 786 | } |
| 787 | 787 | |
| 788 | 788 | if ($reminder == 2) { |
@@ -794,53 +794,53 @@ discard block |
||
| 794 | 794 | $current_question = 1; //set by default the 1st question |
| 795 | 795 | |
| 796 | 796 | if (!empty($my_remind_list)) { |
| 797 | - // Checking which questions we are going to call from the remind list |
|
| 798 | - for ($i = 0; $i < count($data_tracking); $i++) { |
|
| 799 | - for($j = 0; $j < count($my_remind_list); $j++) { |
|
| 800 | - |
|
| 801 | - if (!empty($remind_question_id)) { |
|
| 802 | - if ($remind_question_id == $my_remind_list[$j]) { |
|
| 803 | - |
|
| 804 | - if ($remind_question_id == $data_tracking[$i]) { |
|
| 805 | - if (isset($my_remind_list[$j+1])) { |
|
| 806 | - $remind_question_id = $my_remind_list[$j+1]; |
|
| 807 | - $current_question = $i + 1; |
|
| 808 | - } else { |
|
| 797 | + // Checking which questions we are going to call from the remind list |
|
| 798 | + for ($i = 0; $i < count($data_tracking); $i++) { |
|
| 799 | + for($j = 0; $j < count($my_remind_list); $j++) { |
|
| 800 | + |
|
| 801 | + if (!empty($remind_question_id)) { |
|
| 802 | + if ($remind_question_id == $my_remind_list[$j]) { |
|
| 803 | + |
|
| 804 | + if ($remind_question_id == $data_tracking[$i]) { |
|
| 805 | + if (isset($my_remind_list[$j+1])) { |
|
| 806 | + $remind_question_id = $my_remind_list[$j+1]; |
|
| 807 | + $current_question = $i + 1; |
|
| 808 | + } else { |
|
| 809 | 809 | // We end the remind list we go to the exercise_reminder.php please |
| 810 | - $remind_question_id = -1; |
|
| 811 | - $current_question = $i + 1; // last question |
|
| 812 | - } |
|
| 813 | - break 2; |
|
| 814 | - } |
|
| 815 | - } |
|
| 816 | - } else { |
|
| 817 | - if ($my_remind_list[$j] == $data_tracking[$i]) { |
|
| 818 | - if (isset($my_remind_list[$j+1])) { |
|
| 819 | - $remind_question_id = $my_remind_list[$j+1]; |
|
| 820 | - $current_question = $i + 1; // last question |
|
| 821 | - } else { |
|
| 810 | + $remind_question_id = -1; |
|
| 811 | + $current_question = $i + 1; // last question |
|
| 812 | + } |
|
| 813 | + break 2; |
|
| 814 | + } |
|
| 815 | + } |
|
| 816 | + } else { |
|
| 817 | + if ($my_remind_list[$j] == $data_tracking[$i]) { |
|
| 818 | + if (isset($my_remind_list[$j+1])) { |
|
| 819 | + $remind_question_id = $my_remind_list[$j+1]; |
|
| 820 | + $current_question = $i + 1; // last question |
|
| 821 | + } else { |
|
| 822 | 822 | // We end the remind list we go to the exercise_reminder.php please |
| 823 | - $remind_question_id = -1; |
|
| 824 | - $current_question = $i + 1; // last question |
|
| 825 | - } |
|
| 826 | - break 2; |
|
| 827 | - } |
|
| 828 | - } |
|
| 829 | - } |
|
| 823 | + $remind_question_id = -1; |
|
| 824 | + $current_question = $i + 1; // last question |
|
| 825 | + } |
|
| 826 | + break 2; |
|
| 827 | + } |
|
| 828 | + } |
|
| 829 | + } |
|
| 830 | 830 | } |
| 831 | 831 | } else { |
| 832 | - if ($objExercise->review_answers) { |
|
| 832 | + if ($objExercise->review_answers) { |
|
| 833 | 833 | if ($debug) { error_log('. redirecting to exercise_reminder.php '); } |
| 834 | - header("Location: exercise_reminder.php?$params"); |
|
| 835 | - exit; |
|
| 836 | - } |
|
| 834 | + header("Location: exercise_reminder.php?$params"); |
|
| 835 | + exit; |
|
| 836 | + } |
|
| 837 | 837 | } |
| 838 | 838 | } |
| 839 | 839 | |
| 840 | 840 | if ($objExercise->review_answers) { |
| 841 | - $script_php = 'exercise_reminder.php'; |
|
| 841 | + $script_php = 'exercise_reminder.php'; |
|
| 842 | 842 | } else { |
| 843 | - $script_php = 'exercise_result.php'; |
|
| 843 | + $script_php = 'exercise_result.php'; |
|
| 844 | 844 | } |
| 845 | 845 | |
| 846 | 846 | if (!empty($error)) { |
@@ -1084,7 +1084,7 @@ discard block |
||
| 1084 | 1084 | <input type="hidden" name="learnpath_item_id" value="'.$learnpath_item_id . '" /> |
| 1085 | 1085 | <input type="hidden" name="learnpath_item_view_id" value="'.$learnpath_item_view_id . '" />'; |
| 1086 | 1086 | |
| 1087 | - // Show list of questions |
|
| 1087 | + // Show list of questions |
|
| 1088 | 1088 | $i = 1; |
| 1089 | 1089 | $attempt_list = array(); |
| 1090 | 1090 | if (isset($exe_id)) { |
@@ -1134,10 +1134,10 @@ discard block |
||
| 1134 | 1134 | |
| 1135 | 1135 | $attributes = array('id' =>'remind_list['.$questionId.']'); |
| 1136 | 1136 | if (in_array($questionId, $remind_list)) { |
| 1137 | - $is_remind_on = true; |
|
| 1138 | - $attributes['checked'] = 1; |
|
| 1139 | - $remind_question = true; |
|
| 1140 | - $remind_highlight = ' remind_highlight '; |
|
| 1137 | + $is_remind_on = true; |
|
| 1138 | + $attributes['checked'] = 1; |
|
| 1139 | + $remind_question = true; |
|
| 1140 | + $remind_highlight = ' remind_highlight '; |
|
| 1141 | 1141 | } |
| 1142 | 1142 | |
| 1143 | 1143 | // Showing the exercise description |
@@ -1211,8 +1211,8 @@ discard block |
||
| 1211 | 1211 | } |
| 1212 | 1212 | // end foreach() |
| 1213 | 1213 | if ($objExercise->type == ALL_ON_ONE_PAGE) { |
| 1214 | - $exercise_actions = $objExercise->show_button($questionId, $current_question); |
|
| 1215 | - echo Display::div($exercise_actions, array('class'=>'exercise_actions')); |
|
| 1214 | + $exercise_actions = $objExercise->show_button($questionId, $current_question); |
|
| 1215 | + echo Display::div($exercise_actions, array('class'=>'exercise_actions')); |
|
| 1216 | 1216 | echo '<br>'; |
| 1217 | 1217 | } |
| 1218 | 1218 | echo '</form>'; |