Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow users to bulk sign up for every session in the activity #93

Merged
merged 3 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backup/moodle2/backup_facetoface_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected function define_structure() {
'confirmationsubject', 'confirmationinstrmngr', 'confirmationmessage', 'waitlistedsubject', 'waitlistedmessage',
'cancellationsubject', 'cancellationinstrmngr', 'cancellationmessage', 'remindersubject', 'reminderinstrmngr',
'remindermessage', 'reminderperiod', 'requestsubject', 'requestinstrmngr', 'requestmessage',
'approvalreqd', 'allowcancellationsdefault'));
'approvalreqd', 'allowcancellationsdefault', 'signuptype', 'multiplesignupmethod'));

$sessions = new backup_nested_element('sessions');

Expand Down
1 change: 1 addition & 0 deletions db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<FIELD NAME="usercalentry" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" SEQUENCE="false"/>
<FIELD NAME="allowcancellationsdefault" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" SEQUENCE="false"/>
<FIELD NAME="signuptype" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="multiplesignupmethod" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for facetoface"/>
Expand Down
13 changes: 13 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -771,5 +771,18 @@ function xmldb_facetoface_upgrade($oldversion=0) {
upgrade_mod_savepoint(true, 2022091900, 'facetoface');
}

if ($oldversion < 2022101100) {
$table = new xmldb_table('facetoface');
$field = new xmldb_field('multiplesignupmethod', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'signuptype');

// Conditionally launch add field multiplesignupmethod.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

// Facetoface savepoint reached.
upgrade_mod_savepoint(true, 2022101100, 'facetoface');
}

return $result;
}
8 changes: 8 additions & 0 deletions lang/en/facetoface.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@
$string['moreinfo'] = 'More info';
$string['multidate'] = '(multi-date)';
$string['multiple'] = 'Multiple';
$string['multiplesignupmethod'] = 'Multiple signup method';
$string['multiplesignupmethod_help'] = 'When set to "Per session" students sign up for each session within the face to face activity individually. When set to "Per activity" students will only have the option to sign up for every session within the face to face activity.';
$string['multiplesignuppersession'] = 'Per session';
$string['multiplesignupperactivity'] = 'Per activity';
$string['newmanageremailaddress'] = 'Manager\'s email address';
$string['noactionableunapprovedrequests'] = 'No actionable unapproved requests';
$string['nocustomfields'] = '<p>No custom fields are defined.</p>';
Expand Down Expand Up @@ -543,11 +547,13 @@
$string['single'] = 'Single';
$string['signups'] = 'Sign-ups';
$string['signupfor'] = 'Sign-up for {$a}';
$string['signupforstream'] = 'Sign-up for stream';
$string['signuptype'] = 'Signup type';
$string['signuptype_help'] = 'When set to "single" a student may only register for one session per Face-to-Face actvitiy. When set to "multiple" a student may register for multiple sessions per activity.';
$string['signupforsession'] = 'Sign-up for an available upcoming session';
$string['signupforthissession'] = 'Sign-up for this Face-to-Face session';
$string['sign-ups'] = 'Sign-ups';
$string['signuptypemismatch'] = 'Signup type must be "multiple" when signup method is per activity';
$string['sitenoticesheading'] = 'Site Notices';
$string['subject'] = 'Change in booking in the course {$a->coursename} ({$a->duedate})';
$string['submissions'] = 'Submissions';
Expand All @@ -565,6 +571,7 @@
$string['status_approved'] = 'Approved';
$string['status_declined'] = 'Declined';
$string['status_session_cancelled'] = 'Session Cancelled';
$string['somesessionsfull'] = 'You have not been signed up for some sessions in the stream as they are at capacity.';
$string['summary'] = 'Summary';
$string['takeattendance'] = 'Take attendance';
$string['time'] = 'Time';
Expand Down Expand Up @@ -592,6 +599,7 @@
$string['usersignedup'] = 'Status: signed up';
$string['usersignedupon'] = 'User signed up on {$a}';
$string['userwillbewaitlisted'] = 'This session is currently full. By clicking the "Sign-up" button, you will be placed on the sessions\'s wait-list.';
$string['upcomingsessions'] = 'Upcoming sessions';
$string['validation:needatleastonedate'] = 'You need to provide at least one date or mark the session as wait-listed.';
$string['venue'] = 'Venue';
$string['viewallsessions'] = 'View all sessions';
Expand Down
35 changes: 28 additions & 7 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
// Signup setting constants.
define('MOD_FACETOFACE_SIGNUP_SINGLE', 0);
define('MOD_FACETOFACE_SIGNUP_MULTIPLE', 1);
define('MOD_FACETOFACE_SIGNUP_MULTIPLE_PER_SESSION', 0);
define('MOD_FACETOFACE_SIGNUP_MULTIPLE_PER_ACTIVITY', 1);

// Signup status codes (remember to update facetoface_statuses()).
define('MDL_F2F_STATUS_USER_CANCELLED', 10);
Expand Down Expand Up @@ -307,6 +309,12 @@ function facetoface_fix_settings($facetoface) {
if (empty($facetoface->approvalreqd)) {
$facetoface->approvalreqd = 0;
}

// When users can only sign up for one session per activity, force the
// signup type to per-session.
if (isset($facetoface->signuptype) && $facetoface->signuptype == MOD_FACETOFACE_SIGNUP_SINGLE) {
$facetoface->multiplesignupmethod = MOD_FACETOFACE_SIGNUP_MULTIPLE_PER_SESSION;
}
}

/**
Expand Down Expand Up @@ -2784,9 +2792,8 @@ function facetoface_cm_info_view(cm_info $coursemodule) {
continue;
} else {
$signupurl = new moodle_url('/mod/facetoface/signup.php', array('s' => $session->id));
$signuptext = 'signup';
$moreinfolink = html_writer::link($signupurl, get_string($signuptext, 'facetoface'), array('class' => 'f2fsessionlinks f2fsessioninfolink'));

$signupstr = $facetoface->multiplesignupmethod == MOD_FACETOFACE_SIGNUP_MULTIPLE_PER_SESSION ? 'signup' : 'signupforstream';
$moreinfolink = html_writer::link($signupurl, get_string($signupstr, 'facetoface'), array('class' => 'f2fsessionlinks f2fsessioninfolink'));
$span = html_writer::tag('span', get_string('options', 'facetoface').':', array('class' => 'f2fsessionnotice'));
}

Expand Down Expand Up @@ -2844,13 +2851,27 @@ function facetoface_cm_info_view(cm_info $coursemodule) {

if (!empty($futuresessions)) {
$output .= html_writer::start_tag('div', array('class' => 'f2fsessiongroup'));
$output .= html_writer::tag('span', get_string('signupforsession', 'facetoface'), array('class' => 'f2fsessionnotice'));

if ($facetoface->multiplesignupmethod == MOD_FACETOFACE_SIGNUP_MULTIPLE_PER_SESSION) {
$output .= html_writer::tag('span', get_string('signupforsession', 'facetoface'), array('class' => 'f2fsessionnotice'));
} else {
$output .= html_writer::tag('span', get_string('upcomingsessions', 'facetoface'), array('class' => 'f2fsessionnotice'));

if (!empty($futuresessions)) {
$firstsession = $futuresessions[array_keys($futuresessions)[0]];
$output .= html_writer::tag('div', $firstsession->moreinfolink, array('class' => 'f2foptions'));
}
}

foreach ($futuresessions as $session) {
$output .= html_writer::start_tag('div', array('class' => 'f2fsession f2ffuture'))
. html_writer::tag('div', $session->date.$session->multidate, array('class' => 'f2fsessiontime'))
. html_writer::tag('div', $session->options . $session->moreinfolink, array('class' => 'f2foptions'))
. html_writer::end_tag('div');
. html_writer::tag('div', $session->date.$session->multidate, array('class' => 'f2fsessiontime'));

if ($facetoface->multiplesignupmethod == MOD_FACETOFACE_SIGNUP_MULTIPLE_PER_SESSION) {
$output .= html_writer::tag('div', $session->options . $session->moreinfolink, array('class' => 'f2foptions'));
}

$output .= html_writer::end_tag('div');
}
$output .= html_writer::end_tag('div');
}
Expand Down
9 changes: 9 additions & 0 deletions mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ public function definition() {
$mform->setDefault('signuptype', MOD_FACETOFACE_SIGNUP_SINGLE);
$mform->addHelpButton('signuptype', 'signuptype', 'facetoface');

$multiplesignupmethods = array(
MOD_FACETOFACE_SIGNUP_MULTIPLE_PER_SESSION => get_string('multiplesignuppersession', 'facetoface'),
MOD_FACETOFACE_SIGNUP_MULTIPLE_PER_ACTIVITY => get_string('multiplesignupperactivity', 'facetoface'),
);
$mform->addElement('select', 'multiplesignupmethod', get_string('multiplesignupmethod', 'facetoface'), $multiplesignupmethods);
$mform->setDefault('signuptype', MOD_FACETOFACE_SIGNUP_MULTIPLE_PER_SESSION);
$mform->addHelpButton('multiplesignupmethod', 'multiplesignupmethod', 'facetoface');
$mform->hideIf('multiplesignupmethod', 'signuptype', 'eq', MOD_FACETOFACE_SIGNUP_SINGLE);

$mform->addElement('header', 'calendaroptions', get_string('calendaroptions', 'facetoface'));

$calendaroptions = array(
Expand Down
4 changes: 2 additions & 2 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class mod_facetoface_renderer extends plugin_renderer_base {
/**
* Builds session list table given an array of sessions
*/
public function print_session_list_table($customfields, $sessions, $viewattendees, $editsessions) {
public function print_session_list_table($customfields, $sessions, $viewattendees, $editsessions, $signuplinks = true) {
$output = '';

$tableheader = array();
Expand Down Expand Up @@ -172,7 +172,7 @@ public function print_session_list_table($customfields, $sessions, $viewattendee
$options .= html_writer::link('cancelsignup.php?s=' . $session->id . '&backtoallsessions=' . $session->facetoface,
get_string('cancelbooking', 'facetoface'), array('title' => get_string('cancelbooking', 'facetoface')));
}
} else if (!$sessionstarted and !$bookedsession) {
} else if (!$sessionstarted && !$bookedsession && $signuplinks) {
$options .= html_writer::link('signup.php?s='.$session->id.'&backtoallsessions='.$session->facetoface,
get_string('signup', 'facetoface'));
}
Expand Down
46 changes: 42 additions & 4 deletions signup.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
redirect($returnurl);
}

$isbulksignup = $facetoface->multiplesignupmethod == MOD_FACETOFACE_SIGNUP_MULTIPLE_PER_ACTIVITY;
if ($fromform = $mform->get_data()) { // Form submitted.

if (empty($fromform->submitbutton)) {
Expand Down Expand Up @@ -124,6 +125,41 @@
$statuscode = MDL_F2F_STATUS_WAITLISTED;
}

if ($isbulksignup) {
$error = '';
$message = get_string('bookingcompleted', 'facetoface');
foreach (facetoface_get_sessions($facetoface->id) as $session) {
if (!facetoface_session_has_capacity($session, $context) && (!$session->allowoverbook)) {
$error = html_writer::empty_tag('br') . html_writer::empty_tag('br') . get_string('somesessionsfull', 'facetoface');
continue;
}

// This shouldn't happen. Bulk signup can only be enabled when multiple signups are allowed.
if ($facetoface->signuptype == MOD_FACETOFACE_SIGNUP_SINGLE && facetoface_get_user_submissions($facetoface->id, $USER->id)) {
throw new moodle_exception('alreadysignedup', 'facetoface', $returnurl);
}

if (facetoface_manager_needed($facetoface) && !facetoface_get_manageremail($USER->id)) {
throw new moodle_exception('error:manageremailaddressmissing', 'facetoface', $returnurl);
}

if ($submissionid = facetoface_user_signup($session, $facetoface, $course, $fromform->discountcode, $fromform->notificationtype, $statuscode, false, false)) {
// Logging and events trigger.
$params = array(
'context' => $contextmodule,
'objectid' => $session->id
);
$event = \mod_facetoface\event\signup_success::create($params);
$event->add_record_snapshot('facetoface_sessions', $session);
$event->add_record_snapshot('facetoface', $facetoface);
$event->trigger();
}
}

$timemessage = 4;
redirect($returnurl, $message . $error, $timemessage);
}

if (!facetoface_session_has_capacity($session, $context) && (!$session->allowoverbook)) {
throw new moodle_exception('sessionisfull', 'facetoface', $returnurl);
} else if ($facetoface->signuptype == MOD_FACETOFACE_SIGNUP_SINGLE && facetoface_get_user_submissions($facetoface->id, $USER->id)) {
Expand Down Expand Up @@ -192,7 +228,7 @@

$timenow = time();

if ($session->datetimeknown && facetoface_has_session_started($session, $timenow)) {
if (!$isbulksignup && $session->datetimeknown && facetoface_has_session_started($session, $timenow)) {
$inprogressstr = get_string('cannotsignupsessioninprogress', 'facetoface');
$overstr = get_string('cannotsignupsessionover', 'facetoface');

Expand All @@ -204,16 +240,18 @@
exit;
}

if (!$signedup && !facetoface_session_has_capacity($session, $context) && (!$session->allowoverbook)) {
if (!$isbulksignup && !$signedup && !facetoface_session_has_capacity($session, $context) && (!$session->allowoverbook)) {
throw new moodle_exception('sessionisfull', 'facetoface', $returnurl);
echo $OUTPUT->box_end();
echo $OUTPUT->footer($course);
exit;
}

echo facetoface_print_session($session, $viewattendees);
if (!$isbulksignup) {
echo facetoface_print_session($session, $viewattendees);
}

if ($signedup) {
if (!$isbulksignup && $signedup) {
if (!($session->datetimeknown && facetoface_has_session_started($session, $timenow)) && $session->allowcancellations) {

// Cancellation link.
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2022091900;
$plugin->version = 2022101100;
$plugin->requires = 2022031500; // Requires 4.0
$plugin->release = '2022091900';
$plugin->component = 'mod_facetoface';
Expand Down
13 changes: 12 additions & 1 deletion view.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ function print_session_list($courseid, $facetoface, $location) {
$viewattendees = has_capability('mod/facetoface:viewattendees', $context);
$editsessions = has_capability('mod/facetoface:editsessions', $context);
$multiplesignups = $facetoface->signuptype == MOD_FACETOFACE_SIGNUP_MULTIPLE;
$bulksignup = $facetoface->multiplesignupmethod == MOD_FACETOFACE_SIGNUP_MULTIPLE_PER_ACTIVITY;

$bookedsession = null;
if ($submissions = facetoface_get_user_submissions($facetoface->id, $USER->id)) {
Expand Down Expand Up @@ -213,11 +214,21 @@ function print_session_list($courseid, $facetoface, $location) {

// Upcoming sessions.
echo $OUTPUT->heading(get_string('upcomingsessions', 'facetoface'));

if ($sessions && $bulksignup) {
$firstsession = $sessions[array_keys($sessions)[0]];
$signupforstreamlink = html_writer::link(
'signup.php?s=' . $firstsession->id . '&backtoallsessions=' . $session->facetoface,
get_string('signupforstream', 'facetoface')
);

echo html_writer::tag('p', $signupforstreamlink);
}
if (empty($upcomingarray) && empty($upcomingtbdarray)) {
print_string('noupcoming', 'facetoface');
} else {
$upcomingarray = array_merge($upcomingarray, $upcomingtbdarray);
echo $f2frenderer->print_session_list_table($customfields, $upcomingarray, $viewattendees, $editsessions);
echo $f2frenderer->print_session_list_table($customfields, $upcomingarray, $viewattendees, $editsessions, !$bulksignup);
}

if ($editsessions) {
Expand Down