Format code, update docs, improve loop.

remotes/angel/1.11.x
jmontoyaa 8 years ago
parent a58807cb1a
commit df55823254
  1. 16
      main/exercise/TestCategory.php
  2. 38
      src/Chamilo/CourseBundle/Component/CourseCopy/CourseBuilder.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;

@ -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);
}
}

Loading…
Cancel
Save