Skip to content

Commit 247e1a0

Browse files
committed
Userportal session list - Show end date null values at the end BT#14252
If setting "my_courses_session_order" is set to: $_configuration['my_courses_session_order'] = ['field' => 'end_date', 'order' => 'asc']; Null values will be shown at the end.
1 parent 4a57d5c commit 247e1a0

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

main/inc/lib/api.lib.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2574,6 +2574,7 @@ function api_get_session_visibility(
25742574

25752575
return SESSION_AVAILABLE;
25762576
}
2577+
25772578
// If start date was set.
25782579
if (!empty($row['access_start_date'])) {
25792580
$visibility = $now > api_strtotime($row['access_start_date'], 'UTC') ? SESSION_AVAILABLE : SESSION_INVISIBLE;
@@ -2589,8 +2590,7 @@ function api_get_session_visibility(
25892590
}
25902591
}
25912592

2592-
/* If I'm a coach the visibility can change in my favor depending in
2593-
the coach dates */
2593+
// If I'm a coach the visibility can change in my favor depending in the coach dates.
25942594
$isCoach = api_is_coach($session_id, $courseId);
25952595

25962596
if ($isCoach) {

main/inc/lib/usermanager.lib.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2923,7 +2923,8 @@ public static function get_sessions_by_category(
29232923
sc.dateStart AS session_category_date_start,
29242924
sc.dateEnd AS session_category_date_end,
29252925
s.coachAccessStartDate AS coach_access_start_date,
2926-
s.coachAccessEndDate AS coach_access_end_date
2926+
s.coachAccessEndDate AS coach_access_end_date,
2927+
CASE WHEN s.accessEndDate IS NULL THEN 1 ELSE 0 END HIDDEN _isFieldNull
29272928
$position
29282929
FROM ChamiloCoreBundle:Session AS s
29292930
LEFT JOIN ChamiloCoreBundle:SessionRelCourseRelUser AS scu WITH scu.session = s
@@ -2949,13 +2950,18 @@ public static function get_sessions_by_category(
29492950
$orderBySettings = api_get_configuration_value('my_courses_session_order');
29502951
if (!empty($orderBySettings) && isset($orderBySettings['field']) && isset($orderBySettings['order'])) {
29512952
$field = $orderBySettings['field'];
2952-
$order = $orderBySettings['order'];
2953+
$orderSetting = $orderBySettings['order'];
29532954
switch ($field) {
29542955
case 'start_date':
2955-
$order = " ORDER BY s.accessStartDate $order";
2956+
$order = " ORDER BY s.accessStartDate $orderSetting";
29562957
break;
29572958
case 'end_date':
2958-
$order = " ORDER BY s.accessEndDate $order";
2959+
$order = " ORDER BY s.accessEndDate $orderSetting ";
2960+
if ($orderSetting == 'asc') {
2961+
// Put null values at the end
2962+
// https://stackoverflow.com/questions/12652034/how-can-i-order-by-null-in-dql
2963+
$order = " ORDER BY _isFieldNull asc, s.accessEndDate asc";
2964+
}
29592965
break;
29602966
}
29612967
}

0 commit comments

Comments
 (0)