From df5582325499d852ef7a90221fe463d3a2c00365 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Fri, 14 Apr 2017 10:50:21 +0200 Subject: [PATCH] Format code, update docs, improve loop. --- main/exercise/TestCategory.php | 16 ++++---- .../Component/CourseCopy/CourseBuilder.php | 38 +++++++++---------- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/main/exercise/TestCategory.php b/main/exercise/TestCategory.php index 92e855daf7..f9ed5a55c9 100644 --- a/main/exercise/TestCategory.php +++ b/main/exercise/TestCategory.php @@ -191,22 +191,22 @@ class TestCategory /** * Return an array of all Category objects in the database - * If in_field=="" Return an array of all category objects in the database + * If $field=="" Return an array of all category objects in the database * Otherwise, return an array of all in_field value * in the database (in_field = id or name or description) * - * @param string $in_field + * @param string $field * @param int $courseId * @return array */ - public static function getCategoryListInfo($in_field = '', $courseId = 0) + public static function getCategoryListInfo($field = '', $courseId = 0) { $courseId = empty($courseId) ? api_get_course_int_id() : (int) $courseId; $table = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY); - $in_field = Database::escape_string($in_field); + $field = Database::escape_string($field); $categories = array(); - if ($in_field == '') { + if (empty($field)) { $sql = "SELECT id FROM $table WHERE c_id = $courseId ORDER BY title ASC"; @@ -216,12 +216,12 @@ class TestCategory $categories[] = $category->getCategory($row['id']); } } else { - $sql = "SELECT $in_field FROM $table + $sql = "SELECT $field FROM $table WHERE c_id = $courseId - ORDER BY $in_field ASC"; + ORDER BY $field ASC"; $res = Database::query($sql); while ($row = Database::fetch_array($res)) { - $categories[] = $row[$in_field]; + $categories[] = $row[$field]; } } return $categories; diff --git a/src/Chamilo/CourseBundle/Component/CourseCopy/CourseBuilder.php b/src/Chamilo/CourseBundle/Component/CourseCopy/CourseBuilder.php index 27cac8a644..bfab187910 100644 --- a/src/Chamilo/CourseBundle/Component/CourseCopy/CourseBuilder.php +++ b/src/Chamilo/CourseBundle/Component/CourseCopy/CourseBuilder.php @@ -556,13 +556,13 @@ class CourseBuilder * @param int $session_id Internal session ID * @param int $courseId Internal course ID * @param bool $with_base_content Whether to include content from the course without session or not - * @param array $id_list If you want to restrict the structure to only the given IDs + * @param array $idList If you want to restrict the structure to only the given IDs */ public function build_quizzes( $session_id = 0, $courseId = 0, $with_base_content = false, - $id_list = array() + $idList = array() ) { $table_qui = Database:: get_course_table(TABLE_QUIZ_TEST); $table_rel = Database:: get_course_table(TABLE_QUIZ_TEST_QUESTION); @@ -591,6 +591,8 @@ class CourseBuilder //select only quizzes with active = 0 or 1 (not -1 which is for deleted quizzes) } + $sql .= 'ORDER BY title'; + $db_result = Database::query($sql); while ($obj = Database::fetch_object($db_result)) { if (strlen($obj->sound) > 0) { @@ -861,32 +863,28 @@ class CourseBuilder /** * Build the test category - * @param int $session_id Internal session ID + * @param int $sessionId Internal session ID * @param int $courseId Internal course ID - * @param bool $with_base_content Whether to include content from the course without session or not - * @param array $id_list If you want to restrict the structure to only the given IDs + * @param bool $withBaseContent Whether to include content from the course without session or not + * @param array $idList If you want to restrict the structure to only the given IDs * @todo add course session */ public function build_test_category( - $session_id = 0, + $sessionId = 0, $courseId = 0, - $with_base_content = false, - $id_list = array() + $withBaseContent = false, + $idList = array() ) { // get all test category in course - $tab_test_categories_id = TestCategory::getCategoryListInfo( - "id", - $courseId - ); - foreach ($tab_test_categories_id as $test_category_id) { - $test_category = new TestCategory(); - $test_category = $test_category->getCategory($test_category_id); - $copy_course_test_category = new CourseCopyTestCategory( - $test_category_id, - $test_category->name, - $test_category->description + $categories = TestCategory::getCategoryListInfo('', $courseId); + foreach ($categories as $category) { + /** @var TestCategory $category */ + $courseCopyTestCategory = new CourseCopyTestCategory( + $category->id, + $category->name, + $category->description ); - $this->course->add_resource($copy_course_test_category); + $this->course->add_resource($courseCopyTestCategory); } }