Moved show_notification from user_portal.php to display.lib.php

skala
ywarnier 14 years ago
parent b07956be40
commit 4af854dba7
  1. 2
      main/inc/lib/course.lib.php
  2. 91
      main/inc/lib/display.lib.php
  3. 36
      main/inc/lib/social.lib.php
  4. 94
      user_portal.php

@ -2705,7 +2705,7 @@ class CourseManager {
$my_course['s'] = $course['status'];
// For each course, get if there is any notification icon to show
// (something that would have changed since the user's last visit).
$show_notification = show_notification($my_course);
$show_notification = Display :: show_notification($my_course);
// New code displaying the user's status in respect to this course.
$status_icon = Display::return_icon('blackboard.png', get_lang('Course'), array('width' => '48px'));

@ -973,4 +973,95 @@ class Display {
}
}
}
/**
* Returns the "what's new" icon notifications
*
* The general logic of this function is to track the last time the user
* entered the course and compare to what has changed inside this course
* since then, based on the item_property table inside this course. Note that,
* if the user never entered the course before, he will not see notification
* icons. This function takes session ID into account (if any) and only shows
* the corresponding notifications.
* @param array Course information array, containing at least elements 'db' and 'k'
* @return string The HTML link to be shown next to the course
*/
function show_notification($my_course) {
$statistic_database = Database :: get_statistic_database();
$user_id = api_get_user_id();
$course_database = $my_course['db'];
$course_tool_table = Database::get_course_table(TABLE_TOOL_LIST, $course_database);
$tool_edit_table = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_database);
$course_group_user_table = Database :: get_course_table(TABLE_GROUP_USER, $course_database);
$t_track_e_access = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
// Get the user's last access dates to all tools of this course
$sqlLastTrackInCourse = "SELECT * FROM $t_track_e_access
USE INDEX (access_cours_code, access_user_id)
WHERE access_cours_code = '".$my_course['k']."'
AND access_user_id = '$user_id' AND access_session_id ='".$my_course['id_session']."'";
$resLastTrackInCourse = Database::query($sqlLastTrackInCourse);
$oldestTrackDate = '3000-01-01 00:00:00';
while ($lastTrackInCourse = Database::fetch_array($resLastTrackInCourse)) {
$lastTrackInCourseDate[$lastTrackInCourse['access_tool']] = $lastTrackInCourse['access_date'];
if ($oldestTrackDate > $lastTrackInCourse['access_date']) {
$oldestTrackDate = $lastTrackInCourse['access_date'];
}
}
// Get the last edits of all tools of this course.
$sql = "SELECT tet.*, tet.lastedit_date last_date, tet.tool tool, tet.ref ref,
tet.lastedit_type type, tet.to_group_id group_id,
ctt.image image, ctt.link link
FROM $tool_edit_table tet, $course_tool_table ctt
WHERE tet.lastedit_date > '$oldestTrackDate'
AND ctt.name = tet.tool
AND ctt.visibility = '1'
AND tet.lastedit_user_id != $user_id AND tet.id_session = '".$my_course['id_session']."'
ORDER BY tet.lastedit_date";
$res = Database::query($sql);
// Get the group_id's with user membership.
$group_ids = GroupManager :: get_group_ids($course_database, $user_id);
$group_ids[] = 0; //add group 'everyone'
// Filter all selected items.
while ($res && ($item_property = Database::fetch_array($res))) {
// First thing to check is if the user never entered the tool
// or if his last visit was earlier than the last modification.
if ((!isset ($lastTrackInCourseDate[$item_property['tool']]) || $lastTrackInCourseDate[$item_property['tool']] < $item_property['lastedit_date'])
// Drop the tool elements that are part of a group that the
// user is not part of.
&& ((in_array($item_property['to_group_id'], $group_ids)
// Drop the dropbox, notebook and chat tools because we don't care.
&& ($item_property['tool'] != TOOL_DROPBOX && $item_property['tool'] != TOOL_NOTEBOOK && $item_property['tool'] != TOOL_CHAT)))
// Take only what's visible or invisible but where the user is a teacher or where the visibility is unset.
&& ($item_property['visibility'] == '1' || ($my_course['s'] == '1' && $item_property['visibility'] == '0') || !isset($item_property['visibility']))) {
// Also drop announcements and events that are not for the user or his group.
if (($item_property['tool'] == TOOL_ANNOUNCEMENT || $item_property['tool'] == TOOL_CALENDAR_EVENT) && (($item_property['to_user_id'] != $user_id ) && (!isset($item_property['to_group_id']) || !in_array($item_property['to_group_id'], $group_ids)))) continue;
// If it's a survey, make sure the user's invited. Otherwise drop it.
if ($item_property['tool'] == TOOL_SURVEY) {
$survey_info = survey_manager::get_survey($item_property['ref'], 0, $my_course['k']);
$invited_users = SurveyUtil::get_invited_users($survey_info['code'], $course_database);
if (!in_array($user_id, $invited_users['course_users'])) continue;
}
$notifications[$item_property['tool']] = $item_property;
}
}
// Show all tool icons where there is something new.
$retvalue = '&nbsp;';
if (isset($notifications)) {
while (list($key, $notification) = each($notifications)) {
$lastDate = date('d/m/Y H:i', convert_mysql_date($notification['lastedit_date']));
$type = $notification['lastedit_type'];
//$notification[image] = str_replace('.png', 'gif', $notification[image]);
//$notification[image] = str_replace('.gif', '_s.gif', $notification[image]);
if (empty($my_course['id_session'])) {
$my_course['id_session'] = 0;
}
$retvalue .= '<a href="'.api_get_path(WEB_CODE_PATH).$notification['link'].'?cidReq='.$my_course['k'].'&amp;ref='.$notification['ref'].'&amp;gidReq='.$notification['to_group_id'].'&amp;id_session='.$my_course['id_session'].'">'.'<img title="-- '.get_lang(ucfirst($notification['tool'])).' -- '.get_lang('_title_notification').": ".get_lang($type)." ($lastDate).\"".' src="'.api_get_path(WEB_CODE_PATH).'img/'.$notification['image'].'" border="0" align="absbottom" /></a>&nbsp;';
}
}
return $retvalue;
}
} //end class Display

@ -367,7 +367,7 @@ class SocialManager extends UserManager {
* Helper functions definition
*/
public static function get_logged_user_course_html($my_course, $count) {
global $nosession;
global $nosession, $nbDigestEntries, $orderKey, $digest, $thisCourseSysCode;
if (api_get_setting('use_session_mode')=='true' && !$nosession) {
global $now, $date_start, $date_end;
}
@ -431,51 +431,17 @@ class SocialManager extends UserManager {
//display course entry
$result .= '<div id="div_'.$count.'">';
//$result .= '<a id="btn_'.$count.'" href="#" onclick="toogle_course(this,\''.$course_database.'\')">';
$result .= '<h2><img src="../img/nolines_plus.gif" id="btn_'.$count.'" onclick="toogle_course(this,\''.$course_database.'\' )">';
$result .= $s_htlm_status_icon;
//show a hyperlink to the course, unless the course is closed and user is not course admin
if ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER) {
$result .= '<a href="javascript:void(0)" id="ln_'.$count.'" onclick=toogle_course(this,\''.$course_database.'\');>&nbsp;'.$course_title.'</a></h2>';
/*
if(api_get_setting('use_session_mode')=='true' && !$nosession) {
if(empty($my_course['id_session'])) {
$my_course['id_session'] = 0;
}
if($user_in_course_status == COURSEMANAGER || ($date_start <= $now && $date_end >= $now) || $date_start=='0000-00-00') {
//$result .= '<a href="'.api_get_path(WEB_COURSE_PATH).$course_directory.'/?id_session='.$my_course['id_session'].'">'.$course_display_title.'</a>';
$result .= '<a href="#">'.$course_display_title.'</a>';
}
} else {
//$result .= '<a href="'.api_get_path(WEB_COURSE_PATH).$course_directory.'/">'.$course_display_title.'</a>';
$result .= '<a href="'.api_get_path(WEB_COURSE_PATH).$course_directory.'/">'.$course_display_title.'</a>';
}*/
} else {
$result .= $course_display_title." "." ".get_lang('CourseClosed')."";
}
// show the course_code and teacher if chosen to display this
// we dont need this!
/*
if (api_get_setting('display_coursecode_in_courselist') == 'true' OR api_get_setting('display_teacher_in_courselist') == 'true') {
$result .= '<br />';
}
if (api_get_setting('display_coursecode_in_courselist') == 'true') {
$result .= $course_display_code;
}
if (api_get_setting('display_coursecode_in_courselist') == 'true' AND api_get_setting('display_teacher_in_courselist') == 'true') {
$result .= ' &ndash; ';
}
if (api_get_setting('display_teacher_in_courselist') == 'true') {
$result .= $course_teacher;
if(!empty($course_teacher_email)) {
$result .= ' ('.$course_teacher_email.')';
}
}
*/
$current_course_settings = CourseManager :: get_access_settings($my_course['k']);
// display the what's new icons
// $result .= show_notification($my_course);
if ((CONFVAL_showExtractInfo == SCRIPTVAL_InCourseList || CONFVAL_showExtractInfo == SCRIPTVAL_Both) && $nbDigestEntries > 0) {
reset($digest);
$result .= '<ul>';

@ -154,8 +154,6 @@ Display :: display_header($nameTools);
FUNCTIONS
display_digest($toolsList, $digest, $orderKey, $courses)
show_notification($my_course)
get_logged_user_course_html($my_course)
get_user_course_categories()
*/
@ -405,7 +403,7 @@ function get_logged_user_course_html($course, $session_id = 0, $class = 'courses
$current_course_settings = CourseManager :: get_access_settings($my_course['k']);
// Display the "what's new" icons.
$result .= show_notification($my_course);
$result .= Display :: show_notification($my_course);
if ((CONFVAL_showExtractInfo == SCRIPTVAL_InCourseList || CONFVAL_showExtractInfo == SCRIPTVAL_Both) && $nbDigestEntries > 0) {
@ -573,97 +571,7 @@ function get_global_courses_list($user_id) {
return $output;
}
/**
* Returns the "what's new" icon notifications
*
* The general logic of this function is to track the last time the user
* entered the course and compare to what has changed inside this course
* since then, based on the item_property table inside this course. Note that,
* if the user never entered the course before, he will not see notification
* icons. This function takes session ID into account (if any) and only shows
* the corresponding notifications.
* @param array Course information array, containing at least elements 'db' and 'k'
* @return string The HTML link to be shown next to the course
*/
function show_notification($my_course) {
$statistic_database = Database :: get_statistic_database();
$user_id = api_get_user_id();
$course_database = $my_course['db'];
$course_tool_table = Database::get_course_table(TABLE_TOOL_LIST, $course_database);
$tool_edit_table = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_database);
$course_group_user_table = Database :: get_course_table(TABLE_GROUP_USER, $course_database);
$t_track_e_access = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
// Get the user's last access dates to all tools of this course
$sqlLastTrackInCourse = "SELECT * FROM $t_track_e_access
USE INDEX (access_cours_code, access_user_id)
WHERE access_cours_code = '".$my_course['k']."'
AND access_user_id = '$user_id' AND access_session_id ='".$my_course['id_session']."'";
$resLastTrackInCourse = Database::query($sqlLastTrackInCourse);
$oldestTrackDate = '3000-01-01 00:00:00';
while ($lastTrackInCourse = Database::fetch_array($resLastTrackInCourse)) {
$lastTrackInCourseDate[$lastTrackInCourse['access_tool']] = $lastTrackInCourse['access_date'];
if ($oldestTrackDate > $lastTrackInCourse['access_date']) {
$oldestTrackDate = $lastTrackInCourse['access_date'];
}
}
// Get the last edits of all tools of this course.
$sql = "SELECT tet.*, tet.lastedit_date last_date, tet.tool tool, tet.ref ref,
tet.lastedit_type type, tet.to_group_id group_id,
ctt.image image, ctt.link link
FROM $tool_edit_table tet, $course_tool_table ctt
WHERE tet.lastedit_date > '$oldestTrackDate'
AND ctt.name = tet.tool
AND ctt.visibility = '1'
AND tet.lastedit_user_id != $user_id AND tet.id_session = '".$my_course['id_session']."'
ORDER BY tet.lastedit_date";
$res = Database::query($sql);
// Get the group_id's with user membership.
$group_ids = GroupManager :: get_group_ids($course_database, $user_id);
$group_ids[] = 0; //add group 'everyone'
// Filter all selected items.
while ($res && ($item_property = Database::fetch_array($res))) {
// First thing to check is if the user never entered the tool
// or if his last visit was earlier than the last modification.
if ((!isset ($lastTrackInCourseDate[$item_property['tool']]) || $lastTrackInCourseDate[$item_property['tool']] < $item_property['lastedit_date'])
// Drop the tool elements that are part of a group that the
// user is not part of.
&& ((in_array($item_property['to_group_id'], $group_ids)
// Drop the dropbox, notebook and chat tools because we don't care.
&& ($item_property['tool'] != TOOL_DROPBOX && $item_property['tool'] != TOOL_NOTEBOOK && $item_property['tool'] != TOOL_CHAT)))
// Take only what's visible or invisible but where the user is a teacher or where the visibility is unset.
&& ($item_property['visibility'] == '1' || ($my_course['s'] == '1' && $item_property['visibility'] == '0') || !isset($item_property['visibility']))) {
// Also drop announcements and events that are not for the user or his group.
if (($item_property['tool'] == TOOL_ANNOUNCEMENT || $item_property['tool'] == TOOL_CALENDAR_EVENT) && (($item_property['to_user_id'] != $user_id ) && (!isset($item_property['to_group_id']) || !in_array($item_property['to_group_id'], $group_ids)))) continue;
// If it's a survey, make sure the user's invited. Otherwise drop it.
if ($item_property['tool'] == TOOL_SURVEY) {
$survey_info = survey_manager::get_survey($item_property['ref'], 0, $my_course['k']);
$invited_users = SurveyUtil::get_invited_users($survey_info['code'], $course_database);
if (!in_array($user_id, $invited_users['course_users'])) continue;
}
$notifications[$item_property['tool']] = $item_property;
}
}
// Show all tool icons where there is something new.
$retvalue = '&nbsp;';
if (isset($notifications)) {
while (list($key, $notification) = each($notifications)) {
$lastDate = date('d/m/Y H:i', convert_mysql_date($notification['lastedit_date']));
$type = $notification['lastedit_type'];
//$notification[image] = str_replace('.png', 'gif', $notification[image]);
//$notification[image] = str_replace('.gif', '_s.gif', $notification[image]);
if (empty($my_course['id_session'])) {
$my_course['id_session'] = 0;
}
$retvalue .= '<a href="'.api_get_path(WEB_CODE_PATH).$notification['link'].'?cidReq='.$my_course['k'].'&amp;ref='.$notification['ref'].'&amp;gidReq='.$notification['to_group_id'].'&amp;id_session='.$my_course['id_session'].'">'.'<img title="-- '.get_lang(ucfirst($notification['tool'])).' -- '.get_lang('_title_notification').": ".get_lang($type)." ($lastDate).\"".' src="'.api_get_path(WEB_CODE_PATH).'img/'.$notification['image'].'" border="0" align="absbottom" /></a>&nbsp;';
}
}
return $retvalue;
}
/**
* Retrieves the user defined course categories

Loading…
Cancel
Save