Minor - format code.

pull/2487/head
jmontoyaa 9 years ago
parent 8b6c2e7a3d
commit 4e3785a452
  1. 5
      main/course_home/course_home.php
  2. 46
      main/inc/lib/course.lib.php

@ -135,14 +135,11 @@ Session::erase('_gid');
$isSpecialCourse = CourseManager::isSpecialCourse($courseId); $isSpecialCourse = CourseManager::isSpecialCourse($courseId);
if ($isSpecialCourse) { if ($isSpecialCourse) {
if (isset($_GET['autoreg'])) { if (isset($_GET['autoreg']) && $_GET['autoreg'] == 1) {
$autoRegistration = Security::remove_XSS($_GET['autoreg']);
if ($autoRegistration == 1) {
if (CourseManager::subscribe_user($user_id, $course_code, STUDENT)) { if (CourseManager::subscribe_user($user_id, $course_code, STUDENT)) {
Session::write('is_allowed_in_course', true); Session::write('is_allowed_in_course', true);
} }
} }
}
} }
if (isset($_GET['action']) && $_GET['action'] == 'subscribe') { if (isset($_GET['action']) && $_GET['action'] == 'subscribe') {

@ -507,9 +507,12 @@ class CourseManager
/** /**
* Subscribe a user to a course. No checks are performed here to see if * Subscribe a user to a course. No checks are performed here to see if
* course subscription is allowed. * course subscription is allowed.
* @param int User ID * @param int $user_id
* @param string Course code * @param string $course_code
* @param int Status (STUDENT, COURSEMANAGER, COURSE_ADMIN, NORMAL_COURSE_MEMBER) * @param int $status (STUDENT, COURSEMANAGER, COURSE_ADMIN, NORMAL_COURSE_MEMBER)
* @param int $session_id
* @param int $userCourseCategoryId
*
* @return bool True on success, false on failure * @return bool True on success, false on failure
* @see add_user_to_course * @see add_user_to_course
* @assert ('', '') === false * @assert ('', '') === false
@ -529,10 +532,9 @@ class CourseManager
$courseInfo = api_get_course_info($course_code); $courseInfo = api_get_course_info($course_code);
$courseId = $courseInfo['real_id']; $courseId = $courseInfo['real_id'];
$courseCode = $courseInfo['code']; $courseCode = $courseInfo['code'];
//$userCourseCategoryId = intval($userCourseCategoryId);
$userCourseCategoryId = intval($userCourseCategoryId); if (empty($user_id) || empty($course_code)) {
if (empty($user_id) || empty ($course_code)) {
return false; return false;
} }
@ -543,23 +545,23 @@ class CourseManager
} }
$status = ($status == STUDENT || $status == COURSEMANAGER) ? $status : STUDENT; $status = ($status == STUDENT || $status == COURSEMANAGER) ? $status : STUDENT;
//$role_id = ($status == COURSEMANAGER) ? COURSE_ADMIN : NORMAL_COURSE_MEMBER;
// A preliminary check whether the user has bben already registered on the platform. // A preliminary check whether the user has bben already registered on the platform.
if (Database::num_rows(Database::query( $sql = "SELECT status FROM " . Database::get_main_table(TABLE_MAIN_USER) . "
"SELECT status FROM " . Database::get_main_table(TABLE_MAIN_USER) . " WHERE user_id = '$user_id' ";
WHERE user_id = '$user_id' ")) == 0 if (Database::num_rows(Database::query($sql)) == 0) {
) {
return false; // The user has not been registered to the platform. return false; // The user has not been registered to the platform.
} }
// Check whether the user has not been already subscribed to the course. // Check whether the user has not been already subscribed to the course.
$sql = "SELECT * FROM " . Database::get_main_table(TABLE_MAIN_COURSE_USER) . "
WHERE
user_id = '$user_id' AND
relation_type <> " . COURSE_RELATION_TYPE_RRHH . " AND
c_id = $courseId
";
if (empty($session_id)) { if (empty($session_id)) {
if (Database::num_rows(Database::query(" if (Database::num_rows(Database::query($sql)) > 0) {
SELECT * FROM " . Database::get_main_table(TABLE_MAIN_COURSE_USER) . "
WHERE user_id = '$user_id' AND relation_type<>" . COURSE_RELATION_TYPE_RRHH . " AND c_id = '$courseId'")) > 0
) {
// The user has been already subscribed to the course. // The user has been already subscribed to the course.
return false; return false;
} }
@ -658,13 +660,18 @@ class CourseManager
* @param int $user_id the id of the user * @param int $user_id the id of the user
* @param string $courseCode the course code * @param string $courseCode the course code
* @param int $status (optional) The user's status in the course * @param int $status (optional) The user's status in the course
* @param int $userCourseCategoryId
* @param int The user category in which this subscription will be classified * @param int The user category in which this subscription will be classified
* *
* @return false|string true if subscription succeeds, boolean false otherwise. * @return false|string true if subscription succeeds, boolean false otherwise.
* @assert ('', '') === false * @assert ('', '') === false
*/ */
public static function add_user_to_course($user_id, $courseCode, $status = STUDENT, $userCourseCategoryId = 0) public static function add_user_to_course(
{ $user_id,
$courseCode,
$status = STUDENT,
$userCourseCategoryId = 0
) {
$debug = false; $debug = false;
$user_table = Database::get_main_table(TABLE_MAIN_USER); $user_table = Database::get_main_table(TABLE_MAIN_USER);
$course_table = Database::get_main_table(TABLE_MAIN_COURSE); $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
@ -832,7 +839,7 @@ class CourseManager
/** /**
* Checks wether a parameter exists. * Checks wether a parameter exists.
* If it doesn't, the function displays an error message. * If it doesn't, the function displays an error message.
* * @deprecated
* @return boolean if parameter is set and not empty, false otherwise * @return boolean if parameter is set and not empty, false otherwise
* @todo move function to better place, main_api ? * @todo move function to better place, main_api ?
*/ */
@ -847,6 +854,7 @@ class CourseManager
/** /**
* Lets the script die when a parameter check fails. * Lets the script die when a parameter check fails.
* @deprecated
* @todo move function to better place, main_api ? * @todo move function to better place, main_api ?
*/ */
public static function check_parameter_or_fail($parameter, $error_message) public static function check_parameter_or_fail($parameter, $error_message)

Loading…
Cancel
Save