Allow set custom url id when creating course - refs BT#14965

pull/2729/head
Angel Fernando Quiroz Campos 7 years ago
parent 564e8f6ec1
commit 5cddc8514d
  1. 15
      main/inc/lib/add_course.lib.inc.php
  2. 22
      main/inc/lib/course.lib.php

@ -1194,14 +1194,15 @@ class AddCourse
/** /**
* Function register_course to create a record in the course table of the main database. * Function register_course to create a record in the course table of the main database.
* *
* @param array Course details (see code for details) * @param array $params Course details (see code for details).
* @param int $accessUrlId Optional.
* *
* @return int Created course ID * @return int Created course ID
* *
* @todo use an array called $params instead of lots of params * @todo use an array called $params instead of lots of params
* @assert (null) === false * @assert (null) === false
*/ */
public static function register_course($params) public static function register_course($params, $accessUrlId = 1)
{ {
global $error_msg, $firstExpirationDelay; global $error_msg, $firstExpirationDelay;
$title = $params['title']; $title = $params['title'];
@ -1372,15 +1373,7 @@ class AddCourse
} }
// Adding the course to an URL. // Adding the course to an URL.
if (api_is_multiple_url_enabled()) { UrlManager::add_course_to_url($course_id, $accessUrlId);
$url_id = 1;
if (api_get_current_access_url_id() != -1) {
$url_id = api_get_current_access_url_id();
}
UrlManager::add_course_to_url($course_id, $url_id);
} else {
UrlManager::add_course_to_url($course_id, 1);
}
// Add event to the system log. // Add event to the system log.
$user_id = api_get_user_id(); $user_id = api_get_user_id();

@ -34,29 +34,29 @@ class CourseManager
/** /**
* Creates a course. * Creates a course.
* *
* @param array $params columns in the main.course table * @param array $params Columns in the main.course table.
* @param int $authorId * @param int $authorId Optional.
* @param int $accessUrlId Optional.
* *
* @return mixed false if the course was not created, array with the course info * @return mixed false if the course was not created, array with the course info
*/ */
public static function create_course($params, $authorId = 0) public static function create_course($params, $authorId = 0, $accessUrlId = 0)
{ {
global $_configuration; global $_configuration;
$hook = HookCreateCourse::create(); $hook = HookCreateCourse::create();
// Check portal limits // Check portal limits
$access_url_id = 1; $accessUrlId = empty($accessUrlId)
if (api_get_multiple_access_url()) { ? (api_get_multiple_access_url() ? api_get_current_access_url_id() : 1)
$access_url_id = api_get_current_access_url_id(); : $accessUrlId;
}
$authorId = empty($authorId) ? api_get_user_id() : (int) $authorId; $authorId = empty($authorId) ? api_get_user_id() : (int) $authorId;
if (isset($_configuration[$access_url_id]) && is_array($_configuration[$access_url_id])) { if (isset($_configuration[$accessUrlId]) && is_array($_configuration[$accessUrlId])) {
$return = self::checkCreateCourseAccessUrlParam( $return = self::checkCreateCourseAccessUrlParam(
$_configuration, $_configuration,
$access_url_id, $accessUrlId,
'hosting_limit_courses', 'hosting_limit_courses',
'PortalCoursesLimitReached' 'PortalCoursesLimitReached'
); );
@ -65,7 +65,7 @@ class CourseManager
} }
$return = self::checkCreateCourseAccessUrlParam( $return = self::checkCreateCourseAccessUrlParam(
$_configuration, $_configuration,
$access_url_id, $accessUrlId,
'hosting_limit_active_courses', 'hosting_limit_active_courses',
'PortalActiveCoursesLimitReached' 'PortalActiveCoursesLimitReached'
); );
@ -99,7 +99,7 @@ class CourseManager
$params['directory'] = $keys['currentCourseRepository']; $params['directory'] = $keys['currentCourseRepository'];
$course_info = api_get_course_info($params['code']); $course_info = api_get_course_info($params['code']);
if (empty($course_info)) { if (empty($course_info)) {
$course_id = AddCourse::register_course($params); $course_id = AddCourse::register_course($params, $accessUrlId);
$course_info = api_get_course_info_by_id($course_id); $course_info = api_get_course_info_by_id($course_id);
if ($hook) { if ($hook) {

Loading…
Cancel
Save