From b406e4a155cf7510d04d8de7b75fd36377f6ec26 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Mon, 28 Apr 2014 15:22:58 +0200 Subject: [PATCH] Moving code into a function, adding keyword filter see BT#7297 Also adding course info (teacher, session list) in the course reporting. --- main/inc/lib/sessionmanager.lib.php | 5 ++-- main/inc/lib/tracking.lib.php | 24 +++++++++++++++++ main/inc/lib/usermanager.lib.php | 22 ++++++++++++---- main/mySpace/index.php | 3 +-- main/mySpace/student.php | 22 ++++------------ main/mySpace/teachers.php | 17 +++--------- main/mySpace/users.php | 26 ++++++------------ main/tracking/courseLog.php | 41 +++++++++++++++++++++++++++++ 8 files changed, 102 insertions(+), 58 deletions(-) diff --git a/main/inc/lib/sessionmanager.lib.php b/main/inc/lib/sessionmanager.lib.php index 42f7af11e3..f3683796d1 100644 --- a/main/inc/lib/sessionmanager.lib.php +++ b/main/inc/lib/sessionmanager.lib.php @@ -3995,7 +3995,7 @@ class SessionManager * @param array $sessionIdList * @param array $studentIdList * @param int $userStatus STUDENT|COURSEMANAGER constants - + * * @return array|int */ public static function getCountUserTracking( @@ -4043,7 +4043,8 @@ class SessionManager null, $active, $lastConnectionDate, - COURSEMANAGER + COURSEMANAGER, + $keyword ); } diff --git a/main/inc/lib/tracking.lib.php b/main/inc/lib/tracking.lib.php index 50d53b34f0..0230ad3a59 100644 --- a/main/inc/lib/tracking.lib.php +++ b/main/inc/lib/tracking.lib.php @@ -3494,6 +3494,29 @@ class Tracking $html = ''; return $html; } + + /** + * @param FormValidator $form + * @return mixed + */ + public static function setUserSearchForm($form) + { + $form->addElement('text', 'keyword', get_lang('Keyword')); + $form->addElement('select', 'active', get_lang('Status'), array(1 => get_lang('Active'), 0 => get_lang('Inactive'))); + if (isset($_configuration['save_user_last_login']) && + $_configuration['save_user_last_login'] + ) { + $form->addElement( + 'select', + 'sleeping_days', + get_lang('InactiveDays'), + array('', 1 => 1, 5 => 5, 15 => 15, 30 => 30, 60 => 60, 90 => 90, 120 => 120) + ); + } + $form->addElement('button', 'submit', get_lang('Search')); + + return $form; + } } /** @@ -4832,4 +4855,5 @@ class TrackingUserLogCSV } return array($title_line, $line); } + } diff --git a/main/inc/lib/usermanager.lib.php b/main/inc/lib/usermanager.lib.php index 0e457f501a..2e7bdcfe33 100644 --- a/main/inc/lib/usermanager.lib.php +++ b/main/inc/lib/usermanager.lib.php @@ -3748,7 +3748,9 @@ class UserManager * @param int $active * @param string $lastConnectionDate * @param int $status the function is called by who? COURSEMANAGER, DRH? - * @return array users + * @param string $keyword + * + * @return array user list */ public static function getUsersFollowedByUser( $userId, @@ -3762,7 +3764,8 @@ class UserManager $direction = null, $active = null, $lastConnectionDate = null, - $status = null + $status = null, + $keyword = null ) { // Database Table Definitions $tbl_user = Database::get_main_table(TABLE_MAIN_USER); @@ -3770,13 +3773,11 @@ class UserManager $tbl_user_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); - $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE); $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); - $tbl_course_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); $tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); - $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER); + $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER); $userId = intval($userId); @@ -3813,6 +3814,17 @@ class UserManager $userConditions .= " AND u.active = $active "; } + if (!empty($keyword)) { + $keyword = Database::escape_string($keyword); + $userConditions .= " AND ( + u.username LIKE '%$keyword%' OR + u.firstname LIKE '%$keyword%' OR + u.lastname LIKE '%$keyword%' OR + u.official_code LIKE '%$keyword%' OR + u.email LIKE '%$keyword%' + )"; + } + if (!empty($lastConnectionDate)) { if (isset($_configuration['save_user_last_login']) && $_configuration['save_user_last_login'] diff --git a/main/mySpace/index.php b/main/mySpace/index.php index 9d46f0fd0e..219b898349 100644 --- a/main/mySpace/index.php +++ b/main/mySpace/index.php @@ -326,8 +326,7 @@ if ($export_csv) { ); $form = new FormValidator('search_user', 'get', api_get_path(WEB_CODE_PATH).'mySpace/student.php'); - $form->addElement('text', 'keyword', get_lang('User')); - $form->addElement('button', 'submit', get_lang('Search')); + $form = Tracking::setUserSearchForm($form); $form->display(); // html part diff --git a/main/mySpace/student.php b/main/mySpace/student.php index 6c6fd1ed64..62d59444cd 100644 --- a/main/mySpace/student.php +++ b/main/mySpace/student.php @@ -72,7 +72,6 @@ function get_users($from, $limit, $column, $direction) if (api_is_drh()) { $column = 'u.user_id'; if (api_drh_can_access_all_session_content()) { - $students = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus( 'drh_all', api_get_user_id(), @@ -105,7 +104,8 @@ function get_users($from, $limit, $column, $direction) $direction, $active, $lastConnectionDate, - COURSEMANAGER + COURSEMANAGER, + $keyword ); } @@ -153,8 +153,8 @@ function get_users($from, $limit, $column, $direction) $row[] = $student_data['lastname']; $row[] = $student_data['firstname']; } - $string_date = Tracking :: get_last_connection_date($student_id, true); - $first_date = Tracking :: get_first_connection_date($student_id); + $string_date = Tracking::get_last_connection_date($student_id, true); + $first_date = Tracking::get_first_connection_date($student_id); $row[] = $first_date; $row[] = $string_date; @@ -249,19 +249,7 @@ if ($export_csv) { } $form = new FormValidator('search_user', 'get', api_get_path(WEB_CODE_PATH).'mySpace/student.php'); -$form->addElement('text', 'keyword', get_lang('Keyword')); -$form->addElement('select', 'active', get_lang('Status'), array(1 => get_lang('Active'), 0 => get_lang('Inactive'))); -if (isset($_configuration['save_user_last_login']) && - $_configuration['save_user_last_login'] -) { - $form->addElement( - 'select', - 'sleeping_days', - get_lang('InactiveDays'), - array('', 1 => 1, 5 => 5, 15 => 15, 30 => 30, 60 => 60, 90 => 90, 120 => 120) - ); -} -$form->addElement('button', 'submit', get_lang('Search')); +$form = Tracking::setUserSearchForm($form); $form->setDefaults($params); if ($export_csv) { diff --git a/main/mySpace/teachers.php b/main/mySpace/teachers.php index ccd2daa234..99f20d2d40 100644 --- a/main/mySpace/teachers.php +++ b/main/mySpace/teachers.php @@ -104,7 +104,8 @@ function get_users($from, $limit, $column, $direction) $direction, $active, $lastConnectionDate, - COURSEMANAGER + COURSEMANAGER, + $keyword ); } @@ -248,19 +249,7 @@ if ($export_csv) { } $form = new FormValidator('search_user', 'get', api_get_path(WEB_CODE_PATH).'mySpace/teachers.php'); -$form->addElement('text', 'keyword', get_lang('Keyword')); -$form->addElement('select', 'active', get_lang('Status'), array(1 => get_lang('Active'), 0 => get_lang('Inactive'))); -if (isset($_configuration['save_user_last_login']) && - $_configuration['save_user_last_login'] -) { - $form->addElement( - 'select', - 'sleeping_days', - get_lang('InactiveDays'), - array('', 1 => 1, 5 => 5, 15 => 15, 30 => 30, 60 => 60, 90 => 90, 120 => 120) - ); -} -$form->addElement('button', 'submit', get_lang('Search')); +$form = Tracking::setUserSearchForm($form); $form->setDefaults($params); if ($export_csv) { diff --git a/main/mySpace/users.php b/main/mySpace/users.php index fe152cefa1..75a6e3c92a 100644 --- a/main/mySpace/users.php +++ b/main/mySpace/users.php @@ -106,7 +106,8 @@ function get_users($from, $limit, $column, $direction) $direction, $active, $lastConnectionDate, - COURSEMANAGER + COURSEMANAGER, + $keyword ); } @@ -251,25 +252,14 @@ if ($export_csv) { } $form = new FormValidator('search_user', 'get', api_get_path(WEB_CODE_PATH).'mySpace/users.php'); -$form->addElement('text', 'keyword', get_lang('User')); -$form->addElement('select', 'active', get_lang('Status'), array(1 => get_lang('Active'), 0 => get_lang('Inactive'))); + $form->addElement('select', 'status', get_lang('Status'), array( - '' => '', - STUDENT => get_lang('Student'), - COURSEMANAGER => get_lang('Teacher'), - DRH => get_lang('DRH')) + '' => '', + STUDENT => get_lang('Student'), + COURSEMANAGER => get_lang('Teacher'), + DRH => get_lang('DRH')) ); -if (isset($_configuration['save_user_last_login']) && - $_configuration['save_user_last_login'] -) { - $form->addElement( - 'select', - 'sleeping_days', - get_lang('InactiveDays'), - array('', 1 => 1, 5 => 5, 15 => 15, 30 => 30, 60 => 60, 90 => 90, 120 => 120) - ); -} -$form->addElement('button', 'submit', get_lang('Search')); +$form = Tracking::setUserSearchForm($form); $form->setDefaults($params); // send the csv file if asked diff --git a/main/tracking/courseLog.php b/main/tracking/courseLog.php index f727a6a398..4755843dce 100644 --- a/main/tracking/courseLog.php +++ b/main/tracking/courseLog.php @@ -282,11 +282,40 @@ if (count($a_students) > 0) { ); } + $teacherList = CourseManager::get_teacher_list_from_course_code_to_string( + $courseInfo['code'], + CourseManager::USER_SEPARATOR, + false + ); + + $coaches = null; + if (!empty($session_id)) { + $coaches = CourseManager::get_coachs_from_course_to_string( + $session_id, + $courseInfo['code'], + CourseManager::USER_SEPARATOR, + false + ); + } + + if (!empty($teacherList)) { + echo Display::page_subheader2(get_lang('Teachers')); + echo $teacherList; + } + + if (!empty($coaches)) { + echo Display::page_subheader2(get_lang('Coaches')); + echo $coaches; + } + + echo Display::page_subheader2(get_lang('StudentList')); + $extra_field_select = TrackingCourseLog::display_additional_profile_fields(); if (!empty($extra_field_select)) { echo $extra_field_select; } + $form->display(); // PERSON_NAME_DATA_EXPORT is buggy @@ -392,6 +421,18 @@ if (count($a_students) > 0) { $table->display(); echo ""; + $sessionList = SessionManager::get_session_by_course($courseInfo['code']); + if (!empty($sessionList)) { + echo Display::page_subheader2(get_lang('SessionList')); + $sessionToShow = array(); + foreach ($sessionList as $session) { + $url = api_get_path(WEB_CODE_PATH).'mySpace/course.php?session_id='.$session['id'].'&cidReq='.$courseInfo['code']; + $sessionToShow[] = Display::url($session['name'], $url); + } + echo implode(',', $sessionToShow); + } + + } else { echo Display::display_warning_message(get_lang('NoUsersInCourse')); }