Example #1
0
 /**
  * Get the session box details as an array
  * @param int       Session ID
  * @return array    Empty array or session array
  * ['title'=>'...','category'=>'','dates'=>'...','coach'=>'...','active'=>true/false,'session_category_id'=>int]
  */
 public static function get_session_title_box($session_id)
 {
     global $nosession;
     if (!$nosession) {
         global $now, $date_start, $date_end;
     }
     $output = array();
     if (!$nosession) {
         $main_user_table = Database::get_main_table(TABLE_MAIN_USER);
         $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.*
                 FROM ' . $tbl_session . ' ts
                 LEFT JOIN ' . $main_user_table . ' tu
                 ON ts.id_coach = tu.user_id
                 WHERE ts.id = ' . intval($session_id);
         $rs = Database::query($sql);
         $session_info = Database::store_result($rs, 'ASSOC');
         $session_info = $session_info[0];
         $session = array();
         $session['title'] = $session_info['name'];
         $session['coach'] = '';
         $session['dates'] = '';
         if ($session_info['access_end_date'] == '0000-00-00' && $session_info['access_start_date'] == '0000-00-00' || empty($session_info['access_end_date']) && empty($session_info['access_start_date'])) {
             if (api_get_setting('session.show_session_coach') === 'true') {
                 $session['coach'] = get_lang('GeneralCoach') . ': ' . api_get_person_name($session_info['firstname'], $session_info['lastname']);
             }
             if (isset($session_info['duration']) && !empty($session_info['duration'])) {
                 $userDurationData = SessionManager::getUserSession(api_get_user_id(), $session_id);
                 $userDuration = 0;
                 if (isset($userDurationData['duration'])) {
                     $userDuration = intval($userDurationData['duration']);
                 }
                 $totalDuration = $session_info['duration'] + $userDuration;
                 $daysLeft = SessionManager::getDayLeftInSession($session_id, api_get_user_id(), $totalDuration);
                 $session['duration'] = sprintf(get_lang('SessionDurationXDaysLeft'), $daysLeft);
             }
             $active = true;
         } else {
             $start = $stop = false;
             $start_buffer = $stop_buffer = '';
             if ($session_info['access_start_date'] == '0000-00-00' || empty($session_info['access_start_date'])) {
                 $session_info['access_start_date'] = '';
             } else {
                 $start = true;
                 $start_buffer = $session_info['access_start_date'];
                 $session_info['access_start_date'] = $session_info['access_start_date'];
             }
             if ($session_info['access_end_date'] == '0000-00-00' || empty($session_info['access_end_date'])) {
                 $session_info['access_end_date'] = '';
             } else {
                 $stop = true;
                 $stop_buffer = $session_info['access_end_date'];
                 $session_info['access_end_date'] = $session_info['access_end_date'];
             }
             if ($start && $stop) {
                 $session['dates'] = Display::tag('em', sprintf(get_lang('FromDateXToDateY'), api_format_date($start_buffer), api_format_date($stop_buffer)));
             } else {
                 $start_buffer = $stop_buffer = null;
                 if (!empty($session_info['access_start_date'])) {
                     $start_buffer = sprintf(get_lang('FromDateX'), api_format_date($session_info['access_start_date']));
                 }
                 if (!empty($session_info['access_end_date'])) {
                     $stop_buffer = sprintf(get_lang('UntilDateX'), api_format_date($session_info['access_end_date']));
                 }
                 $session['dates'] = Display::tag('em', "{$start_buffer} {$stop_buffer}");
             }
             if (api_get_setting('session.show_session_coach') === 'true') {
                 $session['coach'] = get_lang('GeneralCoach') . ': ' . api_get_person_name($session_info['firstname'], $session_info['lastname']);
             }
             $active = $date_start <= $now && $date_end >= $now;
         }
         $session['active'] = $active;
         $session['session_category_id'] = $session_info['session_category_id'];
         $session['description'] = $session_info['description'];
         $session['show_description'] = $session_info['show_description'];
         $entityManager = Database::getManager();
         $fieldValuesRepo = $entityManager->getRepository('ChamiloCoreBundle:ExtraFieldValues');
         $extraFieldValues = $fieldValuesRepo->getVisibleValues(Chamilo\CoreBundle\Entity\ExtraField::SESSION_FIELD_TYPE, $session_id);
         $session['extra_fields'] = [];
         foreach ($extraFieldValues as $value) {
             $session['extra_fields'][] = ['field' => ['variable' => $value->getField()->getVariable(), 'display_text' => $value->getField()->getDisplayText()], 'value' => $value->getValue()];
         }
         $output = $session;
     }
     return $output;
 }
Example #2
0
 /**
  * Get the session box details as an array
  * @param int       Session ID
  * @return array    Empty array or session array ['title'=>'...','category'=>'','dates'=>'...','coach'=>'...','active'=>true/false,'session_category_id'=>int]
  */
 public static function get_session_title_box($session_id)
 {
     global $nosession;
     if (!$nosession) {
         global $now, $date_start, $date_end;
     }
     $output = array();
     if (!$nosession) {
         $main_user_table = Database::get_main_table(TABLE_MAIN_USER);
         $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.*
                 FROM ' . $tbl_session . ' ts  LEFT JOIN ' . $main_user_table . ' tu ON ts.id_coach = tu.user_id
                 WHERE ts.id = ' . intval($session_id);
         $rs = Database::query($sql);
         $session_info = Database::store_result($rs, 'ASSOC');
         $session_info = $session_info[0];
         $session = array();
         $session['title'] = $session_info['name'];
         $session['coach'] = '';
         $session['dates'] = '';
         if ($session_info['date_end'] == '0000-00-00' && $session_info['date_start'] == '0000-00-00') {
             if (api_get_setting('show_session_coach') === 'true') {
                 $session['coach'] = get_lang('GeneralCoach') . ': ' . api_get_person_name($session_info['firstname'], $session_info['lastname']);
             }
             if (isset($session_info['duration']) && !empty($session_info['duration'])) {
                 $userDurationData = SessionManager::getUserSession(api_get_user_id(), $session_id);
                 $userDuration = 0;
                 if (isset($userDurationData['duration'])) {
                     $userDuration = intval($userDurationData['duration']);
                 }
                 $totalDuration = $session_info['duration'] + $userDuration;
                 $daysLeft = SessionManager::getDayLeftInSession($session_id, api_get_user_id(), $totalDuration);
                 $session['duration'] = sprintf(get_lang('SessionDurationXDaysLeft'), $daysLeft);
             }
             $active = true;
         } else {
             $start = $stop = false;
             $start_buffer = $stop_buffer = '';
             if ($session_info['date_start'] == '0000-00-00') {
                 $session_info['date_start'] = '';
             } else {
                 $start = true;
                 $start_buffer = $session_info['date_start'];
                 $session_info['date_start'] = get_lang('From') . ' ' . $session_info['date_start'];
             }
             if ($session_info['date_end'] == '0000-00-00') {
                 $session_info['date_end'] = '';
             } else {
                 $stop = true;
                 $stop_buffer = $session_info['date_end'];
                 $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));
             } else {
                 $session['dates'] = Display::tag('i', $session_info['date_start'] . ' ' . $session_info['date_end']);
             }
             if (api_get_setting('show_session_coach') === 'true') {
                 $session['coach'] = get_lang('GeneralCoach') . ': ' . api_get_person_name($session_info['firstname'], $session_info['lastname']);
             }
             $active = $date_start <= $now && $date_end >= $now;
         }
         $session['active'] = $active;
         $session['session_category_id'] = $session_info['session_category_id'];
         if (array_key_exists('show_description', $session_info)) {
             if (!empty($session_info['show_description'])) {
                 $session['description'] = $session_info['description'];
             }
         }
         $output = $session;
     }
     return $output;
 }
$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);
// 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'));