Example #1
0
function organizer_unregister_appointment($slotid, $groupid)
{
    global $DB, $USER;
    $ok = true;
    if (organizer_is_group_mode()) {
        $memberids = $DB->get_fieldset_select('groups_members', 'userid', "groupid = {$groupid}");
        foreach ($memberids as $memberid) {
            $ok ^= organizer_unregister_single_appointment($slotid, $memberid);
        }
    } else {
        $ok ^= organizer_unregister_single_appointment($slotid, $USER->id);
    }
    list($cm, $course, $organizer, $context) = organizer_get_course_module_data();
    $slot = $DB->get_record('organizer_slots', array('id' => $slotid));
    organizer_add_event_slot($cm->id, $slot);
    //FIXME!!!
    return $ok;
}
Example #2
0
function migrate_slots($cm, $scheduler, $organizer)
{
    global $DB;
    $query = "SELECT CONCAT(scheduler, starttime, teacher) AS tempid, scheduler, starttime, duration, teacher,\n        appointmentlocation, timemodified, hideuntil, emaildate, maxstudents, notes, appointmentnote, exclusive\n        FROM {scheduler_slots} s\n        WHERE scheduler = :scheduler AND teacher IS NOT NULL AND teacher > 0 AND starttime > 0 AND duration > 0\n        GROUP BY scheduler, starttime, duration, teacher, appointmentlocation";
    echo "\tReading associated slots from scheduler... ";
    $oldslots = $DB->get_records_sql($query, array('scheduler' => $scheduler->id));
    echo "done.\n";
    $slotcount = 0;
    foreach ($oldslots as $oldslot) {
        echo "\tProcessing slot tempid = {$oldslot->tempid}...\n";
        echo "\t\tReading slot data... ";
        if (ORGANIZER_CHECK_USERS) {
            if (!$DB->get_record('user', array('id' => $oldslot->teacher))) {
                echo "\t\tTeacher with user id = {$oldslot->teacher} does not exist in the database! Skipping slot entry.";
                continue;
            }
        }
        $newslot = new stdClass();
        $newslot->organizerid = $organizer->id;
        $newslot->starttime = $oldslot->starttime;
        $newslot->duration = $oldslot->duration == 0 ? 5 * 60 : $oldslot->duration * 60;
        $newslot->location = $oldslot->appointmentlocation ? $oldslot->appointmentlocation : '';
        $newslot->locationlink = ORGANIZER_DEFAULT_SLOT_LOCATIONLINK;
        $newslot->maxparticipants = $oldslot->exclusive != 1 ? $oldslot->maxstudents : 1;
        $newslot->teacherid = $oldslot->teacher;
        $newslot->isanonymous = $oldslot->exclusive == 2 ? 1 : 0;
        $newslot->availablefrom = $oldslot->hideuntil > 0 ? $oldslot->hideuntil : 0;
        $newslot->timemodified = $oldslot->timemodified > 0 ? $oldslot->timemodified : 0;
        $newslot->notificationtime = $oldslot->emaildate > 0 ? $oldslot->starttime - $oldslot->emaildate : null;
        $newslot->comments = isset($oldslot->appointmentnote) ? $oldslot->appointmentnote : '';
        $newslot->teachervisible = ORGANIZER_DEFAULT_SLOT_TEACHERVISIBLE;
        $newslot->notified = ORGANIZER_DEFAULT_SLOT_NOTIFIED;
        echo "done.\n";
        echo "\t\tInserting new slot record... ";
        $newslot->id = $DB->insert_record("organizer_slots", $newslot);
        $newslot->eventid = organizer_add_event_slot($cm->id, $newslot->id);
        echo "\t\tEvent id = {$newslot->eventid}... ";
        $DB->update_record("organizer_slots", $newslot);
        echo "done. New slot id = {$newslot->id}\n";
        echo "\t\tReading appointment data from scheduler_slots...\n";
        $query = "SELECT s.*\n            FROM mdl_scheduler_slots s\n            WHERE s.scheduler = :schedulerid AND s.starttime = :starttime AND\n            s.teacher = :teacherid AND student IS NOT NULL AND student > 0";
        $oldapps = $DB->get_records_sql($query, array('schedulerid' => $oldslot->scheduler, 'starttime' => $oldslot->starttime, 'teacherid' => $oldslot->teacher));
        $appcount = 0;
        foreach ($oldapps as $oldapp) {
            if (ORGANIZER_CHECK_USERS) {
                if (!$DB->get_record('user', array('id' => $oldapp->student))) {
                    echo "\t\tStudent with user id = {$oldapp->student} does not exist in the database!\n                        Skipping appointment entry.";
                    continue;
                }
            }
            $newapp = new stdClass();
            $newapp->slotid = $newslot->id;
            $newapp->userid = $oldapp->student;
            $newapp->groupid = ORGANIZER_DEFAULT_APPOINTMENT_GROUPID;
            $newapp->applicantid = $oldapp->student;
            $newapp->attended = $oldapp->attended;
            $newapp->grade = ORGANIZER_DEFAULT_APPOINTMENT_GRADE;
            $newapp->feedback = '';
            $newapp->comments = isset($oldapp->notes) ? $oldapp->notes : '';
            $newapp->notified = ORGANIZER_DEFAULT_APPOINTMENT_NOTIFIED;
            $newapp->allownewappointments = ORGANIZER_DEFAULT_ALLOW_NEW_APPOINTMENTS;
            echo "\t\t\tInserting new appointment record for slot id = {$newslot->id} ...";
            $newapp->id = $DB->insert_record('organizer_slot_appointments', $newapp);
            $newapp->eventid = organizer_add_event_appointment($cm->id, $newapp->id);
            echo "\t\t\tEvent id = {$newapp->eventid}... ";
            $DB->update_record('organizer_slot_appointments', $newapp);
            echo "done. Appointment id = {$newapp->id}\n";
            $appcount++;
        }
        echo "\t\tDone. {$appcount} appointments migrated.\n";
        $slotcount++;
    }
    echo "Organizer migrated successfully. {$slotcount} slots migrated.\n";
}