Kaynağa Gözat

Fixing session history page in order to use userportal/history instead of user_portal.php?history=1

Julio Montoya 12 yıl önce
ebeveyn
işleme
34699ed2f3

+ 14 - 10
main/inc/ajax/admin.ajax.php

@@ -11,7 +11,7 @@ api_protect_admin_script();
 $action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null;
 
 switch ($action) {
-    case 'user_exists':        
+    case 'user_exists':
         $user_info = api_get_user_info($_REQUEST['id']);
         if (empty($user_info)) {
             echo 0;
@@ -24,25 +24,29 @@ switch ($action) {
         $json_coaches = array();
         if (!empty($coaches)) {
             foreach ($coaches as $coach) {
-                $json_coaches[] = array('key' => $coach['user_id'], 'value' => api_get_person_name($coach['firstname'], $coach['lastname']));
+                $json_coaches[] = array(
+                    'key' => $coach['user_id'],
+                    'value' => api_get_person_name($coach['firstname'], $coach['lastname'])
+                );
             }
         }
         echo json_encode($json_coaches);
         break;
 	case 'update_changeable_setting':
-        $url_id = api_get_current_access_url_id();        
-        if (api_is_global_platform_admin() && $url_id == 1) {            
-            if (isset($_GET['id']) && !empty($_GET['id'])) {                
+        $url_id = api_get_current_access_url_id();
+        if (api_is_global_platform_admin() && $url_id == 1) {
+            if (isset($_GET['id']) && !empty($_GET['id'])) {
                 $params = array('variable = ? ' =>  array($_GET['id']));
-                $data = api_get_settings_params($params);                
+                $data = api_get_settings_params($params);
                 if (!empty($data)) {
-                    foreach ($data as $item) {                
+                    foreach ($data as $item) {
                         $params = array('id' =>$item['id'], 'access_url_changeable' => $_GET['changeable']);
-                        api_set_setting_simple($params);        
+                        api_set_setting_simple($params);
                     }
-                }                
+                }
                 echo '1';
-            }        
+            }
         }
         break;
 }
+exit;

+ 4 - 1
main/inc/ajax/message.ajax.php

@@ -66,7 +66,10 @@ switch ($action) {
         $return = array();
 		if (Database::num_rows($result) > 0) {
             while ($row = Database::fetch_array($result,'ASSOC')) {
-				$return[] = array('key'=>$row['id'], 'value' => $row['name']);
+				$return[] = array(
+                    'key' => $row['id'],
+                    'value' => $row['name']
+                );
 			}
 		}
 		echo json_encode($return);

+ 3 - 2
main/inc/global.inc.php

@@ -940,7 +940,7 @@ $app['legacy.controller'] = $app->share(function () use ($app) {
     return new ChamiloLMS\Controller\LegacyController();
 });
 
-$app['userportal.controller'] = $app->share(function () use ($app) {
+$app['userPortal.controller'] = $app->share(function () use ($app) {
     return new ChamiloLMS\Controller\UserPortalController();
 });
 
@@ -979,7 +979,8 @@ $app->post('/', 'legacy.controller:classicAction');
 $app->get('/index', 'index.controller:indexAction')->bind('index');
 
 //user_portal.php
-$app->get('/userportal', 'userportal.controller:indexAction');
+$app->get('/userportal', 'userPortal.controller:indexAction');
+$app->get('/userportal/{filter}', 'userPortal.controller:indexAction');
 
 //Logout page
 $app->get('/logout', 'index.controller:logoutAction')->bind('logout');

+ 11 - 11
main/inc/lib/page.lib.php

@@ -53,7 +53,7 @@ class PageController
      * @return string HTML <div> with links
      * @assert () != ''
      */
-    static function return_course_block() {
+    static function return_course_block($filter = null) {
         $show_create_link = false;
         $show_course_link = false;
 
@@ -97,14 +97,14 @@ class PageController
             if (!api_is_drh()) {
                 $my_account_content[] = array('href' => api_get_path(WEB_CODE_PATH).'auth/courses.php', 'title' => get_lang('CourseCatalog'));
 
-                if (isset($_GET['history']) && intval($_GET['history']) == 1) {
-                    $my_account_content [] = array(
-                        'href' => 'user_portal.php',
+                if (isset($filter) && $filter == 'history') {
+                    $my_account_content[] = array(
+                        'href' => api_get_path(WEB_PUBLIC_PATH).'userportal',
                         'title' => get_lang('DisplayTrainingList')
                     );
                 } else {
-                    $my_account_content [] = array(
-                        'href' => 'user_portal.php?history=1',
+                    $my_account_content[] = array(
+                        'href' => api_get_path(WEB_PUBLIC_PATH).'userportal/history',
                         'title' => get_lang('HistoryTrainingSessions')
                     );
                 }
@@ -752,13 +752,13 @@ class PageController
      * @return string HTML list of sessions and courses
      * @assert () === false
      */
-    static function return_courses_and_sessions($user_id) {
+    static function return_courses_and_sessions($user_id, $filter = null) {
         if (empty($user_id)) {
             return false;
         }
 
         $session_categories = array();
-        $load_history = (isset($_GET['history']) && intval($_GET['history']) == 1) ? true : false;
+        $load_history = (isset($filter) && $filter == 'history') ? true : false;
 
         if ($load_history) {
             //Load sessions in category in *history*
@@ -768,7 +768,7 @@ class PageController
             $session_categories = UserManager::get_sessions_by_category($user_id, false);
         }
 
-        $html = '';
+        $html = null;
         //Showing history title
         if ($load_history) {
             $html .= Display::page_subheader(get_lang('HistoryTrainingSession'));
@@ -783,7 +783,7 @@ class PageController
         $load_directories_preview = api_get_setting('show_documents_preview') == 'true' ? true : false;
 
         // If we're not in the history view...
-        if (!isset($_GET['history'])) {
+        if ($load_history == false) {
 
             //Display special courses
             $special_courses = CourseManager::display_special_courses($user_id, $load_directories_preview);
@@ -792,7 +792,7 @@ class PageController
             $courses_html .= CourseManager::display_courses($user_id, $load_directories_preview);
         }
 
-        $sessions_with_category = '';
+        $sessions_with_category = $html;
         $sessions_with_no_category = '';
 
         if (is_array($session_categories)) {

+ 10 - 12
main/inc/lib/usermanager.lib.php

@@ -2435,11 +2435,11 @@ class UserManager {
     public static function get_personal_session_course_list($user_id) {
         // Database Table Definitions
         $tbl_course                 = Database :: get_main_table(TABLE_MAIN_COURSE);
-        $tbl_user                     = Database :: get_main_table(TABLE_MAIN_USER);
-        $tbl_session                 = Database :: get_main_table(TABLE_MAIN_SESSION);
-        $tbl_session_user            = Database :: get_main_table(TABLE_MAIN_SESSION_USER);
-        $tbl_course_user             = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
-        $tbl_session_course_user     = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
+        $tbl_user                   = Database :: get_main_table(TABLE_MAIN_USER);
+        $tbl_session                = Database :: get_main_table(TABLE_MAIN_SESSION);
+        $tbl_session_user           = Database :: get_main_table(TABLE_MAIN_SESSION_USER);
+        $tbl_course_user            = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
+        $tbl_session_course_user    = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
 
         if ($user_id != strval(intval($user_id))) return array();
 
@@ -2656,13 +2656,11 @@ class UserManager {
             //check if user is general coach for this session
             $s = api_get_session_info($session_id);
             if ($s['id_coach'] == $user_id) {
-                if (count($course_list)==0) {
-                    $course_list = SessionManager::get_course_list_by_session_id($session_id);
-                    if (!empty($course_list)) {
-                        foreach ($course_list as $course) {
-                            if (!in_array($course['code'],$courses)) {
-                                $personal_course_list[] = $course;
-                            }
+                $course_list = SessionManager::get_course_list_by_session_id($session_id);
+                if (!empty($course_list)) {
+                    foreach ($course_list as $course) {
+                        if (!in_array($course['code'],$courses)) {
+                            $personal_course_list[] = $course;
                         }
                     }
                 }

+ 6 - 6
src/ChamiloLMS/Controller/UserPortalController.php

@@ -8,12 +8,12 @@ use Symfony\Component\HttpFoundation\Response;
 class UserPortalController
 {
 
-    function indexAction(Application $app)
+    function indexAction(Application $app, $filter = null)
     {
-        //@todo use filters like after/before to manage user access
+        //@todo Use filters like "after/before|finish" to manage user access
         api_block_anonymous_users();
 
-        //User is not allowed
+        //Abort request because the user is not allowed here - @todo use filters
         if ($app['allowed'] == false) {
             return $app->abort(403);
         }
@@ -80,10 +80,10 @@ class UserPortalController
           } */
 
         // Main courses and session list
-        $courses_and_sessions = \PageController::return_courses_and_sessions(api_get_user_id());
+        $courses_and_sessions = \PageController::return_courses_and_sessions(api_get_user_id(), $filter);
 
         //Show the chamilo mascot
-        if (empty($courses_and_sessions) && !isset($_GET['history'])) {
+        if (empty($courses_and_sessions) && empty($filter)) {
             \PageController::return_welcome_to_course_block($app['template']);
         }
 
@@ -114,7 +114,7 @@ class UserPortalController
 
         \PageController::return_profile_block();
         \PageController::return_user_image_block();
-        \PageController::return_course_block();
+        \PageController::return_course_block($filter);
 
         $app['template']->assign('navigation_course_links', $app['template']->returnNavigationLinks());
         \PageController::return_reservation_block();