Beispiel #1
0
/**
 * Import user and signup to session
 *
 * @access  public
 * @param   object  $course             Record from the course table
 * @param   object  $facetoface         Record from the facetoface table
 * @param   object  $session            Session to signup user to
 * @param   mixed   $userid             User to signup (normally int)
 * @param   array   $params             Optional suppressemail, ignoreconflicts, bulkaddsource, discountcode, notificationtype
 *          boolean $suppressemail      Suppress notifications flag
 *          boolean $ignoreconflicts    Ignore booking conflicts flag
 *          string  $bulkaddsource      Flag to indicate if $userid is actually another field
 *          string  $discountcode       Optional A user may specify a discount code
 *          integer $notificationtype   Optional A user may choose the type of notifications they will receive
 * @return  array
 */
function facetoface_user_import($course, $facetoface, $session, $userid, $params = array()) {
    global $DB, $CFG, $USER;

    $result = array();
    $result['id'] = $userid;

    $suppressemail    = (isset($params['suppressemail'])    ? $params['suppressemail']    : false);
    $ignoreconflicts  = (isset($params['ignoreconflicts'])  ? $params['ignoreconflicts']  : false);
    $bulkaddsource    = (isset($params['bulkaddsource'])    ? $params['bulkaddsource']    : 'bulkaddsourceuserid');
    $discountcode     = (isset($params['discountcode'])     ? $params['discountcode']     : '');
    $notificationtype = (isset($params['notificationtype']) ? $params['notificationtype'] : MDL_F2F_BOTH);

    if (isset($params['approvalreqd'])) {
        // Overwrite default behaviour as bulkadd_* is requested
        $facetoface->approvalreqd = $params['approvalreqd'];
        $facetoface->ccmanager = (isset($params['ccmanager']) ? $params['ccmanager'] : 0);
    }

    // Check parameters.
    if ($bulkaddsource == 'bulkaddsourceuserid') {
        if (!is_int($userid) && !ctype_digit($userid)) {
            $result['name'] = '';
            $result['result'] = get_string('error:userimportuseridnotanint', 'facetoface', $userid);
            return $result;
        }
    }

    // Get user.
    switch ($bulkaddsource) {
        case 'bulkaddsourceuserid':
            $user = $DB->get_record('user', array('id' => $userid));
            break;
        case 'bulkaddsourceidnumber':
            $user = $DB->get_record('user', array('idnumber' => $userid));
            break;
        case 'bulkaddsourceusername':
            $user = $DB->get_record('user', array('username' => $userid));
            break;
    }
    if (!$user) {
        $result['name'] = '';
        $a = array('fieldname' => get_string($bulkaddsource, 'facetoface'), 'value' => $userid);
        $result['result'] = get_string('userdoesnotexist', 'facetoface', $a);
        return $result;
    }

    $result['name'] = fullname($user);

    if (isguestuser($user)) {
        $a = array('fieldname' => get_string($bulkaddsource, 'facetoface'), 'value' => $userid);
        $result['result'] = get_string('cannotsignupguest', 'facetoface', $a);
        return $result;
    }

    // Make sure that the user is enroled in the course
    $context   = context_course::instance($course->id);
    if (!is_enrolled($context, $user)) {

        $defaultlearnerrole = $DB->get_record('role', array('id' => $CFG->learnerroleid));

        if (!enrol_try_internal_enrol($course->id, $user->id, $defaultlearnerrole->id, time())) {
            $result['result'] = get_string('error:enrolmentfailed', 'facetoface', fullname($user));
            return $result;
        }
    }

    // Check if they are already signed up
    $minimumstatus = ($session->datetimeknown) ? MDL_F2F_STATUS_BOOKED : MDL_F2F_STATUS_REQUESTED;
    // If multiple sessions are allowed then just check against this session
    // Otherwise check against all sessions
    $multisessionid = ($facetoface->multiplesessions ? $session->id : null);
    if (facetoface_get_user_submissions($facetoface->id, $user->id, $minimumstatus, MDL_F2F_STATUS_FULLY_ATTENDED, $multisessionid)) {
        if ($user->id == $USER->id) {
            $result['result'] = get_string('error:addalreadysignedupattendeeaddself', 'facetoface');
        } else {
            $result['result'] = get_string('error:addalreadysignedupattendee', 'facetoface');
        }
        return $result;
    }

    if (!facetoface_session_has_capacity($session, $context)) {
        if ($session->allowoverbook) {
            $status = MDL_F2F_STATUS_WAITLISTED;
        } else {
            $result['result'] = get_string('full', 'facetoface');
            return $result;
        }
    }

    // Check if we are waitlisting or booking
    if ($session->datetimeknown) {
        if (!isset($status)) {
            $status = MDL_F2F_STATUS_BOOKED;
        }

        // Check if there are any date conflicts
        if (!$ignoreconflicts) {
            $dates = facetoface_get_session_dates($session->id);
            if ($availability = facetoface_get_sessions_within($dates, $user->id)) {
                $result['result'] = facetoface_get_session_involvement($user, $availability);
                $result['conflict'] = true;
                return $result;
            }
        }
    } else {
        $status = MDL_F2F_STATUS_WAITLISTED;
    }

    // Finally attempt to enrol
    if (!facetoface_user_signup(
        $session,
        $facetoface,
        $course,
        $discountcode,
        $notificationtype,
        $status,
        $user->id,
        !$suppressemail)) {
            $result['result'] = get_string('error:addattendee', 'facetoface', fullname($user));
            return $result;
    }

    $result['result'] = true;
    return $result;
}
Beispiel #2
0
            if (facetoface_get_user_submissions($facetoface->id, $adduser)) {
                $erruser = $DB->get_record('user', array('id' => $adduser), "id, {$usernamefields}");
                $errors[] = get_string('error:addalreadysignedupattendee', 'facetoface', fullname($erruser));
            } else {
                if (!facetoface_session_has_capacity($session, $context)) {
                    $errors[] = get_string('full', 'facetoface');
                    break;
                    // No point in trying to add other people.
                }
                // Check if we are waitlisting or booking.
                if ($session->datetimeknown) {
                    $status = MDL_F2F_STATUS_BOOKED;
                } else {
                    $status = MDL_F2F_STATUS_WAITLISTED;
                }
                if (!facetoface_user_signup($session, $facetoface, $course, '', MDL_F2F_BOTH, $status, $adduser, !$suppressemail)) {
                    $erruser = $DB->get_record('user', array('id' => $adduser), "id, {$usernamefields}");
                    $errors[] = get_string('error:addattendee', 'facetoface', fullname($erruser));
                }
            }
        }
        $potentialuserselector->invalidate_selected_users();
        $existinguserselector->invalidate_selected_users();
    }
}
// Process removing user assignments from session.
if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
    require_capability('mod/facetoface:removeattendees', $context);
    $userstoremove = $existinguserselector->get_selected_users();
    if (!empty($userstoremove)) {
        foreach ($userstoremove as $removeuser) {
Beispiel #3
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;
}
Beispiel #4
0
         // Save available.
         $statuscode = MDL_F2F_STATUS_BOOKED;
     } else {
         $statuscode = MDL_F2F_STATUS_WAITLISTED;
     }
 }
 if (!facetoface_session_has_capacity($session, $context) && !$session->allowoverbook) {
     print_error('sessionisfull', 'facetoface', $returnurl);
 } else {
     if (facetoface_get_user_submissions($facetoface->id, $USER->id)) {
         print_error('alreadysignedup', 'facetoface', $returnurl);
     } else {
         if (facetoface_manager_needed($facetoface) && !facetoface_get_manageremail($USER->id)) {
             print_error('error:manageremailaddressmissing', 'facetoface', $returnurl);
         } else {
             if ($submissionid = facetoface_user_signup($session, $facetoface, $course, $fromform->discountcode, $fromform->notificationtype, $statuscode)) {
                 // Logging and events trigger.
                 $params = array('context' => $contextmodule, 'objectid' => $session->id);
                 $event = \mod_facetoface\event\signup_success::create($params);
                 $event->add_record_snapshot('facetoface_sessions', $session);
                 $event->add_record_snapshot('facetoface', $facetoface);
                 $event->trigger();
                 $message = get_string('bookingcompleted', 'facetoface');
                 if ($session->datetimeknown && $facetoface->confirmationinstrmngr) {
                     $message .= html_writer::empty_tag('br') . html_writer::empty_tag('br') . get_string('confirmationsentmgr', 'facetoface');
                 } else {
                     $message .= html_writer::empty_tag('br') . html_writer::empty_tag('br') . get_string('confirmationsent', 'facetoface');
                 }
                 $timemessage = 4;
                 redirect($returnurl, $message, $timemessage);
             } else {
          if($insert){ 
             $assigned_course=$DB->get_record_sql("SELECT * FROM {local_batch_courses} WHERE batchid=$batchid");
             /*==========================Started by rajut for batch users are assigne as signup users (date:17-11-2015)==========*/        
             //$assigned_users=$DB->get_records_sql("SELECT * FROM {local_batch_users} WHERE f2fid=$session->facetoface");
              //$assigned_course=$DB->get_records_sql("SELECT * FROM {local_batch_courses} WHERE batchid=$session->facetoface");
             $session_up=$DB->record_exists('facetoface_sessions',array('facetoface'=>$batchid));
             if($session_up){
                    $sessions=$DB->get_records('facetoface_sessions',array('facetoface'=>$batchid));
                   foreach($sessions as $session){ 
                    $face2face=$DB->get_record('facetoface',array('id'=>$session->facetoface));
                  
                        $course=$DB->get_record('course',array('id'=>$assigned_course->courseid));
                        $statuscode = MDL_F2F_STATUS_BOOKED;
                        $notifytype = ((int)$notificationtype == MDL_F2F_NONE ? false : true);
                         facetoface_user_signup($session,$face2face,$course,$discountcode,
                                                $notifytype,$statuscode,$add_user,
                                                $notifyuser = false);
                         
                   }
             }
            /*==========================ended by rajut for batch users are assigne as signup users (date:17-11-2015)==========*/   
            
              $manual = enrol_get_plugin('manual');
             $studentrole = $DB->get_record('role', array('shortname'=>'student'));
              enroll_users_tocourse($add_user,$assigned_course,$studentrole,$manual);
//             $instance = $DB->get_record('enrol', array('courseid'=>$assigned_course->courseid, 'enrol'=>'manual'), '*', MUST_EXIST);
//             if($instance){
//                $timeend='';
//                $add_user[]=$get_trainerid->trainerid;
//                $manual->enrol_user($instance,$add_user, $studentrole->id,time(),$timeend);
//				/* add members to a group*/
    function test_facetoface_user_signup() {
        // Test variables.
        $session1 = $this->sessions['sess0'];
        $sess0 = $this->array_to_object($session1);
        $sess0->sessiondates = array(0 => new stdClass());
        $sess0->sessiondates[0]->timestart = time() - 100;
        $sess0->sessiondates[0]->timefinish = time() + 100;

        $facetoface1 = $this->facetoface['f2f0'];
        $f2f = $this->array_to_object($facetoface1);

        $discountcode1 = 'disc1';
        $notificationtype1 = 1;
        $statuscode1 = 1;
        $userid1 = 1;

        $notifyuser1 = TRUE;
        $displayerrors = TRUE;

        // Test for valid case.
        $this->assertTrue((bool)facetoface_user_signup($sess0, $f2f, $this->course1, $discountcode1, $notificationtype1, $statuscode1), $this->msgtrue);
        //TODO invalid case?
        $this->resetAfterTest(true);
    }