Allow to teachers select a course as template - refs #8134

ofaj
Angel Fernando Quiroz Campos 10 years ago
parent b9dac78374
commit 4c31be0392
  1. 13
      main/admin/course_add.php
  2. 13
      main/create_course/add_course.php
  3. 28
      main/inc/ajax/course.ajax.php
  4. 34
      main/inc/lib/course.lib.php
  5. 2
      main/inc/lib/course_category.lib.php

@ -103,6 +103,19 @@ $form->applyFilter('department_url', 'html_filter');
$form->addElement('select_language', 'course_language', get_lang('CourseLanguage')); $form->addElement('select_language', 'course_language', get_lang('CourseLanguage'));
$form->applyFilter('select_language', 'html_filter'); $form->applyFilter('select_language', 'html_filter');
if (api_get_setting('teacher_can_select_course_template') === 'true') {
$form->addElement(
'select_ajax',
'course_template',
[
get_lang('CourseTemplate'),
get_lang('PickACourseAsATemplateForThisNewCourse'),
],
null,
['url' => api_get_path(WEB_AJAX_PATH) . 'course.ajax.php?a=search_course']
);
}
$form->addElement('checkbox', 'exemplary_content', '', get_lang('FillWithExemplaryContent')); $form->addElement('checkbox', 'exemplary_content', '', get_lang('FillWithExemplaryContent'));
$group = array(); $group = array();

@ -221,6 +221,19 @@ if ($course_validation_feature) {
$obj = new GradeModel(); $obj = new GradeModel();
$obj->fill_grade_model_select_in_form($form); $obj->fill_grade_model_select_in_form($form);
if (api_get_setting('teacher_can_select_course_template') === 'true') {
$form->addElement(
'select_ajax',
'course_template',
[
get_lang('CourseTemplate'),
get_lang('PickACourseAsATemplateForThisNewCourse'),
],
null,
['url' => api_get_path(WEB_AJAX_PATH) . 'course.ajax.php?a=search_course']
);
}
$form->addElement('html', '</div>'); $form->addElement('html', '</div>');
// Submit button. // Submit button.

@ -58,7 +58,7 @@ switch ($action) {
} }
break; break;
case 'search_course': case 'search_course':
if (api_is_platform_admin()) { if (api_is_teacher()) {
if (!empty($_GET['session_id']) && intval($_GET['session_id'])) { if (!empty($_GET['session_id']) && intval($_GET['session_id'])) {
//if session is defined, lets find only courses of this session //if session is defined, lets find only courses of this session
$courseList = SessionManager::get_course_list_by_session_id( $courseList = SessionManager::get_course_list_by_session_id(
@ -68,16 +68,20 @@ switch ($action) {
} else { } else {
//if session is not defined lets search all courses STARTING with $_GET['q'] //if session is not defined lets search all courses STARTING with $_GET['q']
//TODO change this function to search not only courses STARTING with $_GET['q'] //TODO change this function to search not only courses STARTING with $_GET['q']
$courseList = CourseManager::get_courses_list( if (api_is_platform_admin()) {
0, //offset $courseList = CourseManager::get_courses_list(
0, //howMany 0, //offset
1, //$orderby = 1 0, //howMany
'ASC', 1, //$orderby = 1
-1, //visibility 'ASC',
$_GET['q'], -1, //visibility
null, //$urlId $_GET['q'],
true //AlsoSearchCode null, //$urlId
); true //AlsoSearchCode
);
} elseif (api_is_teacher()) {
$courseList = CourseManager::get_course_list_of_user_as_course_admin(api_get_user_id(), $_GET['q']);
}
} }
$results = array(); $results = array();
@ -91,7 +95,7 @@ switch ($action) {
$title = $course['title']; $title = $course['title'];
if (!empty($course['category_code'])) { if (!empty($course['category_code'])) {
$parents = self::getParentsToString($course['category_code']); $parents = CourseCategory::getParentsToString($course['category_code']);
$title = $parents . $course['title']; $title = $parents . $course['title'];
} }

@ -126,13 +126,25 @@ class CourseManager
// If parameter defined, copy the contents from a specific // If parameter defined, copy the contents from a specific
// template course into this new course // template course into this new course
$template = api_get_setting('course_creation_use_template'); $template = api_get_setting('course_creation_use_template');
if (!empty($template)) { $teacherCanSelectCourseTemplate = api_get_setting('teacher_can_select_course_template') === 'true';
$courseTemplate = isset($params['course_template']) ? intval($params['course_template']) : 0;
$useTemplate = false;
if ($teacherCanSelectCourseTemplate && $courseTemplate) {
$useTemplate = true;
$originCourse = api_get_course_info_by_id($courseTemplate);
} elseif (!empty($template)) {
$useTemplate = true;
$originCourse = api_get_course_info_by_id($template);
}
if ($useTemplate) {
// Include the necessary libraries to generate a course copy // Include the necessary libraries to generate a course copy
require_once api_get_path(SYS_CODE_PATH) . 'coursecopy/classes/CourseBuilder.class.php'; require_once api_get_path(SYS_CODE_PATH) . 'coursecopy/classes/CourseBuilder.class.php';
require_once api_get_path(SYS_CODE_PATH) . 'coursecopy/classes/CourseRestorer.class.php'; require_once api_get_path(SYS_CODE_PATH) . 'coursecopy/classes/CourseRestorer.class.php';
require_once api_get_path(SYS_CODE_PATH) . 'coursecopy/classes/CourseSelectForm.class.php'; require_once api_get_path(SYS_CODE_PATH) . 'coursecopy/classes/CourseSelectForm.class.php';
// Call the course copy object // Call the course copy object
$originCourse = api_get_course_info_by_id($template);
$originCourse['official_code'] = $originCourse['code']; $originCourse['official_code'] = $originCourse['code'];
$cb = new CourseBuilder(null, $originCourse); $cb = new CourseBuilder(null, $originCourse);
$course = $cb->build(null, $originCourse['code']); $course = $cb->build(null, $originCourse['code']);
@ -921,10 +933,11 @@ class CourseManager
/** /**
* @param int $user_id * @param int $user_id
* @param string $startsWith Optional
* @return array An array with the course info of all the courses (real and virtual) * @return array An array with the course info of all the courses (real and virtual)
* of which the current user is course admin. * of which the current user is course admin.
*/ */
public static function get_course_list_of_user_as_course_admin($user_id) public static function get_course_list_of_user_as_course_admin($user_id, $startsWith = null)
{ {
if ($user_id != strval(intval($user_id))) { if ($user_id != strval(intval($user_id))) {
return array(); return array();
@ -940,14 +953,15 @@ class CourseManager
course.code, course.code,
course.title, course.title,
course.id, course.id,
course.id as real_id course.id as real_id,
course.category_code
FROM $tbl_course_user as course_rel_user FROM $tbl_course_user as course_rel_user
INNER JOIN $tbl_course as course INNER JOIN $tbl_course as course
ON course.id = course_rel_user.c_id ON course.id = course_rel_user.c_id
WHERE WHERE
course_rel_user.user_id='$user_id' AND course_rel_user.user_id='$user_id' AND
course_rel_user.status='1' course_rel_user.status='1'
ORDER BY course.title"; ";
if (api_get_multiple_access_url()) { if (api_get_multiple_access_url()) {
$tbl_course_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); $tbl_course_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
@ -968,10 +982,18 @@ class CourseManager
access_url_id = $access_url_id AND access_url_id = $access_url_id AND
course_rel_user.user_id = '$user_id' AND course_rel_user.user_id = '$user_id' AND
course_rel_user.status = '1' course_rel_user.status = '1'
ORDER BY course.title"; ";
} }
} }
if (!empty($startsWith)) {
$startsWith = Database::escape_string($startsWith);
$sql .= " AND (course.title LIKE '$startsWith%' OR course.code LIKE '$startsWith%')";
}
$sql .= ' ORDER BY course.title';
$result_nb_cours = Database::query($sql); $result_nb_cours = Database::query($sql);
if (Database::num_rows($result_nb_cours) > 0) { if (Database::num_rows($result_nb_cours) > 0) {
while ($row = Database::fetch_array($result_nb_cours, 'ASSOC')) { while ($row = Database::fetch_array($result_nb_cours, 'ASSOC')) {

@ -360,7 +360,7 @@ class CourseCategory
while ($row = Database::fetch_array($result, 'ASSOC')) { while ($row = Database::fetch_array($result, 'ASSOC')) {
$parent = self::getCategory($row['parent_id']); $parent = self::getCategory($row['parent_id']);
$children[] = $row; $children[] = $row;
$subChildren = self::getParents($parent['code']); $subChildren = self::getParents($parent ? $parent['code'] : null);
$children = array_merge($children, $subChildren); $children = array_merge($children, $subChildren);
} }

Loading…
Cancel
Save