Skip to content

Commit

Permalink
Merge pull request #151 from catalyst/150-upload-bookings
Browse files Browse the repository at this point in the history
feat: bulk book users to sessions via csv file
  • Loading branch information
Peterburnett authored May 10, 2024
2 parents c9b1dac + d3efc17 commit bc4ef02
Show file tree
Hide file tree
Showing 67 changed files with 2,479 additions and 1,078 deletions.
173 changes: 90 additions & 83 deletions attendees.php

Large diffs are not rendered by default.

32 changes: 14 additions & 18 deletions backup/moodle1/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
* @author Francois Marier <francois@catalyst.net.nz>
*/

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

/**
* Glossary conversion handler
*/
Expand All @@ -55,24 +53,20 @@ class moodle1_mod_facetoface_handler extends moodle1_mod_handler {
* @return array of {@link convert_path} instances
*/
public function get_paths() {
return array(
return [
new convert_path(
'facetoface', '/MOODLE_BACKUP/COURSE/MODULES/MOD/FACETOFACE',
array(
'renamefields' => array(
'description' => 'intro',
),
'newfields' => array(
'introformat' => FORMAT_MOODLE,
),
)
[
'renamefields' => ['description' => 'intro'],
'newfields' => ['introformat' => FORMAT_MOODLE],
]
),
new convert_path('facetoface_sessions', '/MOODLE_BACKUP/COURSE/MODULES/MOD/FACETOFACE/SESSIONS'),
new convert_path('facetoface_session', '/MOODLE_BACKUP/COURSE/MODULES/MOD/FACETOFACE/SESSIONS/SESSION'),
new convert_path('facetoface_sessions_dates', '/MOODLE_BACKUP/COURSE/MODULES/MOD/FACETOFACE/SESSIONS/SESSION/DATES'),
new convert_path('facetoface_sessions_date',
'/MOODLE_BACKUP/COURSE/MODULES/MOD/FACETOFACE/SESSIONS/SESSION/DATES/DATE'),
);
];
}

/**
Expand Down Expand Up @@ -104,9 +98,11 @@ public function process_facetoface($data) {

// Start writing facetoface.xml.
$this->open_xml_writer("activities/facetoface_{$this->moduleid}/facetoface.xml");
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid,
'modulename' => 'facetoface', 'contextid' => $contextid));
$this->xmlwriter->begin_tag('facetoface', array('id' => $instanceid));
$this->xmlwriter->begin_tag('activity', [
'id' => $instanceid, 'moduleid' => $this->moduleid,
'modulename' => 'facetoface', 'contextid' => $contextid,
]);
$this->xmlwriter->begin_tag('facetoface', ['id' => $instanceid]);

unset($data['id']);
foreach ($data as $field => $value) {
Expand All @@ -128,7 +124,7 @@ public function on_facetoface_sessions_start() {
* data available
*/
public function process_facetoface_session($data) {
$this->write_xml('session', $data, array('/session/id'));
$this->write_xml('session', $data, ['/session/id']);

}

Expand All @@ -148,7 +144,7 @@ public function on_facetoface_sessions_dates_start() {
}

public function process_facetoface_sessions_date($data) {
$this->write_xml('sessions_date', $data, array('/date/id'));
$this->write_xml('sessions_date', $data, ['/date/id']);
}

public function on_facetoface_sessions_dates_end() {
Expand All @@ -170,7 +166,7 @@ public function on_facetoface_end() {
$this->xmlwriter->begin_tag('inforef');
$this->xmlwriter->begin_tag('fileref');
foreach ($this->fileman->get_fileids() as $fileid) {
$this->write_xml('file', array('id' => $fileid));
$this->write_xml('file', ['id' => $fileid]);
}
$this->xmlwriter->end_tag('fileref');
$this->xmlwriter->end_tag('inforef');
Expand Down
51 changes: 28 additions & 23 deletions backup/moodle2/backup_facetoface_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
* @author Francois Marier <francois@catalyst.net.nz>
*/

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

class backup_facetoface_activity_structure_step extends backup_activity_structure_step {

protected function define_structure() {
Expand All @@ -38,45 +36,52 @@ protected function define_structure() {
$userinfo = $this->get_setting_value('userinfo');

// Define each element separated.
$facetoface = new backup_nested_element('facetoface', array('id'), array(
$facetoface = new backup_nested_element('facetoface', ['id'], [
'name', 'intro', 'introformat', 'thirdparty', 'thirdpartywaitlist', 'display',
'timecreated', 'timemodified', 'shortname', 'showoncalendar', 'usercalentry',
'confirmationsubject', 'confirmationinstrmngr', 'confirmationmessage', 'waitlistedsubject', 'waitlistedmessage',
'cancellationsubject', 'cancellationinstrmngr', 'cancellationmessage', 'remindersubject', 'reminderinstrmngr',
'remindermessage', 'reminderperiod', 'requestsubject', 'requestinstrmngr', 'requestmessage',
'approvalreqd', 'allowcancellationsdefault', 'signuptype', 'multiplesignupmethod', 'completionattendance'));
'approvalreqd', 'allowcancellationsdefault', 'signuptype', 'multiplesignupmethod', 'completionattendance',
]);

$sessions = new backup_nested_element('sessions');

$session = new backup_nested_element('session', array('id'), array(
$session = new backup_nested_element('session', ['id'], [
'facetoface', 'capacity', 'allowoverbook', 'details', 'datetimeknown', 'duration', 'normalcost',
'discountcost', 'allowcancellations', 'timecreated', 'timemodified'));
'discountcost', 'allowcancellations', 'timecreated', 'timemodified',
]);

$signups = new backup_nested_element('signups');

$signup = new backup_nested_element('signup', array('id'), array(
'sessionid', 'userid', 'mailedreminder', 'discountcode', 'notificationtype'));
$signup = new backup_nested_element('signup', ['id'], [
'sessionid', 'userid', 'mailedreminder', 'discountcode', 'notificationtype',
]);

$signupsstatus = new backup_nested_element('signups_status');

$signupstatus = new backup_nested_element('signup_status', array('id'), array(
'signupid', 'statuscode', 'superceded', 'grade', 'note', 'advice', 'createdby', 'timecreated'));
$signupstatus = new backup_nested_element('signup_status', ['id'], [
'signupid', 'statuscode', 'superceded', 'grade', 'note', 'advice', 'createdby', 'timecreated',
]);

$sessionroles = new backup_nested_element('session_roles');

$sessionrole = new backup_nested_element('session_role', array('id'), array(
'sessionid', 'roleid', 'userid'));
$sessionrole = new backup_nested_element('session_role', ['id'], [
'sessionid', 'roleid', 'userid',
]);

$sessiondata = new backup_nested_element('session_data');

// May need to replace first item 'data' with better value.
$sessiondataelement = new backup_nested_element('data', array('id'), array(
'fieldid', 'sessionid', 'data'));
$sessiondataelement = new backup_nested_element('data', ['id'], [
'fieldid', 'sessionid', 'data',
]);

$sessionsdates = new backup_nested_element('sessions_dates');

$sessionsdate = new backup_nested_element('sessions_date', array('id'), array(
'sessionid', 'timestart', 'timefinish'));
$sessionsdate = new backup_nested_element('sessions_date', ['id'], [
'sessionid', 'timestart', 'timefinish',
]);

// Build the tree.
$facetoface->add_child($sessions);
Expand All @@ -98,20 +103,20 @@ protected function define_structure() {
$sessionsdates->add_child($sessionsdate);

// Define sources.
$facetoface->set_source_table('facetoface', array('id' => backup::VAR_ACTIVITYID));
$facetoface->set_source_table('facetoface', ['id' => backup::VAR_ACTIVITYID]);

$session->set_source_table('facetoface_sessions', array('facetoface' => backup::VAR_PARENTID));
$session->set_source_table('facetoface_sessions', ['facetoface' => backup::VAR_PARENTID]);

$sessionsdate->set_source_table('facetoface_sessions_dates', array('sessionid' => backup::VAR_PARENTID));
$sessionsdate->set_source_table('facetoface_sessions_dates', ['sessionid' => backup::VAR_PARENTID]);

if ($userinfo) {
$signup->set_source_table('facetoface_signups', array('sessionid' => backup::VAR_PARENTID));
$signup->set_source_table('facetoface_signups', ['sessionid' => backup::VAR_PARENTID]);

$signupstatus->set_source_table('facetoface_signups_status', array('signupid' => backup::VAR_PARENTID));
$signupstatus->set_source_table('facetoface_signups_status', ['signupid' => backup::VAR_PARENTID]);

$sessionrole->set_source_table('facetoface_session_roles', array('sessionid' => backup::VAR_PARENTID));
$sessionrole->set_source_table('facetoface_session_roles', ['sessionid' => backup::VAR_PARENTID]);

$sessiondataelement->set_source_table('facetoface_session_data', array('sessionid' => backup::VAR_PARENTID));
$sessiondataelement->set_source_table('facetoface_session_data', ['sessionid' => backup::VAR_PARENTID]);
}

// Define id annotations.
Expand Down
11 changes: 4 additions & 7 deletions backup/moodle2/restore_facetoface_activity_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,15 @@ protected function define_my_steps() {
* processed by the link decoder
*/
public static function define_decode_contents() {
$contents = array();
// $contents[] = new restore_decode_content('facetoface', array(), 'facetoface');
return $contents;
return [];
}

/**
* Define the decoding rules for links belonging
* to the activity to be executed by the link decoder
*/
public static function define_decode_rules() {
$rules = array();
$rules = [];
$rules[] = new restore_decode_rule('FACETOFACEVIEWBYID', '/mod/facetoface/view.php?id=$1', 'course_module');
$rules[] = new restore_decode_rule('FACETOFACEINDEX', '/mod/facetoface/index.php?id=$1', 'course');
return $rules;
Expand All @@ -77,8 +75,7 @@ public static function define_decode_rules() {
* of {@link restore_log_rule} objects
*/
public static function define_restore_log_rules() {
$rules = array();
return $rules;
return [];
}

/**
Expand All @@ -92,7 +89,7 @@ public static function define_restore_log_rules() {
* activity level. All them are rules not linked to any module instance (cmid = 0)
*/
public static function define_restore_log_rules_for_course() {
$rules = array();
$rules = [];
$rules[] = new restore_log_rule('facetoface', 'view all', 'index.php?id={course}', null);
return $rules;
}
Expand Down
50 changes: 33 additions & 17 deletions backup/moodle2/restore_facetoface_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,42 @@
* @author Francois Marier <francois@catalyst.net.nz>
*/

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

/**
* Structure step to restore one facetoface activity
*/
class restore_facetoface_activity_structure_step extends restore_activity_structure_step {

protected function define_structure() {
$paths = array();
$paths = [];
$userinfo = $this->get_setting_value('userinfo');

$paths[] = new restore_path_element('facetoface', '/activity/facetoface');
$paths[] = new restore_path_element('facetoface_session', '/activity/facetoface/sessions/session');
$paths[] = new restore_path_element('facetoface_sessions_dates', '/activity/facetoface/sessions/session/sessions_dates/sessions_date');
$paths[] = new restore_path_element('facetoface_session_data', '/activity/facetoface/sessions/session/session_data/session_data_element');
$paths[] = new restore_path_element('facetoface_session_field', '/activity/facetoface/sessions/session/session_field/session_field_element');
$paths[] = new restore_path_element(
'facetoface_sessions_dates',
'/activity/facetoface/sessions/session/sessions_dates/sessions_date'
);
$paths[] = new restore_path_element(
'facetoface_session_data',
'/activity/facetoface/sessions/session/session_data/session_data_element'
);
$paths[] = new restore_path_element(
'facetoface_session_field',
'/activity/facetoface/sessions/session/session_field/session_field_element'
);
if ($userinfo) {
$paths[] = new restore_path_element('facetoface_signup', '/activity/facetoface/sessions/session/signups/signup');
$paths[] = new restore_path_element('facetoface_signups_status', '/activity/facetoface/sessions/session/signups/signup/signups_status/signup_status');
$paths[] = new restore_path_element('facetoface_session_roles', '/activity/facetoface/sessions/session/session_roles/session_role');
$paths[] = new restore_path_element(
'facetoface_signup',
'/activity/facetoface/sessions/session/signups/signup'
);
$paths[] = new restore_path_element(
'facetoface_signups_status',
'/activity/facetoface/sessions/session/signups/signup/signups_status/signup_status'
);
$paths[] = new restore_path_element(
'facetoface_session_roles',
'/activity/facetoface/sessions/session/session_roles/session_role'
);
}

// Return the paths wrapped into standard activity structure.
Expand All @@ -57,7 +73,7 @@ protected function define_structure() {
protected function process_facetoface($data) {
global $DB;

$data = (object)$data;
$data = (object) $data;
$oldid = $data->id;
$data->course = $this->get_courseid();

Expand All @@ -69,7 +85,7 @@ protected function process_facetoface($data) {
protected function process_facetoface_session($data) {
global $DB;

$data = (object)$data;
$data = (object) $data;
$oldid = $data->id;

$data->facetoface = $this->get_new_parentid('facetoface');
Expand All @@ -85,7 +101,7 @@ protected function process_facetoface_session($data) {
protected function process_facetoface_signup($data) {
global $DB;

$data = (object)$data;
$data = (object) $data;
$oldid = $data->id;

$data->sessionid = $this->get_new_parentid('facetoface_session');
Expand All @@ -99,7 +115,7 @@ protected function process_facetoface_signup($data) {
protected function process_facetoface_signups_status($data) {
global $DB;

$data = (object)$data;
$data = (object) $data;
$oldid = $data->id;

$data->signupid = $this->get_new_parentid('facetoface_signup');
Expand All @@ -113,7 +129,7 @@ protected function process_facetoface_signups_status($data) {
protected function process_facetoface_session_roles($data) {
global $DB;

$data = (object)$data;
$data = (object) $data;
$oldid = $data->id;

$data->sessionid = $this->get_new_parentid('facetoface_session');
Expand All @@ -127,7 +143,7 @@ protected function process_facetoface_session_roles($data) {
protected function process_facetoface_session_data($data) {
global $DB;

$data = (object)$data;
$data = (object) $data;
$oldid = $data->id;

$data->sessionid = $this->get_new_parentid('facetoface_session');
Expand All @@ -141,7 +157,7 @@ protected function process_facetoface_session_data($data) {
protected function process_facetoface_session_field($data) {
global $DB;

$data = (object)$data;
$data = (object) $data;
$oldid = $data->id;

// Insert the entry record.
Expand All @@ -151,7 +167,7 @@ protected function process_facetoface_session_field($data) {
protected function process_facetoface_sessions_dates($data) {
global $DB;

$data = (object)$data;
$data = (object) $data;
$oldid = $data->id;

$data->sessionid = $this->get_new_parentid('facetoface_session');
Expand Down
Loading

0 comments on commit bc4ef02

Please sign in to comment.