Пример #1
0
/**
 * Mark users' booking requests as declined or approved
 *
 * @param array $data array containing the sessionid under the 's' key
 *                    and an array of request approval/denies
 */
function facetoface_approve_requests($data)
{
    global $USER, $DB;
    // Check request data.
    if (empty($data->requests) || !is_array($data->requests)) {
        error_log('F2F: No request data supplied');
        return false;
    }
    $sessionid = $data->s;
    // Load session.
    if (!($session = facetoface_get_session($sessionid))) {
        error_log('F2F: Could not load facetoface session');
        return false;
    }
    // Load facetoface.
    if (!($facetoface = $DB->get_record('facetoface', array('id' => $session->facetoface)))) {
        error_log('F2F: Could not load facetoface instance');
        return false;
    }
    // Load course.
    if (!($course = $DB->get_record('course', array('id' => $facetoface->course)))) {
        error_log('F2F: Could not load course');
        return false;
    }
    // Loop through requests.
    foreach ($data->requests as $key => $value) {
        // Check key/value.
        if (!is_numeric($key) || !is_numeric($value)) {
            continue;
        }
        // Load user submission.
        if (!($attendee = facetoface_get_attendee($sessionid, $key))) {
            error_log('F2F: User ' . $key . ' not an attendee of this session');
            continue;
        }
        // Update status.
        switch ($value) {
            // Decline.
            case 1:
                facetoface_update_signup_status($attendee->submissionid, MDL_F2F_STATUS_DECLINED, $USER->id);
                // Send a cancellation notice to the user.
                facetoface_send_cancellation_notice($facetoface, $session, $attendee->id);
                break;
                // Approve.
            // Approve.
            case 2:
                facetoface_update_signup_status($attendee->submissionid, MDL_F2F_STATUS_APPROVED, $USER->id);
                if (!($cm = get_coursemodule_from_instance('facetoface', $facetoface->id, $course->id))) {
                    print_error('error:incorrectcoursemodule', 'facetoface');
                }
                $contextmodule = context_module::instance($cm->id);
                // Check if there is capacity.
                if (facetoface_session_has_capacity($session, $contextmodule)) {
                    $status = MDL_F2F_STATUS_BOOKED;
                } else {
                    if ($session->allowoverbook) {
                        $status = MDL_F2F_STATUS_WAITLISTED;
                    }
                }
                // Signup user.
                if (!facetoface_user_signup($session, $facetoface, $course, $attendee->discountcode, $attendee->notificationtype, $status, $attendee->id)) {
                    continue;
                }
                break;
            case 0:
            default:
                // Change nothing.
                continue;
        }
    }
    return true;
}
Пример #2
0
/**
 * Event that is triggered when a user is unenrolled from a course
 *
 * Cancels a user from any future sessions when they are unenrolled from a course,
 * this is to make sure unenrolled users aren't using space in sessions
 * when there is limited capacity
 *
 * @param object $data
 */
function facetoface_eventhandler_user_unenrolled($data) {
    global $DB;

    $uid = $data->userid;
    $cid = $data->courseid;

    // Get all the facetofaces associated with the course.
    $f2fs = $DB->get_fieldset_select('facetoface', 'id', 'course = :cid', array('cid' => $cid));

    if (!empty($f2fs)) {
        // Get all the sessions for the facetofaces.
        list($insql, $inparams) = $DB->get_in_or_equal($f2fs);
        $sql = "SELECT id FROM {facetoface_sessions} WHERE facetoface {$insql}";
        $sessids = $DB->get_fieldset_sql($sql, $inparams);
        $strvar = new stdClass();
        $strvar->coursename = $DB->get_field('course', 'fullname', array('id' => $cid));

        foreach ($sessids as $sessid) {
            // Check if user is enrolled on any sessions in the future.
            if ($user = facetoface_get_attendee($sessid, $uid)) {
                if (empty($strvar->username)) {
                    $strvar->username = fullname($user);
                }

                // And cancel them.
                $sess = facetoface_get_session($sessid); // Get the proper session object, complete with dates.
                facetoface_user_cancel($sess, $uid, false, $null, get_string('cancellationreasoncourseunenrollment', 'mod_facetoface', $strvar));
            }
        }
    }

    return true;
}
Пример #3
0
    function test_facetoface_get_attendee() {
        // Test variables.
        $sessionid1 = 1;
        $sessionid2 = 42;
        $userid1 = 1;
        $userid2 = 14;

        // Test for valid case.
        $this->assertTrue((bool)is_object(facetoface_get_attendee($sessionid1, $userid1)), $this->msgtrue);

        // Test for invalid case.
        $this->assertFalse((bool)facetoface_get_attendee($sessionid2, $userid2), $this->msgfalse);
        $this->resetAfterTest(true);
    }