Admin: Add course template option to course import feature - refs #3970

Author: @villalvilla
pull/4517/head
Yannick Warnier 3 years ago committed by GitHub
parent 82c555bce2
commit 3593ff8dac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 42
      main/admin/course_import.php

@ -126,6 +126,21 @@ function save_courses_data($courses)
$params['user_id'] = $creatorId;
$addMeAsTeacher = isset($_POST['add_me_as_teacher']) ? $_POST['add_me_as_teacher'] : false;
$params['add_user_as_teacher'] = $addMeAsTeacher;
// Check if there is a course template stated for this course. In that case, we check if that code exists in DB:
if (array_key_exists('CourseTemplate', $course) && $course['CourseTemplate'] != '') {
$result = Database::fetch_array(
Database::query(
"SELECT id as real_id FROM ".Database::get_main_table(TABLE_MAIN_COURSE)."
WHERE code = '".Database::escape_string($course['CourseTemplate'])."'"
),
'ASSOC'
);
if (count($result) && array_key_exists('real_id', $result)) {
$params['course_template'] = $result['real_id'];
}
}
$courseInfo = CourseManager::create_course($params);
if (!empty($courseInfo)) {
@ -141,6 +156,25 @@ function save_courses_data($courses)
$msg .= '<a href="'.api_get_path(WEB_COURSE_PATH).$courseInfo['directory'].'/">
'.$courseInfo['title'].'</a> '.get_lang('Created').'<br />';
}
// Check if necessary to clone tools' first page from the original course to the imported course:
if (array_key_exists('CloneHomepageTools', $course) && $course['CloneHomepageTools'] == 'true' && array_key_exists('course_template', $params)) {
$results = Database::store_result(
Database::query(
"SELECT * FROM ".Database::get_course_table(TABLE_TOOL_LIST)."
WHERE c_id = ".$params['course_template']
),
'ASSOC'
);
if (count($results)) {
foreach ($results as $row) {
Database::update(
Database::get_course_table(TABLE_TOOL_LIST),
['visibility' => $row['visibility']],
['c_id = ? and name = ?' => [$courseInfo['real_id'], $row['name']]]
);
}
}
}
}
if (!empty($msg)) {
@ -233,10 +267,10 @@ $form->display();
<blockquote>
<pre>
<strong>Code</strong>;<strong>Title</strong>;<strong>CourseCategory</strong>;<strong>CourseCategoryName</strong>;Teacher;Language
BIO0015;Biology;BIO;Science;teacher1;english
BIO0016;Maths;MATH;Engineerng;teacher2|teacher3;english
BIO0017;Language;LANG;;;english
<strong>Code</strong>;<strong>Title</strong>;<strong>CourseCategory</strong>;<strong>CourseCategoryName</strong>;Teacher;Language;CourseTemplate;CloneHomepageTools
BIO0015;Biology;BIO;Science;teacher1;english;TEMPLATE1;true
BIO0016;Maths;MATH;Engineerng;teacher2|teacher3;english;;
BIO0017;Language;LANG;;;english;;
</pre>
</blockquote>

Loading…
Cancel
Save