|
@@ -298,12 +298,12 @@ class CourseManager
|
|
|
|
|
|
/**
|
|
|
* Returns the status of a user in a course, which is COURSEMANAGER or STUDENT.
|
|
|
- * @param int $user_id
|
|
|
+ * @param int $userId
|
|
|
* @param int $courseId
|
|
|
*
|
|
|
* @return int|bool the status of the user in that course (or false if the user is not in that course)
|
|
|
*/
|
|
|
- public static function getUserInCourseStatus($user_id, $courseId)
|
|
|
+ public static function getUserInCourseStatus($userId, $courseId)
|
|
|
{
|
|
|
$courseId = (int) $courseId;
|
|
|
if (empty($courseId)) {
|
|
@@ -315,7 +315,7 @@ class CourseManager
|
|
|
"SELECT status FROM " . Database::get_main_table(TABLE_MAIN_COURSE_USER) . "
|
|
|
WHERE
|
|
|
c_id = $courseId AND
|
|
|
- user_id = " . intval($user_id)
|
|
|
+ user_id = " . intval($userId)
|
|
|
)
|
|
|
);
|
|
|
|
|
@@ -1717,7 +1717,8 @@ class CourseManager
|
|
|
$courseInfo = api_get_course_info($course_code);
|
|
|
$courseId = $courseInfo['real_id'];
|
|
|
|
|
|
- $sql = 'SELECT DISTINCT count(*) as count FROM ' . Database::get_main_table(TABLE_MAIN_USER) . ' as user ';
|
|
|
+ $sql = 'SELECT DISTINCT count(user.id) as count
|
|
|
+ FROM ' . Database::get_main_table(TABLE_MAIN_USER) . ' as user ';
|
|
|
$where = array();
|
|
|
if (!empty($session_id)) {
|
|
|
$sql .= ' LEFT JOIN ' . Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER) . ' as session_course_user
|
|
@@ -1760,8 +1761,8 @@ class CourseManager
|
|
|
|
|
|
/**
|
|
|
* Get a list of coaches of a course and a session
|
|
|
- * @param string Course code
|
|
|
- * @param int Session ID
|
|
|
+ * @param string $course_code
|
|
|
+ * @param int $session_id
|
|
|
* @param bool $addGeneralCoach
|
|
|
* @return array List of users
|
|
|
*/
|
|
@@ -1864,7 +1865,6 @@ class CourseManager
|
|
|
|
|
|
// students subscribed to the course through a session
|
|
|
if ($with_session) {
|
|
|
-
|
|
|
$joinSession = "";
|
|
|
//Session creation date
|
|
|
if (!empty($date_from) && !empty($date_to)) {
|
|
@@ -1937,17 +1937,19 @@ class CourseManager
|
|
|
return $teachers;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* Return user info array of all teacher-users registered in a course
|
|
|
* This only returns the users that are registered in this actual course, not linked courses.
|
|
|
*
|
|
|
* @param int $courseId
|
|
|
+ * @param bool $loadAvatars
|
|
|
+ *
|
|
|
* @return array with user id
|
|
|
*/
|
|
|
- public static function getTeachersFromCourse($courseId)
|
|
|
+ public static function getTeachersFromCourse($courseId, $loadAvatars = true)
|
|
|
{
|
|
|
$courseId = (int) $courseId;
|
|
|
+
|
|
|
if (empty($courseId)) {
|
|
|
return false;
|
|
|
}
|
|
@@ -1968,18 +1970,23 @@ class CourseManager
|
|
|
$rs = Database::query($sql);
|
|
|
$listTeachers = array();
|
|
|
$teachers = array();
|
|
|
+ $url = api_get_path(WEB_AJAX_PATH) . 'user_manager.ajax.php?a=get_user_popup';
|
|
|
while ($teacher = Database::fetch_array($rs)) {
|
|
|
- $userPicture = UserManager::getUserPicture($teacher['user_id'], USER_IMAGE_SIZE_SMALL);
|
|
|
$teachers['id'] = $teacher['user_id'];
|
|
|
$teachers['lastname'] = $teacher['lastname'];
|
|
|
$teachers['firstname'] = $teacher['firstname'];
|
|
|
$teachers['email'] = $teacher['email'];
|
|
|
$teachers['username'] = $teacher['username'];
|
|
|
$teachers['status'] = $teacher['status'];
|
|
|
- $teachers['avatar'] = $userPicture;
|
|
|
- $teachers['url'] = api_get_path(WEB_AJAX_PATH) . 'user_manager.ajax.php?a=get_user_popup&user_id=' . $teacher['user_id'];
|
|
|
- $listTeachers[]=$teachers;
|
|
|
+ $teachers['avatar'] = '';
|
|
|
+ if ($loadAvatars) {
|
|
|
+ $userPicture = UserManager::getUserPicture($teacher['user_id'], USER_IMAGE_SIZE_SMALL);
|
|
|
+ $teachers['avatar'] = $userPicture;
|
|
|
+ }
|
|
|
+ $teachers['url'] = $url.'&user_id='. $teacher['user_id'];
|
|
|
+ $listTeachers[] = $teachers;
|
|
|
}
|
|
|
+
|
|
|
return $listTeachers;
|
|
|
}
|
|
|
|
|
@@ -2020,7 +2027,7 @@ class CourseManager
|
|
|
}
|
|
|
|
|
|
if (!empty($list)) {
|
|
|
- if ($orderList === true){
|
|
|
+ if ($orderList === true) {
|
|
|
$html .= '<ul class="user-teacher">';
|
|
|
foreach ($list as $teacher){
|
|
|
$html .= Display::tag('li', Display::return_icon('teacher.png', $teacher, null, ICON_SIZE_TINY) . ' ' . $teacher);
|
|
@@ -2058,7 +2065,6 @@ class CourseManager
|
|
|
|
|
|
$tbl_user = Database:: get_main_table(TABLE_MAIN_USER);
|
|
|
$tbl_session_course_user = Database:: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
|
|
|
- $coaches = array();
|
|
|
|
|
|
$sql = "SELECT DISTINCT
|
|
|
u.user_id,
|
|
@@ -2074,15 +2080,15 @@ class CourseManager
|
|
|
scu.status = 2";
|
|
|
$rs = Database::query($sql);
|
|
|
|
|
|
+ $coaches = array();
|
|
|
if (Database::num_rows($rs) > 0) {
|
|
|
while ($row = Database::fetch_array($rs)) {
|
|
|
$completeName = api_get_person_name($row['firstname'], $row['lastname']);
|
|
|
$coaches[] = $row + ['full_name' => $completeName];
|
|
|
}
|
|
|
- return $coaches;
|
|
|
- } else {
|
|
|
- return false;
|
|
|
}
|
|
|
+
|
|
|
+ return $coaches;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -2094,17 +2100,16 @@ class CourseManager
|
|
|
*/
|
|
|
public static function get_coachs_from_course_to_string(
|
|
|
$session_id = 0,
|
|
|
- $courseId = null,
|
|
|
+ $courseId = 0,
|
|
|
$separator = self::USER_SEPARATOR,
|
|
|
$add_link_to_profile = false,
|
|
|
$orderList = false
|
|
|
) {
|
|
|
- $coachs_course = self::get_coachs_from_course($session_id, $courseId);
|
|
|
+ $coachList = self::get_coachs_from_course($session_id, $courseId);
|
|
|
$course_coachs = array();
|
|
|
- $html = '';
|
|
|
- if (is_array($coachs_course)) {
|
|
|
- foreach ($coachs_course as $coach_course) {
|
|
|
- $coach_name = api_get_person_name($coach_course['firstname'], $coach_course['lastname']);
|
|
|
+ if (!empty($coachList)) {
|
|
|
+ foreach ($coachList as $coach_course) {
|
|
|
+ $coach_name = $coach_course['full_name'];
|
|
|
if ($add_link_to_profile) {
|
|
|
$url = api_get_path(WEB_AJAX_PATH) . 'user_manager.ajax.php?a=get_user_popup&user_id=' . $coach_course['user_id'];
|
|
|
$coach_name = Display::url(
|
|
@@ -2119,19 +2124,21 @@ class CourseManager
|
|
|
$course_coachs[] = $coach_name;
|
|
|
}
|
|
|
}
|
|
|
- $coaches_to_string = null;
|
|
|
|
|
|
+ $html = '';
|
|
|
if (!empty($course_coachs)) {
|
|
|
- if ($orderList === true){
|
|
|
+ if ($orderList === true) {
|
|
|
$html .= '<ul class="user-coachs">';
|
|
|
- foreach ($course_coachs as $coachs){
|
|
|
- $html .= Display::tag('li', Display::return_icon('teacher.png', $coachs, null, ICON_SIZE_TINY) . ' ' . $coachs);
|
|
|
- }
|
|
|
+ foreach ($course_coachs as $coachs) {
|
|
|
+ $html .= Display::tag(
|
|
|
+ 'li',
|
|
|
+ Display::return_icon('teacher.png', $coachs, null, ICON_SIZE_TINY) . ' ' . $coachs
|
|
|
+ );
|
|
|
+ }
|
|
|
$html .= '</ul>';
|
|
|
} else {
|
|
|
- $coaches_to_string = array_to_string($course_coachs, $separator);
|
|
|
+ $html = array_to_string($course_coachs, $separator);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
return $html;
|
|
@@ -2148,15 +2155,13 @@ class CourseManager
|
|
|
*/
|
|
|
public static function get_real_and_linked_user_list($course_code, $with_sessions = true, $session_id = 0)
|
|
|
{
|
|
|
- $complete_user_list = array();
|
|
|
-
|
|
|
- //get users from real course
|
|
|
- $user_list = self::get_user_list_from_course_code($course_code, $session_id);
|
|
|
- foreach ($user_list as $this_user) {
|
|
|
- $complete_user_list[] = $this_user;
|
|
|
+ $list = array();
|
|
|
+ $userList = self::get_user_list_from_course_code($course_code, $session_id);
|
|
|
+ foreach ($userList as $user) {
|
|
|
+ $list[] = $user;
|
|
|
}
|
|
|
|
|
|
- return $complete_user_list;
|
|
|
+ return $list;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -2397,7 +2402,7 @@ class CourseManager
|
|
|
|
|
|
/**
|
|
|
* Creates a file called mysql_dump.sql in the course folder
|
|
|
- * @param $course_code The code of the course
|
|
|
+ * @param string $course_code The code of the course
|
|
|
* @todo Implementation for single database
|
|
|
*/
|
|
|
public static function create_database_dump($course_code)
|
|
@@ -2630,7 +2635,7 @@ class CourseManager
|
|
|
$extraFieldType = EntityExtraField::COURSE_FIELD_TYPE;
|
|
|
|
|
|
// get course list auto-register
|
|
|
- $sql = "SELECT DISTINCT(c.code)
|
|
|
+ $sql = "SELECT DISTINCT(c.id)
|
|
|
FROM $tbl_course_field_value tcfv
|
|
|
INNER JOIN $tbl_course_field tcf
|
|
|
ON tcfv.field_id = tcf.id $join_access_url
|
|
@@ -2646,7 +2651,7 @@ class CourseManager
|
|
|
|
|
|
if (Database::num_rows($result) > 0) {
|
|
|
while ($result_row = Database::fetch_array($result)) {
|
|
|
- $courseList[] = $result_row['code'];
|
|
|
+ $courseList[] = $result_row['id'];
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -2657,19 +2662,20 @@ class CourseManager
|
|
|
* Get the course codes that have been restricted in the catalogue, and if byUserId is set
|
|
|
* then the courses that the user is allowed or not to see in catalogue
|
|
|
*
|
|
|
- * @param boolean allowed Either if the courses have some users that are or are not allowed to see in catalogue
|
|
|
- * @param boolean byUserId if the courses are or are not allowed to see to the user
|
|
|
+ * @param boolean $allowed Either if the courses have some users that are or are not allowed to see in catalogue
|
|
|
+ * @param boolean $byUserId if the courses are or are not allowed to see to the user
|
|
|
* @return array Course codes allowed or not to see in catalogue by some user or the user
|
|
|
*/
|
|
|
public static function getCatalogueCourseList($allowed = true, $byUserId = -1)
|
|
|
{
|
|
|
$courseTable = Database:: get_main_table(TABLE_MAIN_COURSE);
|
|
|
$tblCourseRelUserCatalogue = Database:: get_main_table(TABLE_MAIN_COURSE_CATALOGUE_USER);
|
|
|
- $visibility = ($allowed?1:0);
|
|
|
+ $visibility = $allowed ? 1 : 0;
|
|
|
|
|
|
// Restriction by user id
|
|
|
$currentUserRestriction = "";
|
|
|
if ($byUserId > 0) {
|
|
|
+ $byUserId = (int) $byUserId;
|
|
|
$currentUserRestriction = " AND tcruc.user_id = $byUserId ";
|
|
|
}
|
|
|
|
|
@@ -2732,8 +2738,8 @@ class CourseManager
|
|
|
$with_special_courses = $without_special_courses = '';
|
|
|
if (!empty($special_course_list)) {
|
|
|
$sc_string = '"' . implode('","', $special_course_list) . '"';
|
|
|
- $with_special_courses = ' course.code IN (' . $sc_string . ')';
|
|
|
- $without_special_courses = ' AND course.code NOT IN (' . $sc_string . ')';
|
|
|
+ $with_special_courses = ' course.id IN (' . $sc_string . ')';
|
|
|
+ $without_special_courses = ' AND course.id NOT IN (' . $sc_string . ')';
|
|
|
}
|
|
|
|
|
|
if (!empty($with_special_courses)) {
|
|
@@ -2793,7 +2799,8 @@ class CourseManager
|
|
|
|
|
|
/**
|
|
|
* Get course ID from a given course directory name
|
|
|
- * @param string Course directory (without any slash)
|
|
|
+ * @param string $path Course directory (without any slash)
|
|
|
+ *
|
|
|
* @return string Course code, or false if not found
|
|
|
*/
|
|
|
public static function get_course_id_from_path($path)
|
|
@@ -2831,10 +2838,10 @@ class CourseManager
|
|
|
|
|
|
/**
|
|
|
* Get emails of tutors to course
|
|
|
- * @param string Visual code
|
|
|
- * @param integer $courseId
|
|
|
+ * @param int $courseId
|
|
|
* @return array List of emails of tutors to course
|
|
|
- * @author @author Carlos Vargas <carlos.vargas@dokeos.com>, Dokeos Latino
|
|
|
+ *
|
|
|
+ * @author Carlos Vargas <carlos.vargas@dokeos.com>, Dokeos Latino
|
|
|
* */
|
|
|
public static function get_emails_of_tutors_to_course($courseId)
|
|
|
{
|
|
@@ -2926,9 +2933,10 @@ class CourseManager
|
|
|
* Updates course attribute. Note that you need to check that your
|
|
|
* attribute is valid before you use this function
|
|
|
*
|
|
|
- * @param int Course id
|
|
|
- * @param string Attribute name
|
|
|
- * @param string Attribute value
|
|
|
+ * @param int $id Course id
|
|
|
+ * @param string $name Attribute name
|
|
|
+ * @param string $value Attribute value
|
|
|
+ *
|
|
|
* @return Doctrine\DBAL\Driver\Statement|null True if attribute was successfully updated,
|
|
|
* false if course was not found or attribute name is invalid
|
|
|
*/
|
|
@@ -2998,11 +3006,15 @@ class CourseManager
|
|
|
*/
|
|
|
public static function get_session_category_id_by_session_id($session_id)
|
|
|
{
|
|
|
+ if (empty($session_id)) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
$sql = 'SELECT sc.id session_category
|
|
|
FROM ' . Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY) . ' sc
|
|
|
INNER JOIN ' . Database::get_main_table(TABLE_MAIN_SESSION) . ' s
|
|
|
ON sc.id = s.session_category_id
|
|
|
- WHERE s.id="' . Database::escape_string($session_id) . '"';
|
|
|
+ WHERE s.id="' . intval($session_id) . '"';
|
|
|
|
|
|
return Database::result(
|
|
|
Database::query($sql),
|
|
@@ -3014,8 +3026,8 @@ class CourseManager
|
|
|
/**
|
|
|
* Gets the value of a course extra field. Returns null if it was not found
|
|
|
*
|
|
|
- * @param string Name of the extra field
|
|
|
- * @param string Course code
|
|
|
+ * @param string $variable Name of the extra field
|
|
|
+ * @param string $code Course code
|
|
|
*
|
|
|
* @return string Value
|
|
|
*/
|
|
@@ -3081,7 +3093,8 @@ class CourseManager
|
|
|
public static function get_course_category($code)
|
|
|
{
|
|
|
$table_categories = Database::get_main_table(TABLE_MAIN_CATEGORY);
|
|
|
- $sql = "SELECT * FROM $table_categories WHERE code = '$code';";
|
|
|
+ $code = Database::escape_string($code);
|
|
|
+ $sql = "SELECT * FROM $table_categories WHERE code = '$code'";
|
|
|
return Database::fetch_array(Database::query($sql));
|
|
|
}
|
|
|
|
|
@@ -3108,9 +3121,10 @@ class CourseManager
|
|
|
* @param string $table The table of which the rows should be counted
|
|
|
* @param int $session_id optionally count rows by session id
|
|
|
* @return int $course_id The number of rows in the given table.
|
|
|
+ *
|
|
|
* @deprecated
|
|
|
*/
|
|
|
- public static function count_rows_course_table($table, $session_id = '', $course_id = null)
|
|
|
+ public static function count_rows_course_table($table, $session_id = '', $course_id = 0)
|
|
|
{
|
|
|
$condition_session = '';
|
|
|
if ($session_id !== '') {
|
|
@@ -3327,6 +3341,7 @@ class CourseManager
|
|
|
$courses[$row['code']] = $row;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
return $courses;
|
|
|
}
|
|
|
|
|
@@ -3455,6 +3470,7 @@ class CourseManager
|
|
|
$html .= '<div class="pull-right course-box-actions">' . $params['right_actions'] . '</div>';
|
|
|
$html .= '</div>';
|
|
|
$html .= '</div>';
|
|
|
+
|
|
|
return $html;
|
|
|
}
|
|
|
|
|
@@ -3587,8 +3603,8 @@ class CourseManager
|
|
|
*
|
|
|
* Special courses are courses that stick on top of the list and are "auto-registerable"
|
|
|
* in the sense that any user clicking them is registered as a student
|
|
|
- * @param int User id
|
|
|
- * @param bool Whether to show the document quick-loader or not
|
|
|
+ * @param int $user_id User id
|
|
|
+ * @param bool $load_dirs Whether to show the document quick-loader or not
|
|
|
* @return string
|
|
|
*/
|
|
|
public static function returnSpecialCourses($user_id, $load_dirs = false)
|
|
@@ -3596,12 +3612,10 @@ class CourseManager
|
|
|
$user_id = intval($user_id);
|
|
|
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
|
|
|
$tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
|
|
|
-
|
|
|
$special_course_list = self::get_special_course_list();
|
|
|
-
|
|
|
$with_special_courses = '';
|
|
|
if (!empty($special_course_list)) {
|
|
|
- $with_special_courses = ' course.code IN ("' . implode('","', $special_course_list) . '")';
|
|
|
+ $with_special_courses = ' AND course.id IN ("' . implode('","', $special_course_list) . '")';
|
|
|
}
|
|
|
|
|
|
$courseList = [];
|
|
@@ -3617,8 +3631,9 @@ class CourseManager
|
|
|
course_rel_user.user_id
|
|
|
FROM $tbl_course course
|
|
|
LEFT JOIN $tbl_course_user course_rel_user
|
|
|
- ON course.id = course_rel_user.c_id AND course_rel_user.user_id = '$user_id'
|
|
|
- WHERE $with_special_courses group by course.code";
|
|
|
+ ON (course.id = course_rel_user.c_id)
|
|
|
+ WHERE course_rel_user.user_id = '$user_id' $with_special_courses
|
|
|
+ GROUP BY course.code";
|
|
|
|
|
|
$rs_special_course = Database::query($sql);
|
|
|
$number_of_courses = Database::num_rows($rs_special_course);
|
|
@@ -3670,7 +3685,7 @@ class CourseManager
|
|
|
$params['title'] = $course_info['title'];
|
|
|
$params['link'] = $course_info['course_public_url'].'?id_session=0&autoreg=1';
|
|
|
if (api_get_setting('display_teacher_in_courselist') === 'true') {
|
|
|
- $params['teachers'] = CourseManager::getTeachersFromCourse($course_info['real_id']);
|
|
|
+ $params['teachers'] = CourseManager::getTeachersFromCourse($course_info['real_id'], false);
|
|
|
}
|
|
|
|
|
|
if ($showCustomIcon === 'true') {
|
|
@@ -3683,22 +3698,20 @@ class CourseManager
|
|
|
}
|
|
|
|
|
|
$params['is_special_course'] = true;
|
|
|
-
|
|
|
$courseList[] = $params;
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return $courseList;
|
|
|
-}
|
|
|
+ return $courseList;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* Display courses (without special courses) as several HTML divs
|
|
|
* of course categories, as class userportal-catalog-item.
|
|
|
* @uses displayCoursesInCategory() to display the courses themselves
|
|
|
- * @param int user id
|
|
|
- * @param bool Whether to show the document quick-loader or not
|
|
|
+ * @param int $user_id
|
|
|
+ * @param bool $load_dirs Whether to show the document quick-loader or not
|
|
|
* @param integer $user_id
|
|
|
* @return string
|
|
|
*/
|
|
@@ -3713,15 +3726,15 @@ class CourseManager
|
|
|
$sql = "SELECT id, title FROM $table
|
|
|
WHERE user_id = '" . $user_id . "'
|
|
|
ORDER BY sort ASC";
|
|
|
+
|
|
|
$result = Database::query($sql);
|
|
|
$listItems = [
|
|
|
'in_category' => [],
|
|
|
'not_category' => []
|
|
|
];
|
|
|
-
|
|
|
while ($row = Database::fetch_array($result)) {
|
|
|
// We simply display the title of the category.
|
|
|
- $courseInCategory = self:: returnCoursesCategories(
|
|
|
+ $courseInCategory = self::returnCoursesCategories(
|
|
|
$row['id'],
|
|
|
$load_dirs
|
|
|
);
|
|
@@ -3735,7 +3748,8 @@ class CourseManager
|
|
|
}
|
|
|
|
|
|
// Step 2: We display the course without a user category.
|
|
|
- $coursesNotCategory = self::returnCoursesWithoutCategories(0, $load_dirs);
|
|
|
+ $coursesNotCategory = self::returnCoursesCategories(0, $load_dirs);
|
|
|
+
|
|
|
if ($coursesNotCategory) {
|
|
|
$listItems['not_category'] = $coursesNotCategory;
|
|
|
}
|
|
@@ -3746,8 +3760,8 @@ class CourseManager
|
|
|
/**
|
|
|
* Display courses inside a category (without special courses) as HTML dics of
|
|
|
* class userportal-course-item.
|
|
|
- * @param int User category id
|
|
|
- * @param bool Whether to show the document quick-loader or not
|
|
|
+ * @param int $user_category_id User category id
|
|
|
+ * @param bool $load_dirs Whether to show the document quick-loader or not
|
|
|
* @return string
|
|
|
*/
|
|
|
public static function returnCoursesCategories($user_category_id, $load_dirs = false)
|
|
@@ -3764,25 +3778,18 @@ class CourseManager
|
|
|
|
|
|
$without_special_courses = '';
|
|
|
if (!empty($special_course_list)) {
|
|
|
- $without_special_courses = ' AND course.code NOT IN ("' . implode('","', $special_course_list) . '")';
|
|
|
+ $without_special_courses = ' AND course.id NOT IN ("' . implode('","', $special_course_list) . '")';
|
|
|
}
|
|
|
|
|
|
- //AND course_rel_user.relation_type<>".COURSE_RELATION_TYPE_RRHH."
|
|
|
$sql = "SELECT
|
|
|
- course.id,
|
|
|
- course.title,
|
|
|
- course.code,
|
|
|
- course.subscribe subscr,
|
|
|
- course.unsubscribe unsubscr,
|
|
|
- course_rel_user.status status,
|
|
|
- course_rel_user.sort sort,
|
|
|
- course_rel_user.user_course_cat user_course_cat
|
|
|
- FROM $TABLECOURS course,
|
|
|
- $TABLECOURSUSER course_rel_user,
|
|
|
- $TABLE_ACCESS_URL_REL_COURSE url
|
|
|
+ course.id,
|
|
|
+ course_rel_user.status status
|
|
|
+ FROM $TABLECOURS course
|
|
|
+ INNER JOIN $TABLECOURSUSER course_rel_user
|
|
|
+ ON (course.id = course_rel_user.c_id)
|
|
|
+ INNER JOIN $TABLE_ACCESS_URL_REL_COURSE url
|
|
|
+ ON (url.c_id = course.id)
|
|
|
WHERE
|
|
|
- course.id = course_rel_user.c_id AND
|
|
|
- url.c_id = course.id AND
|
|
|
course_rel_user.user_id = '" . $user_id . "' AND
|
|
|
course_rel_user.user_course_cat = '" . $user_category_id . "'
|
|
|
$without_special_courses ";
|
|
@@ -3800,28 +3807,26 @@ class CourseManager
|
|
|
$courseList = array();
|
|
|
$showCustomIcon = api_get_setting('course_images_in_courses_list');
|
|
|
// Browse through all courses.
|
|
|
- while ($course = Database::fetch_array($result)) {
|
|
|
- $course_info = api_get_course_info($course['code']);
|
|
|
+ while ($row = Database::fetch_array($result)) {
|
|
|
+ $course_info = api_get_course_info_by_id($row['id']);
|
|
|
if (isset($course_info['visibility']) &&
|
|
|
$course_info['visibility'] == COURSE_VISIBILITY_HIDDEN
|
|
|
) {
|
|
|
continue;
|
|
|
}
|
|
|
$course_info['id_session'] = null;
|
|
|
- $course_info['status'] = $course['status'];
|
|
|
-
|
|
|
+ $course_info['status'] = $row['status'];
|
|
|
// For each course, get if there is any notification icon to show
|
|
|
// (something that would have changed since the user's last visit).
|
|
|
$showNotification = Display::show_notification($course_info);
|
|
|
$iconName = basename($course_info['course_image']);
|
|
|
|
|
|
+ $params = array();
|
|
|
if ($showCustomIcon === 'true' && $iconName != 'course.png') {
|
|
|
$params['thumbnails'] = $course_info['course_image'];
|
|
|
$params['image'] = $course_info['course_image_large'];
|
|
|
}
|
|
|
|
|
|
- $params = array();
|
|
|
-
|
|
|
$thumbnails = null;
|
|
|
$image = null;
|
|
|
|
|
@@ -3832,12 +3837,12 @@ class CourseManager
|
|
|
$image = Display::return_icon('session_default.png', null, null, null,null, true);
|
|
|
}
|
|
|
|
|
|
- $params['course_id'] = $course['id'];
|
|
|
+ $params['course_id'] = $course_info['real_id'];
|
|
|
$params['edit_actions'] = '';
|
|
|
$params['document'] = '';
|
|
|
if (api_is_platform_admin()) {
|
|
|
- $params['edit_actions'] .= api_get_path(WEB_CODE_PATH) . 'course_info/infocours.php?cidReq=' . $course['code'];
|
|
|
- if($load_dirs){
|
|
|
+ $params['edit_actions'] .= api_get_path(WEB_CODE_PATH) . 'course_info/infocours.php?cidReq=' . $course_info['code'];
|
|
|
+ if ($load_dirs) {
|
|
|
$params['document'] = '<a id="document_preview_' . $course_info['real_id'] . '_0" class="document_preview btn btn-default btn-sm" href="javascript:void(0);">'
|
|
|
. Display::returnFontAwesomeIcon('folder-open') . '</a>';
|
|
|
$params['document'] .= Display::div('', array('id' => 'document_result_' . $course_info['real_id'] . '_0', 'class' => 'document_preview_container'));
|
|
@@ -3850,13 +3855,12 @@ class CourseManager
|
|
|
}
|
|
|
|
|
|
$courseUrl = api_get_path(WEB_COURSE_PATH) . $course_info['path'] . '/index.php?id_session=0';
|
|
|
-
|
|
|
+ $teachers = [];
|
|
|
if (api_get_setting('display_teacher_in_courselist') === 'true') {
|
|
|
- $teachers = CourseManager::getTeachersFromCourse($course_info['real_id']);
|
|
|
+ $teachers = CourseManager::getTeachersFromCourse($course_info['real_id'], false);
|
|
|
}
|
|
|
|
|
|
- $params['status'] = $course['status'];
|
|
|
-
|
|
|
+ $params['status'] = $row['status'];
|
|
|
if (api_get_setting('display_coursecode_in_courselist') == 'true') {
|
|
|
$params['code_course'] = '(' . $course_info['visual_code'] . ') ';
|
|
|
}
|
|
@@ -3882,6 +3886,7 @@ class CourseManager
|
|
|
/**
|
|
|
* Display courses inside a category (without special courses) as HTML dics of
|
|
|
* class userportal-course-item.
|
|
|
+ * @deprecated use self::returnCoursesCategories(0);
|
|
|
* @param int User category id
|
|
|
* @param bool Whether to show the document quick-loader or not
|
|
|
* @return string
|
|
@@ -3901,25 +3906,24 @@ class CourseManager
|
|
|
|
|
|
$without_special_courses = '';
|
|
|
if (!empty($special_course_list)) {
|
|
|
- $without_special_courses = ' AND course.code NOT IN ("' . implode('","', $special_course_list) . '")';
|
|
|
+ $without_special_courses = ' AND course.id NOT IN ("' . implode('","', $special_course_list) . '")';
|
|
|
}
|
|
|
|
|
|
- //AND course_rel_user.relation_type<>".COURSE_RELATION_TYPE_RRHH."
|
|
|
$sql = "SELECT
|
|
|
- course.id,
|
|
|
- course.title,
|
|
|
- course.code,
|
|
|
- course.subscribe subscr,
|
|
|
- course.unsubscribe unsubscr,
|
|
|
- course_rel_user.status status,
|
|
|
- course_rel_user.sort sort,
|
|
|
- course_rel_user.user_course_cat user_course_cat
|
|
|
- FROM $TABLECOURS course,
|
|
|
- $TABLECOURSUSER course_rel_user,
|
|
|
- $TABLE_ACCESS_URL_REL_COURSE url
|
|
|
+ course.id,
|
|
|
+ course.title,
|
|
|
+ course.code,
|
|
|
+ course.subscribe subscr,
|
|
|
+ course.unsubscribe unsubscr,
|
|
|
+ course_rel_user.status status,
|
|
|
+ course_rel_user.sort sort,
|
|
|
+ course_rel_user.user_course_cat user_course_cat
|
|
|
+ FROM $TABLECOURS course
|
|
|
+ INNER JOIN $TABLECOURSUSER course_rel_user
|
|
|
+ ON (course.id = course_rel_user.c_id)
|
|
|
+ INNER JOIN $TABLE_ACCESS_URL_REL_COURSE url
|
|
|
+ ON (url.c_id = course.id)
|
|
|
WHERE
|
|
|
- course.id = course_rel_user.c_id AND
|
|
|
- url.c_id = course.id AND
|
|
|
course_rel_user.user_id = '" . $user_id . "' AND
|
|
|
course_rel_user.user_course_cat = '" . $user_category_id . "'
|
|
|
$without_special_courses ";
|
|
@@ -3935,15 +3939,15 @@ class CourseManager
|
|
|
|
|
|
$showCustomIcon = api_get_setting('course_images_in_courses_list');
|
|
|
// Browse through all courses.
|
|
|
- while ($course = Database::fetch_array($result)) {
|
|
|
- $course_info = api_get_course_info($course['code']);
|
|
|
+ while ($row = Database::fetch_array($result)) {
|
|
|
+ $course_info = api_get_course_info($row['code']);
|
|
|
if (isset($course_info['visibility']) &&
|
|
|
$course_info['visibility'] == COURSE_VISIBILITY_HIDDEN
|
|
|
) {
|
|
|
continue;
|
|
|
}
|
|
|
$course_info['id_session'] = null;
|
|
|
- $course_info['status'] = $course['status'];
|
|
|
+ $course_info['status'] = $row['status'];
|
|
|
|
|
|
// For each course, get if there is any notification icon to show
|
|
|
// (something that would have changed since the user's last visit).
|
|
@@ -3964,7 +3968,7 @@ class CourseManager
|
|
|
$params['edit_actions'] = '';
|
|
|
$params['document'] = '';
|
|
|
if (api_is_platform_admin()) {
|
|
|
- $params['edit_actions'] .= api_get_path(WEB_CODE_PATH) . 'course_info/infocours.php?cidReq=' . $course['code'];
|
|
|
+ $params['edit_actions'] .= api_get_path(WEB_CODE_PATH) . 'course_info/infocours.php?cidReq=' . $course_info['code'];
|
|
|
if($load_dirs){
|
|
|
$params['document'] = '<a id="document_preview_' . $course_info['real_id'] . '_0" class="document_preview btn btn-default btn-sm" href="javascript:void(0);">'
|
|
|
. Display::returnFontAwesomeIcon('folder-open') . '</a>';
|
|
@@ -3979,12 +3983,11 @@ class CourseManager
|
|
|
|
|
|
$course_title_url = api_get_path(WEB_COURSE_PATH) . $course_info['path'] . '/index.php?id_session=0';
|
|
|
|
|
|
- $teachers = '';
|
|
|
-
|
|
|
+ $teachers = [];
|
|
|
if (api_get_setting('display_teacher_in_courselist') === 'true') {
|
|
|
- $teachers = CourseManager::getTeachersFromCourse($course_info['real_id']);
|
|
|
+ $teachers = CourseManager::getTeachersFromCourse($course_info['real_id'], false);
|
|
|
}
|
|
|
- $params['status'] = $course['status'];
|
|
|
+ $params['status'] = $row['status'];
|
|
|
|
|
|
if (api_get_setting('display_coursecode_in_courselist') == 'true') {
|
|
|
$params['code_course'] = '(' . $course_info['visual_code'] . ') ';
|
|
@@ -4003,7 +4006,6 @@ class CourseManager
|
|
|
}
|
|
|
|
|
|
$courseList[] = $params;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
return $courseList;
|
|
@@ -4024,7 +4026,8 @@ class CourseManager
|
|
|
|
|
|
$output = array();
|
|
|
$table_category = Database::get_main_table(TABLE_USER_COURSE_CATEGORY);
|
|
|
- $sql = "SELECT * FROM $table_category WHERE user_id = '".intval($realUserId)."'";
|
|
|
+ $sql = "SELECT * FROM $table_category
|
|
|
+ WHERE user_id = '".intval($realUserId)."'";
|
|
|
$result = Database::query($sql);
|
|
|
while ($row = Database::fetch_array($result)) {
|
|
|
$output[$row['id']] = $row['title'];
|
|
@@ -4069,7 +4072,7 @@ class CourseManager
|
|
|
*
|
|
|
* @param string $value Original course code
|
|
|
* @param string $variable Original field name
|
|
|
- * @return int Course id
|
|
|
+ * @return array
|
|
|
*/
|
|
|
public static function getCourseInfoFromOriginalId($value, $variable)
|
|
|
{
|
|
@@ -4084,7 +4087,7 @@ class CourseManager
|
|
|
return $courseInfo;
|
|
|
}
|
|
|
|
|
|
- return 0;
|
|
|
+ return [];
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -4119,7 +4122,6 @@ class CourseManager
|
|
|
$session_accessible = true,
|
|
|
$load_dirs = false
|
|
|
) {
|
|
|
- $entityManager = Database::getManager();
|
|
|
$now = date('Y-m-d h:i:s');
|
|
|
$user_id = api_get_user_id();
|
|
|
$course_info = api_get_course_info_by_id($course['real_id']);
|
|
@@ -4137,7 +4139,7 @@ class CourseManager
|
|
|
$course_info['status'] = empty($session_id) ? $userInCourseStatus : STUDENT;
|
|
|
$course_info['id_session'] = $session_id;
|
|
|
|
|
|
- $is_coach = api_is_coach($course_info['id_session'], $course_info['real_id']);
|
|
|
+ $is_coach = api_is_coach($session_id, $course_info['real_id']);
|
|
|
|
|
|
// Display course entry.
|
|
|
// Show a hyperlink to the course, unless the course is closed and user is not course admin.
|
|
@@ -4154,8 +4156,10 @@ class CourseManager
|
|
|
|
|
|
// Display the "what's new" icons
|
|
|
$notifications = '';
|
|
|
- if ($course_visibility != COURSE_VISIBILITY_CLOSED && $course_visibility != COURSE_VISIBILITY_HIDDEN) {
|
|
|
- $notifications .= Display:: show_notification($course_info);
|
|
|
+ if ($course_visibility != COURSE_VISIBILITY_CLOSED &&
|
|
|
+ $course_visibility != COURSE_VISIBILITY_HIDDEN
|
|
|
+ ) {
|
|
|
+ $notifications .= Display::show_notification($course_info);
|
|
|
}
|
|
|
|
|
|
if ($session_accessible) {
|
|
@@ -4230,7 +4234,8 @@ class CourseManager
|
|
|
|
|
|
if (api_get_setting('display_teacher_in_courselist') === 'true') {
|
|
|
$teacher_list = CourseManager::getTeachersFromCourse(
|
|
|
- $course_info['real_id']
|
|
|
+ $course_info['real_id'],
|
|
|
+ false
|
|
|
);
|
|
|
|
|
|
$course_coachs = self::get_coachs_from_course(
|
|
@@ -4300,6 +4305,7 @@ class CourseManager
|
|
|
);
|
|
|
|
|
|
if (api_get_setting('allow_skills_tool') === 'true') {
|
|
|
+ $entityManager = Database::getManager();
|
|
|
$objUser = $entityManager->find('ChamiloUserBundle:User', $user_id);
|
|
|
$objCourse = $entityManager->find('ChamiloCoreBundle:Course', $course['real_id']);
|
|
|
$objSession = $entityManager->find('ChamiloCoreBundle:Session', $session_id);
|
|
@@ -4404,7 +4410,7 @@ class CourseManager
|
|
|
$wanted_code = CourseManager::generate_course_code($wanted_code);
|
|
|
$table = Database::get_main_table(TABLE_MAIN_COURSE);
|
|
|
$wanted_code = Database::escape_string($wanted_code);
|
|
|
- $sql = "SELECT count(*) as count
|
|
|
+ $sql = "SELECT count(id) as count
|
|
|
FROM $table
|
|
|
WHERE code LIKE '$wanted_code%'";
|
|
|
$result = Database::query($sql);
|
|
@@ -4860,11 +4866,8 @@ class CourseManager
|
|
|
public static function process_hot_course_item($courses, $my_course_code_list = array())
|
|
|
{
|
|
|
$hotCourses = [];
|
|
|
-
|
|
|
$ajax_url = api_get_path(WEB_AJAX_PATH) . 'course.ajax.php?a=add_course_vote';
|
|
|
-
|
|
|
$stok = Security::get_existing_token();
|
|
|
-
|
|
|
$user_id = api_get_user_id();
|
|
|
|
|
|
foreach ($courses as $courseId) {
|
|
@@ -4881,8 +4884,8 @@ class CourseManager
|
|
|
$my_course_code_list
|
|
|
);
|
|
|
|
|
|
- $user_registerd_in_course = CourseManager::is_user_subscribed_in_course($user_id, $course_info['code']);
|
|
|
- $user_registerd_in_course_as_teacher = CourseManager::is_course_teacher($user_id, $course_info['code']);
|
|
|
+ $user_registerd_in_course = CourseManager::is_user_subscribed_in_course($user_id, $courseCode);
|
|
|
+ $user_registerd_in_course_as_teacher = CourseManager::is_course_teacher($user_id, $courseCode);
|
|
|
$user_registerd_in_course_as_student = ($user_registerd_in_course && !$user_registerd_in_course_as_teacher);
|
|
|
|
|
|
// if user registered as student
|
|
@@ -4959,13 +4962,14 @@ class CourseManager
|
|
|
);
|
|
|
//}
|
|
|
/* get_lang('Description') */
|
|
|
- $my_course['teachers'] = CourseManager::getTeachersFromCourse($course_info['real_id']);
|
|
|
+ $my_course['teachers'] = CourseManager::getTeachersFromCourse($course_info['real_id'], false);
|
|
|
$point_info = self::get_course_ranking($course_info['real_id'], 0);
|
|
|
$my_course['rating_html'] = Display::return_rating_system('star_' . $course_info['real_id'],
|
|
|
$ajax_url . '&course_id=' . $course_info['real_id'], $point_info);
|
|
|
|
|
|
$hotCourses[] = $my_course;
|
|
|
}
|
|
|
+
|
|
|
return $hotCourses;
|
|
|
}
|
|
|
|
|
@@ -4985,6 +4989,7 @@ class CourseManager
|
|
|
'all',
|
|
|
true
|
|
|
);
|
|
|
+
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
@@ -5094,7 +5099,7 @@ class CourseManager
|
|
|
|
|
|
$withoutSpecialCourses = '';
|
|
|
if (!empty($specialCourseList)) {
|
|
|
- $withoutSpecialCourses = ' AND c.code NOT IN ("' . implode('","', $specialCourseList) . '")';
|
|
|
+ $withoutSpecialCourses = ' AND c.id NOT IN ("' . implode('","', $specialCourseList) . '")';
|
|
|
}
|
|
|
|
|
|
$visibilityCondition = self::getCourseVisibilitySQLCondition('c');
|
|
@@ -6029,7 +6034,7 @@ class CourseManager
|
|
|
|
|
|
$without_special_courses = '';
|
|
|
if (!empty($special_course_list)) {
|
|
|
- $without_special_courses = ' AND course.code NOT IN ("'.implode('","',$special_course_list).'")';
|
|
|
+ $without_special_courses = ' AND course.id NOT IN ("'.implode('","',$special_course_list).'")';
|
|
|
}
|
|
|
|
|
|
//AND course_rel_user.relation_type<>".COURSE_RELATION_TYPE_RRHH."
|