function scheduler_slots_restore_mods($old_scheduler_id, $new_scheduler_id, $info, $restore) { global $CFG; $status = true; //Get the slots array $slots = $info['MOD']['#']['SLOTS']['0']['#']['SLOT']; //Iterate over slots for ($i = 0; $i < sizeof($slots); $i++) { $slot_info = $slots[$i]; //traverse_xmlize($slot_info); //Debug //print_object ($GLOBALS['traverse_array']); //Debug //$GLOBALS['traverse_array']=""; //Debug //We'll need this later!! $oldid = backup_todb($slot_info['#']['ID']['0']['#']); //Now, build the SCHEDULER_SLOTS record structure $slot->schedulerid = $new_scheduler_id; $slot->starttime = backup_todb($slot_info['#']['STARTTIME']['0']['#']); $slot->duration = backup_todb($slot_info['#']['DURATION']['0']['#']); $slot->teacherid = backup_todb($slot_info['#']['TEACHERID']['0']['#']); $slot->appointmentlocation = backup_todb($slot_info['#']['APPOINTMENTLOCATION']['0']['#']); $slot->reuse = backup_todb($slot_info['#']['REUSE']['0']['#']); $slot->timemodified = backup_todb($slot_info['#']['TIMEMODIFIED']['0']['#']); $slot->notes = backup_todb($slot_info['#']['NOTES']['0']['#']); $slot->exclusivity = backup_todb($slot_info['#']['EXCLUSIVITY']['0']['#']); $slot->appointmentnote = backup_todb($slot_info['#']['APPOINTMENTNOTE']['0']['#']); $slot->emaildate = backup_todb($slot_info['#']['EMAILDATE']['0']['#']); $slot->hideuntil = backup_todb($slot_info['#']['HIDEUNTIL']['0']['#']); //We have to recode the teacher field $user = backup_getid($restore->backup_unique_code, "user", $slot->teacherid); if ($user) { $slot->teacherid = $user->new_id; } //The structure is equal to the db, so insert the scheduler_slot $newid = insert_record('scheduler_slots', $slot); // FIXME: Shouldn't we check for conflicts? // We have to add the events to the calendar as well $course = get_record('course', 'id', $restore->course_id); //restore slot id for events generation $slot->id = $newid; scheduler_add_update_calendar_events($slot, $course); //Do some output if (($i + 1) % 50 == 0) { echo "."; if (($i + 1) % 1000 == 0) { echo "<br />"; } backup_flush(300); } if ($newid) { //We have the newid, update backup_ids backup_putid($restore->backup_unique_code, 'scheduler_slots', $oldid, $newid); } else { $status = false; } } return $status; }
$vars = array('SITE' => $SITE->shortname, 'SITE_URL' => $CFG->wwwroot, 'COURSE_SHORT' => $COURSE->shortname, 'COURSE' => $COURSE->fullname, 'COURSE_URL' => $CFG->wwwroot . '/course/view.php?id=' . $COURSE->id, 'MODULE' => $scheduler->name, 'USER' => fullname($student), 'DATE' => userdate($slot->starttime, get_string('strftimedate')), 'TIME' => userdate($slot->starttime, get_string('strftimetime')), 'DURATION' => $slot->duration); $notification = compile_mail_template('applied', $vars); $notificationHtml = compile_mail_template('applied_html', $vars); email_to_user($teacher, $student, get_string('newappointment', 'scheduler', $SITE->shortname), $notification, $notificationHtml); } } } // *********************************** Disengage alone from the slot ******************************/ if ($action == 'disengage') { $appointments = get_records_select('scheduler_appointment', "studentid = {$USER->id} AND attended = 0"); if ($appointments) { foreach ($appointments as $appointment) { $oldslot = get_record('scheduler_slots', 'id', $appointment->slotid); scheduler_delete_appointment($appointment->id, $oldslot, $scheduler); // notify teacher if ($scheduler->allownotifications) { $student = get_record('user', 'id', $USER->id); $teacher = get_record('user', 'id', $oldslot->teacherid); include_once $CFG->dirroot . '/mod/scheduler/mailtemplatelib.php'; $vars = array('SITE' => $SITE->shortname, 'SITE_URL' => $CFG->wwwroot, 'COURSE_SHORT' => $COURSE->shortname, 'COURSE' => $COURSE->fullname, 'COURSE_URL' => $CFG->wwwroot . '/course/view.php?id=' . $COURSE->id, 'MODULE' => $scheduler->name, 'USER' => fullname($student), 'DATE' => userdate($oldslot->starttime, get_string('strftimedate')), 'TIME' => userdate($oldslot->starttime, get_string('strftimetime')), 'DURATION' => $oldslot->duration); $notification = compile_mail_template('cancelled', $vars); $notificationHtml = compile_mail_template('cancelled_html', $vars); email_to_user($teacher, $student, get_string('cancelledbystudent', 'scheduler', $SITE->shortname), $notification, $notificationHtml); } } // delete calendar events for that slot scheduler_delete_calendar_events($oldslot); // renew all calendar events as some appointments may be left for other students scheduler_add_update_calendar_events($oldslot, $course); } }
/** * This function decides if a slot should have calendar events associated with it, * and calls the update/delete functions if neccessary. * it must be passed the complete scheduler_slots record to function correctly. * The course parameter should be the record that belongs to the course for this scheduler. * @param object $slot the slot instance * @param object $course the actual course */ function scheduler_events_update($slot, $course) { $slotDoesntHaveAStudent = !count_records('scheduler_appointment', 'slotid', $slot->id); $slotWasAttended = count_records('scheduler_appointment', 'slotid', $slot->id, 'attended', 1); if ($slotDoesntHaveAStudent || $slotWasAttended) { scheduler_delete_calendar_events($slot); } else { scheduler_add_update_calendar_events($slot, $course); } }