Improve backup export/import speed see BT#14425

- Remove <input name ="course" value="base64" only for the create backup
- Only load orphan questions when are selected
pull/2573/head
Julio 7 years ago
parent fcd95132e3
commit bb00c108f2
  1. 26
      main/coursecopy/create_backup.php
  2. 292
      src/Chamilo/CourseBundle/Component/CourseCopy/CourseBuilder.php
  3. 27
      src/Chamilo/CourseBundle/Component/CourseCopy/CourseRestorer.php
  4. 277
      src/Chamilo/CourseBundle/Component/CourseCopy/CourseSelectForm.php

@ -40,23 +40,20 @@ Display::display_header($nameTools);
// Display the tool title
echo Display::page_header($nameTools);
$action = isset($_POST['action']) ? $_POST['action'] : '';
$backupOption = isset($_POST['backup_option']) ? $_POST['backup_option'] : '';
if (Security::check_token('post') && (
(
isset($_POST['action']) &&
$_POST['action'] == 'course_select_form'
) || (
isset($_POST['backup_option']) &&
$_POST['backup_option'] == 'full_backup'
)
)
if (Security::check_token('post') &&
($action === 'course_select_form' || $backupOption === 'full_backup')
) {
// Clear token
Security::clear_token();
$cb = new CourseBuilder();
$course = $cb->build();
if (isset($_POST['action']) && $_POST['action'] == 'course_select_form') {
if ($action === 'course_select_form') {
$course = $cb->build(0, null, false, array_keys($_POST['resource']), $_POST['resource']);
$course = CourseSelectForm::get_posted_course(null, 0, '', $course);
} else {
$course = $cb->build();
}
$zipFile = CourseArchiver::createBackup($course);
echo Display::return_message(get_lang('BackupCreated'), 'confirm');
@ -66,11 +63,7 @@ if (Security::check_token('post') && (
api_get_path(WEB_CODE_PATH).'course_info/download.php?archive='.$zipFile.'&'.api_get_cidreq(),
['class' => 'btn btn-primary btn-large']
);
} elseif (Security::check_token('post') && (
isset($_POST['backup_option']) &&
$_POST['backup_option'] == 'select_items'
)
) {
} elseif (Security::check_token('post') && $backupOption === 'select_items') {
// Clear token
Security::clear_token();
$cb = new CourseBuilder('partial');
@ -120,3 +113,4 @@ if (Security::check_token('post') && (
}
Display::display_footer();

@ -76,6 +76,29 @@ class CourseBuilder
'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
to be added in the course obj (only works with LPs) */
public $specific_id_list = [];
@ -136,30 +159,50 @@ class CourseBuilder
* @param string $courseCode
* @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)
* @param array $parseOnlyToolList
* @param array $toolsFromPost
*
* @return Course The course object structure
*/
public function build(
$session_id = 0,
$courseCode = '',
$withBaseContent = false
$withBaseContent = false,
$parseOnlyToolList = [],
$toolsFromPost = []
) {
$course = api_get_course_info($courseCode);
$courseId = $course['real_id'];
foreach ($this->tools_to_build as $tool) {
if (!empty($parseOnlyToolList) && !in_array($this->toolToName[$tool], $parseOnlyToolList)) {
continue;
}
$function_build = 'build_'.$tool;
$specificIdList = isset($this->specific_id_list[$tool]) ? $this->specific_id_list[$tool] : null;
$this->$function_build(
$session_id,
$courseId,
$withBaseContent,
$specificIdList
);
$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(
$session_id,
$courseId,
$withBaseContent,
$specificIdList
);
}
}
// 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
$asset = new Asset(
$course['course_image_source'],
@ -180,20 +223,25 @@ class CourseBuilder
// from the item_property table and order them in the "resources" array
$table = Database::get_course_table(TABLE_ITEM_PROPERTY);
foreach ($this->course->resources as $type => $resources) {
if (!empty($parseOnlyToolList) && !in_array($this->toolToName[$tool], $parseOnlyToolList)) {
continue;
}
foreach ($resources as $id => $resource) {
$tool = $resource->get_tool();
if ($tool != null) {
$sql = "SELECT * FROM $table
WHERE
c_id = $courseId AND
tool = '".$tool."' AND
ref = '".$resource->get_id()."'";
$res = Database::query($sql);
$properties = [];
while ($property = Database::fetch_array($res)) {
$properties[] = $property;
if ($resource) {
$tool = $resource->get_tool();
if ($tool != null) {
$sql = "SELECT * FROM $table
WHERE
c_id = $courseId AND
tool = '".$tool."' AND
ref = '".$resource->get_id()."'";
$res = Database::query($sql);
$properties = [];
while ($property = Database::fetch_array($res)) {
$properties[] = $property;
}
$this->course->resources[$type][$id]->item_properties = $properties;
}
$this->course->resources[$type][$id]->item_properties = $properties;
}
}
}
@ -230,7 +278,7 @@ class CourseBuilder
}
if (!empty($courseId) && !empty($session_id)) {
$session_id = intval($session_id);
$session_id = (int) $session_id;
if ($withBaseContent) {
$session_condition = api_get_session_condition(
$session_id,
@ -615,12 +663,14 @@ class CourseBuilder
* @param int $courseId Internal course ID
* @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 bool $buildOrphanQuestions
*/
public function build_quizzes(
$session_id = 0,
$courseId = 0,
$withBaseContent = false,
$idList = []
$idList = [],
$buildOrphanQuestions = true
) {
$table_qui = Database::get_course_table(TABLE_QUIZ_TEST);
$table_rel = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
@ -634,7 +684,7 @@ class CourseBuilder
}
if (!empty($courseId) && !empty($session_id)) {
$session_id = intval($session_id);
$session_id = (int) $session_id;
if ($withBaseContent) {
$sessionCondition = api_get_session_condition(
$session_id,
@ -666,8 +716,8 @@ class CourseBuilder
}
$sql .= ' ORDER BY title';
$db_result = Database::query($sql);
$questionList = [];
while ($obj = Database::fetch_object($db_result)) {
if (strlen($obj->sound) > 0) {
$sql = "SELECT id FROM $table_doc
@ -676,40 +726,45 @@ class CourseBuilder
$doc = Database::fetch_object($res);
$obj->sound = $doc->id;
}
$quiz = new Quiz($obj);
$sql = 'SELECT * FROM '.$table_rel.'
WHERE c_id = '.$courseId.' AND exercice_id = '.$obj->id;
$db_result2 = Database::query($sql);
while ($obj2 = Database::fetch_object($db_result2)) {
$quiz->add_question($obj2->question_id, $obj2->question_order);
$questionList[] = $obj2->question_id;
}
$this->course->add_resource($quiz);
}
if (!empty($courseId)) {
$this->build_quiz_questions($courseId);
$this->build_quiz_questions($courseId, $questionList, $buildOrphanQuestions);
} else {
$this->build_quiz_questions();
$this->build_quiz_questions(0, $questionList, $buildOrphanQuestions);
}
}
/**
* 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_rel = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$table_que = Database::get_course_table(TABLE_QUIZ_QUESTION);
$table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER);
$courseId = (int) $courseId;
$questionListToString = implode("','", $questionList);
// Building normal tests.
// Building normal tests (many queries)
$sql = "SELECT * FROM $table_que
WHERE c_id = $courseId ";
WHERE c_id = $courseId AND id IN ('$questionListToString')";
$result = Database::query($sql);
while ($obj = Database::fetch_object($result)) {
@ -738,7 +793,6 @@ class CourseBuilder
$sql = 'SELECT * FROM '.$table_ans.'
WHERE c_id = '.$courseId.' AND question_id = '.$obj->id;
$db_result2 = Database::query($sql);
while ($obj2 = Database::fetch_object($db_result2)) {
$question->add_answer(
$obj2->id,
@ -764,105 +818,105 @@ class CourseBuilder
$this->course->add_resource($question);
}
// Building a fictional test for collecting orphan questions.
// When a course is emptied this option should be activated (true).
$build_orphan_questions = !empty($_POST['recycle_option']);
// 1st union gets the orphan questions from deleted exercises
// 2nd union gets the orphan questions from question that were deleted in a exercise.
$sql = " (
SELECT question_id, q.* FROM $table_que q
INNER JOIN $table_rel r
ON (q.c_id = r.c_id AND q.id = r.question_id)
INNER JOIN $table_qui ex
ON (ex.id = r.exercice_id AND ex.c_id = r.c_id)
WHERE ex.c_id = $courseId AND ex.active = '-1'
)
UNION
(
SELECT question_id, q.* FROM $table_que q
left OUTER JOIN $table_rel r
ON (q.c_id = r.c_id AND q.id = r.question_id)
WHERE q.c_id = $courseId AND r.question_id is null
)
UNION
(
SELECT question_id, q.* FROM $table_que q
INNER JOIN $table_rel r
ON (q.c_id = r.c_id AND q.id = r.question_id)
WHERE r.c_id = $courseId AND (r.exercice_id = '-1' OR r.exercice_id = '0')
)
";
if ($buildOrphanQuestions) {
// Building a fictional test for collecting orphan questions.
// When a course is emptied this option should be activated (true).
//$build_orphan_questions = !empty($_POST['recycle_option']);
// 1st union gets the orphan questions from deleted exercises
// 2nd union gets the orphan questions from question that were deleted in a exercise.
$sql = " (
SELECT question_id, q.* FROM $table_que q
INNER JOIN $table_rel r
ON (q.c_id = r.c_id AND q.id = r.question_id)
INNER JOIN $table_qui ex
ON (ex.id = r.exercice_id AND ex.c_id = r.c_id)
WHERE ex.c_id = $courseId AND ex.active = '-1'
)
UNION
(
SELECT question_id, q.* FROM $table_que q
left OUTER JOIN $table_rel r
ON (q.c_id = r.c_id AND q.id = r.question_id)
WHERE q.c_id = $courseId AND r.question_id is null
)
UNION
(
SELECT question_id, q.* FROM $table_que q
INNER JOIN $table_rel r
ON (q.c_id = r.c_id AND q.id = r.question_id)
WHERE r.c_id = $courseId AND (r.exercice_id = '-1' OR r.exercice_id = '0')
)
";
$result = Database::query($sql);
if (Database::num_rows($result) > 0) {
$build_orphan_questions = true;
$orphanQuestionIds = [];
while ($obj = Database::fetch_object($result)) {
// Orphan questions
if (!empty($obj->question_id)) {
$obj->id = $obj->question_id;
}
$result = Database::query($sql);
if (Database::num_rows($result) > 0) {
$orphanQuestionIds = [];
while ($obj = Database::fetch_object($result)) {
// Orphan questions
if (!empty($obj->question_id)) {
$obj->id = $obj->question_id;
}
// Avoid adding the same question twice
if (!isset($this->course->resources[$obj->id])) {
// find the question category
// @todo : need to be adapted for multi category questions in 1.10
$question_category_id = TestCategory::getCategoryForQuestion($obj->id, $courseId);
$question = new QuizQuestion(
$obj->id,
$obj->question,
$obj->description,
$obj->ponderation,
$obj->type,
$obj->position,
$obj->picture,
$obj->level,
$obj->extra,
$question_category_id
);
$question->addPicture($this);
$sql = "SELECT * FROM $table_ans
WHERE c_id = $courseId AND question_id = ".$obj->id;
$db_result2 = Database::query($sql);
if (Database::num_rows($db_result2)) {
while ($obj2 = Database::fetch_object($db_result2)) {
$question->add_answer(
$obj2->id,
$obj2->answer,
$obj2->correct,
$obj2->comment,
$obj2->ponderation,
$obj2->position,
$obj2->hotspot_coordinates,
$obj2->hotspot_type
);
// Avoid adding the same question twice
if (!isset($this->course->resources[$obj->id])) {
// find the question category
// @todo : need to be adapted for multi category questions in 1.10
$question_category_id = TestCategory::getCategoryForQuestion($obj->id, $courseId);
$question = new QuizQuestion(
$obj->id,
$obj->question,
$obj->description,
$obj->ponderation,
$obj->type,
$obj->position,
$obj->picture,
$obj->level,
$obj->extra,
$question_category_id
);
$question->addPicture($this);
$sql = "SELECT * FROM $table_ans
WHERE c_id = $courseId AND question_id = ".$obj->id;
$db_result2 = Database::query($sql);
if (Database::num_rows($db_result2)) {
while ($obj2 = Database::fetch_object($db_result2)) {
$question->add_answer(
$obj2->id,
$obj2->answer,
$obj2->correct,
$obj2->comment,
$obj2->ponderation,
$obj2->position,
$obj2->hotspot_coordinates,
$obj2->hotspot_type
);
}
$orphanQuestionIds[] = $obj->id;
}
$orphanQuestionIds[] = $obj->id;
$this->course->add_resource($question);
}
$this->course->add_resource($question);
}
}
}
if ($build_orphan_questions) {
$obj = [
'id' => -1,
'title' => get_lang('OrphanQuestions', ''),
'type' => 2,
];
$newQuiz = new Quiz((object) $obj);
if (!empty($orphanQuestionIds)) {
foreach ($orphanQuestionIds as $index => $orphanId) {
$order = $index + 1;
$newQuiz->add_question($orphanId, $order);
}
$obj = [
'id' => -1,
'title' => get_lang('OrphanQuestions'),
'type' => 2,
];
$newQuiz = new Quiz((object) $obj);
if (!empty($orphanQuestionIds)) {
foreach ($orphanQuestionIds as $index => $orphanId) {
$order = $index + 1;
$newQuiz->add_question($orphanId, $order);
}
$this->course->add_resource($newQuiz);
}
$this->course->add_resource($newQuiz);
}
/**
* @deprecated
* Build the orphan questions.
*/
public function build_quiz_orphan_questions()

@ -152,7 +152,7 @@ class CourseRestorer
}
$this->destination_course_id = $course_info['real_id'];
//Getting first teacher (for the forums)
// Getting first teacher (for the forums)
$teacher_list = CourseManager::get_teacher_list_from_course_code(
$course_info['code']
);
@ -207,7 +207,6 @@ class CourseRestorer
// Restore the item properties
$table = Database::get_course_table(TABLE_ITEM_PROPERTY);
foreach ($this->course->resources as $type => $resources) {
if (is_array($resources)) {
foreach ($resources as $id => $resource) {
@ -222,7 +221,7 @@ class CourseRestorer
$params = [];
if (!empty($session_id)) {
$params['session_id'] = intval($session_id);
$params['session_id'] = (int) $session_id;
}
$res = Database::query($sql);
@ -1080,7 +1079,7 @@ class CourseRestorer
public function restore_forums($sessionId = 0)
{
if ($this->course->has_resources(RESOURCE_FORUM)) {
$sessionId = intval($sessionId);
$sessionId = (int) $sessionId;
$table_forum = Database::get_course_table(TABLE_FORUM);
$resources = $this->course->resources;
foreach ($resources[RESOURCE_FORUM] as $id => $forum) {
@ -1458,7 +1457,7 @@ class CourseRestorer
public function restore_tool_intro($sessionId = 0)
{
if ($this->course->has_resources(RESOURCE_TOOL_INTRO)) {
$sessionId = intval($sessionId);
$sessionId = (int) $sessionId;
$tool_intro_table = Database::get_course_table(TABLE_TOOL_INTRO);
$resources = $this->course->resources;
foreach ($resources[RESOURCE_TOOL_INTRO] as $id => $tool_intro) {
@ -1503,7 +1502,7 @@ class CourseRestorer
public function restore_events($sessionId = 0)
{
if ($this->course->has_resources(RESOURCE_EVENT)) {
$sessionId = intval($sessionId);
$sessionId = (int) $sessionId;
$table = Database::get_course_table(TABLE_AGENDA);
$resources = $this->course->resources;
foreach ($resources[RESOURCE_EVENT] as $id => $event) {
@ -1638,7 +1637,7 @@ class CourseRestorer
);
$params = [];
$session_id = intval($session_id);
$session_id = (int) $session_id;
$params['session_id'] = $session_id;
$params['c_id'] = $this->destination_course_id;
$params['description_type'] = self::DBUTF8($descriptionType);
@ -1668,7 +1667,7 @@ class CourseRestorer
public function restore_announcements($sessionId = 0)
{
if ($this->course->has_resources(RESOURCE_ANNOUNCEMENT)) {
$sessionId = intval($sessionId);
$sessionId = (int) $sessionId;
$table = Database::get_course_table(TABLE_ANNOUNCEMENT);
$resources = $this->course->resources;
foreach ($resources[RESOURCE_ANNOUNCEMENT] as $id => $announcement) {
@ -1880,7 +1879,7 @@ class CourseRestorer
$params['session_id'] = $my_session_id;
} else {
if (!empty($session_id)) {
$session_id = intval($session_id);
$session_id = (int) $session_id;
$params['session_id'] = $session_id;
}
}
@ -1897,7 +1896,6 @@ class CourseRestorer
}
$this->course->resources[RESOURCE_QUIZ][$id]->destination_id = $new_id;
$order = 0;
if (!empty($quiz->question_ids)) {
foreach ($quiz->question_ids as $index => $question_id) {
@ -1911,6 +1909,7 @@ class CourseRestorer
Database::query($sql);
}
}
}
}
}
@ -2030,7 +2029,6 @@ class CourseRestorer
$quizAnswer
->setId($answerId)
->setIdAuto($answerId);
$em->merge($quizAnswer);
$em->flush();
@ -2299,7 +2297,7 @@ class CourseRestorer
*/
public function restore_surveys($sessionId = 0)
{
$sessionId = intval($sessionId);
$sessionId = (int) $sessionId;
if ($this->course->has_resources(RESOURCE_SURVEY)) {
$table_sur = Database::get_course_table(TABLE_SURVEY);
$table_que = Database::get_course_table(TABLE_SURVEY_QUESTION);
@ -2405,7 +2403,6 @@ class CourseRestorer
// Delete the existing survey with the same code and language and
// import the one of the source course
// getting the information of the survey (used for when the survey is shared)
$sql = "SELECT * FROM $table_sur
WHERE
c_id = ".$this->destination_course_id." AND
@ -2641,7 +2638,7 @@ class CourseRestorer
}
$condition_session = $my_session_id;
} else {
$session_id = intval($session_id);
$session_id = (int) $session_id;
$condition_session = $session_id;
}
}
@ -3011,7 +3008,7 @@ class CourseRestorer
foreach ($resources[RESOURCE_GLOSSARY] as $id => $glossary) {
$params = [];
if (!empty($session_id)) {
$session_id = intval($session_id);
$session_id = (int) $session_id;
$params['session_id'] = $session_id;
}

@ -18,6 +18,36 @@ use Display;
*/
class CourseSelectForm
{
/**
* @return array
*/
public static function getResourceTitleList()
{
$list = [];
$list[RESOURCE_LEARNPATH_CATEGORY] = get_lang('Learnpath').' '.get_lang('Category');
$list[RESOURCE_ASSET] = get_lang('Assets');
$list[RESOURCE_GRADEBOOK] = get_lang('Gradebook');
$list[RESOURCE_EVENT] = get_lang('Events');
$list[RESOURCE_ANNOUNCEMENT] = get_lang('Announcements');
$list[RESOURCE_DOCUMENT] = get_lang('Documents');
$list[RESOURCE_LINK] = get_lang('Links');
$list[RESOURCE_COURSEDESCRIPTION] = get_lang('CourseDescription');
$list[RESOURCE_FORUM] = get_lang('Forums');
$list[RESOURCE_FORUMCATEGORY] = get_lang('ForumCategory');
$list[RESOURCE_QUIZ] = get_lang('Tests');
$list[RESOURCE_TEST_CATEGORY] = get_lang('QuestionCategory');
$list[RESOURCE_LEARNPATH] = get_lang('ToolLearnpath');
$list[RESOURCE_SCORM] = 'SCORM';
$list[RESOURCE_TOOL_INTRO] = get_lang('ToolIntro');
$list[RESOURCE_SURVEY] = get_lang('Survey');
$list[RESOURCE_GLOSSARY] = get_lang('Glossary');
$list[RESOURCE_WIKI] = get_lang('Wiki');
$list[RESOURCE_THEMATIC] = get_lang('Thematic');
$list[RESOURCE_ATTENDANCE] = get_lang('Attendance');
$list[RESOURCE_WORK] = get_lang('ToolStudentPublication');
return $list;
}
/**
* Display the form.
*
@ -34,27 +64,7 @@ class CourseSelectForm
$avoidCourseInForm = false
) {
global $charset;
$resource_titles[RESOURCE_LEARNPATH_CATEGORY] = get_lang('Learnpath').' '.get_lang('Category');
$resource_titles[RESOURCE_ASSET] = get_lang('Assets');
$resource_titles[RESOURCE_GRADEBOOK] = get_lang('Gradebook');
$resource_titles[RESOURCE_EVENT] = get_lang('Events');
$resource_titles[RESOURCE_ANNOUNCEMENT] = get_lang('Announcements');
$resource_titles[RESOURCE_DOCUMENT] = get_lang('Documents');
$resource_titles[RESOURCE_LINK] = get_lang('Links');
$resource_titles[RESOURCE_COURSEDESCRIPTION] = get_lang('CourseDescription');
$resource_titles[RESOURCE_FORUM] = get_lang('Forums');
$resource_titles[RESOURCE_FORUMCATEGORY] = get_lang('ForumCategory');
$resource_titles[RESOURCE_QUIZ] = get_lang('Tests');
$resource_titles[RESOURCE_TEST_CATEGORY] = get_lang('QuestionCategory');
$resource_titles[RESOURCE_LEARNPATH] = get_lang('ToolLearnpath');
$resource_titles[RESOURCE_SCORM] = 'SCORM';
$resource_titles[RESOURCE_TOOL_INTRO] = get_lang('ToolIntro');
$resource_titles[RESOURCE_SURVEY] = get_lang('Survey');
$resource_titles[RESOURCE_GLOSSARY] = get_lang('Glossary');
$resource_titles[RESOURCE_WIKI] = get_lang('Wiki');
$resource_titles[RESOURCE_THEMATIC] = get_lang('Thematic');
$resource_titles[RESOURCE_ATTENDANCE] = get_lang('Attendance');
$resource_titles[RESOURCE_WORK] = get_lang('ToolStudentPublication'); ?>
?>
<script>
function exp(item) {
el = document.getElementById('div_'+item);
@ -62,6 +72,7 @@ class CourseSelectForm
el.style.display = '';
$('#img_'+item).removeClass();
$('#img_'+item).addClass('fa fa-minus-square-o fa-lg');
} else {
el.style.display = 'none';
$('#img_'+item).removeClass();
@ -157,6 +168,7 @@ class CourseSelectForm
echo get_lang('DestinationCourse').' : '.$courseInfo['title'].' ('.$courseInfo['code'].') '.$sessionTitle;
echo '</h3>';
}
echo '<script src="'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/upload.js" type="text/javascript"></script>';
echo '<div class="tool-backups-options">';
echo '<form method="post" id="upload_form" name="course_select_form">';
@ -173,7 +185,6 @@ class CourseSelectForm
echo '<input type="hidden" name="origin_session" value="'.$hidden_fields['origin_session'].'"/>';
}
$element_count = 0;
$forum_categories = [];
$forums = [];
$forum_topics = [];
@ -183,98 +194,8 @@ class CourseSelectForm
echo '</p>';
echo Display::return_message(get_lang('DontForgetToSelectTheMediaFilesIfYourResourceNeedIt'));
foreach ($course->resources as $type => $resources) {
if (count($resources) > 0) {
switch ($type) {
// Resources to avoid
case RESOURCE_FORUMCATEGORY:
foreach ($resources as $id => $resource) {
$forum_categories[$id] = $resource;
}
$element_count++;
break;
case RESOURCE_FORUM:
foreach ($resources as $id => $resource) {
$forums[$resource->obj->forum_category][$id] = $resource;
}
$element_count++;
break;
case RESOURCE_FORUMTOPIC:
foreach ($resources as $id => $resource) {
$forum_topics[$resource->obj->forum_id][$id] = $resource;
}
$element_count++;
break;
case RESOURCE_LINKCATEGORY:
case RESOURCE_FORUMPOST:
case RESOURCE_QUIZQUESTION:
case RESOURCE_SURVEYQUESTION:
case RESOURCE_SURVEYINVITATION:
case RESOURCE_SCORM:
break;
default:
echo '<div class="item-backup" onclick="javascript:exp('."'$type'".');">';
echo '<em id="img_'.$type.'" class="fa fa-plus-square-o fa-lg" ></em>';
echo '<span class="title">'.$resource_titles[$type].'</span></div>';
echo '<div class="item-content" id="div_'.$type.'">';
if ($type == RESOURCE_LEARNPATH) {
echo Display::return_message(
get_lang(
'ToExportLearnpathWithQuizYouHaveToSelectQuiz'
),
'warning'
);
echo Display::return_message(
get_lang(
'IfYourLPsHaveAudioFilesIncludedYouShouldSelectThemFromTheDocuments'
),
'warning'
);
}
if ($type == RESOURCE_DOCUMENT) {
if (api_get_setting('show_glossary_in_documents') != 'none') {
echo Display::return_message(
get_lang(
'ToExportDocumentsWithGlossaryYouHaveToSelectGlossary'
),
'warning'
);
}
}
echo '<div class="well">';
echo '<div class="btn-group">';
echo "<a class=\"btn btn-default\"
href=\"javascript: void(0);\"
onclick=\"javascript: setCheckbox('$type',true);\" >".get_lang('All')."</a>";
echo "<a class=\"btn btn-default\"
href=\"javascript: void(0);\"
onclick=\"javascript:setCheckbox('$type',false);\" >".get_lang('None')."</a>";
echo '</div>';
echo '<ul class="list-backups-options">';
foreach ($resources as $id => $resource) {
if ($resource) {
echo '<li>';
// Event obj in 1.9.x in 1.10.x the class is CalendarEvent
Resource::setClassType($resource);
echo '<label class="checkbox">';
echo '<input
type="checkbox"
name="resource['.$type.']['.$id.']"
id="resource['.$type.']['.$id.']" />';
$resource->show();
echo '</label>';
echo '</li>';
}
}
echo '</ul>';
echo '</div>';
echo '</div>';
echo '<script language="javascript">exp('."'$type'".')</script>';
$element_count++;
}
}
}
$resource_titles = self::getResourceTitleList();
$element_count = self::parseResources($resource_titles, $course->resources, true, true);
// Fixes forum order
if (!empty($forum_categories)) {
@ -395,6 +316,127 @@ class CourseSelectForm
echo '<div id="dynamic_div" style="display:block;margin-left:40%;margin-top:10px;height:50px;"></div>';
}
/**
* @param array $resource_titles
* @param array $resourceList
* @param bool $showHeader
* @param bool $showItems
*
* @return int
*/
public static function parseResources(
$resource_titles,
$resourceList,
$showHeader = true,
$showItems = true
) {
$element_count = 0;
foreach ($resourceList as $type => $resources) {
if (count($resources) > 0) {
switch ($type) {
// Resources to avoid
case RESOURCE_FORUMCATEGORY:
foreach ($resources as $id => $resource) {
$forum_categories[$id] = $resource;
}
$element_count++;
break;
case RESOURCE_FORUM:
foreach ($resources as $id => $resource) {
$forums[$resource->obj->forum_category][$id] = $resource;
}
$element_count++;
break;
case RESOURCE_FORUMTOPIC:
foreach ($resources as $id => $resource) {
$forum_topics[$resource->obj->forum_id][$id] = $resource;
}
$element_count++;
break;
case RESOURCE_LINKCATEGORY:
case RESOURCE_FORUMPOST:
case RESOURCE_QUIZQUESTION:
case RESOURCE_SURVEYQUESTION:
case RESOURCE_SURVEYINVITATION:
case RESOURCE_SCORM:
break;
default:
if ($showHeader) {
echo '<div class="item-backup" onclick="javascript:exp('."'$type'".');">';
echo '<em id="img_'.$type.'" class="fa fa-plus-square-o fa-lg"></em>';
echo '<span class="title">'.$resource_titles[$type].'</span>';
echo '</div>';
echo '<div class="item-content" id="div_'.$type.'">';
}
if ($type == RESOURCE_LEARNPATH) {
echo Display::return_message(
get_lang(
'ToExportLearnpathWithQuizYouHaveToSelectQuiz'
),
'warning'
);
echo Display::return_message(
get_lang(
'IfYourLPsHaveAudioFilesIncludedYouShouldSelectThemFromTheDocuments'
),
'warning'
);
}
if ($type == RESOURCE_DOCUMENT) {
if (api_get_setting('show_glossary_in_documents') != 'none') {
echo Display::return_message(
get_lang(
'ToExportDocumentsWithGlossaryYouHaveToSelectGlossary'
),
'warning'
);
}
}
if ($showItems) {
echo '<div class="well">';
echo '<div class="btn-group">';
echo "<a class=\"btn btn-default\"
href=\"javascript: void(0);\"
onclick=\"javascript: setCheckbox('$type',true);\" >".get_lang('All')."</a>";
echo "<a class=\"btn btn-default\"
href=\"javascript: void(0);\"
onclick=\"javascript:setCheckbox('$type',false);\" >".get_lang('None')."</a>";
echo '</div>';
echo '<ul class="list-backups-options">';
foreach ($resources as $id => $resource) {
if ($resource) {
echo '<li>';
// Event obj in 1.9.x in 1.10.x the class is CalendarEvent
Resource::setClassType($resource);
echo '<label class="checkbox">';
echo '<input
type="checkbox"
name="resource['.$type.']['.$id.']"
id="resource['.$type.']['.$id.']" />';
$resource->show();
echo '</label>';
echo '</li>';
}
}
echo '</ul>';
echo '</div>';
}
if ($showHeader) {
echo '</div>';
echo '<script language="javascript">exp('."'$type'".')</script>';
}
$element_count++;
}
}
}
return $element_count;
}
/**
* @param $course
*/
@ -638,8 +680,11 @@ class CourseSelectForm
}
}
}
if (!isset($_POST['resource'][$type][$id]) && !$resource_is_used_elsewhere) {
unset($course->resources[$type][$id]);
// quiz question can be, not attached to an exercise
if ($type != RESOURCE_QUIZQUESTION) {
if (!isset($_POST['resource'][$type][$id]) && !$resource_is_used_elsewhere) {
unset($course->resources[$type][$id]);
}
}
}
}

Loading…
Cancel
Save