|
|
|
@ -76,6 +76,29 @@ class CourseBuilder |
|
|
|
'gradebook', |
|
|
|
'gradebook', |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public $toolToName = [ |
|
|
|
|
|
|
|
'announcements' => RESOURCE_ANNOUNCEMENT, |
|
|
|
|
|
|
|
'attendance' => RESOURCE_ATTENDANCE, |
|
|
|
|
|
|
|
'course_descriptions' => RESOURCE_COURSEDESCRIPTION, |
|
|
|
|
|
|
|
'documents' => RESOURCE_DOCUMENT, |
|
|
|
|
|
|
|
'events' => RESOURCE_EVENT, |
|
|
|
|
|
|
|
'forum_category' => RESOURCE_FORUMCATEGORY, |
|
|
|
|
|
|
|
'forums' => RESOURCE_FORUM, |
|
|
|
|
|
|
|
'forum_topics' => RESOURCE_FORUMTOPIC, |
|
|
|
|
|
|
|
'glossary' => RESOURCE_GLOSSARY, |
|
|
|
|
|
|
|
'quizzes' => RESOURCE_QUIZ, |
|
|
|
|
|
|
|
'test_category' => RESOURCE_TEST_CATEGORY, |
|
|
|
|
|
|
|
'learnpath_category' => RESOURCE_LEARNPATH_CATEGORY, |
|
|
|
|
|
|
|
'learnpaths' => RESOURCE_LEARNPATH, |
|
|
|
|
|
|
|
'links' => RESOURCE_LINK, |
|
|
|
|
|
|
|
'surveys' => RESOURCE_SURVEY, |
|
|
|
|
|
|
|
'tool_intro' => RESOURCE_TOOL_INTRO, |
|
|
|
|
|
|
|
'thematic' => RESOURCE_THEMATIC, |
|
|
|
|
|
|
|
'wiki' => RESOURCE_WIKI, |
|
|
|
|
|
|
|
'works' => RESOURCE_WORK, |
|
|
|
|
|
|
|
'gradebook' => RESOURCE_GRADEBOOK, |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
/* With this array you can filter wich elements of the tools are going |
|
|
|
/* With this array you can filter wich elements of the tools are going |
|
|
|
to be added in the course obj (only works with LPs) */ |
|
|
|
to be added in the course obj (only works with LPs) */ |
|
|
|
public $specific_id_list = []; |
|
|
|
public $specific_id_list = []; |
|
|
|
@ -136,20 +159,39 @@ class CourseBuilder |
|
|
|
* @param string $courseCode |
|
|
|
* @param string $courseCode |
|
|
|
* @param bool $withBaseContent true if you want to get the elements that exists in the course and |
|
|
|
* @param bool $withBaseContent true if you want to get the elements that exists in the course and |
|
|
|
* in the session, (session_id = 0 or session_id = X) |
|
|
|
* in the session, (session_id = 0 or session_id = X) |
|
|
|
|
|
|
|
* @param array $parseOnlyToolList |
|
|
|
|
|
|
|
* @param array $toolsFromPost |
|
|
|
* |
|
|
|
* |
|
|
|
* @return Course The course object structure |
|
|
|
* @return Course The course object structure |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function build( |
|
|
|
public function build( |
|
|
|
$session_id = 0, |
|
|
|
$session_id = 0, |
|
|
|
$courseCode = '', |
|
|
|
$courseCode = '', |
|
|
|
$withBaseContent = false |
|
|
|
$withBaseContent = false, |
|
|
|
|
|
|
|
$parseOnlyToolList = [], |
|
|
|
|
|
|
|
$toolsFromPost = [] |
|
|
|
) { |
|
|
|
) { |
|
|
|
$course = api_get_course_info($courseCode); |
|
|
|
$course = api_get_course_info($courseCode); |
|
|
|
$courseId = $course['real_id']; |
|
|
|
$courseId = $course['real_id']; |
|
|
|
|
|
|
|
|
|
|
|
foreach ($this->tools_to_build as $tool) { |
|
|
|
foreach ($this->tools_to_build as $tool) { |
|
|
|
|
|
|
|
if (!empty($parseOnlyToolList) && !in_array($this->toolToName[$tool], $parseOnlyToolList)) { |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
$function_build = 'build_'.$tool; |
|
|
|
$function_build = 'build_'.$tool; |
|
|
|
$specificIdList = isset($this->specific_id_list[$tool]) ? $this->specific_id_list[$tool] : null; |
|
|
|
$specificIdList = isset($this->specific_id_list[$tool]) ? $this->specific_id_list[$tool] : null; |
|
|
|
|
|
|
|
$buildOrphanQuestions = true; |
|
|
|
|
|
|
|
if ($tool == 'quizzes') { |
|
|
|
|
|
|
|
if (!isset($toolsFromPost['quiz'][-1])) { |
|
|
|
|
|
|
|
$buildOrphanQuestions = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$this->build_quizzes( |
|
|
|
|
|
|
|
$session_id, |
|
|
|
|
|
|
|
$courseId, |
|
|
|
|
|
|
|
$withBaseContent, |
|
|
|
|
|
|
|
$specificIdList, |
|
|
|
|
|
|
|
$buildOrphanQuestions |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} else { |
|
|
|
$this->$function_build( |
|
|
|
$this->$function_build( |
|
|
|
$session_id, |
|
|
|
$session_id, |
|
|
|
$courseId, |
|
|
|
$courseId, |
|
|
|
@ -157,9 +199,10 @@ class CourseBuilder |
|
|
|
$specificIdList |
|
|
|
$specificIdList |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Add asset |
|
|
|
// Add asset |
|
|
|
if ($course['course_image_source'] && basename($course['course_image_source']) != 'course.png') { |
|
|
|
if ($course['course_image_source'] && basename($course['course_image_source']) !== 'course.png') { |
|
|
|
// Add course image courses/XXX/course-pic85x85.png |
|
|
|
// Add course image courses/XXX/course-pic85x85.png |
|
|
|
$asset = new Asset( |
|
|
|
$asset = new Asset( |
|
|
|
$course['course_image_source'], |
|
|
|
$course['course_image_source'], |
|
|
|
@ -180,7 +223,11 @@ class CourseBuilder |
|
|
|
// from the item_property table and order them in the "resources" array |
|
|
|
// from the item_property table and order them in the "resources" array |
|
|
|
$table = Database::get_course_table(TABLE_ITEM_PROPERTY); |
|
|
|
$table = Database::get_course_table(TABLE_ITEM_PROPERTY); |
|
|
|
foreach ($this->course->resources as $type => $resources) { |
|
|
|
foreach ($this->course->resources as $type => $resources) { |
|
|
|
|
|
|
|
if (!empty($parseOnlyToolList) && !in_array($this->toolToName[$tool], $parseOnlyToolList)) { |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
foreach ($resources as $id => $resource) { |
|
|
|
foreach ($resources as $id => $resource) { |
|
|
|
|
|
|
|
if ($resource) { |
|
|
|
$tool = $resource->get_tool(); |
|
|
|
$tool = $resource->get_tool(); |
|
|
|
if ($tool != null) { |
|
|
|
if ($tool != null) { |
|
|
|
$sql = "SELECT * FROM $table |
|
|
|
$sql = "SELECT * FROM $table |
|
|
|
@ -197,6 +244,7 @@ class CourseBuilder |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $this->course; |
|
|
|
return $this->course; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -230,7 +278,7 @@ class CourseBuilder |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!empty($courseId) && !empty($session_id)) { |
|
|
|
if (!empty($courseId) && !empty($session_id)) { |
|
|
|
$session_id = intval($session_id); |
|
|
|
$session_id = (int) $session_id; |
|
|
|
if ($withBaseContent) { |
|
|
|
if ($withBaseContent) { |
|
|
|
$session_condition = api_get_session_condition( |
|
|
|
$session_condition = api_get_session_condition( |
|
|
|
$session_id, |
|
|
|
$session_id, |
|
|
|
@ -615,12 +663,14 @@ class CourseBuilder |
|
|
|
* @param int $courseId Internal course ID |
|
|
|
* @param int $courseId Internal course ID |
|
|
|
* @param bool $withBaseContent Whether to include content from the course without session or not |
|
|
|
* @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 |
|
|
|
* @param array $idList If you want to restrict the structure to only the given IDs |
|
|
|
|
|
|
|
* @param bool $buildOrphanQuestions |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function build_quizzes( |
|
|
|
public function build_quizzes( |
|
|
|
$session_id = 0, |
|
|
|
$session_id = 0, |
|
|
|
$courseId = 0, |
|
|
|
$courseId = 0, |
|
|
|
$withBaseContent = false, |
|
|
|
$withBaseContent = false, |
|
|
|
$idList = [] |
|
|
|
$idList = [], |
|
|
|
|
|
|
|
$buildOrphanQuestions = true |
|
|
|
) { |
|
|
|
) { |
|
|
|
$table_qui = Database::get_course_table(TABLE_QUIZ_TEST); |
|
|
|
$table_qui = Database::get_course_table(TABLE_QUIZ_TEST); |
|
|
|
$table_rel = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); |
|
|
|
$table_rel = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); |
|
|
|
@ -634,7 +684,7 @@ class CourseBuilder |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!empty($courseId) && !empty($session_id)) { |
|
|
|
if (!empty($courseId) && !empty($session_id)) { |
|
|
|
$session_id = intval($session_id); |
|
|
|
$session_id = (int) $session_id; |
|
|
|
if ($withBaseContent) { |
|
|
|
if ($withBaseContent) { |
|
|
|
$sessionCondition = api_get_session_condition( |
|
|
|
$sessionCondition = api_get_session_condition( |
|
|
|
$session_id, |
|
|
|
$session_id, |
|
|
|
@ -666,8 +716,8 @@ class CourseBuilder |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$sql .= ' ORDER BY title'; |
|
|
|
$sql .= ' ORDER BY title'; |
|
|
|
|
|
|
|
|
|
|
|
$db_result = Database::query($sql); |
|
|
|
$db_result = Database::query($sql); |
|
|
|
|
|
|
|
$questionList = []; |
|
|
|
while ($obj = Database::fetch_object($db_result)) { |
|
|
|
while ($obj = Database::fetch_object($db_result)) { |
|
|
|
if (strlen($obj->sound) > 0) { |
|
|
|
if (strlen($obj->sound) > 0) { |
|
|
|
$sql = "SELECT id FROM $table_doc |
|
|
|
$sql = "SELECT id FROM $table_doc |
|
|
|
@ -676,20 +726,22 @@ class CourseBuilder |
|
|
|
$doc = Database::fetch_object($res); |
|
|
|
$doc = Database::fetch_object($res); |
|
|
|
$obj->sound = $doc->id; |
|
|
|
$obj->sound = $doc->id; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$quiz = new Quiz($obj); |
|
|
|
$quiz = new Quiz($obj); |
|
|
|
$sql = 'SELECT * FROM '.$table_rel.' |
|
|
|
$sql = 'SELECT * FROM '.$table_rel.' |
|
|
|
WHERE c_id = '.$courseId.' AND exercice_id = '.$obj->id; |
|
|
|
WHERE c_id = '.$courseId.' AND exercice_id = '.$obj->id; |
|
|
|
$db_result2 = Database::query($sql); |
|
|
|
$db_result2 = Database::query($sql); |
|
|
|
while ($obj2 = Database::fetch_object($db_result2)) { |
|
|
|
while ($obj2 = Database::fetch_object($db_result2)) { |
|
|
|
$quiz->add_question($obj2->question_id, $obj2->question_order); |
|
|
|
$quiz->add_question($obj2->question_id, $obj2->question_order); |
|
|
|
|
|
|
|
$questionList[] = $obj2->question_id; |
|
|
|
} |
|
|
|
} |
|
|
|
$this->course->add_resource($quiz); |
|
|
|
$this->course->add_resource($quiz); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!empty($courseId)) { |
|
|
|
if (!empty($courseId)) { |
|
|
|
$this->build_quiz_questions($courseId); |
|
|
|
$this->build_quiz_questions($courseId, $questionList, $buildOrphanQuestions); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
$this->build_quiz_questions(); |
|
|
|
$this->build_quiz_questions(0, $questionList, $buildOrphanQuestions); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -697,19 +749,22 @@ class CourseBuilder |
|
|
|
* Build the Quiz-Questions. |
|
|
|
* Build the Quiz-Questions. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param int $courseId Internal course ID |
|
|
|
* @param int $courseId Internal course ID |
|
|
|
|
|
|
|
* @param array $questionList |
|
|
|
|
|
|
|
* @param bool $buildOrphanQuestions |
|
|
|
|
|
|
|
* |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function build_quiz_questions($courseId = 0) |
|
|
|
public function build_quiz_questions($courseId = 0, $questionList = [], $buildOrphanQuestions = true) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$table_qui = Database::get_course_table(TABLE_QUIZ_TEST); |
|
|
|
$table_qui = Database::get_course_table(TABLE_QUIZ_TEST); |
|
|
|
$table_rel = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); |
|
|
|
$table_rel = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); |
|
|
|
$table_que = Database::get_course_table(TABLE_QUIZ_QUESTION); |
|
|
|
$table_que = Database::get_course_table(TABLE_QUIZ_QUESTION); |
|
|
|
$table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER); |
|
|
|
$table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER); |
|
|
|
|
|
|
|
|
|
|
|
$courseId = (int) $courseId; |
|
|
|
$courseId = (int) $courseId; |
|
|
|
|
|
|
|
$questionListToString = implode("','", $questionList); |
|
|
|
|
|
|
|
|
|
|
|
// Building normal tests. |
|
|
|
// Building normal tests (many queries) |
|
|
|
$sql = "SELECT * FROM $table_que |
|
|
|
$sql = "SELECT * FROM $table_que |
|
|
|
WHERE c_id = $courseId "; |
|
|
|
WHERE c_id = $courseId AND id IN ('$questionListToString')"; |
|
|
|
$result = Database::query($sql); |
|
|
|
$result = Database::query($sql); |
|
|
|
|
|
|
|
|
|
|
|
while ($obj = Database::fetch_object($result)) { |
|
|
|
while ($obj = Database::fetch_object($result)) { |
|
|
|
@ -738,7 +793,6 @@ class CourseBuilder |
|
|
|
$sql = 'SELECT * FROM '.$table_ans.' |
|
|
|
$sql = 'SELECT * FROM '.$table_ans.' |
|
|
|
WHERE c_id = '.$courseId.' AND question_id = '.$obj->id; |
|
|
|
WHERE c_id = '.$courseId.' AND question_id = '.$obj->id; |
|
|
|
$db_result2 = Database::query($sql); |
|
|
|
$db_result2 = Database::query($sql); |
|
|
|
|
|
|
|
|
|
|
|
while ($obj2 = Database::fetch_object($db_result2)) { |
|
|
|
while ($obj2 = Database::fetch_object($db_result2)) { |
|
|
|
$question->add_answer( |
|
|
|
$question->add_answer( |
|
|
|
$obj2->id, |
|
|
|
$obj2->id, |
|
|
|
@ -764,9 +818,10 @@ class CourseBuilder |
|
|
|
$this->course->add_resource($question); |
|
|
|
$this->course->add_resource($question); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($buildOrphanQuestions) { |
|
|
|
// Building a fictional test for collecting orphan questions. |
|
|
|
// Building a fictional test for collecting orphan questions. |
|
|
|
// When a course is emptied this option should be activated (true). |
|
|
|
// When a course is emptied this option should be activated (true). |
|
|
|
$build_orphan_questions = !empty($_POST['recycle_option']); |
|
|
|
//$build_orphan_questions = !empty($_POST['recycle_option']); |
|
|
|
|
|
|
|
|
|
|
|
// 1st union gets the orphan questions from deleted exercises |
|
|
|
// 1st union gets the orphan questions from deleted exercises |
|
|
|
// 2nd union gets the orphan questions from question that were deleted in a exercise. |
|
|
|
// 2nd union gets the orphan questions from question that were deleted in a exercise. |
|
|
|
@ -796,7 +851,6 @@ class CourseBuilder |
|
|
|
|
|
|
|
|
|
|
|
$result = Database::query($sql); |
|
|
|
$result = Database::query($sql); |
|
|
|
if (Database::num_rows($result) > 0) { |
|
|
|
if (Database::num_rows($result) > 0) { |
|
|
|
$build_orphan_questions = true; |
|
|
|
|
|
|
|
$orphanQuestionIds = []; |
|
|
|
$orphanQuestionIds = []; |
|
|
|
while ($obj = Database::fetch_object($result)) { |
|
|
|
while ($obj = Database::fetch_object($result)) { |
|
|
|
// Orphan questions |
|
|
|
// Orphan questions |
|
|
|
@ -844,11 +898,11 @@ class CourseBuilder |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($build_orphan_questions) { |
|
|
|
|
|
|
|
$obj = [ |
|
|
|
$obj = [ |
|
|
|
'id' => -1, |
|
|
|
'id' => -1, |
|
|
|
'title' => get_lang('OrphanQuestions', ''), |
|
|
|
'title' => get_lang('OrphanQuestions'), |
|
|
|
'type' => 2, |
|
|
|
'type' => 2, |
|
|
|
]; |
|
|
|
]; |
|
|
|
$newQuiz = new Quiz((object) $obj); |
|
|
|
$newQuiz = new Quiz((object) $obj); |
|
|
|
@ -860,9 +914,9 @@ class CourseBuilder |
|
|
|
} |
|
|
|
} |
|
|
|
$this->course->add_resource($newQuiz); |
|
|
|
$this->course->add_resource($newQuiz); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
|
|
|
|
* @deprecated |
|
|
|
* Build the orphan questions. |
|
|
|
* Build the orphan questions. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function build_quiz_orphan_questions() |
|
|
|
public function build_quiz_orphan_questions() |
|
|
|
|