Commit c4e4848a authored by Astor Bizard's avatar Astor Bizard
Browse files

Removed duplicate method.

parent 770c9cdc
......@@ -55,84 +55,6 @@ function vpl_get_overrideactions($id, $overrideid, $editing) {
}
}
/**
* TODO
* @param stdClass $override
* @param stdClass $vplinstance
* @param stdClass $oldoverride
* @param boolean $delete
*/
function vpl_update_override_calendar_events($override, $vplinstance, $oldoverride = null, $delete = false) {
global $DB, $CFG;
require_once($CFG->dirroot . '/calendar/lib.php');
$targets = array(
'userid' => CALENDAR_EVENT_USER_OVERRIDE_PRIORITY,
'groupid' => $override->id
);
foreach ($targets as $target => $priority) { // Process once for users and once for groups.
$params = array(
'modulename' => VPL,
'instance' => $vplinstance->id,
'priority' => $priority
);
if ($oldoverride !== null && !empty($oldoverride->{$target . 's'})) {
$oldtargets = array_fill_keys(explode(',', $oldoverride->{$target . 's'}), false);
} else {
$oldtargets = array();
}
if (!empty($override->{$target . 's'})) {
foreach (explode(',', $override->{$target . 's'}) as $userorgroupid) { // Loop over users or groups.
$params[$target] = $userorgroupid;
$currenteventid = $DB->get_field( 'event', 'id', $params ); // Get current calendar event.
if (isset($override->override_duedate) && !$delete) {
if ($target == 'userid') {
$userorgroupname = fullname($DB->get_record( 'user', array('id' => $userorgroupid) ));
} else {
$userorgroupname = groups_get_group($userorgroupid)->name;
}
$newevent = vpl_create_event($vplinstance, $vplinstance->id);
$newevent->name = get_string('overridefor', VPL, array(
'base' => $newevent->name,
'for' => $userorgroupname
));
if ($target == 'userid') {
// User overrides events do not show correctly if courseid is non zero.
$newevent->courseid = 0;
}
$newevent->timestart = $override->duedate;
$newevent->timesort = $override->duedate;
$newevent->{$target} = $userorgroupid;
$newevent->priority = $priority;
if ($currenteventid === false) {
// No event exist for current user or group, create a new one.
calendar_event::create( $newevent );
} else {
// An event already exists, update it.
calendar_event::load( $currenteventid )->update( $newevent );
}
} else {
if ($currenteventid !== false) {
calendar_event::load( $currenteventid )->delete();
}
}
// This user or group is in newly processed data (or has already been removed).
$oldtargets[$userorgroupid] = true;
}
}
// Discard events related to users or groups removed from override.
foreach ($oldtargets as $oldtarget => $tokeep) {
if (!$tokeep) {
$params[$target] = $oldtarget;
$eventid = $DB->get_field( 'event', 'id', $params );
if ($eventid !== false) {
calendar_event::load( $eventid )->delete();
}
}
}
}
}
class vpl_override_users_form extends moodleform {
protected $users;
protected $groups;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment