Skip to content

Commit

Permalink
Admin: Add config "multiple_access_url_show_shared_course_marker"
Browse files Browse the repository at this point in the history
Add icon in userportal.php if course was shared in other portals
Add url list in course_edit.php

See BT#17783
  • Loading branch information
jmontoyaa committed Oct 1, 2020
1 parent 7c94fa0 commit ea5a077
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 53 deletions.
12 changes: 10 additions & 2 deletions main/admin/course_edit.php
Expand Up @@ -320,6 +320,15 @@
true
);

if (api_get_configuration_value('multiple_access_url_show_shared_course_marker')) {
$urls = UrlManager::get_access_url_from_course($courseId);
$urlToString = '';
foreach ($urls as $url) {
$urlToString .= $url['url'];
}
$form->addLabel('URLs', $urlToString);
}

$htmlHeadXtra[] = '
<script>
$(function() {
Expand Down Expand Up @@ -554,7 +563,6 @@ function valide() {
}
</script>";

// Display the form
$form->display();

Display:: display_footer();
Display::display_footer();
45 changes: 36 additions & 9 deletions main/inc/lib/course.lib.php
Expand Up @@ -3833,6 +3833,9 @@ public static function returnSpecialCourses(

$courseList = [];
if ($number_of_courses > 0) {
$hideCourseNotification = api_get_configuration_value('hide_course_notification');
$showUrlMarker = api_get_configuration_value('multiple_access_url_show_shared_course_marker') &&
(api_is_platform_admin() || api_is_teacher());
while ($course = Database::fetch_array($rs_special_course)) {
$course_info = api_get_course_info($course['code']);
$courseId = $course_info['real_id'];
Expand All @@ -3841,7 +3844,7 @@ public static function returnSpecialCourses(
}

$params = [];
//Param (course_code) needed to get the student info in page "My courses"
// Param (course_code) needed to get the student info in page "My courses"
$params['course_code'] = $course['code'];
$params['code'] = $course['code'];
// Get notifications.
Expand All @@ -3853,9 +3856,7 @@ public static function returnSpecialCourses(
} else {
$course_info['status'] = $courseUserInfo['status'];
}
$show_notification = !api_get_configuration_value('hide_course_notification')
? Display::show_notification($course_info)
: '';
$show_notification = !$hideCourseNotification ? Display::show_notification($course_info) : '';
$params['edit_actions'] = '';
$params['document'] = '';
if (api_is_platform_admin()) {
Expand Down Expand Up @@ -3885,7 +3886,12 @@ public static function returnSpecialCourses(
null
);

if (api_get_setting('display_coursecode_in_courselist') == 'true') {
$params['url_marker'] = '';
if ($showUrlMarker) {
$params['url_marker'] = self::getUrlMarker($courseId);
}

if (api_get_setting('display_coursecode_in_courselist') === 'true') {
$params['code_course'] = '('.$course_info['visual_code'].')';
}

Expand Down Expand Up @@ -4082,6 +4088,9 @@ public static function returnCoursesCategories(
// Browse through all courses.
$courseAdded = [];
$courseList = [];
$hideNotification = api_get_configuration_value('hide_course_notification');
$showUrlMarker = api_get_configuration_value('multiple_access_url_show_shared_course_marker') &&
(api_is_platform_admin() || api_is_teacher());

while ($row = Database::fetch_array($result)) {
$course_info = api_get_course_info_by_id($row['id']);
Expand All @@ -4103,13 +4112,11 @@ public static function returnCoursesCategories(
$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)
: '';
$showNotification = !$hideNotification ? Display::show_notification($course_info) : '';
$iconName = basename($course_info['course_image']);

$params = [];
//Param (course_code) needed to get the student process
// Param (course_code) needed to get the student process
$params['course_code'] = $row['course_code'];
$params['code'] = $row['course_code'];

Expand Down Expand Up @@ -4177,6 +4184,11 @@ public static function returnCoursesCategories(
$params['code_course'] = '('.$course_info['visual_code'].') ';
}

$params['url_marker'] = '';
if ($showUrlMarker) {
$params['url_marker'] = self::getUrlMarker($course_info['real_id']);
}

$params['current_user_is_teacher'] = false;
/** @var array $teacher */
foreach ($teachers as $teacher) {
Expand Down Expand Up @@ -7112,4 +7124,19 @@ private static function fillCourse($courseInfo, $params, $authorId = 0)
$courseFieldValue = new ExtraFieldValue('course');
$courseFieldValue->saveFieldValues($params);
}

public static function getUrlMarker($courseId)
{
if (UrlManager::getCountAccessUrlFromCourse($courseId) > 1) {
return '&nbsp;'.Display::returnFontAwesomeIcon(
'link',
null,
null,
null,
get_lang('CourseUsedInOtherURL')
);
}

return '';
}
}
9 changes: 5 additions & 4 deletions main/inc/lib/display.lib.php
Expand Up @@ -2639,15 +2639,16 @@ public static function toolbarAction($id, $content, $colsWidth = [])
* @param string $name The icon name. Example: "mail-reply"
* @param int|string $size Optional. The size for the icon. (Example: lg, 2, 3, 4, 5)
* @param bool $fixWidth Optional. Whether add the fw class
* @param string $additionalClass Optional. Additional class
*
* @param string $additionalClass
* @param string $title
* @return string
*/
public static function returnFontAwesomeIcon(
$name,
$size = '',
$fixWidth = false,
$additionalClass = ''
$additionalClass = '',
$title = ''
) {
$className = "fa fa-$name";

Expand All @@ -2671,7 +2672,7 @@ public static function returnFontAwesomeIcon(
$className .= " $additionalClass";
}

$icon = self::tag('em', null, ['class' => $className]);
$icon = self::tag('em', null, ['class' => $className, 'title' => $title]);

return "$icon ";
}
Expand Down
77 changes: 48 additions & 29 deletions main/inc/lib/urlmanager.lib.php
Expand Up @@ -479,7 +479,7 @@ public static function relationUrlUsergroupExist($userGroupId, $urlId)
{
$table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USERGROUP);
$sql = "SELECT usergroup_id FROM $table
WHERE
WHERE
access_url_id = ".intval($urlId)." AND
usergroup_id = ".intval($userGroupId);
$result = Database::query($sql);
Expand Down Expand Up @@ -534,8 +534,8 @@ public static function add_users_to_urls($user_list, $url_list)
$count = self::relation_url_user_exist($user_id, $urlId);
if (0 == $count) {
$sql = "INSERT INTO $table
SET
user_id = ".intval($user_id).",
SET
user_id = ".intval($user_id).",
access_url_id = ".intval($urlId);
$result = Database::query($sql);
if ($result) {
Expand Down Expand Up @@ -672,7 +672,7 @@ public static function relationUrlCourseCategoryExist($categoryCourseId, $urlId)
{
$table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY);
$sql = "SELECT course_category_id FROM $table
WHERE
WHERE
access_url_id = ".intval($urlId)." AND
course_category_id = ".intval($categoryCourseId);
$result = Database::query($sql);
Expand Down Expand Up @@ -861,8 +861,8 @@ public static function delete_url_rel_user($user_id, $urlId)
$result = true;
if (!empty($user_id) && !empty($urlId)) {
$sql = "DELETE FROM $table
WHERE
user_id = ".intval($user_id)." AND
WHERE
user_id = ".intval($user_id)." AND
access_url_id = ".intval($urlId);
$result = Database::query($sql);
}
Expand Down Expand Up @@ -947,7 +947,7 @@ public static function deleteUrlRelCourseCategory($userGroupId, $urlId)
{
$table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY);
$sql = "DELETE FROM $table
WHERE
WHERE
course_category_id = '".intval($userGroupId)."' AND
access_url_id=".intval($urlId)." ";
$result = Database::query($sql);
Expand All @@ -969,8 +969,8 @@ public static function delete_url_rel_session($session_id, $urlId)
{
$table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
$sql = "DELETE FROM $table
WHERE
session_id = ".intval($session_id)." AND
WHERE
session_id = ".intval($session_id)." AND
access_url_id=".intval($urlId)." ";
$result = Database::query($sql, 'ASSOC');

Expand All @@ -992,8 +992,8 @@ public static function update_urls_rel_user($user_list, $urlId)
$table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$urlId = (int) $urlId;

$sql = "SELECT user_id
FROM $table
$sql = "SELECT user_id
FROM $table
WHERE access_url_id = $urlId";
$result = Database::query($sql);
$existing_users = [];
Expand Down Expand Up @@ -1087,7 +1087,7 @@ public static function update_urls_rel_usergroup($userGroupList, $urlId)
{
$table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USERGROUP);

$sql = "SELECT usergroup_id FROM $table
$sql = "SELECT usergroup_id FROM $table
WHERE access_url_id = ".intval($urlId);
$result = Database::query($sql);
$existingItems = [];
Expand Down Expand Up @@ -1121,8 +1121,8 @@ public static function update_urls_rel_usergroup($userGroupList, $urlId)
public static function updateUrlRelCourseCategory($list, $urlId)
{
$table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY);
$sql = "SELECT course_category_id
FROM $table
$sql = "SELECT course_category_id
FROM $table
WHERE access_url_id = ".intval($urlId);
$result = Database::query($sql);
$existingItems = [];
Expand Down Expand Up @@ -1171,7 +1171,7 @@ public static function update_urls_rel_session($session_list, $urlId)
{
$table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);

$sql = "SELECT session_id FROM $table
$sql = "SELECT session_id FROM $table
WHERE access_url_id=".intval($urlId);
$result = Database::query($sql);
$existing_sessions = [];
Expand Down Expand Up @@ -1211,15 +1211,14 @@ public static function get_access_url_from_user($user_id)
{
$table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$table_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL);
$sql = "SELECT url, access_url_id
FROM $table url_rel_user
$sql = "SELECT url, access_url_id
FROM $table url_rel_user
INNER JOIN $table_url u
ON (url_rel_user.access_url_id = u.id)
WHERE user_id = ".intval($user_id);
$result = Database::query($sql);
$url_list = Database::store_result($result, 'ASSOC');

return $url_list;
return Database::store_result($result, 'ASSOC');
}

/**
Expand All @@ -1231,15 +1230,35 @@ public static function get_access_url_from_course($courseId)
{
$table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
$table_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL);
$sql = "SELECT url, access_url_id FROM $table c
$courseId = (int) $courseId;
$sql = "SELECT url, access_url_id FROM $table c
INNER JOIN $table_url u
ON (c.access_url_id = u.id)
WHERE c_id = ".intval($courseId);
WHERE c_id = $courseId";

$result = Database::query($sql);
$url_list = Database::store_result($result, 'ASSOC');

return $url_list;
return Database::store_result($result, 'ASSOC');
}

public static function getCountAccessUrlFromCourse($courseId)
{
$courseId = (int) $courseId;
$table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
$table_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL);
$sql = "SELECT count(u.id) count FROM $table c
INNER JOIN $table_url u
ON (c.access_url_id = u.id)
WHERE c_id = $courseId ";

$result = Database::query($sql);
if ($result) {
$row = Database::fetch_array($result, 'ASSOC');

return (int) $row['count'];
}

return 0;
}

/**
Expand All @@ -1251,8 +1270,8 @@ public static function get_access_url_from_session($sessionId)
{
$table_url_rel_session = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
$table_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL);
$sql = "SELECT url, access_url_id
FROM $table_url_rel_session url_rel_session
$sql = "SELECT url, access_url_id
FROM $table_url_rel_session url_rel_session
INNER JOIN $table_url u
ON (url_rel_session.access_url_id = u.id)
WHERE session_id = ".intval($sessionId);
Expand All @@ -1270,7 +1289,7 @@ public static function get_access_url_from_session($sessionId)
public static function get_url_id($url)
{
$table = Database::get_main_table(TABLE_MAIN_ACCESS_URL);
$sql = "SELECT id FROM $table
$sql = "SELECT id FROM $table
WHERE url = '".Database::escape_string($url)."'";
$result = Database::query($sql);
$urlId = Database::result($result, 0, 0);
Expand All @@ -1294,10 +1313,10 @@ public static function searchCourseCategoryAjax($needle)
$needle = api_convert_encoding($needle, $charset, 'utf-8');
$needle = Database::escape_string($needle);
// search courses where username or firstname or lastname begins likes $needle
$sql = 'SELECT id, name
$sql = 'SELECT id, name
FROM '.Database::get_main_table(TABLE_MAIN_CATEGORY).' u
WHERE
name LIKE "'.$needle.'%" AND
WHERE
name LIKE "'.$needle.'%" AND
(parent_id IS NULL or parent_id = 0)
ORDER BY name
LIMIT 11';
Expand Down
7 changes: 5 additions & 2 deletions main/install/configuration.dist.php
Expand Up @@ -1616,7 +1616,7 @@
//$_configuration['show_my_lps_page'] = false;

// When exercise is finished send results by email to users, depending the settings below:
$_configuration['exercise_finished_email_settings'] = [
/*$_configuration['exercise_finished_email_settings'] = [
'send_by_status' => [
[
'status' => 5, // 5 = student that is doing the exercise send to the Chamilo inbox + email
Expand All @@ -1633,7 +1633,10 @@
'type' => 'only_score',
],
],
];
];*/

// Shows a marker if the course was shared in other portals.
//$_configuration['multiple_access_url_show_shared_course_marker'] = false;

// KEEP THIS AT THE END
// -------- Custom DB changes
Expand Down
1 change: 1 addition & 0 deletions main/lang/english/trad4all.inc.php
Expand Up @@ -8672,4 +8672,5 @@
$MyLps = "My learning paths";
$LastVisitedLp = "Last visited learning path";
$YouDidNotVisitALpHereTheLpList = "You haven't visited any learning paths yet, here is the list of your learning paths.";
$CourseUsedInOtherURL = "This course is used in at least one other portal";
?>
1 change: 1 addition & 0 deletions main/lang/french/trad4all.inc.php
Expand Up @@ -8604,4 +8604,5 @@
$MyLps = "Mes parcours";
$LastVisitedLp = "Dernier parcours visité";
$YouDidNotVisitALpHereTheLpList = "Vous n'avez encore visité aucun parcours, voici la liste de vos parcours.";
$CourseUsedInOtherURL = "Ce cours est utilisé sur au moins un autre portail";
?>
1 change: 1 addition & 0 deletions main/lang/spanish/trad4all.inc.php
Expand Up @@ -8700,4 +8700,5 @@
$MyLps = "Mis lecciones";
$LastVisitedLp = "Última lección visitada";
$YouDidNotVisitALpHereTheLpList = "Aún no ha visitado una lección, aquí está la lista de sus lecciones.";
$CourseUsedInOtherURL = "Este curso es usado en otro portal";
?>

0 comments on commit ea5a077

Please sign in to comment.