fix PR new grid view sessions -refs BT#11017

remotes/angel/1.11.x
Alex Aragon 9 years ago
parent a395fa9b20
commit eb52a24c7f
  1. 10
      main/auth/courses_controller.php
  2. 78
      main/inc/lib/internationalization.lib.php
  3. 21
      main/inc/lib/sessionmanager.lib.php
  4. 11
      main/template/default/auth/session_catalog.tpl

@ -792,6 +792,14 @@ class CoursesController
$hasRequirements = true;
break;
}
$cat = $session->getCategory();
if (empty($cat)) {
$cat = null;
$catName = '';
} else {
$catName = $cat->getName();
}
$coachId = $session->getGeneralCoach()->getId();
$coachName = $session->getGeneralCoach()->getCompleteName();
$actions = null;
@ -818,7 +826,7 @@ class CoursesController
),
'show_description' => $session->getShowDescription(),
'description' => $session->getDescription(),
'category' => $session->getCategory()->getName(),
'category' => $catName,
'tags' => $sessionCourseTags,
'edit_actions' => $actions
);

@ -427,78 +427,21 @@ function api_get_utc_datetime($time = null, $return_null_if_invalid_date = false
* @author Guillaume Viguier <guillaume.viguier@beeznest.com>
*/
function api_get_local_time(
$time = null,
$to_timezone = null,
$from_timezone = null,
$return_null_if_invalid_date = false
) {
// Determining the timezone to be converted from
if (is_null($from_timezone)) {
$from_timezone = 'UTC';
}
// Determining the timezone to be converted to
if (is_null($to_timezone)) {
$to_timezone = _api_get_timezone();
}
// If time is a timestamp, convert it to a string
if (is_null($time) || empty($time) || $time == '0000-00-00 00:00:00') {
if ($return_null_if_invalid_date) {
return null;
}
$from_timezone = 'UTC';
$time = gmdate('Y-m-d H:i:s');
}
if (is_numeric($time)) {
$time = intval($time);
$from_timezone = 'UTC';
$time = gmdate('Y-m-d H:i:s', $time);
}
if ($time instanceof DateTime) {
$time = $time->format('Y-m-d H:i:s');
$from_timezone = 'UTC';
}
try {
$date = new DateTime($time, new DateTimezone($from_timezone));
$date->setTimezone(new DateTimeZone($to_timezone));
return $date->format('Y-m-d H:i:s');
} catch (Exception $e) {
return null;
}
}
/**
* Returns a DATETIME string converted to the right timezone
* @param mixed The time to be converted
* @param string The timezone to be converted to.
* If null, the timezone will be determined based on user preference,
* or timezone chosen by the admin for the platform.
* @param string The timezone to be converted from. If null, UTC will be assumed.
* @param boolen view time in formatted
* @return string The converted time formatted as Y-m-d H:i:s
*
* @author Guillaume Viguier <guillaume.viguier@beeznest.com>
*/
function apiGetTimeForHumans(
$time = null,
$to_timezone = null,
$from_timezone = null,
$return_null_if_invalid_date = false,
$showTime = true
$showTime = true,
$dateHuman = false
) {
// Determining the timezone to be converted from
if (is_null($from_timezone)) {
$from_timezone = 'UTC';
}
// Determining the timezone to be converted to
if (is_null($to_timezone)) {
$to_timezone = _api_get_timezone();
}
// If time is a timestamp, convert it to a string
if (is_null($time) || empty($time) || $time == '0000-00-00 00:00:00') {
if ($return_null_if_invalid_date) {
@ -519,13 +462,20 @@ function apiGetTimeForHumans(
try {
$date = new DateTime($time, new DateTimezone($from_timezone));
$date->setTimezone(new DateTimeZone($to_timezone));
if($showTime){
return $date->format('j M Y, g:i a');
}else{
return $date->format('j M Y');
if ($showTime) {
if ($dateHuman) {
return $date->format('j M Y H:i:s');
} else {
return $date->format('Y-m-d H:i:s');
}
} else {
if ($dateHuman) {
return $date->format('j M Y');
} else {
return $date->format('Y-m-d');
}
}
} catch (Exception $e) {
return null;
}
}

@ -6587,18 +6587,17 @@ class SessionManager
*
* @return string
*/
private static function convertSessionDateToString($startDate, $endDate)
private static function convertSessionDateToString($startDate, $endDate, $showTime, $dateHuman)
{
$startDateToLocal = '';
$endDateToLocal = '';
// This will clean the variables if 0000-00-00 00:00:00 the variable will be empty
if (isset($startDateToLocal)) {
$startDateToLocal = apiGetTimeForHumans($startDate, null, null, true, false);
$startDateToLocal = api_get_local_time($startDate, null, null, true, $showTime, $dateHuman);
}
if (isset($endDateToLocal)) {
$endDateToLocal = apiGetTimeForHumans($endDate, null, null, true, false);
$endDateToLocal = api_get_local_time($endDate, null, null, true, $showTime, $dateHuman);
}
$result = '';
if (!empty($startDateToLocal) && !empty($endDateToLocal)) {
$result = sprintf(get_lang('FromDateXToDateY'), $startDateToLocal, $endDateToLocal);
@ -6610,11 +6609,9 @@ class SessionManager
$result = get_lang('Until').' '.$endDateToLocal;
}
}
if (empty($result)) {
$result = get_lang('NoTimeLimits');
}
return $result;
}
/**
@ -6626,16 +6623,22 @@ class SessionManager
{
$displayDates = self::convertSessionDateToString(
$sessionInfo['display_start_date'],
$sessionInfo['display_end_date']
$sessionInfo['display_end_date'],
false,
true
);
$accessDates = self::convertSessionDateToString(
$sessionInfo['access_start_date'],
$sessionInfo['access_end_date']
$sessionInfo['access_end_date'],
false,
true
);
$coachDates = self::convertSessionDateToString(
$sessionInfo['coach_access_start_date'],
$sessionInfo['coach_access_end_date']
$sessionInfo['coach_access_end_date'],
false,
true
);
$result = [

@ -58,8 +58,8 @@
<img class="img-responsive" src="{{ item.image ? _p.web_upload ~ item.image : _p.web_img ~ 'session_default.png' }}">
{% if item.category != '' %}
<span class="category">{{ item.category }}</span>
{% endif %}
<div class="cribbon"></div>
{% endif %}
<div class="black-shadow">
{% if show_tutor %}
<div class="author-card">
@ -79,7 +79,6 @@
<i class="fa fa-calendar-o" aria-hidden="true"></i> {{ item.date }}
</div>
</div>
<div class="admin-actions">
<div class="btn-group" role="group">
{% if item.edit_actions != '' %}
@ -92,7 +91,6 @@
{% endif %}
</div>
</div>
</div>
<div class="description">
<h4 class="title">
@ -163,7 +161,6 @@
{% else %}
content = "{{ 'NoDependencies'|get_lang }}";
{% endif %}
return content;
}
});
@ -181,7 +178,5 @@
</div>
</div>
<!-- end view session grib -->
{{ catalog_pagination }}
{% endblock %}
{{ catalog_pagination }}
{% endblock %}
Loading…
Cancel
Save