Browse Source

Merge branch '1.9.x' of ssh://github.com/chamilo/chamilo-lms into chamilo19

Julio Montoya 10 years ago
parent
commit
a27d677b3d

+ 1 - 1
main/admin/resume_session.php

@@ -459,7 +459,7 @@ if ($session['nbr_users']==0) {
             if (isset($sessionInfo['duration']) && !empty($sessionInfo['duration'])) {
                 $editUrl = api_get_path(WEB_CODE_PATH) . 'admin/session_user_edit.php?session_id=' . $id_session . '&user_id=' . $user['user_id'];
                 $editUrl = Display::url(
-                    Display::return_icon('edit.png', get_lang('Edit')),
+                    Display::return_icon('agenda.png', get_lang('SessionDurationEdit')),
                     $editUrl
                 );
             }

+ 42 - 3
main/admin/session_user_edit.php

@@ -38,15 +38,54 @@ $interbreadcrumb[] = array('url' => "resume_session.php?id_session=".$sessionId,
 $form = new FormValidator('edit', 'post', api_get_self().'?session_id='.$sessionId.'&user_id='.$userId);
 $form->add_header(get_lang('EditUserSessionDuration'));
 $data = SessionManager::getUserSession($userId, $sessionId);
+$userInfo = api_get_user_info($userId);
 
-$form->addElement('text', 'duration', array(get_lang('Duration'), null, get_lang('Days')));
+// Show current end date for the session for this user, if any
+$userAccess = CourseManager::getFirstCourseAccessPerSessionAndUser(
+    $sessionId,
+    $userId
+);
+if (count($userAccess) == 0) {
+    // User never accessed the session. End date is still open
+    $msg = sprintf(get_lang('UserNeverAccessedSessionDefaultDurationIsX'), $sessionInfo['duration']);
+} else {
+    // The user already accessed the session. Show a clear detail of the days count.
+    $duration = $sessionInfo['duration'];
+    if (!empty($data['duration'])) {
+        $duration = $duration + $data['duration'];
+    }
+    $days = SessionManager::getDayLeftInSession($sessionId, $userId, $duration);
+    $firstAccess = api_strtotime($userAccess['login_course_date'], 'UTC');
+    $firstAccessString = api_convert_and_format_date($userAccess['login_course_date'], DATE_FORMAT_SHORT, 'UTC');
+    if ($days > 0) {
+        $msg = sprintf(get_lang('FirstAccessWasXSessionDurationYEndDateInZDays'), $firstAccessString, $duration, $days);
+    } else {
+        $endDateInSeconds = $firstAccess + $duration*24*60*60;
+        $last = api_convert_and_format_date($endDateInSeconds, DATE_FORMAT_SHORT);
+        $msg = sprintf(get_lang('FirstAccessWasXSessionDurationYEndDateWasZ'), $firstAccessString, $duration, $last);
+    }
+}
+$form->addElement('html', sprintf(get_lang('UserXSessionY'), $userInfo['complete_name'], $sessionInfo['name']));
+$form->addElement('html', '<br>');
+$form->addElement('html', $msg);
+
+$form->addElement('text', 'duration', array(get_lang('ExtraDurationForUser'), null, get_lang('Days')));
 $form->addElement('button', 'submit', get_lang('Send'));
+
+if (empty($data['duration'])) {
+    $data['duration'] = 0;
+}
 $form->setDefaults($data);
 $message = null;
 if ($form->validate()) {
     $duration = $form->getSubmitValue('duration');
-    SessionManager::editUserSessionDuration($duration, $userId, $sessionId);
-    $message = Display::return_message(get_lang('ItemUpdated'), 'confirmation');
+    // Only update if the duration is different from the default duration
+    if ($duration != 0) {
+        SessionManager::editUserSessionDuration($duration, $userId, $sessionId);
+        $message = Display::return_message(get_lang('ItemUpdated'), 'confirmation');
+    } else {
+        $message = Display::return_message(get_lang('DurationIsSameAsDefault'), 'warning');
+    }
 }
 
 // display the header

+ 2 - 1
main/inc/lib/course.lib.php

@@ -4695,7 +4695,8 @@ class CourseManager
     }
 
     /**
-     * Get information from the track_e_course_access table
+     * Get login information from the track_e_course_access table, for any
+     * course in the given session
      * @param int $sessionId
      * @param int $userId
      * @return array

+ 5 - 0
main/inc/lib/main_api.lib.php

@@ -2024,6 +2024,11 @@ function api_get_session_visibility($session_id, $course_code = null, $ignore_vi
                             $session_id,
                             api_get_user_id()
                         );
+                        // If there is a session duration but there is no previous
+                        // access by the user, then the session is still available
+                        if (count($courseAccess) == 0) {
+                            return SESSION_AVAILABLE;
+                        }
                         $currentTime = time();
                         $firstAccess = 0;
                         if (isset($courseAccess['login_course_date'])) {

+ 13 - 4
main/inc/lib/sessionmanager.lib.php

@@ -4684,6 +4684,8 @@ class SessionManager
     }
 
     /**
+     * Returns the number of days the student has left in a session when using
+     * sessions durations
      * @param int $userId
      * @param int $sessionId
      * @param int $duration in days
@@ -4691,6 +4693,8 @@ class SessionManager
      */
     public static function getDayLeftInSession($sessionId, $userId, $duration)
     {
+        // Get an array with the details of the first access of the student to
+        // this session
         $courseAccess = CourseManager::getFirstCourseAccessPerSessionAndUser(
             $sessionId,
             $userId
@@ -4698,6 +4702,11 @@ class SessionManager
 
         $currentTime = time();
 
+        // If no previous access, return false
+        if (count($courseAccess) == 0) {
+            return false;
+        }
+
         $firstAccess = api_strtotime($courseAccess['login_course_date'], 'UTC');
 
         $endDateInSeconds = $firstAccess + $duration*24*60*60;
@@ -4728,10 +4737,10 @@ class SessionManager
     }
 
     /**
-     * @param int $userId
-     * @param int $sessionId
-     *
-     * @param return array
+     * Gets one row from the session_rel_user table
+     * @param int The user ID
+     * @param int The session ID
+     * @return array
      */
     public static function getUserSession($userId, $sessionId)
     {

+ 3 - 3
main/tracking/courseLog.php

@@ -379,14 +379,14 @@ if (count($a_students) > 0) {
     $table->set_header(3, get_lang('Login'), false);
     $tab_table_header[] = get_lang('Login');
 
-    $table->set_header(4, get_lang('TrainingTime'), false);
+    $table->set_header(4, get_lang('TrainingTime').'&nbsp;'.Display::return_icon('info3.gif', get_lang('TrainingTimeInfo'), array('align' => 'absmiddle', 'hspace' => '3px')), false, array('style' => 'width:110px;'));
     $tab_table_header[] = get_lang('TrainingTime');
     $table->set_header(5, get_lang('CourseProgress').'&nbsp;'.Display::return_icon('info3.gif', get_lang('ScormAndLPProgressTotalAverage'), array('align' => 'absmiddle', 'hspace' => '3px')), false, array('style' => 'width:110px;'));
     $tab_table_header[] = get_lang('CourseProgress');
 
-    $table->set_header(6, get_lang('ExerciseProgress'), false);
+    $table->set_header(6, get_lang('ExerciseProgress').'&nbsp;'.Display::return_icon('info3.gif', get_lang('ExerciseProgressInfo'), array('align' => 'absmiddle', 'hspace' => '3px')), false, array('style' => 'width:110px;'));
     $tab_table_header[] = get_lang('ExerciseProgress');
-    $table->set_header(7, get_lang('ExerciseAverage'), false);
+    $table->set_header(7, get_lang('ExerciseAverage').'&nbsp;'.Display::return_icon('info3.gif', get_lang('ExerciseAverageInfo'), array('align' => 'absmiddle', 'hspace' => '3px')), false, array('style' => 'width:110px;'));
     $tab_table_header[] = get_lang('ExerciseAverage');
     $table->set_header(8, get_lang('Score').'&nbsp;'.Display::return_icon('info3.gif', get_lang('ScormAndLPTestTotalAverage'), array('align' => 'absmiddle', 'hspace' => '3px')), false, array('style' => 'width:110px;'));
     $tab_table_header[] = get_lang('Score');