Skip to content

Commit

Permalink
Improvement: Filter and sorting for bookable/free places as settings …
Browse files Browse the repository at this point in the history
…to be turned on or off Wunderbyte-GmbH/moodle-local-wunderbyte_table#69
  • Loading branch information
eynimeni committed Jan 23, 2025
1 parent 4a1e0a4 commit c6c9ad9
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 34 deletions.
61 changes: 27 additions & 34 deletions classes/shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -758,15 +758,18 @@ private static function inittableforcourses($booking) {
*
*/
private static function add_standardfilters(&$table) {
$callbackfilter = new callback('bookable', get_string('bookable', 'local_musi'));
$callbackfilter->add_options([
0 => get_string('notbookable', 'local_musi'),
1 => get_string('bookable', 'local_musi'),
]);
// This filter expects a record from booking options table.
// We check if it is bookable for the user.
$callbackfilter->define_callbackfunction('local_musi\shortcodes::filter_bookable');
$table->add_filter($callbackfilter);
// Turn on or off.
if (get_config('local_musi', 'musishortcodesshowfilterbookable')) {
$callbackfilter = new callback('bookable', get_string('bookable', 'local_musi'));
$callbackfilter->add_options([
0 => get_string('notbookable', 'local_musi'),
1 => get_string('bookable', 'local_musi'),
]);
// This filter expects a record from booking options table.
// We check if it is bookable for the user.
$callbackfilter->define_callbackfunction('local_musi\shortcodes::filter_bookable');
$table->add_filter($callbackfilter);
}

$standardfilter = new standardfilter('sport', get_string('sport', 'local_musi'));
$table->add_filter($standardfilter);
Expand Down Expand Up @@ -861,33 +864,23 @@ private static function set_table_options_from_arguments(&$table, $args) {
'sportsdivision' => get_string('sportsdivision', 'local_musi'),
'sport' => get_string('sport', 'local_musi'),
'location' => get_string('location', 'local_musi'),
// 'bookedplaces' => get_string('freeplaces', 'local_musi'),
];

// As the "free places sorting" functionality is not yet tested and not yet integrated into Wunderbyte table...
// ... we currently comment this out. We'll add it later on...
/*
$sortbycallback = new \local_wunderbyte_table\local\sortables\types\callback(
'freeplaces',
get_string('freeplaces', 'local_musi')
);
// $sortbycallback->define_callbackfunction('local_musi\shortcodes::sort_freeplaces');
// $table->add_sortable($sortbycallback);
*/

$standardsortable = new \local_wunderbyte_table\local\sortables\types\standardsortable(
'freeplaces',
get_string('freeplaces', 'local_musi')
);
$select = '(SELECT COALESCE(NULLIF(s1.maxanswers, 0), 999999) - COUNT(ba.id)
FROM {booking_answers} ba
WHERE ba.optionid = s1.id AND ba.waitinglist < 3) AS freeplaces';
$from = '';
$where = '';
$standardsortable->define_sql($select, $from, $where);

$standardsortable->define_cache('mod_booking', 'bookedusertable');
$table->add_sortable($standardsortable);
if (get_config('local_musi', 'musishortcodesshowsortingfreeplaces')) {
$standardsortable = new \local_wunderbyte_table\local\sortables\types\standardsortable(
'freeplaces',
get_string('freeplaces', 'local_musi')
);
$select = '(SELECT COALESCE(NULLIF(s1.maxanswers, 0), 999999) - COUNT(ba.id)
FROM {booking_answers} ba
WHERE ba.optionid = s1.id AND ba.waitinglist < 3) AS freeplaces';
$from = '';
$where = '';
$standardsortable->define_sql($select, $from, $where);

$standardsortable->define_cache('mod_booking', 'bookedusertable');
$table->add_sortable($standardsortable);
}

if (get_config('local_musi', 'musishortcodesshowstart')) {
$sortablecolumns['coursestarttime'] = get_string('coursestarttime', 'mod_booking');
Expand Down
2 changes: 2 additions & 0 deletions lang/de/local_musi.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@
$string['musishortcodes:showbookablefrom'] = '"Buchbar ab" anzeigen';
$string['musishortcodes:showbookableuntil'] = '"Buchbar bis" anzeigen';
$string['musishortcodes:showfiltercoursetime'] = 'Filter "Kurs beginnt um" anzeigen';
$string['musishortcodes:showfilterbookable'] = 'Filter "Buchbar" anzeigen';
$string['musishortcodes:showfilterbookingtime'] = 'Filter "Anmeldezeiten" anzeigen';
$string['musishortcodes:showsortingfreeplaces'] = 'Sortiermöglichkeit "Freie Plätze" anzeigen';

// General strings.
$string['campaigns'] = 'Kampagnen';
Expand Down
2 changes: 2 additions & 0 deletions lang/en/local_musi.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@
$string['musishortcodes:showbookablefrom'] = 'Show "Bookable from"';
$string['musishortcodes:showbookableuntil'] = 'Show "Bookable until"';
$string['musishortcodes:showfiltercoursetime'] = 'Show filter "Course starts at"';
$string['musishortcodes:showfilterbookable'] = 'Show filter "Bookable"';
$string['musishortcodes:showfilterbookingtime'] = 'Show filter "Booking time"';
$string['musishortcodes:showsortingfreeplaces'] = 'Show sorting "Free places"';

// General strings.
$string['campaigns'] = 'Campaigns';
Expand Down
22 changes: 22 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,28 @@
});
$settings->add($showfilterbookingtimesetting);

$showfilterbookable = new admin_setting_configcheckbox(
'local_musi/musishortcodesshowfilterbookable',
get_string('musishortcodes:showfilterbookable', 'local_musi'),
'',
0
);
$showfilterbookable->set_updatedcallback(function () {
cache_helper::purge_by_event('setbackoptionstable');
});
$settings->add($showfilterbookable);

$showsortingfreeplaces = new admin_setting_configcheckbox(
'local_musi/musishortcodesshowsortingfreeplaces',
get_string('musishortcodes:showsortingfreeplaces', 'local_musi'),
'',
0
);
$showsortingfreeplaces->set_updatedcallback(function () {
cache_helper::purge_by_event('setbackoptionstable');
});
$settings->add($showsortingfreeplaces);

$collapsedescriptionoptions = [
0 => get_string('collapsedescriptionoff', 'local_musi'),
100 => "100",
Expand Down

0 comments on commit c6c9ad9

Please sign in to comment.