|
@@ -1,8 +1,13 @@
|
|
|
<?php
|
|
|
/* For licensing terms, see /license.txt*/
|
|
|
|
|
|
+require_once api_get_path(CONFIGURATION_PATH).'add_course.conf.php';
|
|
|
+require_once api_get_path(LIBRARY_PATH).'add_course.lib.inc.php';
|
|
|
+
|
|
|
/**
|
|
|
- * This is the course library for Chamilo.
|
|
|
+ * Class CourseManager
|
|
|
+ *
|
|
|
+ * This is the course library for Chamilo.
|
|
|
*
|
|
|
* All main course functions should be placed here.
|
|
|
*
|
|
@@ -16,16 +21,6 @@
|
|
|
*
|
|
|
* @package chamilo.library
|
|
|
*/
|
|
|
-
|
|
|
-/* INIT SECTION */
|
|
|
-
|
|
|
-require_once api_get_path(CONFIGURATION_PATH).'add_course.conf.php';
|
|
|
-require_once api_get_path(LIBRARY_PATH).'add_course.lib.inc.php';
|
|
|
-
|
|
|
-/**
|
|
|
- * CourseManager Class
|
|
|
- * @package chamilo.library
|
|
|
- */
|
|
|
class CourseManager
|
|
|
{
|
|
|
const MAX_COURSE_LENGTH_CODE = 40;
|
|
@@ -112,10 +107,12 @@ class CourseManager
|
|
|
$cr->set_file_option();
|
|
|
$cr->restore($course_info['id']); //course_info[id] is the course.code value (I know...)
|
|
|
}
|
|
|
+
|
|
|
return $course_info;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -140,7 +137,8 @@ class CourseManager
|
|
|
* @return an array with all the fields of the course table
|
|
|
* @assert ('') === false
|
|
|
*/
|
|
|
- public static function get_course_information_by_id($course_id) {
|
|
|
+ public static function get_course_information_by_id($course_id)
|
|
|
+ {
|
|
|
return Database::select('*, id as real_id', Database::get_main_table(TABLE_MAIN_COURSE), array('where'=>array('id = ?' =>intval($course_id))),'first');
|
|
|
}
|
|
|
|
|
@@ -572,7 +570,8 @@ class CourseManager
|
|
|
* @return int Course id
|
|
|
* @assert ('', '') === false
|
|
|
*/
|
|
|
- public static function get_course_code_from_original_id($original_course_id_value, $original_course_id_name) {
|
|
|
+ public static function get_course_code_from_original_id($original_course_id_value, $original_course_id_name)
|
|
|
+ {
|
|
|
$t_cfv = Database::get_main_table(TABLE_MAIN_COURSE_FIELD_VALUES);
|
|
|
$table_field = Database::get_main_table(TABLE_MAIN_COURSE_FIELD);
|
|
|
$sql = "SELECT course_code FROM $table_field cf INNER JOIN $t_cfv cfv ON cfv.field_id=cf.id
|
|
@@ -622,9 +621,9 @@ class CourseManager
|
|
|
public static function add_user_to_course($user_id, $course_code, $status = STUDENT)
|
|
|
{
|
|
|
$debug = false;
|
|
|
- $user_table = Database::get_main_table(TABLE_MAIN_USER);
|
|
|
- $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
|
|
|
- $course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
|
|
|
+ $user_table = Database::get_main_table(TABLE_MAIN_USER);
|
|
|
+ $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
|
|
|
+ $course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
|
|
|
|
|
|
$status = ($status == STUDENT || $status == COURSEMANAGER) ? $status : STUDENT;
|
|
|
if (empty($user_id) || empty($course_code) || ($user_id != strval(intval($user_id)))) {
|
|
@@ -674,7 +673,8 @@ class CourseManager
|
|
|
* @return true if parameter is set and not empty, false otherwise
|
|
|
* @todo move function to better place, main_api ?
|
|
|
*/
|
|
|
- public static function check_parameter($parameter, $error_message) {
|
|
|
+ public static function check_parameter($parameter, $error_message)
|
|
|
+ {
|
|
|
if (empty($parameter)) {
|
|
|
Display::display_normal_message($error_message);
|
|
|
return false;
|
|
@@ -686,7 +686,8 @@ class CourseManager
|
|
|
* Lets the script die when a parameter check fails.
|
|
|
* @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)
|
|
|
+ {
|
|
|
if (!self::check_parameter($parameter, $error_message)) {
|
|
|
die();
|
|
|
}
|
|
@@ -696,9 +697,11 @@ class CourseManager
|
|
|
* @return true if there already are one or more courses
|
|
|
* with the same code OR visual_code (visualcode), false otherwise
|
|
|
*/
|
|
|
- public static function course_code_exists($wanted_course_code) {
|
|
|
+ public static function course_code_exists($wanted_course_code)
|
|
|
+ {
|
|
|
$wanted_course_code = Database::escape_string($wanted_course_code);
|
|
|
- $sql = "SELECT COUNT(*) as number FROM ".Database::get_main_table(TABLE_MAIN_COURSE)." WHERE code = '$wanted_course_code' OR visual_code = '$wanted_course_code'";
|
|
|
+ $sql = "SELECT COUNT(*) as number FROM ".Database::get_main_table(TABLE_MAIN_COURSE)."
|
|
|
+ WHERE code = '$wanted_course_code' OR visual_code = '$wanted_course_code'";
|
|
|
$result = Database::fetch_array(Database::query($sql));
|
|
|
return $result['number'] > 0;
|
|
|
}
|
|
@@ -707,7 +710,8 @@ class CourseManager
|
|
|
* @return an array with the course info of all real courses on the platform
|
|
|
*/
|
|
|
public static function get_real_course_list() {
|
|
|
- $sql_result = Database::query("SELECT * FROM ".Database::get_main_table(TABLE_MAIN_COURSE)." WHERE target_course_code IS NULL");
|
|
|
+ $sql_result = Database::query("SELECT * FROM ".Database::get_main_table(TABLE_MAIN_COURSE)."
|
|
|
+ WHERE target_course_code IS NULL");
|
|
|
$real_course_list = array();
|
|
|
while ($result = Database::fetch_array($sql_result)) {
|
|
|
$real_course_list[$result['code']] = $result;
|
|
@@ -734,7 +738,8 @@ class CourseManager
|
|
|
* the current user is course admin
|
|
|
* @return array A list of courses details for courses to which the user is subscribed as course admin (status = 1)
|
|
|
*/
|
|
|
- public static function get_real_course_list_of_user_as_course_admin($user_id) {
|
|
|
+ public static function get_real_course_list_of_user_as_course_admin($user_id)
|
|
|
+ {
|
|
|
$result_array = array();
|
|
|
if ($user_id != strval(intval($user_id))) {
|
|
|
return $result_array;
|
|
@@ -846,7 +851,7 @@ class CourseManager
|
|
|
|
|
|
/**
|
|
|
* @param int $user_id
|
|
|
- * @return 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.
|
|
|
*/
|
|
|
public static function get_course_list_of_user_as_course_admin($user_id)
|
|
@@ -912,15 +917,15 @@ class CourseManager
|
|
|
* (I'm not sure about the last case, but this seems not too bad)
|
|
|
*
|
|
|
* @author Roan Embrechts
|
|
|
- * @param $user_id, the id of the user
|
|
|
- * @param $course_info, an array with course info that you get using Database::get_course_info($course_system_code);
|
|
|
- * @return an array with indices
|
|
|
+ * @param int $user_id, the id of the user
|
|
|
+ * @param array $course_info, an array with course info that you get using Database::get_course_info($course_system_code);
|
|
|
+ * @return array An array with indices
|
|
|
* $return_result['title'] - the course title of the combined courses
|
|
|
* $return_result['code'] - the course code of the combined courses
|
|
|
* @deprecated use api_get_course_info()
|
|
|
*/
|
|
|
- public static function determine_course_title_from_course_info($user_id, $course_info) {
|
|
|
-
|
|
|
+ public static function determine_course_title_from_course_info($user_id, $course_info)
|
|
|
+ {
|
|
|
if ($user_id != strval(intval($user_id))) {
|
|
|
return array();
|
|
|
}
|
|
@@ -970,7 +975,6 @@ class CourseManager
|
|
|
*/
|
|
|
public static function create_combined_name($user_is_registered_in_real_course, $real_course_name, $virtual_course_list)
|
|
|
{
|
|
|
-
|
|
|
$complete_course_name = array();
|
|
|
|
|
|
if ($user_is_registered_in_real_course) {
|
|
@@ -992,7 +996,6 @@ class CourseManager
|
|
|
*/
|
|
|
public static function create_combined_code($user_is_registered_in_real_course, $real_course_code, $virtual_course_list)
|
|
|
{
|
|
|
-
|
|
|
$complete_course_code = array();
|
|
|
|
|
|
if ($user_is_registered_in_real_course) {
|
|
@@ -1187,8 +1190,8 @@ class CourseManager
|
|
|
*
|
|
|
* @return true if the user is registered in the real course or linked courses, false otherwise
|
|
|
*/
|
|
|
- public static function is_user_subscribed_in_real_or_linked_course($user_id, $course_code, $session_id = '') {
|
|
|
-
|
|
|
+ public static function is_user_subscribed_in_real_or_linked_course($user_id, $course_code, $session_id = '')
|
|
|
+ {
|
|
|
if ($user_id != strval(intval($user_id))) {
|
|
|
return false;
|
|
|
}
|
|
@@ -1211,7 +1214,6 @@ class CourseManager
|
|
|
$session_id = intval($session_id);
|
|
|
|
|
|
// From here we trust session id.
|
|
|
-
|
|
|
// Is he/she subscribed to the session's course?
|
|
|
|
|
|
// A user?
|
|
@@ -1547,7 +1549,8 @@ class CourseManager
|
|
|
* @param int $session_id
|
|
|
* @return int
|
|
|
*/
|
|
|
- public static function get_users_count_in_course($course_code, $session_id = 0) {
|
|
|
+ public static function get_users_count_in_course($course_code, $session_id = 0)
|
|
|
+ {
|
|
|
// variable initialisation
|
|
|
$session_id = intval($session_id);
|
|
|
$course_code = Database::escape_string($course_code);
|
|
@@ -1594,8 +1597,8 @@ class CourseManager
|
|
|
* @param int Session ID
|
|
|
* @return array List of users
|
|
|
*/
|
|
|
- public static function get_coach_list_from_course_code($course_code, $session_id) {
|
|
|
-
|
|
|
+ public static function get_coach_list_from_course_code($course_code, $session_id)
|
|
|
+ {
|
|
|
if ($session_id != strval(intval($session_id))) {
|
|
|
return array();
|
|
|
}
|
|
@@ -1625,6 +1628,7 @@ class CourseManager
|
|
|
$user_info['tutor_id'] = $user['tutor_id'];
|
|
|
$user_info['email'] = $user['email'];
|
|
|
$users[$session_id_coach] = $user_info;
|
|
|
+
|
|
|
return $users;
|
|
|
}
|
|
|
|
|
@@ -1755,8 +1759,8 @@ class CourseManager
|
|
|
* @return array - array containing user_id, lastname, firstname, username
|
|
|
*
|
|
|
*/
|
|
|
- public static function get_coachs_from_course($session_id=0, $course_code='') {
|
|
|
-
|
|
|
+ public static function get_coachs_from_course($session_id=0, $course_code='')
|
|
|
+ {
|
|
|
if (!empty($session_id)) {
|
|
|
$session_id = intval($session_id);
|
|
|
} else {
|
|
@@ -1787,7 +1791,12 @@ class CourseManager
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static function get_coachs_from_course_to_string($session_id = 0, $course_code = null, $separator = self::USER_SEPARATOR, $add_link_to_profile = false) {
|
|
|
+ public static function get_coachs_from_course_to_string(
|
|
|
+ $session_id = 0,
|
|
|
+ $course_code = null,
|
|
|
+ $separator = self::USER_SEPARATOR,
|
|
|
+ $add_link_to_profile = false
|
|
|
+ ) {
|
|
|
$coachs_course = self::get_coachs_from_course($session_id, $course_code);
|
|
|
$course_coachs = array();
|
|
|
|
|
@@ -1808,7 +1817,8 @@ class CourseManager
|
|
|
return $coaches_to_string;
|
|
|
}
|
|
|
|
|
|
- public static function get_coach_list_from_course_code_to_string($course_code, $session_id) {
|
|
|
+ public static function get_coach_list_from_course_code_to_string($course_code, $session_id)
|
|
|
+ {
|
|
|
$tutor_data = '';
|
|
|
if ($session_id != 0) {
|
|
|
$coaches = self::get_email_of_tutor_to_session($session_id, $course_code);
|
|
@@ -1823,7 +1833,6 @@ class CourseManager
|
|
|
return $tutor_data;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* Return user info array of all users registered in the specified course
|
|
|
* this includes the users of the course itsel and the users of all linked courses.
|
|
@@ -1831,7 +1840,8 @@ class CourseManager
|
|
|
* @param array $course_info
|
|
|
* @return array with user info
|
|
|
*/
|
|
|
- public static function get_real_and_linked_user_list($course_code, $with_sessions = true, $session_id = 0) {
|
|
|
+ public static function get_real_and_linked_user_list($course_code, $with_sessions = true, $session_id = 0)
|
|
|
+ {
|
|
|
//get list of virtual courses
|
|
|
$virtual_course_list = self::get_virtual_courses_linked_to_real_course($course_code);
|
|
|
$complete_user_list = array();
|
|
@@ -1864,7 +1874,8 @@ class CourseManager
|
|
|
* @return array of course info arrays
|
|
|
* @deprecated virtual course feature is not supported
|
|
|
*/
|
|
|
- public static function get_list_of_virtual_courses_for_specific_user_and_real_course($user_id, $course_code) {
|
|
|
+ public static function get_list_of_virtual_courses_for_specific_user_and_real_course($user_id, $course_code)
|
|
|
+ {
|
|
|
$result_array = array();
|
|
|
|
|
|
if ($user_id != strval(intval($user_id))) {
|
|
@@ -3972,27 +3983,37 @@ class CourseManager
|
|
|
return $wanted_code;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* Gets the status of the users agreement in a course course-session
|
|
|
*
|
|
|
- * @param int user id
|
|
|
- * @param string course code
|
|
|
- * @param int session id
|
|
|
+ * @param int $user_id
|
|
|
+ * @param string $course_code
|
|
|
+ * @param int $session_id
|
|
|
* @return boolean
|
|
|
*/
|
|
|
- public static function is_user_accepted_legal($user_id, $course_code, $session_id = null) {
|
|
|
- $user_id = intval($user_id);
|
|
|
+ public static function is_user_accepted_legal($user_id, $course_code, $session_id = null)
|
|
|
+ {
|
|
|
+ $user_id = intval($user_id);
|
|
|
$course_code = Database::escape_string($course_code);
|
|
|
$session_id = intval($session_id);
|
|
|
+
|
|
|
+ // Course legal
|
|
|
+ $enabled = api_get_plugin_setting('courselegal', 'tool_enable');
|
|
|
+
|
|
|
+ if ($enabled == 'true') {
|
|
|
+ require_once api_get_path(SYS_PLUGIN_PATH).'courselegal/config.php';
|
|
|
+ $plugin = CourseLegalPlugin::create();
|
|
|
+ return $plugin->isUserAcceptedLegal($user_id, $course_code, $session_id);
|
|
|
+ }
|
|
|
+
|
|
|
if (empty($session_id)) {
|
|
|
$table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
|
|
|
$sql = "SELECT legal_agreement FROM $table
|
|
|
- WHERE user_id = $user_id AND course_code ='$course_code' ";
|
|
|
+ WHERE user_id = $user_id AND course_code ='$course_code' ";
|
|
|
$result = Database::query($sql);
|
|
|
if (Database::num_rows($result) > 0 ) {
|
|
|
$result = Database::fetch_array($result);
|
|
|
- if ($result['legal_agreement'] == 1 ) {
|
|
|
+ if ($result['legal_agreement'] == 1) {
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
@@ -4000,11 +4021,11 @@ class CourseManager
|
|
|
} else {
|
|
|
$table = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
|
|
|
$sql = "SELECT legal_agreement FROM $table
|
|
|
- WHERE id_user = $user_id AND course_code ='$course_code' AND id_session = $session_id";
|
|
|
+ WHERE id_user = $user_id AND course_code ='$course_code' AND id_session = $session_id";
|
|
|
$result = Database::query($sql);
|
|
|
if (Database::num_rows($result) > 0 ) {
|
|
|
$result = Database::fetch_array($result);
|
|
|
- if ($result['legal_agreement'] == 1 ) {
|
|
|
+ if ($result['legal_agreement'] == 1) {
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
@@ -4019,25 +4040,43 @@ class CourseManager
|
|
|
* @param string course code
|
|
|
* @param int session id
|
|
|
*/
|
|
|
- function save_user_legal($user_id, $course_code, $session_id = null) {
|
|
|
+ public static function save_user_legal($user_id, $course_code, $session_id = null)
|
|
|
+ {
|
|
|
+ // Course plugin legal
|
|
|
+ $enabled = api_get_plugin_setting('courselegal', 'tool_enable');
|
|
|
+
|
|
|
+ if ($enabled == 'true') {
|
|
|
+ require_once api_get_path(SYS_PLUGIN_PATH).'courselegal/config.php';
|
|
|
+ $plugin = CourseLegalPlugin::create();
|
|
|
+ return $plugin->saveUserLegal($user_id, $course_code, $session_id);
|
|
|
+ }
|
|
|
|
|
|
- $user_id = intval($user_id);
|
|
|
+ $user_id = intval($user_id);
|
|
|
$course_code = Database::escape_string($course_code);
|
|
|
$session_id = intval($session_id);
|
|
|
+
|
|
|
if (empty($session_id)) {
|
|
|
$table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
|
|
|
$sql = "UPDATE $table SET legal_agreement = '1'
|
|
|
WHERE user_id = $user_id AND course_code ='$course_code' ";
|
|
|
- $result = Database::query($sql);
|
|
|
+ Database::query($sql);
|
|
|
} else {
|
|
|
$table = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
|
|
|
$sql = "UPDATE $table SET legal_agreement = '1'
|
|
|
WHERE id_user = $user_id AND course_code = '$course_code' AND id_session = $session_id";
|
|
|
- $result = Database::query($sql);
|
|
|
+ Database::query($sql);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static function get_user_course_vote($user_id, $course_id, $session_id = null, $url_id = null) {
|
|
|
+ /**
|
|
|
+ * @param int $user_id
|
|
|
+ * @param int $course_id
|
|
|
+ * @param int $session_id
|
|
|
+ * @param int $url_id
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public static function get_user_course_vote($user_id, $course_id, $session_id = null, $url_id = null)
|
|
|
+ {
|
|
|
$table_user_course_vote = Database::get_main_table(TABLE_MAIN_USER_REL_COURSE_VOTE);
|
|
|
|
|
|
$session_id = !isset($session_id) ? api_get_session_id() : intval($session_id);
|
|
@@ -4069,8 +4108,9 @@ class CourseManager
|
|
|
* @param int $url_id
|
|
|
* @return array
|
|
|
*/
|
|
|
- public static function get_course_ranking($course_id, $session_id = null, $url_id = null) {
|
|
|
- $table_course_ranking = Database::get_main_table(TABLE_STATISTIC_TRACK_COURSE_RANKING);
|
|
|
+ public static function get_course_ranking($course_id, $session_id = null, $url_id = null)
|
|
|
+ {
|
|
|
+ $table_course_ranking = Database::get_main_table(TABLE_STATISTIC_TRACK_COURSE_RANKING);
|
|
|
|
|
|
$session_id = !isset($session_id) ? api_get_session_id() : intval($session_id);
|
|
|
$url_id = empty($url_id) ? api_get_current_access_url_id() : intval($url_id);
|
|
@@ -4121,8 +4161,15 @@ class CourseManager
|
|
|
* @param id url id
|
|
|
*
|
|
|
**/
|
|
|
- public static function update_course_ranking($course_id = null, $session_id = null, $url_id = null, $points_to_add = null, $add_access = true, $add_user = true) {
|
|
|
- //Course catalog stats modifications see #4191
|
|
|
+ public static function update_course_ranking(
|
|
|
+ $course_id = null,
|
|
|
+ $session_id = null,
|
|
|
+ $url_id = null,
|
|
|
+ $points_to_add = null,
|
|
|
+ $add_access = true,
|
|
|
+ $add_user = true
|
|
|
+ ) {
|
|
|
+ // Course catalog stats modifications see #4191
|
|
|
$table_course_ranking = Database::get_main_table(TABLE_STATISTIC_TRACK_COURSE_RANKING);
|
|
|
|
|
|
$now = api_get_utc_datetime();
|
|
@@ -4138,7 +4185,12 @@ class CourseManager
|
|
|
'creation_date' => $now,
|
|
|
);
|
|
|
|
|
|
- $result = Database::select('id, accesses, total_score, users', $table_course_ranking, array('where' => array('c_id = ? AND session_id = ? AND url_id = ?' => $params)), 'first');
|
|
|
+ $result = Database::select(
|
|
|
+ 'id, accesses, total_score, users',
|
|
|
+ $table_course_ranking,
|
|
|
+ array('where' => array('c_id = ? AND session_id = ? AND url_id = ?' => $params)),
|
|
|
+ 'first'
|
|
|
+ );
|
|
|
|
|
|
// Problem here every time we load the courses/XXXX/index.php course home page we update the access
|
|
|
|
|
@@ -4168,13 +4220,17 @@ class CourseManager
|
|
|
}
|
|
|
|
|
|
if (!empty($my_params)) {
|
|
|
- $result = Database::update($table_course_ranking, $my_params, array('c_id = ? AND session_id = ? AND url_id = ?' => $params));
|
|
|
+ $result = Database::update(
|
|
|
+ $table_course_ranking,
|
|
|
+ $my_params,
|
|
|
+ array('c_id = ? AND session_id = ? AND url_id = ?' => $params)
|
|
|
+ );
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* Add user vote to a course
|
|
|
*
|
|
@@ -4184,10 +4240,9 @@ class CourseManager
|
|
|
* @param int session id
|
|
|
* @param int url id (access_url_id)
|
|
|
* @return mixed 'added', 'updated' or 'nothing'
|
|
|
- *
|
|
|
*/
|
|
|
-
|
|
|
- public static function add_course_vote($user_id, $vote, $course_id, $session_id = null, $url_id = null) {
|
|
|
+ public static function add_course_vote($user_id, $vote, $course_id, $session_id = null, $url_id = null)
|
|
|
+ {
|
|
|
$table_user_course_vote = Database::get_main_table(TABLE_MAIN_USER_REL_COURSE_VOTE);
|
|
|
$course_id = empty($course_id) ? api_get_course_int_id() : intval($course_id);
|
|
|
|