Reordering session categories see BT#4687

skala
Julio Montoya 12 years ago
parent f51a175cba
commit e5d1fc9861
  1. 9
      main/inc/lib/course.lib.php
  2. 7
      main/inc/lib/display.lib.php
  3. 106
      main/inc/lib/usermanager.lib.php
  4. 341
      main/inc/lib/userportal.lib.php
  5. 1
      user_portal.php

@ -2940,9 +2940,6 @@ class CourseManager {
$user_id = api_get_user_id();
}
// Step 0: We display the course without a user category.
$html = self :: display_courses_in_category(0, $load_dirs);
// Step 1: We get all the categories of the user
$tucc = Database::get_user_personal_table(TABLE_USER_COURSE_CATEGORY);
$sql = "SELECT id, title FROM $tucc WHERE user_id='".$user_id."' ORDER BY sort ASC";
@ -2954,6 +2951,10 @@ class CourseManager {
$params['title'] = $row['title'];
$html .= self::course_item_parent(self::course_item_html($params, true), self :: display_courses_in_category($row['id'], $load_dirs));
}
// Step 2: We display the course without a user category.
$html .= self :: display_courses_in_category(0, $load_dirs);
return $html;
}
@ -2981,7 +2982,7 @@ class CourseManager {
}
//AND course_rel_user.relation_type<>".COURSE_RELATION_TYPE_RRHH."
$sql = "SELECT course.id, course.code, course.subscribe subscr, course.unsubscribe unsubscr, course_rel_user.status status,
$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

@ -1230,8 +1230,7 @@ class Display {
$output = array();
if (!$nosession) {
$main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
$tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
$tbl_session_category = Database :: get_main_table(TABLE_MAIN_SESSION_CATEGORY);
$tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
$active = false;
// Request for the name of the general coach
$sql ='SELECT tu.lastname, tu.firstname, ts.name, ts.date_start, ts.date_end, ts.session_category_id
@ -1253,7 +1252,7 @@ class Display {
$active = true;
} else {
$start = $stop = false;
$startt_buffer = $stop_buffer = '';
$start_buffer = $stop_buffer = '';
if ($session_info['date_start'] == '0000-00-00') {
$session_info['date_start'] = '';
} else {
@ -1269,7 +1268,7 @@ class Display {
$session_info['date_end'] = get_lang('Until').' '.$session_info['date_end'];
}
if ($start && $stop) {
$session['dates'] = Display::tag('i', sprintf(get_lang('FromDateXToDateY'),$start_buffer, $stop_buffer));
$session['dates'] = Display::tag('i', sprintf(get_lang('FromDateXToDateY'), $start_buffer, $stop_buffer));
} else {
$session['dates'] = Display::tag('i', $session_info['date_start'].' '.$session_info['date_end']);
}

@ -1926,88 +1926,54 @@ class UserManager {
* @return array list of statuses [session_category][session_id]
* @todo ensure multiple access urls are managed correctly
*/
public static function get_sessions_by_category ($user_id, $fill_first = false, $is_time_over = false, $sort_by_session_name = false) {
// Database Table Definitions
$tbl_session_user = Database :: get_main_table(TABLE_MAIN_SESSION_USER);
$tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
$tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
public static function get_sessions_by_category($user_id, $is_time_over = false) {
// Database Table Definitions
$tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
$tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$tbl_session_category = Database :: get_main_table(TABLE_MAIN_SESSION_CATEGORY);
if ($user_id != strval(intval($user_id))) return array();
$categories = array();
$names = array();
if ($fill_first) {
$categories[0] = array();
}
// Get the list of sessions where the user is subscribed as student
// Get the list of sessions per user
$condition_date_end = "";
if ($is_time_over) {
$condition_date_end = " AND date_end < CURDATE() AND date_end != '0000-00-00' ";
$condition_date_end = " AND (session.date_end < CURDATE() AND session.session_category.date_end != '0000-00-00') AND ";
} else {
$condition_date_end = " AND (date_end >= CURDATE() OR date_end = '0000-00-00') ";
}
$sessions_sql = "SELECT DISTINCT id, session_category_id, session.name
FROM $tbl_session_user, $tbl_session
WHERE id_session=id AND id_user=$user_id $condition_date_end
ORDER BY session_category_id, date_start, date_end";
$result = Database::query($sessions_sql);
if (Database::num_rows($result) > 0) {
while ($row = Database::fetch_array($result)) {
$categories[$row['session_category_id']][] = $row['id'];
$names[$row['id']] = $row['name'];
}
}
// Get the list of sessions where the user is subscribed as coach in a
// course, from table session_rel_course_rel_user
$sessions_sql = "SELECT DISTINCT id, session_category_id, session.name
FROM $tbl_session as session INNER JOIN $tbl_session_course_user as session_rel_course_user
ON session_rel_course_user.id_session = session.id AND
session_rel_course_user.id_user = $user_id AND
session_rel_course_user.status = 2 $condition_date_end
ORDER BY session_category_id, date_start, date_end";
$condition_date_end = " AND (session.date_end >= CURDATE() OR session.date_end = '0000-00-00') ";
}
//ORDER BY session_category_id, date_start, date_end
$sql = "SELECT DISTINCT session.id, session.name, session.date_start, session.date_end, session_category_id,
session_category.name as session_category_name,
session_category.date_start session_category_date_start,
session_category.date_end session_category_date_end
FROM $tbl_session as session LEFT JOIN $tbl_session_category session_category ON (session_category_id = session_category.id)
INNER JOIN $tbl_session_course_user as session_rel_course_user ON (session_rel_course_user.id_session = session.id)
WHERE (session_rel_course_user.id_user = $user_id) OR
(session.id_coach = $user_id)
ORDER BY session_category_name, name";
$result = Database::query($sessions_sql);
if (Database::num_rows($result)>0) {
$result = Database::query($sql);
if (Database::num_rows($result) > 0) {
while ($row = Database::fetch_array($result)) {
$categories[$row['session_category_id']][] = $row['id'];
$names[$row['id']] = $row['name'];
$categories[$row['session_category_id']]['session_category']['id'] = $row['session_category_id'];
$categories[$row['session_category_id']]['session_category']['name'] = $row['session_category_name'];
$categories[$row['session_category_id']]['session_category']['date_start'] = $row['session_category_date_start'];
$categories[$row['session_category_id']]['session_category']['date_end'] = $row['session_category_date_end'];
$categories[$row['session_category_id']]['sessions'][$row['id']]['session_name'] = $row['name'];
$categories[$row['session_category_id']]['sessions'][$row['id']]['session_id'] = $row['id'];
$categories[$row['session_category_id']]['sessions'][$row['id']]['date_start'] = $row['date_start'];
$categories[$row['session_category_id']]['sessions'][$row['id']]['date_end'] = $row['date_end'];
$categories[$row['session_category_id']]['sessions'][$row['id']]['nb_days_access_before_beginning'] = $row['nb_days_access_before_beginning'];
$categories[$row['session_category_id']]['sessions'][$row['id']]['courses'] = UserManager::get_courses_list_by_session($user_id, $row['id']);
}
}
// Get the list of sessions where the user is subscribed as a session coach
$sessions_sql = "SELECT DISTINCT id, session_category_id, session.name FROM $tbl_session as session
WHERE session.id_coach = $user_id $condition_date_end
ORDER BY session_category_id, date_start, date_end";
$result = Database::query($sessions_sql);
if (Database::num_rows($result)>0) {
while ($row = Database::fetch_array($result)) {
$categories[$row['session_category_id']][] = $row['id'];
$names[$row['id']] = $row['name'];
}
}
if ($sort_by_session_name) {
// reorder sessions alphabetically inside categories
if (!empty($categories)) {
foreach ($categories as $cat_id => $category) {
// inside each category, prepare a new empty array to sort sessions
$new_cat = array();
if (is_array($category) && !empty($category)) {
foreach ($category as $session) {
$new_cat[$names[$session]] = $session;
}
uksort($new_cat, 'strnatcmp');
$categories[$cat_id] = $new_cat;
}
}
}
}
return $categories;
}
@ -2689,7 +2655,7 @@ class UserManager {
$tag_tmp = array();
foreach ($user_tags as $tag) {
if ($show_links) {
$tag_tmp[] = '<a href="'.api_get_path(WEB_PATH).'main/search/?q='.$tag['tag'].'">'.$tag['tag'].'</a>';
$tag_tmp[] = '<a href="'.api_get_path(WEB_PATH).'main/search/index.php?q='.$tag['tag'].'">'.$tag['tag'].'</a>';
} else {
$tag_tmp[] = $tag['tag'];
}

@ -854,40 +854,16 @@ class IndexManager {
*
* */
function return_courses_and_sessions($user_id) {
$courses_tree = array();
$session_categories = array();
$load_history = (isset($_GET['history']) && intval($_GET['history']) == 1) ? true : false;
if ($load_history) {
//Load sessions in category in *history*
$courses_tree = UserManager::get_sessions_by_category($user_id, true, true, true);
if (empty($courses_tree[0]) && count($courses_tree) == 1) {
$courses_tree = null;
}
$session_categories = UserManager::get_sessions_by_category($user_id, true);
} else {
//Load sessions in category
$courses_tree = UserManager::get_sessions_by_category($user_id, true, false, true);
}
if (!empty($courses_tree)) {
foreach ($courses_tree as $cat => $sessions) {
//Get session category
$courses_tree[$cat]['details'] = SessionManager::get_session_category($cat);
//Get courses
if ($cat == 0) {
$courses_tree[$cat]['courses'] = CourseManager::get_courses_list_by_user_id($user_id, false);
}
$courses_tree[$cat]['sessions'] = array_flip(array_flip($sessions));
//Get courses in sessions
if (count($courses_tree[$cat]['sessions']) > 0) {
foreach ($courses_tree[$cat]['sessions'] as $k => $s_id) {
$courses_tree[$cat]['sessions'][$k] = array('details' => SessionManager::fetch($s_id));
$courses_tree[$cat]['sessions'][$k]['courses'] = UserManager::get_courses_list_by_session($user_id, $s_id);
}
}
}
}
$session_categories = UserManager::get_sessions_by_category($user_id, false);
}
$html = '';
@ -895,168 +871,181 @@ class IndexManager {
if ($load_history) {
$html .= Display::page_subheader(get_lang('HistoryTrainingSession'));
if (empty($courses_tree)) {
if (empty($session_categories)) {
$html .= get_lang('YouDoNotHaveAnySessionInItsHistory');
}
}
if (is_array($courses_tree)) {
foreach ($courses_tree as $key => $category) {
}
$courses_html = '';
$special_courses = '';
// If we're not in the history view...
if (!isset($_GET['history'])) {
//Display special courses
$special_courses = CourseManager :: display_special_courses($user_id, $this->load_directories_preview);
//Display courses
$courses_html .= CourseManager :: display_courses($user_id, $this->load_directories_preview);
}
$sessions_with_category = '';
$sessions_with_no_category = '';
if (is_array($session_categories)) {
foreach ($session_categories as $session_category) {
$session_category_id = $session_category['session_category']['id'];
// Sessions and courses that are not in a session category
if ($key == 0) {
// If we're not in the history view...
if (!isset($_GET['history'])) {
//Display special courses
$html .= CourseManager :: display_special_courses($user_id, $this->load_directories_preview);
//Display courses
$html .= CourseManager :: display_courses($user_id, $this->load_directories_preview);
}
if ($session_category_id == 0) {
// Independent sessions
foreach ($category['sessions'] as $session) {
// Don't show empty sessions.
if (count($session['courses']) < 1) {
continue;
}
// Courses inside the current session.
$date_session_start = $session['details']['date_start'];
$days_access_before_beginning = $session['details']['nb_days_access_before_beginning'] * 24 * 3600;
$session_now = time();
$html_courses_session = '';
$count_courses_session = 0;
foreach ($session['courses'] as $course) {
$is_coach_course = api_is_coach($session['details']['id'], $course['code']);
$allowed_time = 0;
if ($date_session_start != '0000-00-00') {
if ($is_coach_course) {
$allowed_time = api_strtotime($date_session_start) - $days_access_before_beginning;
} else {
$allowed_time = api_strtotime($date_session_start);
}
}
if ($session_now > $allowed_time) {
//read only and accesible
if (api_get_setting('hide_courses_in_sessions') == 'false') {
$c = CourseManager :: get_logged_user_course_html($course, $session['details']['id'], 'session_course_item', true, $this->load_directories_preview);
$html_courses_session .= $c[1];
}
$count_courses_session++;
}
}
if ($count_courses_session > 0) {
$params = array();
$session_box = Display :: get_session_title_box($session['details']['id']);
$params['icon'] = Display::return_icon('window_list.png', $session_box['title'], array('id' => 'session_img_'.$session['details']['id']), ICON_SIZE_LARGE);
$extra_info = (!empty($session_box['coach']) ? $session_box['coach'].' | ' : '').$session_box['dates'];
// Independent sessions
foreach ($session_category['sessions'] as $session) {
$session_id = $session['session_id'];
// Don't show empty sessions.
if (count($session['courses']) < 1) {
continue;
}
// Courses inside the current session.
$date_session_start = $session['date_start'];
$days_access_before_beginning = $session['nb_days_access_before_beginning'] * 24 * 3600;
$session_now = time();
$html_courses_session = '';
$count_courses_session = 0;
foreach ($session['courses'] as $course) {
$is_coach_course = api_is_coach($session_id, $course['code']);
$allowed_time = 0;
if ($date_session_start != '0000-00-00') {
if ($is_coach_course) {
$allowed_time = api_strtotime($date_session_start) - $days_access_before_beginning;
} else {
$allowed_time = api_strtotime($date_session_start);
}
}
if ($session_now > $allowed_time) {
//read only and accesible
if (api_get_setting('hide_courses_in_sessions') == 'false') {
$c = CourseManager :: get_logged_user_course_html($course, $session_id, 'session_course_item', true, $this->load_directories_preview);
$html_courses_session .= $c[1];
}
$count_courses_session++;
}
}
if ($count_courses_session > 0) {
$params = array();
$session_box = Display :: get_session_title_box($session_id);
$params['icon'] = Display::return_icon('window_list.png', $session_box['title'], array('id' => 'session_img_'.$session_id), ICON_SIZE_LARGE);
$extra_info = (!empty($session_box['coach']) ? $session_box['coach'].' | ' : '').$session_box['dates'];
if (api_is_drh()) {
$session_link = $session_box['title'];
$params['link'] = null;
} else {
$session_link = Display::tag('a', $session_box['title'], array('href'=>api_get_path(WEB_CODE_PATH).'session/?session_id='.$session['details']['id']));
$params['link'] = api_get_path(WEB_CODE_PATH).'session/?session_id='.$session['details']['id'];
$session_link = Display::tag('a', $session_box['title'], array('href'=>api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id));
$params['link'] = api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id;
}
$params['title'] = $session_link.$extra_info;
$params['title'] = $session_link.$extra_info;
$params['right_actions'] = '';
if (api_is_platform_admin()) {
$params['right_actions'] .= '<a href="'.api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$session['details']['id'].'">';
$params['right_actions'] .= Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'),22).'</a>';
}
if (api_get_setting('hide_courses_in_sessions') == 'false') {
// $params['extra'] .= $html_courses_session;
}
$html .= CourseManager::course_item_parent(CourseManager::course_item_html($params, true), $html_courses_session);
}
}
} else {
// All sessions included in.
if (!empty($category['details'])) {
$count_courses_session = 0;
$html_sessions = '';
foreach ($category['sessions'] as $session) {
// Don't show empty sessions.
if (count($session['courses']) < 1) {
continue;
}
$date_session_start = $session['details']['date_start'];
$days_access_before_beginning = $session['details']['nb_days_access_before_beginning'] * 24 * 3600;
$session_now = time();
$html_courses_session = '';
$count = 0;
foreach ($session['courses'] as $course) {
$is_coach_course = api_is_coach($session['details']['id'], $course['code']);
if ($is_coach_course) {
$allowed_time = api_strtotime($date_session_start) - $days_access_before_beginning;
} else {
$allowed_time = api_strtotime($date_session_start);
}
if ($session_now > $allowed_time) {
$c = CourseManager :: get_logged_user_course_html($course, $session['details']['id'], 'session_course_item');
$html_courses_session .= $c[1];
$count_courses_session++;
$count++;
}
}
$params = array();
if ($count > 0) {
$session_box = Display :: get_session_title_box($session['details']['id']);
$params['icon'] = Display::return_icon('window_list.png', $session_box['title'], array('width' => '48px', 'align' => 'absmiddle', 'id' => 'session_img_'.$session['details']['id'])) . ' ';
if (api_is_drh()) {
$session_link = $session_box['title'];
$params['link'] = null;
} else {
$session_link = Display::tag('a', $session_box['title'], array('href'=>api_get_path(WEB_CODE_PATH).'session/?session_id='.$session['details']['id']));
$params['link'] = api_get_path(WEB_CODE_PATH).'session/?session_id='.$session['details']['id'];
}
$params['title'] .= $session_link;
$params['subtitle'] = (!empty($s['coach']) ? $session_box['coach'].' | ' : '').$session_box['dates'];
if (api_is_platform_admin()) {
$params['right_actions'] .= '<a href="'.api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$session['details']['id'].'">'.Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'),22).'</a>';
}
$html_sessions .= CourseManager::course_item_html($params, true).$html_courses_session;
}
}
if ($count_courses_session > 0) {
$params = array();
$params['icon'] = Display::return_icon('folder_blue.png', $category['details']['name'], array(), ICON_SIZE_LARGE);
if (api_is_platform_admin()) {
$params['right_actions'] .= '<a href="'.api_get_path(WEB_CODE_PATH).'admin/session_category_edit.php?&id='.$category['details']['id'].'">'.Display::return_icon('edit.png', get_lang('Edit'), array(),22).'</a>';
}
$params['title'] .= $category['details']['name'];
if (api_is_platform_admin()) {
$params['link'] = api_get_path(WEB_CODE_PATH).'admin/session_category_edit.php?&id='.$category['details']['id'];
$params['right_actions'] .= '<a href="'.api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$session_id.'">';
$params['right_actions'] .= Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'), ICON_SIZE_SMALL).'</a>';
}
if ($category['details']['date_end'] != '0000-00-00') {
$params['subtitle'] = sprintf(get_lang('FromDateXToDateY'),$category['details']['date_start'], $category['details']['date_end']);
}
$html .= CourseManager::course_item_parent(CourseManager::course_item_html($params, true), $html_sessions);
}
}
if (api_get_setting('hide_courses_in_sessions') == 'false') {
// $params['extra'] .= $html_courses_session;
}
$sessions_with_no_category .= CourseManager::course_item_parent(CourseManager::course_item_html($params, true), $html_courses_session);
}
}
} else {
// All sessions included in
$count_courses_session = 0;
$html_sessions = '';
foreach ($session_category['sessions'] as $session) {
$session_id = $session['session_id'];
//var_dump($session);var_dump($session_category);
// Don't show empty sessions.
if (count($session['courses']) < 1) {
continue;
}
$date_session_start = $session['date_start'];
//api_get_session_visibility($session_id);
$days_access_before_beginning = $session['nb_days_access_before_beginning'] * 24 * 3600;
$session_now = time();
$html_courses_session = '';
$count = 0;
foreach ($session['courses'] as $course) {
$is_coach_course = api_is_coach($session_id, $course['code']);
if ($is_coach_course) {
$allowed_time = api_strtotime($date_session_start) - $days_access_before_beginning;
} else {
$allowed_time = api_strtotime($date_session_start);
}
if ($session_now > $allowed_time) {
$c = CourseManager :: get_logged_user_course_html($course, $session_id, 'session_course_item');
$html_courses_session .= $c[1];
$count_courses_session++;
$count++;
}
}
$params = array();
if ($count > 0) {
$session_box = Display :: get_session_title_box($session_id);
$params['icon'] = Display::return_icon('window_list.png', $session_box['title'], array('width' => '48px', 'align' => 'absmiddle', 'id' => 'session_img_'.$session_id)) . ' ';
if (api_is_drh()) {
$session_link = $session_box['title'];
$params['link'] = null;
} else {
$session_link = Display::tag('a', $session_box['title'], array('href'=>api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id));
$params['link'] = api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id;
}
$params['title'] .= $session_link;
$params['subtitle'] = (!empty($session_box['coach']) ? $session_box['coach'].' | ' : '').$session_box['dates'];
if (api_is_platform_admin()) {
$params['right_actions'] .= '<a href="'.api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$session_id.'">'.Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'), ICON_SIZE_SMALL).'</a>';
}
$html_sessions .= CourseManager::course_item_html($params, true).$html_courses_session;
}
}
if ($count_courses_session > 0) {
$params = array();
$params['icon'] = Display::return_icon('folder_blue.png', $session_category['session_category']['name'], array(), ICON_SIZE_LARGE);
if (api_is_platform_admin()) {
$params['right_actions'] .= '<a href="'.api_get_path(WEB_CODE_PATH).'admin/session_category_edit.php?&id='.$session_category['session_category']['id'].'">'.Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>';
}
$params['title'] .= $session_category['session_category']['name'];
if (api_is_platform_admin()) {
$params['link'] = api_get_path(WEB_CODE_PATH).'admin/session_category_edit.php?&id='.$session_category['session_category']['id'];
}
if ($session_category['session_category']['date_end'] != '0000-00-00') {
$params['subtitle'] = sprintf(get_lang('FromDateXToDateY'), $session_category['session_category']['date_start'], $session_category['session_category']['date_end']);
}
$sessions_with_category .= CourseManager::course_item_parent(CourseManager::course_item_html($params, true), $html_sessions);
}
}
}
}
return $html;
}
return $sessions_with_category.$sessions_with_no_category.$courses_html.$special_courses;
}
function return_hot_courses() {

@ -154,6 +154,7 @@ $user_id = api_get_user_id();
// Main courses and session list
$courses_and_sessions = $controller->return_courses_and_sessions($user_id);
$controller->tpl->assign('content', $courses_and_sessions);
if (api_get_setting('allow_browser_sniffer') == 'true') {

Loading…
Cancel
Save