Skip to content

Commit

Permalink
Improvement: GH-709 Empty tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
WunderJacob committed Dec 6, 2024
1 parent 8c031e0 commit 73a5a86
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 32 deletions.
90 changes: 59 additions & 31 deletions classes/output/mobile.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,24 +215,25 @@ public static function mobile_mybookings_list($args) {
global $OUTPUT, $USER, $DB;

$mybookings = $DB->get_records_sql(
"SELECT ba.id id, c.id courseid, c.fullname fullname, b.id bookingid, b.name, bo.text, bo.id optionid,
bo.coursestarttime coursestarttime, bo.courseendtime courseendtime, cm.id cmid
FROM
{booking_answers} ba
LEFT JOIN
{booking_options} bo ON ba.optionid = bo.id
LEFT JOIN
{booking} b ON b.id = bo.bookingid
LEFT JOIN
{course} c ON c.id = b.course
LEFT JOIN
{course_modules} cm ON cm.module = (SELECT
id
"SELECT ba.id id, c.id courseid, c.fullname fullname, b.id bookingid, b.name, bo.text, bo.id optionid,
bo.coursestarttime coursestarttime, bo.courseendtime courseendtime, cm.id cmid
FROM
{modules}
WHERE
name = 'booking')
WHERE instance = b.id AND ba.userid = {$USER->id} AND cm.visible = 1");
{booking_answers} ba
LEFT JOIN
{booking_options} bo ON ba.optionid = bo.id
LEFT JOIN
{booking} b ON b.id = bo.bookingid
LEFT JOIN
{course} c ON c.id = b.course
LEFT JOIN
{course_modules} cm ON cm.module = (SELECT
id
FROM
{modules}
WHERE
name = 'booking')
WHERE instance = b.id AND ba.userid = {$USER->id} AND cm.visible = 1"
);

$outputdata = [];

Expand Down Expand Up @@ -278,7 +279,9 @@ public static function mobile_course_view($args) {
global $DB, $OUTPUT, $USER;

$cmid = $args['cmid'];
$whichview = $args['whichview'] ?? 'showall';
$availablenavtabs = self::get_available_nav_tabs();
$whichview = self::set_active_nav_tabs($availablenavtabs, $args['whichview']);

if (empty($cmid)) {
throw new moodle_exception('nocmidselected', 'mod_booking');
}
Expand All @@ -303,10 +306,11 @@ public static function mobile_course_view($args) {
$outputdata[] = $data;
}

$data['availablenavtabs'] = $availablenavtabs;
$data['whichview'] = $whichview;
$data['cmid'] = $cmid;
$data['mybookings'] = $outputdata;
$data['availablenavtabs'] = self::get_available_nav_tabs($whichview);
$data['timestamp'] = time();
return [
'templates' => [
[
Expand All @@ -331,7 +335,7 @@ public static function get_available_booking_options($selectedview, $cmid) {
$params = [];
switch ($selectedview) {
case 'showactive':
$params = self::get_rendered_all_options_table($booking);
$params = self::get_rendered_active_options_table($booking);
break;
case 'mybooking':
$params = self::get_rendered_my_booked_options_table($booking);
Expand Down Expand Up @@ -361,10 +365,14 @@ public static function get_available_booking_options($selectedview, $cmid) {
[],
$params['wherearray'],
$userid ?? null,
null,
$params['bookingparams'] ?? null,
$params['additionalwhere'] ?? null
);

if ($selectedview == 'showactive') {
$params['timenow'] = strtotime('today 00:00');
}

$sql = "SELECT $fields
FROM $from
WHERE $where";
Expand Down Expand Up @@ -446,6 +454,7 @@ public static function get_rendered_active_options_table($booking): array {
return [
'wherearray' => $wherearray,
'additionalwhere' => $additionalwhere,
'bookingparams' => [MOD_BOOKING_STATUSPARAM_BOOKED],
];
}

Expand Down Expand Up @@ -477,24 +486,43 @@ public static function get_rendered_all_options_table($booking): array {
}

/**
* Get all selected nav tabs from the config
* @param string $activetab
* Get all selected nav tabs from the config$activetab
* @return array
*/
public static function get_available_nav_tabs($activetab) {
public static function get_available_nav_tabs() {
$selectednavlabelnames = [];
$navlabelnames = self::match_view_label_and_names();
$navtabs = explode(',', get_config('booking', 'mobileviewoptions'));
foreach ($navtabs as $navtab) {
$selectednavlabelnames[] = [
'label' => $navtab,
'name' => $navlabelnames[$navtab],
'class' => $activetab === $navtab ? 'active' : false,
];
$configmobileviewoptions = get_config('booking', 'mobileviewoptions');
if ($configmobileviewoptions !== '') {
$navtabs = explode(',', get_config('booking', 'mobileviewoptions'));
foreach ($navtabs as $navtab) {
$selectednavlabelnames[] = [
'label' => $navtab,
'name' => $navlabelnames[$navtab],
'class' => $activetab === $navtab ? 'active' : false,
];
}
}
return $selectednavlabelnames;
}

/**
* Get all selected nav tabs from the config$activetab
* @param array $tabs
* @param string $activetab
* @return string
*/
public static function set_active_nav_tabs(&$tabs, $activetab) {
$whichview = $activetab ?? $tabs[0]['label'] ?? 'showall';
foreach ($tabs as &$tab) {
if ($tab['label'] == $whichview) {
$tab['class'] = 'active';
break;
}
}
return $whichview;
}

/**
* Config options my name
* @return array
Expand Down
2 changes: 1 addition & 1 deletion templates/mobile/mobile_mybookings_list.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
title="<% text %>"
component="mod_booking"
method="mobile_course_view"
[args]="{cmid: <% cmid %>, whichview: '<% label %>'}"
[args]="{cmid: <% cmid %>, whichview: '<% label %>', timestamp: <% timestamp %>}"
class="<% class %>"
>
<% isactive %>
Expand Down

0 comments on commit 73a5a86

Please sign in to comment.