Skip to content

Commit

Permalink
Next step for presence tracking in optiondate scope #721
Browse files Browse the repository at this point in the history
  • Loading branch information
ibernhardf committed Jan 30, 2025
1 parent b9ed8aa commit a440ca0
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 88 deletions.
46 changes: 43 additions & 3 deletions classes/booking_answers.php
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,8 @@ public static function number_actively_booked(int $userid, int $teacherid = 0) {
* @return (string|int[])[]
*/
public static function return_sql_for_booked_users(string $scope, int $scopeid, int $statusparam) {

if ($scope != "option") {
global $DB;
if (!in_array($scope, ["option", "optiondate"])) {
$advancedsqlstart = "SELECT
ba.id,
cm.id AS cmid,
Expand Down Expand Up @@ -706,6 +706,46 @@ public static function return_sql_for_booked_users(string $scope, int $scopeid,
$where = '1=1';

switch ($scope) {
case 'optiondate':
$optiondateid = $scopeid;
// We need to set a limit for the query in mysqlfamily.
$fields = 's1.*';
$from = "(
SELECT " .
$DB->sql_concat("bod.id", "'-'", "u.id") .
" uniqueid,
bod.id optiondateid,
bod.coursestarttime,
bod.courseendtime,
boda.userid,
boda.status,
boda.json,
boda.notes,
boda.optionid,
bo.titleprefix,
bo.text,
boda.userid,
u.firstname,
u.lastname,
u.email
FROM {booking_optiondates} bod
JOIN {booking_options} bo
ON bo.id = bod.optionid
JOIN {booking_answers} ba
ON bo.id = ba.optionid
JOIN {user} u
ON u.id = ba.userid
LEFT JOIN {booking_optiondates_answers} boda
ON bod.id = boda.optiondateid AND bo.id = boda.optionid AND ba.userid = boda.userid
WHERE bod.id = :optiondateid AND ba.waitinglist = :statusparam
ORDER BY bod.coursestarttime, u.lastname, u.firstname ASC
LIMIT 10000000000
) s1";
$params = [
'optiondateid' => $optiondateid,
'statusparam' => MOD_BOOKING_STATUSPARAM_BOOKED,
];
break;
case 'option':
$optionid = $scopeid;
// We need to set a limit for the query in mysqlfamily.
Expand Down Expand Up @@ -863,7 +903,7 @@ private function get_all_answers_for_user_cached(
$cache->set('myanswers', $data);
}
} catch (Throwable $e) {
if ($CFG->debug = (E_ALL | E_STRICT)) {
if ($CFG->debug === E_ALL) {
throw $e;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@


/**
* Class to handle optiondates, presence status etc.
* Class to handle booking answers for specific optiondates, e.g. for presence status.
*/
class optiondate {
class optiondate_answer {
/**
* $userid
*
Expand Down Expand Up @@ -136,7 +136,7 @@ public function delete_record() {
*
* @return array An array of record objects.
*/
public function get_records_by_optiondate() {
public function get_records_for_optiondate() {
global $DB;
return $DB->get_records(
'booking_optiondates_answers',
Expand All @@ -151,8 +151,6 @@ public function get_records_by_optiondate() {
* @return bool True on success, false on failure.
*/
public function add_or_update_status($status) {
global $DB;

return $this->save_record($status);
}

Expand All @@ -163,8 +161,6 @@ public function add_or_update_status($status) {
* @return bool True on success, false on failure.
*/
public function add_or_update_notes($note) {
global $DB;

return $this->save_record(null, $note);
}
}
154 changes: 84 additions & 70 deletions classes/output/booked_users.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,50 @@ public function __construct(
bool $showtonotify = false,
bool $showdeleted = false
) {
// Columns.
$bookeduserscols = ['name', 'action_delete'];
$waitinglistcols = ['name', 'action_confirm_delete'];
$reserveduserscols = ['name', 'action_delete'];
$userstonotifycols = ['name', 'action_delete'];
$deleteduserscols = ['name', 'timemodified'];
if ($scope == 'optiondate') {
// For optiondates we only show booked users.
// Also, we have no delete action but presence tracking.
$bookeduserscols = ['lastname', 'firstname', 'email', 'status', 'notes'];
$bookedusersheaders = [
get_string('lastname', 'core'),
get_string('firstname', 'core'),
get_string('email', 'core'),
get_string('presence', 'mod_booking'),
get_string('notes', 'mod_booking'),
];
} else {
// Define columns and headers for the tables.
$bookeduserscols = ['name', 'action_delete'];
$waitinglistcols = ['name', 'action_confirm_delete'];
$reserveduserscols = ['name', 'action_delete'];
$userstonotifycols = ['name', 'action_delete'];
$deleteduserscols = ['name', 'timemodified'];

// Headers.
$bookedusersheaders = [get_string('user', 'core'), get_string('delete', 'mod_booking')];
$waitinglistheaders = [
get_string('user', 'core'),
get_string('delete', 'mod_booking'),
];
$reservedusersheaders = [get_string('user', 'core'), get_string('delete', 'mod_booking')];
$userstonotifyheaders = [get_string('user', 'core'), get_string('delete', 'mod_booking')];
$deletedusersheaders = [get_string('user', 'core'), get_string('date')];
$bookedusersheaders = [
get_string('user', 'core'),
get_string('delete', 'mod_booking'),
];
$waitinglistheaders = [
get_string('user', 'core'),
get_string('delete', 'mod_booking'),
];
$reservedusersheaders = [
get_string('user', 'core'),
get_string('delete', 'mod_booking'),
];
$userstonotifyheaders = [
get_string('user', 'core'),
get_string('delete', 'mod_booking'),
];
$deletedusersheaders = [
get_string('user', 'core'),
get_string('date'),
];
}

// If the scope contains more than one option...
// ...then we have to add an option column!
if ($scope != 'option') {
if (!in_array($scope, ['option', 'optiondate'])) {
array_unshift($bookeduserscols, 'option');
array_unshift($waitinglistcols, 'option');
array_unshift($reserveduserscols, 'option');
Expand All @@ -111,27 +135,14 @@ public function __construct(
array_unshift($reservedusersheaders, get_string('bookingoption', 'mod_booking'));
array_unshift($userstonotifyheaders, get_string('bookingoption', 'mod_booking'));
array_unshift($deletedusersheaders, get_string('bookingoption', 'mod_booking'));
} else {
} else if ($scope == 'option') {
// We are in 'option' scope.
if (get_config('booking', 'waitinglistshowplaceonwaitinglist')) {
array_unshift($waitinglistcols, 'rank');
array_unshift($waitinglistheaders, get_string('rank', 'mod_booking'));
}
}

// We currently only support checkboxes in option scope.
// We might change this in future versions.
// phpcs:ignore Squiz.PHP.CommentedOutCode.Found
/* if ($scope == 'option') {
// Checkboxes are currently only supported for booked users and users on waiting list.
// We might change this in future versions.
array_unshift($bookeduserscols, 'checkbox');
array_unshift($waitinglistcols, 'checkbox');
$headercheckboxhtml = '<input type="checkbox" id="usercheckboxall" name="selectall" value="0" />';
array_unshift($bookedusersheaders, $headercheckboxhtml);
array_unshift($waitinglistheaders, $headercheckboxhtml);
} */

$this->bookedusers = $showbooked ?
$this->render_users_table(
$scope,
Expand All @@ -142,44 +153,47 @@ public function __construct(
$bookedusersheaders
) : null;

$this->waitinglist = $showwaiting ? $this->render_users_table(
$scope,
$scopeid,
MOD_BOOKING_STATUSPARAM_WAITINGLIST,
'waitinglist',
$waitinglistcols,
$waitinglistheaders,
true
) : null;
// For optiondate scope, we only show booked users.
if ($scope != 'optiondate') {
$this->waitinglist = $showwaiting ? $this->render_users_table(
$scope,
$scopeid,
MOD_BOOKING_STATUSPARAM_WAITINGLIST,
'waitinglist',
$waitinglistcols,
$waitinglistheaders,
true
) : null;

$this->reservedusers = $showreserved ? $this->render_users_table(
$scope,
$scopeid,
MOD_BOOKING_STATUSPARAM_RESERVED,
'reserved',
$reserveduserscols,
$reservedusersheaders,
) : null;
$this->reservedusers = $showreserved ? $this->render_users_table(
$scope,
$scopeid,
MOD_BOOKING_STATUSPARAM_RESERVED,
'reserved',
$reserveduserscols,
$reservedusersheaders,
) : null;

$this->userstonotify = $showtonotify ? $this->render_users_table(
$scope,
$scopeid,
MOD_BOOKING_STATUSPARAM_NOTIFYMELIST,
'notifymelist',
$userstonotifycols,
$userstonotifyheaders
) : null;
$this->userstonotify = $showtonotify ? $this->render_users_table(
$scope,
$scopeid,
MOD_BOOKING_STATUSPARAM_NOTIFYMELIST,
'notifymelist',
$userstonotifycols,
$userstonotifyheaders
) : null;

$this->deletedusers = $showdeleted ? $this->render_users_table(
$scope,
$scopeid,
MOD_BOOKING_STATUSPARAM_DELETED,
'deleted',
$deleteduserscols,
$deletedusersheaders,
false,
true
) : null;
$this->deletedusers = $showdeleted ? $this->render_users_table(
$scope,
$scopeid,
MOD_BOOKING_STATUSPARAM_DELETED,
'deleted',
$deleteduserscols,
$deletedusersheaders,
false,
true
) : null;
}
}

/**
Expand Down Expand Up @@ -269,11 +283,11 @@ private function render_users_table(
*/
public function export_for_template(renderer_base $output): array {
return array_filter([
'bookedusers' => $this->bookedusers,
'waitinglist' => $this->waitinglist,
'reservedusers' => $this->reservedusers,
'userstonotify' => $this->userstonotify,
'deletedusers' => $this->deletedusers,
'bookedusers' => $this->bookedusers ?? null,
'waitinglist' => $this->waitinglist ?? null,
'reservedusers' => $this->reservedusers ?? null,
'userstonotify' => $this->userstonotify ?? null,
'deletedusers' => $this->deletedusers ?? null,
]);
}
}
23 changes: 23 additions & 0 deletions classes/table/manageusers_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,29 @@ public function col_name(stdClass $values) {
return $OUTPUT->render_from_template('mod_booking/booked_user', $data);
}

/**
* Return presence column.
*
* @param stdClass $values
* @return string
*/
public function col_status(stdClass $values) {
$possiblepresences = [
5 => get_string('statusunknown', 'mod_booking'),
6 => get_string('statusattending', 'mod_booking'),
1 => get_string('statuscomplete', 'mod_booking'),
2 => get_string('statusincomplete', 'mod_booking'),
3 => get_string('statusnoshow', 'mod_booking'),
4 => get_string('statusfailed', 'mod_booking'),
7 => get_string('statusexcused', 'mod_booking'),
];
if (isset($possiblepresences[$values->status])) {
return $possiblepresences[$values->status];
} else {
return get_string('statusunknown', 'mod_booking');
}
}

/**
* Change number of rows. Uses the transmitaction pattern (actionbutton).
* @param int $id
Expand Down
2 changes: 1 addition & 1 deletion lang/de/booking.php
Original file line number Diff line number Diff line change
Expand Up @@ -1543,7 +1543,7 @@
$string['notemplate'] = 'Nicht als Vorlage benutzen';
$string['notemplateyet'] = 'Es gibt noch kein Template';
$string['notenoughcreditstobook'] = 'Nicht genug Credit um zu buchen';
$string['notes'] = 'Anmerkungen zur Buchung';
$string['notes'] = 'Anmerkungen';
$string['notfullwaitinglist'] = 'Nicht volle Warteliste';
$string['notfullybooked'] = 'Nicht ausgebucht';
$string['notificationlist'] = 'Benachrichtigungsliste';
Expand Down
2 changes: 1 addition & 1 deletion lang/en/booking.php
Original file line number Diff line number Diff line change
Expand Up @@ -1547,7 +1547,7 @@
$string['notemplate'] = 'Do not use as template';
$string['notemplateyet'] = 'No template yet';
$string['notenoughcreditstobook'] = 'Not enough credit to book';
$string['notes'] = 'Booking notes';
$string['notes'] = 'Notes';
$string['notfullwaitinglist'] = 'Not full waitinglist';
$string['notfullybooked'] = 'Not fully booked';
$string['notificationlist'] = 'Notification list';
Expand Down
3 changes: 3 additions & 0 deletions report2.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
$scopes = ['system', 'course', 'instance', 'option', 'optiondate'];
$scope = 'optiondate'; // A specific date of a booking option.
$scopeid = $optiondateid;
if (empty($optionid)) {
$optionid = $DB->get_field('booking_optiondates', 'optionid', ['id' => $optiondateid]);
}
$optionsettings = singleton_service::get_instance_of_booking_option_settings($optionid);
$cmid = $optionsettings->cmid;
$bookingsettings = singleton_service::get_instance_of_booking_settings_by_cmid($cmid);
Expand Down
Loading

0 comments on commit a440ca0

Please sign in to comment.