Minor - update from 1.11.x

pull/3016/head
Julio 6 years ago
parent 441dc85b43
commit 268b31f633
  1. 2
      main/course_home/activity.php
  2. 2
      main/course_home/vertical_activity.php
  3. 7
      main/course_info/about.php
  4. 2
      main/inc/ajax/lang.ajax.php
  5. 2
      main/inc/lib/CourseChatUtils.php
  6. 379
      main/inc/lib/course.lib.php
  7. 75
      main/inc/lib/course_category.lib.php
  8. 61
      main/inc/lib/course_description.lib.php
  9. 9
      main/inc/lib/exercise.lib.php
  10. 65
      main/inc/lib/groupmanager.lib.php
  11. 87
      main/inc/lib/link.lib.php
  12. 67
      main/inc/lib/message.lib.php
  13. 19
      main/inc/lib/notification.lib.php
  14. 278
      main/inc/lib/sessionmanager.lib.php

@ -69,5 +69,5 @@ $activityView = new Template('', false, false, false, false, false, false);
$activityView->assign('blocks', $blocks);
$content .= $activityView->fetch(
$activityView->get_template('course_home/activity.html.twig')
$activityView->get_template('course_home/activity.tpl')
);

@ -129,5 +129,5 @@ $activityView = new Template('', false, false, false, false, false, false);
$activityView->assign('blocks', $blocks);
$content .= $activityView->fetch(
$activityView->get_template('course_home/vertical_activity.html.twig')
$activityView->get_template('course_home/vertical_activity.tpl')
);

@ -19,6 +19,11 @@ $cidReset = true;
require_once __DIR__.'/../inc/global.inc.php';
$courseId = isset($_GET['course_id']) ? (int) $_GET['course_id'] : 0;
if (empty($courseId)) {
api_not_allowed(true);
}
$token = Security::get_existing_token();
$em = Database::getManager();
//userID
@ -173,7 +178,7 @@ $template->assign('is_premium', $courseIsPremium);
$template->assign('allow_subscribe', $allowSubscribe);
$template->assign('token', $token);
$template->assign('url', $urlCourse);
$layout = $template->get_template('course_home/about.html.twig');
$layout = $template->get_template('course_home/about.tpl');
$content = $template->fetch($layout);
$template->assign('content', $content);
$template->display_one_col_template();

@ -12,6 +12,8 @@ $action = $_REQUEST['a'];
switch ($action) {
case 'translate_html':
header('Content-type: application/x-javascript');
$translate = api_get_configuration_value('translate_html');
if (!$translate) {

@ -90,6 +90,8 @@ class CourseChatUtils
if (empty($message)) {
return false;
}
$friendId = (int) $friendId;
$user = api_get_user_entity($this->userId);
$courseInfo = api_get_course_info_by_id($this->courseId);
$isMaster = api_is_course_admin();

@ -1125,11 +1125,10 @@ class CourseManager
$session_id = 0
) {
$user_id = (int) $user_id;
$session_id = (int) $session_id;
if (empty($session_id)) {
$session_id = api_get_session_id();
} else {
$session_id = (int) $session_id;
}
$condition_course = '';
@ -1162,21 +1161,21 @@ class CourseManager
$tableSessionCourseUser = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$sql = 'SELECT 1 FROM '.$tableSessionCourseUser.'
WHERE user_id = '.$user_id.' AND session_id = '.$session_id.' '.$condition_course;
WHERE user_id = '.$user_id.' AND session_id = '.$session_id.' '.$condition_course;
if (Database::num_rows(Database::query($sql)) > 0) {
return true;
}
$sql = 'SELECT 1 FROM '.$tableSessionCourseUser.'
WHERE user_id = '.$user_id.' AND session_id = '.$session_id.' AND status = 2 '.$condition_course;
WHERE user_id = '.$user_id.' AND session_id = '.$session_id.' AND status = 2 '.$condition_course;
if (Database::num_rows(Database::query($sql)) > 0) {
return true;
}
$sql = 'SELECT 1 FROM '.Database::get_main_table(TABLE_MAIN_SESSION).
' WHERE id = '.$session_id.' AND id_coach='.$user_id;
' WHERE id = '.$session_id.' AND id_coach='.$user_id;
if (Database::num_rows(Database::query($sql)) > 0) {
return true;
@ -1733,7 +1732,7 @@ class CourseManager
$status = null
) {
// variable initialisation
$session_id = intval($session_id);
$session_id = (int) $session_id;
$course_code = Database::escape_string($course_code);
$tblUser = Database::get_main_table(TABLE_MAIN_USER);
$tblSessionCourseUser = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
@ -1809,7 +1808,7 @@ class CourseManager
$course_code = Database::escape_string($course_code);
$courseInfo = api_get_course_info($course_code);
$courseId = $courseInfo['real_id'];
$session_id = intval($session_id);
$session_id = (int) $session_id;
$users = [];
// We get the coach for the given course in a given session.
@ -3100,27 +3099,6 @@ class CourseManager
return $extraField->save($params);
}
/**
* Updates course attribute. Note that you need to check that your
* attribute is valid before you use this function.
*
* @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
*/
public static function update_attribute($id, $name, $value)
{
$id = (int) $id;
$table = Database::get_main_table(TABLE_MAIN_COURSE);
$sql = "UPDATE $table SET $name = '".Database::escape_string($value)."'
WHERE id = $id";
return Database::query($sql);
}
/**
* Update course attributes. Will only update attributes with a non-empty value.
* Note that you NEED to check that your attributes are valid before using this function.
@ -3589,89 +3567,6 @@ class CourseManager
}
}
/**
* Builds the course block in user_portal.php.
*
* @todo use Twig
*
* @param array $params
*
* @return string
*/
public static function course_item_html_no_icon($params)
{
$html = '<div class="course_item">';
$html .= '<div class="row">';
$html .= '<div class="col-md-7">';
$notifications = isset($params['notifications']) ? $params['notifications'] : null;
$html .= '<h3>'.$params['title'].$notifications.'</h3> ';
if (isset($params['description'])) {
$html .= '<p>'.$params['description'].'</p>';
}
if (!empty($params['subtitle'])) {
$html .= '<small>'.$params['subtitle'].'</small>';
}
if (!empty($params['teachers'])) {
$html .= '<h5 class="teacher">'.
Display::return_icon(
'teacher.png',
get_lang('Teacher'),
[],
ICON_SIZE_TINY
).
$params['teachers'].'</h5>';
}
if (!empty($params['coaches'])) {
$html .= '<h5 class="teacher">'.
Display::return_icon(
'teacher.png',
get_lang('Coach'),
[],
ICON_SIZE_TINY
).
$params['coaches'].'</h5>';
}
$html .= '</div>';
$params['right_actions'] = isset($params['right_actions']) ? $params['right_actions'] : null;
$html .= '<div class="float-right course-box-actions">'.$params['right_actions'].'</div>';
$html .= '</div>';
$html .= '</div>';
return $html;
}
/**
* @param $params
* @param bool|false $is_sub_content
*
* @return string
*/
public static function session_items_html($params, $is_sub_content = false)
{
$html = '';
$html .= '<div class="row">';
$html .= '<div class="col-md-2">';
if (!empty($params['link'])) {
$html .= '<a class="thumbnail" href="'.$params['link'].'">';
$html .= $params['icon'];
$html .= '</a>';
} else {
$html .= $params['icon'];
}
$html .= '</div>';
$html .= '<div class="col-md-10">';
$html .= $params['title'];
$html .= $params['coaches'];
$html .= '</div>';
$html .= '</div>';
return $html;
}
/**
* Display special courses (and only these) as several HTML divs of class userportal-course-item.
*
@ -3689,7 +3584,7 @@ class CourseManager
$load_dirs = false,
$useUserLanguageFilterIfAvailable = true
) {
$user_id = intval($user_id);
$user_id = (int) $user_id;
$table = Database::get_main_table(TABLE_MAIN_COURSE);
$specialCourseList = self::get_special_course_list();
@ -4093,150 +3988,6 @@ class CourseManager
return $courseList;
}
/**
* 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 array
*/
public static function returnCoursesWithoutCategories($user_category_id, $load_dirs = false)
{
$user_id = api_get_user_id();
// Table definitions
$TABLECOURS = Database::get_main_table(TABLE_MAIN_COURSE);
$TABLECOURSUSER = Database::get_main_table(TABLE_MAIN_COURSE_USER);
$TABLE_ACCESS_URL_REL_COURSE = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
$current_url_id = api_get_current_access_url_id();
$courseList = [];
// Get course list auto-register
$special_course_list = self::get_special_course_list();
$without_special_courses = '';
if (!empty($special_course_list)) {
$without_special_courses = ' AND course.id NOT IN ("'.implode('","', $special_course_list).'")';
}
$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
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_rel_user.user_id = $user_id AND
course_rel_user.user_course_cat = $user_category_id
$without_special_courses ";
// If multiple URL access mode is enabled, only fetch courses
// corresponding to the current URL.
if (api_get_multiple_access_url() && $current_url_id != -1) {
$sql .= " AND url.c_id = course.id AND access_url_id = $current_url_id ";
}
// Use user's classification for courses (if any).
$sql .= " ORDER BY course_rel_user.user_course_cat, course_rel_user.sort ASC";
$result = Database::query($sql);
$showCustomIcon = api_get_setting('course_images_in_courses_list');
// Browse through all courses.
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'] = $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 = !api_get_configuration_value('hide_course_notification')
? Display::show_notification($course_info)
: '';
$thumbnails = null;
$image = null;
$iconName = basename($course_info['course_image']);
if ($showCustomIcon === 'true' && $iconName != 'course.png') {
$thumbnails = $course_info['course_image'];
$image = $course_info['course_image_large'];
} else {
$image = Display::return_icon(
'session_default.png',
null,
null,
null,
null,
true
);
}
$params = [];
//Param (course_code) needed to get the student process
$params['course_code'] = $row['code'];
$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_info['code'];
if ($load_dirs) {
$params['document'] = '<a id="document_preview_'.$course_info['real_id'].'_0" class="document_preview btn btn-outline-secondary btn-sm" href="javascript:void(0);">'
.Display::returnFontAwesomeIcon('folder-open').'</a>';
$params['document'] .= Display::div('', ['id' => 'document_result_'.$course_info['real_id'].'_0', 'class' => 'document_preview_container']);
}
}
if ($load_dirs) {
$params['document'] = '<a id="document_preview_'.$course_info['real_id'].'_0" class="document_preview btn btn-outline-secondary btn-sm" href="javascript:void(0);">'
.Display::returnFontAwesomeIcon('folder-open').'</a>';
$params['document'] .= Display::div('', ['id' => 'document_result_'.$course_info['real_id'].'_0', 'class' => 'document_preview_container']);
}
$course_title_url = 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 = self::getTeachersFromCourse(
$course_info['real_id'],
false
);
}
$params['status'] = $row['status'];
if (api_get_setting('display_coursecode_in_courselist') == 'true') {
$params['code_course'] = '('.$course_info['visual_code'].') ';
}
$params['visibility'] = $course_info['visibility'];
$params['link'] = $course_title_url;
$params['thumbnails'] = $thumbnails;
$params['image'] = $image;
$params['title'] = $course_info['title'];
$params['category'] = $course_info['categoryName'];
$params['teachers'] = $teachers;
if ($course_info['visibility'] != COURSE_VISIBILITY_CLOSED) {
$params['notifications'] = $showNotification;
}
$courseList[] = $params;
}
return $courseList;
}
/**
* Retrieves the user defined course categories.
*
@ -5247,27 +4998,6 @@ class CourseManager
return $hotCourses;
}
/**
* @param int $limit
*
* @return array
*/
public static function return_most_accessed_courses($limit = 5)
{
$table = Database::get_main_table(TABLE_STATISTIC_TRACK_COURSE_RANKING);
$params['url_id'] = api_get_current_access_url_id();
$result = Database::select(
'c_id, accesses, total_score, users',
$table,
['where' => ['url_id = ?' => $params], 'order' => 'accesses DESC', 'limit' => $limit],
'all',
true
);
return $result;
}
/**
* Get courses count.
*
@ -5730,7 +5460,7 @@ class CourseManager
public static function hasCourseSetting($variable, $courseId)
{
$courseSetting = Database::get_course_table(TABLE_COURSE_SETTING);
$courseId = intval($courseId);
$courseId = (int) $courseId;
$variable = Database::escape_string($variable);
$sql = "SELECT variable FROM $courseSetting
WHERE c_id = $courseId AND variable = '$variable'";
@ -5739,34 +5469,6 @@ class CourseManager
return Database::num_rows($result) > 0;
}
/**
* Get information from the track_e_course_access table.
*
* @param int $sessionId
* @param int $userId
* @param int $limit
*
* @return array
*/
public static function getCourseAccessPerSessionAndUser($sessionId, $userId, $limit = 0)
{
$table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
$sessionId = intval($sessionId);
$userId = intval($userId);
$sql = "SELECT * FROM $table
WHERE session_id = $sessionId AND user_id = $userId";
if (!empty($limit)) {
$limit = intval($limit);
$sql .= " LIMIT $limit";
}
$result = Database::query($sql);
return Database::store_result($result);
}
/**
* Get information from the track_e_course_access table.
*
@ -5972,27 +5674,6 @@ class CourseManager
);
}
/**
* @param $courseId
*
* @return array
*/
public static function getCourseSettings($courseId)
{
$settingTable = Database::get_course_table(TABLE_COURSE_SETTING);
$courseId = intval($courseId);
$sql = "SELECT * FROM $settingTable WHERE c_id = $courseId";
$result = Database::query($sql);
$settings = [];
if (Database::num_rows($result)) {
while ($row = Database::fetch_array($result, 'ASSOC')) {
$settings[$row['variable']] = $row;
}
}
return $settings;
}
/**
* this function gets all the users of the course,
* including users from linked courses.
@ -6750,50 +6431,6 @@ class CourseManager
return api_get_path(WEB_COURSE_PATH).$course->getDirectory().'/course-pic85x85.png';
}
/**
* @return int
*/
public static function getCountOpenCourses()
{
$visibility = [
COURSE_VISIBILITY_REGISTERED,
COURSE_VISIBILITY_OPEN_PLATFORM,
COURSE_VISIBILITY_OPEN_WORLD,
];
$table = Database::get_main_table(TABLE_MAIN_COURSE);
$sql = "SELECT count(id) count
FROM $table
WHERE visibility IN (".implode(',', $visibility).")";
$result = Database::query($sql);
$row = Database::fetch_array($result);
return (int) $row['count'];
}
/**
* @return int
*/
public static function getCountExercisesFromOpenCourse()
{
$visibility = [
COURSE_VISIBILITY_REGISTERED,
COURSE_VISIBILITY_OPEN_PLATFORM,
COURSE_VISIBILITY_OPEN_WORLD,
];
$table = Database::get_main_table(TABLE_MAIN_COURSE);
$tableExercise = Database::get_course_table(TABLE_QUIZ_TEST);
$sql = "SELECT count(e.iid) count
FROM $table c INNER JOIN $tableExercise e
ON (c.id = e.c_id)
WHERE e.active <> -1 AND visibility IN (".implode(',', $visibility).")";
$result = Database::query($sql);
$row = Database::fetch_array($result);
return (int) $row['count'];
}
/**
* @param ToolChain $toolList
*/

@ -70,7 +70,6 @@ class CourseCategory
$conditions = null;
$table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY);
$conditions = " INNER JOIN $table a ON (t1.id = a.course_category_id)";
$whereCondition = " AND a.access_url_id = ".api_get_current_access_url_id();
$allowBaseCategories = api_get_configuration_value('allow_base_course_category');
@ -484,8 +483,8 @@ class CourseCategory
*/
public static function listCategories($categorySource)
{
$categorySource = isset($categorySource) ? $categorySource : null;
$categories = self::getCategories($categorySource);
$categorySource = Security::remove_XSS($categorySource);
if (count($categories) > 0) {
$table = new HTML_Table(['class' => 'table data_table']);
@ -678,51 +677,6 @@ class CourseCategory
return (int) $row['count'];
}
/**
* create recursively all categories as option of the select passed in parameter.
*
* @param HTML_QuickForm_Element $element
* @param string $defaultCode the option value to select by default (used mainly for edition of courses)
* @param string $parentCode the parent category of the categories added (default=null for root category)
* @param string $padding the indent param (you shouldn't indicate something here)
*/
public static function setCategoriesInForm(
$element,
$defaultCode = null,
$parentCode = null,
$padding = null
) {
$tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY);
$table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY);
$conditions = " INNER JOIN $table a ON (c.id = a.course_category_id)";
$whereCondition = " AND a.access_url_id = ".api_get_current_access_url_id();
$sql = "SELECT code, name, auth_course_child, auth_cat_child
FROM $tbl_category c
$conditions
WHERE parent_id ".(empty($parentCode) ? "IS NULL" : "='".Database::escape_string($parentCode)."'")."
$whereCondition
ORDER BY name, code";
$res = Database::query($sql);
while ($cat = Database::fetch_array($res, 'ASSOC')) {
$params = $cat['auth_course_child'] == 'TRUE' ? '' : 'disabled';
$params .= ($cat['code'] == $defaultCode) ? ' selected' : '';
$option = $padding.' '.$cat['name'].' ('.$cat['code'].')';
$element->addOption($option, $cat['code'], $params);
if ($cat['auth_cat_child'] == 'TRUE') {
self::setCategoriesInForm(
$element,
$defaultCode,
$cat['code'],
$padding.' - '
);
}
}
}
/**
* @param array $list
*
@ -780,33 +734,6 @@ class CourseCategory
return Database::store_result($result, 'ASSOC');
}
/**
* @param array $list
*
* @return array
*/
public static function searchCategoryById($list)
{
if (empty($list)) {
return [];
} else {
$list = array_map('intval', $list);
$list = implode("','", $list);
}
$tableCategory = Database::get_main_table(TABLE_MAIN_CATEGORY);
$table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY);
$conditions = " INNER JOIN $table a ON (c.id = a.course_category_id)";
$whereCondition = " AND a.access_url_id = ".api_get_current_access_url_id();
$sql = "SELECT c.*, c.name as text FROM $tableCategory c $conditions
WHERE c.id IN $list $whereCondition";
$result = Database::query($sql);
return Database::store_result($result, 'ASSOC');
}
/**
* Get Pagination HTML div.
*

@ -248,44 +248,6 @@ class CourseDescription
return $last_id > 0 ? 1 : 0;
}
/**
* Insert a row like history inside track_e_item_property table
* first you must set description_type, title, content, progress and
* session_id properties with the object CourseDescription.
*
* @param int $description_type
*
* @return int affected rows
*/
public function insert_stats($description_type)
{
$table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ITEM_PROPERTY);
$description_id = $this->get_id_by_description_type($description_type);
$course_id = api_get_course_int_id();
$course_code = api_get_course_id();
$item_property_id = api_get_item_property_id(
$course_code,
TOOL_COURSE_DESCRIPTION,
$description_id
);
$params = [
'c_id' => api_get_course_int_id(),
'course_id' => $course_id,
'item_property_id' => $item_property_id,
'title' => $this->title,
'content' => $this->content,
'progress' => $this->progress,
'lastedit_date' => api_get_utc_datetime(),
'lastedit_user_id' => api_get_user_id(),
'session_id' => $this->session_id,
];
$result = Database::insert($table, $params);
return $result ? 1 : 0;
}
/**
* Update a description, first you must set description_type, title, content, progress
* and session_id properties with the object CourseDescription.
@ -358,29 +320,6 @@ class CourseDescription
return $affected_rows;
}
/**
* Get description id by description type.
*
* @param int $description_type
*
* @return int description id
*/
public function get_id_by_description_type($description_type)
{
$table = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$course_id = api_get_course_int_id();
$sql = "SELECT id FROM $table
WHERE
c_id = $course_id AND
description_type = '".intval($description_type)."'";
$rs = Database::query($sql);
$row = Database::fetch_array($rs);
$description_id = $row['id'];
return $description_id;
}
/**
* Get description titles by default.
*

@ -47,8 +47,13 @@ class ExerciseLib
$show_answers = false,
$show_icon = false
) {
$course_id = empty($exercise->course_id) ? api_get_course_int_id() : $exercise->course_id;
$course = api_get_course_info_by_id($course_id);
$course_id = $exercise->course_id;
if (empty($course_id)) {
return '';
}
$course = $exercise->course;
// Change false to true in the following line to enable answer hinting
$debug_mark_answer = $show_answers;
// Reads question information

@ -2059,32 +2059,6 @@ class GroupManager
return $groups;
}
/**
* Remove all users that are not students and all users who have tutor status
* from the list.
*
* @param array $user_array_in
*
* @return array
*/
public static function filter_only_students($user_array_in)
{
$user_array_out = [];
foreach ($user_array_in as $this_user) {
if (api_get_session_id()) {
if ($this_user['status_session'] == 0) {
$user_array_out[] = $this_user;
}
} else {
if ($this_user['status_rel'] == STUDENT) {
$user_array_out[] = $this_user;
}
}
}
return $user_array_out;
}
/**
* Check if a user has access to a certain group tool.
*
@ -2285,45 +2259,6 @@ class GroupManager
return $groups;
}
/**
* @param array $userList
* @param array $groupInfo
*
* @return mixed
*/
public static function getNumberLeftFromGroupFromUserList($userList, $groupInfo)
{
$groupIid = (int) $groupInfo['iid'];
$category = self::get_category_from_group($groupIid);
$number_groups_per_user = $groupInfo['maximum_number_of_students'];
$categoryId = 0;
if ($category) {
$groups_per_user = $category['groups_per_user'];
$number_groups_per_user = $groups_per_user == self::GROUP_PER_MEMBER_NO_LIMIT ? self::INFINITE : $groups_per_user;
$categoryId = $category['id'];
}
$usersAdded = [];
foreach ($userList as &$userInfo) {
// find # of groups the user is enrolled in
$numberOfGroups = self::user_in_number_of_groups(
$userInfo['user_id'],
$categoryId
);
if (in_array($userInfo['user_id'], $usersAdded)) {
continue;
}
$usersAdded[] = $userInfo['user_id'];
// add # of groups to user list
$userInfo['number_groups_left'] = $number_groups_per_user - $numberOfGroups;
}
return $userList;
}
/**
* @param array $group_list
* @param int $category_id

@ -861,7 +861,6 @@ class Link extends Model
'LinkCategoryAdded',
api_get_user_id()
);
//api_set_default_visibility($category['id'], TOOL_LINK_CATEGORY);
}
}
@ -1430,81 +1429,6 @@ class Link extends Model
return $rv;
}
/**
* CSV file import functions.
*
* @author René Haentjens , Ghent University
*/
public static function import_link($linkdata)
{
// url, category_id, title, description, ...
// Field names used in the uploaded file
$known_fields = [
'url',
'category',
'title',
'description',
'on_homepage',
'hidden',
];
$hide_fields = [
'kw',
'kwd',
'kwds',
'keyword',
'keywords',
];
// All other fields are added to description, as "name:value".
// Only one hide_field is assumed to be present, <> is removed from value.
if (!($url = trim($linkdata['url'])) || !($title = trim($linkdata['title']))) {
return 0; // 0 = fail
}
$cat = ($catname = trim($linkdata['category'])) ? self::get_cat($catname) : 0;
$regs = []; // Will be passed to ereg()
$d = '';
foreach ($linkdata as $key => $value) {
if (!in_array($key, $known_fields)) {
if (in_array($key, $hide_fields) && ereg(
'^<?([^>]*)>?$',
$value,
$regs
)
) { // possibly in <...>
if (($kwlist = trim($regs[1])) != '') {
$kw = '<i kw="'.htmlspecialchars($kwlist).'">';
} else {
$kw = '';
}
// i.e. assume only one of the $hide_fields will be present
// and if found, hide the value as expando property of an <i> tag
} elseif (trim($value)) {
$d .= ', '.$key.':'.$value;
}
}
}
if (!empty($d)) {
$d = substr($d, 2).' - ';
}
return self::put_link(
$url,
$cat,
$title,
$kw.ereg_replace(
'\[((/?(b|big|i|small|sub|sup|u))|br/)\]',
'<\\1>',
htmlspecialchars($d.$linkdata['description'])
).($kw ? '</i>' : ''),
$linkdata['on_homepage'] ? '1' : '0',
$linkdata['hidden'] ? '1' : '0'
);
// i.e. allow some BBcode tags, e.g. [b]...[/b]
}
/**
* This function checks if the url is a vimeo link.
*
@ -1514,7 +1438,7 @@ class Link extends Model
*/
public static function isVimeoLink($url)
{
$isLink = strrpos($url, "vimeo.com");
$isLink = strrpos($url, 'vimeo.com');
return $isLink;
}
@ -1553,9 +1477,9 @@ class Link extends Model
*/
public static function is_youtube_link($url)
{
$is_youtube_link = strrpos($url, "youtube") || strrpos(
$is_youtube_link = strrpos($url, 'youtube') || strrpos(
$url,
"youtu.be"
'youtu.be'
);
return $is_youtube_link;
@ -1876,6 +1800,9 @@ class Link extends Model
*/
public static function getCategoryForm($id, $action)
{
$id = (int) $id;
$action = Security::remove_XSS($action);
$form = new FormValidator(
'category',
'post',
@ -1908,7 +1835,7 @@ class Link extends Model
public static function getCategory($id)
{
$table = Database::get_course_table(TABLE_LINK_CATEGORY);
$id = intval($id);
$id = (int) $id;
$courseId = api_get_course_int_id();
if (empty($id) || empty($courseId)) {

@ -989,35 +989,6 @@ class MessageManager
}
}
/**
* update messages by user id and message id.
*
* @param int $user_id
* @param int $message_id
*
* @return bool
*/
public static function update_message($user_id, $message_id)
{
$user_id = (int) $user_id;
$message_id = (int) $message_id;
if (empty($user_id) || empty($message_id)) {
return false;
}
$table = Database::get_main_table(TABLE_MESSAGE);
$sql = "UPDATE $table SET
msg_status = '".MESSAGE_STATUS_NEW."'
WHERE
msg_status <> ".MESSAGE_STATUS_OUTBOX." AND
user_receiver_id = ".$user_id." AND
id = '".$message_id."'";
Database::query($sql);
return true;
}
/**
* @param int $user_id
* @param int $message_id
@ -1044,31 +1015,6 @@ class MessageManager
Database::query($sql);
}
/**
* get messages by user id and message id.
*
* @param int $user_id
* @param int $message_id
*
* @return array
*/
public static function get_message_by_user($user_id, $message_id)
{
$user_id = (int) $user_id;
$message_id = (int) $message_id;
if (empty($user_id) || empty($message_id)) {
return false;
}
$table = Database::get_main_table(TABLE_MESSAGE);
$query = "SELECT * FROM $table
WHERE user_receiver_id=".$user_id." AND id='".$message_id."'";
$result = Database::query($query);
return $row = Database::fetch_array($result);
}
/**
* get messages by group id.
*
@ -2008,19 +1954,6 @@ class MessageManager
}
}
/**
* Sort date by desc from a multi-dimensional array.
*
* @param array $array1 first array to compare
* @param array $array2 second array to compare
*
* @return bool
*/
public function order_desc_date($array1, $array2)
{
return strcmp($array2['send_date'], $array1['send_date']);
}
/**
* @param int $messageId
*

@ -450,25 +450,6 @@ class Notification extends Model
$content = $content.'<br /><br />'.$linkToNewMessage;
}
/*$courseInfo = api_get_course_info();
// Add course info
if (!empty($courseInfo)) {
$sessionId = api_get_session_id();
if (empty($sessionId)) {
$courseNotification = sprintf(get_lang('ThisEmailWasSentViaCourseX'), $courseInfo['title']);
} else {
$sessionInfo = api_get_session_info($sessionId);
if (!empty($sessionInfo)) {
$courseNotification = sprintf(
get_lang('ThisEmailWasSentViaCourseXInSessionX'),
$courseInfo['title'],
$sessionInfo['title']
);
}
}
$content = $content.'<br /><br />'.$courseNotification;
}*/
// You have received this message because you are subscribed text
$content = $content.'<br /><hr><i>'.
sprintf(

@ -736,35 +736,6 @@ class SessionManager
return $formattedSessions;
}
/**
* Get total of records for progress of learning paths in the given session.
*
* @param int session id
*
* @return int
*/
public static function get_count_session_lp_progress($sessionId = 0)
{
$tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
$tbl_lp_view = Database::get_course_table(TABLE_LP_VIEW);
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
$sessionId = intval($sessionId);
$sql = "SELECT count(*) as total_rows
FROM $tbl_lp_view v
INNER JOIN $tbl_lp l ON l.id = v.lp_id
INNER JOIN $tbl_user u ON u.user_id = v.user_id
INNER JOIN $tbl_course c
WHERE v.session_id = ".$sessionId;
$result_rows = Database::query($sql);
$row = Database::fetch_array($result_rows);
$num = $row['total_rows'];
return $num;
}
/**
* Gets the progress of learning paths in the given session.
*
@ -786,8 +757,6 @@ class SessionManager
//escaping vars
$sessionId = $sessionId == 'T' ? 'T' : intval($sessionId);
$courseId = intval($courseId);
$date_from = Database::escape_string($date_from);
$date_to = Database::escape_string($date_to);
//tables
$session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
@ -795,18 +764,6 @@ class SessionManager
$tbl_course_lp_view = Database::get_course_table(TABLE_LP_VIEW);
$course = api_get_course_info_by_id($courseId);
//getting all the students of the course
//we are not using this because it only returns user ids
/* if (empty($sessionId)
{
// Registered students in a course outside session.
$users = CourseManager::get_student_list_from_course_code($course_code);
} else {
// Registered students in session.
$users = CourseManager::get_student_list_from_course_code($course_code, true, $sessionId);
} */
$sessionCond = 'and session_id = %s';
if ($sessionId == 'T') {
$sessionCond = '';
@ -2149,7 +2106,7 @@ class SessionManager
$courseInfo,
$status = null
) {
$sessionId = intval($sessionId);
$sessionId = (int) $sessionId;
$courseId = $courseInfo['real_id'];
if (empty($sessionId) || empty($courseId)) {
@ -2158,7 +2115,7 @@ class SessionManager
$statusCondition = null;
if (isset($status) && !is_null($status)) {
$status = intval($status);
$status = (int) $status;
$statusCondition = " AND status = $status";
}
@ -2254,7 +2211,7 @@ class SessionManager
) {
$table = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$tableSessionCourse = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$sessionId = intval($sessionId);
$sessionId = (int) $sessionId;
if (empty($sessionId) || empty($userList) || empty($courseInfo)) {
return false;
@ -2441,8 +2398,6 @@ class SessionManager
$session_id = (int) $session_id;
$user_id = (int) $user_id;
$tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
@ -2541,7 +2496,7 @@ class SessionManager
$removeExistingCoursesWithUsers = true,
$copyEvaluation = false
) {
$sessionId = intval($sessionId);
$sessionId = (int) $sessionId;
if (empty($sessionId) || empty($courseList)) {
return false;
@ -2811,7 +2766,6 @@ class SessionManager
// Get course code
$course_code = CourseManager::get_course_code_from_course_id($course_id);
$course_id = intval($course_id);
if (empty($course_code)) {
return false;
@ -2959,6 +2913,8 @@ class SessionManager
{
$table = Database::get_main_table(TABLE_MAIN_SESSION);
$name = Database::escape_string(trim($name));
$sessionId = (int) $sessionId;
if (empty($name)) {
return false;
}
@ -3310,7 +3266,7 @@ class SessionManager
public static function get_session_category($id)
{
$table = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
$id = intval($id);
$id = (int) $id;
$sql = "SELECT id, name, date_start, date_end
FROM $table
WHERE id= $id";
@ -3330,8 +3286,9 @@ class SessionManager
*/
public static function getSessionImage($id)
{
$id = (int) $id;
$extraFieldValuesTable = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES);
$sql = "SELECT value FROM extra_field_values WHERE field_id = 16 AND item_id = ".intval($id);
$sql = "SELECT value FROM $extraFieldValuesTable WHERE field_id = 16 AND item_id = ".$id;
$result = Database::query($sql);
if (Database::num_rows($result) > 0) {
while ($row = Database::fetch_array($result, 'ASSOC')) {
@ -3429,9 +3386,9 @@ class SessionManager
$data = Database::store_result($result, 'ASSOC');
return $data;
} else {
return false;
}
return false;
}
/**
@ -3683,8 +3640,8 @@ class SessionManager
$tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
$tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
$userId = intval($userId);
$sessionId = intval($sessionId);
$userId = (int) $userId;
$sessionId = (int) $sessionId;
$select = " SELECT * ";
if (api_is_multiple_url_enabled()) {
@ -3696,7 +3653,7 @@ class SessionManager
sru.session_id = '$sessionId' AND
sru.relation_type = '".SESSION_RELATION_TYPE_RRHH."' AND
access_url_id = ".api_get_current_access_url_id()."
";
";
} else {
$sql = "$select FROM $tbl_session s
INNER JOIN $tbl_session_rel_user sru
@ -4105,7 +4062,7 @@ class SessionManager
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$session_id = intval($session_id);
$session_id = (int) $session_id;
$course_name = Database::escape_string($course_name);
// select the courses
@ -4147,7 +4104,7 @@ class SessionManager
{
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$session_id = intval($session_id);
$session_id = (int) $session_id;
// select the courses
$sql = "SELECT COUNT(c.code) count
@ -4278,7 +4235,7 @@ class SessionManager
public static function get_sessions_by_general_coach($user_id, $asPlatformAdmin = false)
{
$session_table = Database::get_main_table(TABLE_MAIN_SESSION);
$user_id = intval($user_id);
$user_id = (int) $user_id;
// Session where we are general coach
$sql = "SELECT DISTINCT *
@ -4413,7 +4370,7 @@ class SessionManager
$params['promotion_id'] = $promotion_id;
if (!empty($list)) {
foreach ($list as $session_id) {
$session_id = intval($session_id);
$session_id = (int) $session_id;
Database::update($table, $params, ['id = ?' => $session_id]);
}
}
@ -4784,7 +4741,7 @@ SQL;
$table_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$table_session = Database::get_main_table(TABLE_MAIN_SESSION);
$url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
$courseId = intval($courseId);
$courseId = (int) $courseId;
$urlId = api_get_current_access_url_id();
if (empty($courseId)) {
@ -5811,8 +5768,8 @@ SQL;
public static function getCoachesByCourseSession($sessionId, $courseId)
{
$table = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$sessionId = intval($sessionId);
$courseId = intval($courseId);
$sessionId = (int) $sessionId;
$courseId = (int) $courseId;
$sql = "SELECT user_id FROM $table
WHERE
@ -6536,64 +6493,6 @@ SQL;
}
}
/**
* @param int $sessionId
* @param int $courseId
*/
public static function addCourseIntroduction($sessionId, $courseId)
{
// @todo create a tool intro lib
$sessionId = intval($sessionId);
$courseId = intval($courseId);
$TBL_INTRODUCTION = Database::get_course_table(TABLE_TOOL_INTRO);
$sql = "SELECT * FROM $TBL_INTRODUCTION WHERE c_id = $courseId";
$result = Database::query($sql);
$result = Database::store_result($result, 'ASSOC');
if (!empty($result)) {
foreach ($result as $result) {
// @todo check if relation exits.
$result['session_id'] = $sessionId;
Database::insert($TBL_INTRODUCTION, $result);
}
}
}
/**
* @param int $sessionId
* @param int $courseId
*/
public static function removeCourseIntroduction($sessionId, $courseId)
{
$sessionId = intval($sessionId);
$courseId = intval($courseId);
$TBL_INTRODUCTION = Database::get_course_table(TABLE_TOOL_INTRO);
$sql = "DELETE FROM $TBL_INTRODUCTION
WHERE c_id = $courseId AND session_id = $sessionId";
Database::query($sql);
}
/**
* @param int $sessionId
* @param int $courseId
*/
public static function addCourseDescription($sessionId, $courseId)
{
/* $description = new CourseDescription();
$descriptions = $description->get_descriptions($courseId);
foreach ($descriptions as $description) {
} */
}
/**
* @param int $sessionId
* @param int $courseId
*/
public static function removeCourseDescription($sessionId, $courseId)
{
}
/**
* @param array $userSessionList format see self::importSessionDrhCSV()
* @param bool $sendEmail
@ -7049,7 +6948,7 @@ SQL;
*/
public static function sessionHasCourse($sessionId, $courseCode)
{
$sessionId = intval($sessionId);
$sessionId = (int) $sessionId;
$courseCode = Database::escape_string($courseCode);
$courseTable = Database::get_main_table(TABLE_MAIN_COURSE);
$sessionRelCourseTable = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
@ -7074,55 +6973,6 @@ SQL;
return false;
}
/**
* Get the list of course coaches.
*
* @return array The list
*/
public static function getAllCourseCoaches()
{
$coaches = [];
$scuTable = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$userTable = Database::get_main_table(TABLE_MAIN_USER);
$idResult = Database::select('DISTINCT user_id', $scuTable, [
'where' => [
'status = ?' => 2,
],
]);
if ($idResult != false) {
foreach ($idResult as $idData) {
$userResult = Database::select(
'user_id, lastname, firstname, username',
$userTable,
[
'where' => [
'user_id = ?' => $idData['user_id'],
],
],
'first'
);
if ($userResult != false) {
$coaches[] = [
'id' => $userResult['user_id'],
'lastname' => $userResult['lastname'],
'firstname' => $userResult['firstname'],
'username' => $userResult['username'],
'completeName' => api_get_person_name(
$userResult['firstname'],
$userResult['lastname']
),
];
}
}
}
return $coaches;
}
/**
* Calculate the total user time in the platform.
*
@ -7134,7 +6984,7 @@ SQL;
*/
public static function getTotalUserTimeInPlatform($userId, $from = '', $until = '')
{
$userId = intval($userId);
$userId = (int) $userId;
$trackLoginTable = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
$whereConditions = [
'login_user_id = ? ' => $userId,
@ -7194,6 +7044,8 @@ SQL;
$tableUser = Database::get_main_table(TABLE_MAIN_USER);
$table = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$sessionId = (int) $sessionId;
if (empty($sessionId)) {
return [];
}
@ -7214,7 +7066,7 @@ SQL;
ON scu.user_id = u.id
WHERE
$courseCondition
scu.session_id = ".intval($sessionId)."
scu.session_id = ".$sessionId."
GROUP BY u.id";
$result = Database::query($sql);
@ -7532,7 +7384,7 @@ SQL;
public static function getDescriptionFromSessionId($sessionId)
{
// Init variables
$sessionId = intval($sessionId);
$sessionId = (int) $sessionId;
$description = '';
// Check if session id is valid
if ($sessionId > 0) {
@ -7750,7 +7602,7 @@ SQL;
case 1:
return get_lang('ReadOnly');
case 2:
return get_lang('Visible');
return get_lang('Visible');
case 3:
return api_ucfirst(get_lang('Invisible'));
}
@ -8995,77 +8847,6 @@ SQL;
return $listResults;
}
/**
* Return HTML code for displaying session_course_for_coach.
*
* @param $userId
*
* @return string
*/
public static function getHtmlNamedSessionCourseForCoach($userId)
{
$htmlRes = '';
$listInfo = self::getNamedSessionCourseForCoach($userId);
foreach ($listInfo as $i => $listCoursesInfo) {
$courseInfo = $listCoursesInfo['course'];
$courseCode = $listCoursesInfo['course']['code'];
$listParamsCourse = [];
$listParamsCourse['icon'] = '<div style="float:left">
<input style="border:none;" type="button" onclick="$(\'#course-'.$courseCode.'\').toggle(\'fast\')" value="+" /></div>'.
Display::return_icon('blackboard.png', $courseInfo['title'], [], ICON_SIZE_LARGE);
$listParamsCourse['link'] = '';
$listParamsCourse['title'] = Display::tag(
'a',
$courseInfo['title'],
['href' => $listParamsCourse['link']]
);
$htmlCourse = '<div class="well" style="border-color:#27587D">'.
CourseManager::course_item_html($listParamsCourse, true);
// for each category of session
$htmlCatSessions = '';
foreach ($listCoursesInfo['sessionCatList'] as $j => $listCatSessionsInfo) {
// we got an array of session categories
$catSessionId = $listCoursesInfo['sessionCatList'][$j]['catSessionId'];
$catSessionName = $listCoursesInfo['sessionCatList'][$j]['catSessionName'];
$listParamsCatSession['icon'] = Display::return_icon('folder_blue.png', $catSessionName, [], ICON_SIZE_LARGE);
$listParamsCatSession['link'] = '';
$listParamsCatSession['title'] = $catSessionName;
$marginShift = 20;
if ($catSessionName != '') {
$htmlCatSessions .= '<div style="margin-left:'.$marginShift.'px;">'.
CourseManager::course_item_html($listParamsCatSession, true).'</div>';
$marginShift = 40;
}
// for each sessions
$listCatSessionSessionList = $listCoursesInfo['sessionCatList'][$j]['sessionList'];
$htmlSession = '';
foreach ($listCatSessionSessionList as $k => $listSessionInfo) {
// we got an array of session info
$sessionId = $listSessionInfo['sessionId'];
$sessionName = $listSessionInfo['sessionName'];
$listParamsSession['icon'] = Display::return_icon('blackboard_blue.png', $sessionName, [], ICON_SIZE_LARGE);
$listParamsSession['link'] = '';
$linkToCourseSession = $courseInfo['course_public_url'].'?id_session='.$sessionId;
$listParamsSession['title'] =
$sessionName.'<div style="font-weight:normal; font-style:italic">
<a href="'.$linkToCourseSession.'">'.get_lang('GoToCourseInsideSession').'</a>
</div>';
$htmlSession .= '<div style="margin-left:'.$marginShift.'px;">'.
CourseManager::course_item_html($listParamsSession, true).'</div>';
}
$htmlCatSessions .= $htmlSession;
}
$htmlRes .= $htmlCourse.'<div style="display:none" id="course-'.$courseCode.'">'.$htmlCatSessions.'</div></div>';
}
return $htmlRes;
}
/**
* @param int $userId
* @param int $courseId
@ -9093,7 +8874,7 @@ SQL;
*/
public static function redirectToSession()
{
$sessionId = ChamiloSession::read('session_redirect');
$sessionId = (int) ChamiloSession::read('session_redirect');
$onlyOneCourseSessionToRedirect = ChamiloSession::read('only_one_course_session_redirect');
if ($sessionId) {
$sessionInfo = api_get_session_info($sessionId);
@ -9213,7 +8994,6 @@ SQL;
return ['collapsed' => $collapsed, 'collapsable_link' => $link];
}
/**
* Converts "start date" and "end date" to "From start date to end date" string.
*

Loading…
Cancel
Save