本文整理汇总了PHP中enrol_try_internal_enrol函数的典型用法代码示例。如果您正苦于以下问题:PHP enrol_try_internal_enrol函数的具体用法?PHP enrol_try_internal_enrol怎么用?PHP enrol_try_internal_enrol使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了enrol_try_internal_enrol函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: setUpDB
/**
* Set up the database for tests
*
* This function is needed so that daily_log_provider has the before-test set up from setUp()
*/
public function setUpDB() {
global $DB;
if ($DB->record_exists('user', array('username' => 'user1'))) {
return;
}
$datagen = self::getDataGenerator();
$user1 = $datagen->create_user(array('username'=>'user1'));
$user2 = $datagen->create_user(array('username'=>'user2'));
$course1 = $datagen->create_course(array('shortname'=>'course1'));
$success = enrol_try_internal_enrol($course1->id, $user1->id, 5);
if (! $success) {
trigger_error('User enrollment failed', E_USER_ERROR);
}
$context = context_system::instance();
role_assign(self::STID, $user2->id, $context->id);
$this->generate_replacement_list();
}
开发者ID:Burick,项目名称:moodle,代码行数:30,代码来源:statslib_test.php
示例2: explode
$ids = explode(',', $course);
foreach ($ids as $course) {
$courserow = new stdClass();
// find course based upon idnumber
if (intval(trim($course)) == $course) {
$courserow = $DB->get_record('course', array('id' => intval($course)));
} elseif (!$courserow && $DB->record_exists('course', array('shortname' => $course))) {
// find course based upon shortname
$courserow = $DB->get_record('course', array('shortname' => $course));
}
if (empty($courserow)) {
continue;
}
// enrol student to course
if (get_config('auth/wp2moodle', 'redirectnoenrol') == 'no') {
if (!enrol_try_internal_enrol($courserow->id, $user->id, $studentrow->id)) {
continue;
}
}
// if the plugin auto-opens the course, then find the course this group is for and set it as the opener link
if (get_config('auth/wp2moodle', 'autoopen') == 'yes') {
$SESSION->wantsurl = new moodle_url('/course/view.php', array('id' => $courserow->id));
}
}
}
// all that's left to do is to authenticate this user and set up their active session
$authplugin = get_auth_plugin('wp2moodle');
// me!
if ($authplugin->user_login($user->username, $user->password)) {
$user->loggedin = true;
$user->site = $CFG->wwwroot;
开发者ID:nagyistoce,项目名称:wp2moodle-moodle,代码行数:31,代码来源:login.php
示例3: block_cmanager_create_new_course_by_record_id
//.........这里部分代码省略.........
$newShortName = $rec->modcode;
}
$new_course->shortname = $newShortName;
$p_key = $rec->modkey;
//course naming
if ($naming == 1) {
$new_course->fullname = $rec->modname;
} else {
if ($naming == 2) {
$new_course->fullname = $rec->modcode . ' - ' . $rec->modname;
} else {
if ($naming == 3) {
$new_course->fullname = $rec->modname . ' (' . $rec->modcode . ')';
// Fullname, shortname
} else {
if ($naming == 4) {
$new_course->fullname = $rec->modcode . ' - ' . $rec->modname . ' (' . date("Y") . ')';
// Shortname, fullname (year)
} else {
if ($naming == 5) {
$new_course->fullname = $rec->modname . ' (' . date("Y") . ')';
}
}
}
}
}
// Enrollment key
// if the key thats been set, otherwise auto gen a key
if (isset($rec->modkey)) {
$modkey = $rec->modkey;
} else {
$modkey = rand(999, 5000);
}
$categoryid = $new_course->category;
$category = $DB->get_record('course_categories', array('id' => $categoryid));
$catcontext = context_coursecat::instance($category->id);
$contextobject = $catcontext;
$editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $CFG->maxbytes, 'trusttext' => false, 'noclean' => true, 'content' => $contextobject);
// Create the course
$course = create_course($new_course, $editoroptions);
// Forward to the course editing page to allow the admin to make
// any changes to the course
$nid = $course->id;
if ($nid == null) {
return $nid;
}
// Update the record to say that it is now complete
$updatedRecord = new stdClass();
$updatedRecord->id = $rec->id;
$updatedRecord->status = 'COMPLETE';
$DB->update_record('block_cmanager_records', $updatedRecord);
// Try enroll the creator
if (!empty($CFG->creatornewroleid)) {
// deal with course creators - enrol them internally with default role
enrol_try_internal_enrol($nid, $rec->createdbyid, $CFG->creatornewroleid);
}
// Check to see if auto create enrollment keys
// is enabled. If this option is set, add an
// enrollment key.
$autoKey = $DB->get_field_select('block_cmanager_config', 'value', "varname = 'autoKey'");
if ($autoKey == 0 || $autoKey == 1) {
// Add enrollnent key
$enrollmentRecord = new stdClass();
$enrollmentRecord->enrol = 'self';
$enrollmentRecord->status = 0;
$enrollmentRecord->courseid = $nid;
$enrollmentRecord->sortorder = 3;
$enrollmentRecord->name = '';
$enrollmentRecord->enrolperiod = 0;
$enrollmentRecord->enrolenddate = 0;
$enrollmentRecord->expirynotify = 0;
$enrollmentRecord->expirythreshold = 0;
$enrollmentRecord->notifyall = 0;
$enrollmentRecord->password = $modkey;
$enrollmentRecord->cost = NULL;
$enrollmentRecord->currency = NULL;
$enrollmentRecord->roleid = 5;
$enrollmentRecord->customint1 = 0;
$enrollmentRecord->customint2 = 0;
$enrollmentRecord->customint3 = 0;
$enrollmentRecord->customint4 = 1;
if ($CFG->version >= 2013051400) {
$enrollmentRecord->customint5 = NULL;
$enrollmentRecord->customint6 = 1;
}
$enrollmentRecord->customchar1 = NULL;
$enrollmentRecord->customchar2 = NULL;
$enrollmentRecord->customdec1 = NULL;
$enrollmentRecord->customdec2 = NULL;
$enrollmentRecord->customtext1 = '';
$enrollmentRecord->customtext2 = NULL;
$enrollmentRecord->timecreated = time();
$enrollmentRecord->timemodified = time();
$DB->insert_record('enrol', $enrollmentRecord);
}
if ($sendMail == true) {
block_cmanager_send_emails($nid, $new_course->shortname, $new_course->fullname, $modkey, $mid);
}
return $nid;
}
开发者ID:kbwebsolutions,项目名称:moodle-block_cmanager,代码行数:101,代码来源:course_lib.php
示例4: redirect
}
redirect($url);
} else if ($data = $editform->get_data()) {
// process data if submitted
if (empty($course->id)) {
// In creating the course
$course = create_course($data, $editoroptions);
// Get the context of the newly created course
$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
if (!empty($CFG->creatornewroleid) and !is_viewing($context, NULL, 'moodle/role:assign') and !is_enrolled($context, NULL, 'moodle/role:assign')) {
// deal with course creators - enrol them internally with default role
enrol_try_internal_enrol($course->id, $USER->id, $CFG->creatornewroleid);
}
if (!is_enrolled($context)) {
// Redirect to manual enrolment page if possible
$instances = enrol_get_instances($course->id, true);
foreach($instances as $instance) {
if ($plugin = enrol_get_plugin($instance->enrol)) {
if ($plugin->get_manual_enrol_link($instance)) {
// we know that the ajax enrol UI will have an option to enrol
redirect(new moodle_url('/enrol/users.php', array('id'=>$course->id)));
}
}
}
}
} else {
开发者ID:ncsu-delta,项目名称:moodle,代码行数:31,代码来源:edit.php
示例5: get_assignable_roles
if (count($users) > 0 and $form = data_submitted() and confirm_sesskey()) {
if (count($users) > 0) {
$assignableroles = get_assignable_roles(get_context_instance(CONTEXT_COURSE, $courseid));
if (array_key_exists($role->id, $assignableroles)) {
// For each "userd" in the form...
foreach ($form->userid as $userid => $value) {
$user_has_role = $DB->record_exists('role_assignments', array('userid' => $userid, 'contextid' => $context->id, 'roleid' => $roleid));
// Assign or Unassign role
/*if ( $assign_unassign == 1 && $user_has_role ) {
role_unassign( $role->id, $userid, $context->id );
} else*/
if (!$user_has_role) {
role_assign($role->id, $userid, $context->id);
}
if (!is_enrolled($context, $userid)) {
enrol_try_internal_enrol($courseid, $userid);
}
}
}
}
global $SESSION;
$SESSION->user_filtering = array();
// Redirect to calling page
redirect('pick.php?courseid=' . $courseid, get_string('changessaved'));
}
$PAGE->set_url('/blocks/pick_students/assign.php');
$PAGE->set_pagelayout('base');
$title = print_context_name($context) . ' - ';
$strtitle = get_string('enrolledusers', 'enrol');
$PAGE->set_title($strtitle);
$PAGE->set_heading($title . $strtitle);
开发者ID:stepsgithub,项目名称:moodle-block_pick_students,代码行数:31,代码来源:assign.php
示例6: test_methodlockslearningobjectivegradesduringupdateforspecificuserid
/**
* Validate that LO grades are locked when they are updated and grade
* is sufficient when run for a specific user
*/
public function test_methodlockslearningobjectivegradesduringupdateforspecificuserid()
{
global $DB;
$this->load_csv_data();
// Create enrolment.
$this->make_course_enrollable();
enrol_try_internal_enrol(2, 100, 1);
enrol_try_internal_enrol(2, 101, 1);
// Create LO and Moodle grade.
$itemid = $this->create_grade_item();
$this->create_grade_grade($itemid, 100, 75, 100, 1);
$this->create_grade_grade($itemid, 101, 75, 100, 1);
$this->create_course_completion('manualitem', 50);
// Enrol in PM class.
$studentgrade = new \student_grade(array('userid' => 103, 'classid' => 100, 'completionid' => 1, 'grade' => 75, 'locked' => 0, 'timegraded' => 1));
$studentgrade->save();
$studentgrade = new \student_grade(array('userid' => 104, 'classid' => 100, 'completionid' => 1, 'grade' => 75, 'locked' => 0, 'timegraded' => 1));
$studentgrade->save();
// Validate setup.
$this->assert_num_student_grades(2);
$count = $DB->count_records(\student_grade::TABLE, array('locked' => 1));
$this->assertEquals(0, $count);
$this->assert_student_grade_exists(100, 103, 1, null, 0);
// Update Moodle info.
$DB->execute("UPDATE {grade_grades} SET finalgrade = 80, timemodified = 2");
// Run and validate.
$sync = new \local_elisprogram\moodle\synchronize();
$sync->synchronize_moodle_class_grades(100);
$this->assert_num_student_grades(2);
$count = $DB->count_records(\student_grade::TABLE, array('locked' => 1));
$this->assertEquals(1, $count);
$this->assert_student_grade_exists(100, 103, 1, null, 1);
}
开发者ID:jamesmcq,项目名称:elis,代码行数:37,代码来源:synchronizemoodleclassgrades_test.php
示例7: enrolment_create
//.........这里部分代码省略.........
}
if (isset($record->grouping)) {
$count = $DB->count_records('groupings', array('name' => $record->grouping, 'courseid' => $context->instanceid));
if ($count > 1) {
//ambiguous
$identifier = $this->mappings['grouping'];
$this->fslogger->log_failure("{$identifier} value of \"{$record->grouping}\" refers to multiple " . "groupings in course with shortname \"{$record->instance}\".", 0, $filename, $this->linenumber, $record, "enrolment");
return false;
} else {
if ($count == 0 && empty($creategroups)) {
//does not exist and not creating
$identifier = $this->mappings['grouping'];
$this->fslogger->log_failure("{$identifier} value of \"{$record->grouping}\" does not refer to " . "a valid grouping in course with shortname \"{$record->instance}\".", 0, $filename, $this->linenumber, $record, "enrolment");
return false;
} else {
//exact grouping exists
$groupingid = groups_get_grouping_by_name($context->instanceid, $record->grouping);
}
}
}
}
//string to describe the user
$user_descriptor = $this->get_user_descriptor($record);
//string to describe the context instance
$context_descriptor = $this->get_context_descriptor($record);
//going to collect all messages for this action
$logmessages = array();
if ($record->context == 'course') {
// Set enrolment start and end time if specified, otherwise set enrolment time to 'now' to allow immediate access.
$timestart = empty($record->enrolmenttime) ? time() : $this->parse_date($record->enrolmenttime);
$timeend = empty($record->completetime) ? 0 : $this->parse_date($record->completetime);
if ($role_assignment_exists && !$enrolment_exists) {
// Role assignment already exists, so just enrol the user.
enrol_try_internal_enrol($context->instanceid, $userid, null, $timestart, $timeend);
} else {
if (!$enrolment_exists) {
// Role assignment does not exist, so enrol and assign role.
enrol_try_internal_enrol($context->instanceid, $userid, $roleid, $timestart, $timeend);
//collect success message for logging at end of action
$logmessages[] = "User with {$user_descriptor} successfully assigned role with shortname " . "\"{$record->role}\" on {$context_descriptor}.";
} else {
if (!$role_assignment_exists) {
//just assign the role
role_assign($roleid, $userid, $context->id);
//collect success message for logging at end of action
$logmessages[] = "User with {$user_descriptor} successfully assigned role with " . "shortname \"{$record->role}\" on {$context_descriptor}.";
} else {
//duplicate enrolment attempt
$this->fslogger->log_failure("User with {$user_descriptor} is already assigned role " . "with shortname \"{$record->role}\" on {$context_descriptor}. " . "User with {$user_descriptor} is already enrolled in course with " . "shortname \"{$record->instance}\".", 0, $filename, $this->linenumber, $record, 'enrolment');
return false;
}
}
}
//collect success message for logging at end of action
if (!$enrolment_exists) {
$logmessages[] = "User with {$user_descriptor} enrolled in course with shortname \"{$record->instance}\".";
if (!empty($context->instanceid) && !empty($userid)) {
$this->newenrolmentemail($userid, $context->instanceid);
}
}
} else {
if ($role_assignment_exists) {
//role assignment already exists, so this action serves no purpose
$this->fslogger->log_failure("User with {$user_descriptor} is already assigned role " . "with shortname \"{$record->role}\" on {$context_descriptor}.", 0, $filename, $this->linenumber, $record, 'enrolment');
return false;
}
开发者ID:jamesmcq,项目名称:elis,代码行数:67,代码来源:version1.class.php
示例8: facetoface_user_import
/**
* 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 {
//.........这里部分代码省略.........
开发者ID:narasimhaeabyas,项目名称:tataaiapro,代码行数:101,代码来源:lib.php
示例9: test_group_event_handlers
/**
* Test the group event handlers
*/
public function test_group_event_handlers() {
global $DB,$CFG;
$this->resetAfterTest();
$this->setAdminUser();
// Setup course, user and groups
$course = $this->getDataGenerator()->create_course();
$user1 = $this->getDataGenerator()->create_user();
$studentrole = $DB->get_record('role', array('shortname'=>'student'));
$this->assertNotEmpty($studentrole);
$this->assertTrue(enrol_try_internal_enrol($course->id, $user1->id, $studentrole->id));
$group1 = $this->getDataGenerator()->create_group(array('courseid'=>$course->id));
$group2 = $this->getDataGenerator()->create_group(array('courseid'=>$course->id));
$this->assertTrue(groups_add_member($group1, $user1));
$this->assertTrue(groups_add_member($group2, $user1));
$uniqueid = 0;
$quiz_generator = $this->getDataGenerator()->get_plugin_generator('mod_quiz');
$quiz = $quiz_generator->create_instance(array('course'=>$course->id, 'timeclose'=>1200, 'timelimit'=>0));
// add a group1 override
$DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'groupid'=>$group1->id, 'timeclose'=>1300, 'timelimit'=>null));
// add an attempt
$attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>100, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++));
// update timecheckstate
quiz_update_open_attempts(array('quizid'=>$quiz->id));
$this->assertEquals(1300, $DB->get_field('quiz_attempts', 'timecheckstate', array('id'=>$attemptid)));
// remove from group
$this->assertTrue(groups_remove_member($group1, $user1));
$this->assertEquals(1200, $DB->get_field('quiz_attempts', 'timecheckstate', array('id'=>$attemptid)));
// add back to group
$this->assertTrue(groups_add_member($group1, $user1));
$this->assertEquals(1300, $DB->get_field('quiz_attempts', 'timecheckstate', array('id'=>$attemptid)));
// delete group
groups_delete_group($group1);
$this->assertEquals(1200, $DB->get_field('quiz_attempts', 'timecheckstate', array('id'=>$attemptid)));
$this->assertEquals(0, $DB->count_records('quiz_overrides', array('quiz'=>$quiz->id)));
// add a group2 override
$DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'groupid'=>$group2->id, 'timeclose'=>1400, 'timelimit'=>null));
quiz_update_open_attempts(array('quizid'=>$quiz->id));
$this->assertEquals(1400, $DB->get_field('quiz_attempts', 'timecheckstate', array('id'=>$attemptid)));
// delete user1 from all groups
groups_delete_group_members($course->id, $user1->id);
$this->assertEquals(1200, $DB->get_field('quiz_attempts', 'timecheckstate', array('id'=>$attemptid)));
// add back to group2
$this->assertTrue(groups_add_member($group2, $user1));
$this->assertEquals(1400, $DB->get_field('quiz_attempts', 'timecheckstate', array('id'=>$attemptid)));
// delete everyone from all groups
groups_delete_group_members($course->id);
$this->assertEquals(1200, $DB->get_field('quiz_attempts', 'timecheckstate', array('id'=>$attemptid)));
}
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:68,代码来源:attempts_test.php
示例10: test_version1importlogsdeletionofenrolmentwhenrolesassignmentsexist
/**
* Validates that, for deletion of a course role that is not assigned, an error is logged
* instead of deleting the user's enrolment if they have some other role assignment on
* the coruse
*/
public function test_version1importlogsdeletionofenrolmentwhenrolesassignmentsexist()
{
global $CFG, $DB;
require_once $CFG->dirroot . '/lib/enrollib.php';
// Set up dependencies.
$userid = $this->create_test_user();
$unassignedroleid = $this->create_test_role('unassigned', 'unassigned', 'unassigned');
$assignedroleid = $this->create_test_role('assigned', 'assigned', 'assigned');
$courseid = $this->create_test_course();
set_config('siteguest', '');
$enrol = new stdClass();
$enrol->enrol = 'manual';
$enrol->courseid = $courseid;
$enrol->status = ENROL_INSTANCE_ENABLED;
$DB->insert_record('enrol', $enrol);
// Set up a role assignment and an enrolment.
enrol_try_internal_enrol($courseid, $userid, $assignedroleid);
// Data.
$data = array('action' => 'delete', 'username' => 'rlipusername', 'context' => 'course', 'instance' => 'rlipshortname', 'role' => 'unassigned');
$message = "[enrolment.csv line 2] User with username \"rlipusername\" could not be unassigned role with shortname";
$message .= " \"unassigned\" on course \"rlipshortname\". User with username \"rlipusername\" could not be unenrolled";
$message .= " from course with shortname \"rlipshortname\". User with username \"rlipusername\" is not assigned role";
$message .= " with shortname \"unassigned\" on course \"rlipshortname\". User with username \"rlipusername\" requires";
$message .= " their enrolment to be maintained because they have another role assignment in this course.\n";
$this->assert_data_produces_error($data, $message, 'enrolment');
}
开发者ID:jamesmcq,项目名称:elis,代码行数:31,代码来源:version1_filesystem_logging_test.php
示例11: test_version1importpreventsduplicateusergroupassignments
/**
* Validate that the import prevents assigning a user to the same group
* twice
*/
public function test_version1importpreventsduplicateusergroupassignments()
{
global $CFG, $DB;
require_once $CFG->dirroot . '/group/lib.php';
// Enrol the user in the course.
enrol_try_internal_enrol(self::$courseid, self::$userid, self::$courseroleid, 0);
// Set up the "pre-existing" group.
$groupid = $this->create_test_group(self::$courseid);
// Add the user to the group.
groups_add_member($groupid, self::$userid);
// Validate setup.
$this->assertEquals($DB->count_records('groups_members'), 1);
// Run the import.
$data = $this->get_core_enrolment_data();
$data['group'] = 'rlipgroup';
$this->run_core_enrolment_import($data, false);
// Compare data.
$this->assertEquals($DB->count_records('groups_members'), 1);
}
开发者ID:jamesmcq,项目名称:elis,代码行数:23,代码来源:version1_enrolment_import_test.php
示例12: test_version1importdeleteuserdeletesassociations
/**
* Validate that the version 1 plugin deletes appropriate associations when
* deleting a user
*/
public function test_version1importdeleteuserdeletesassociations()
{
global $CFG, $DB;
set_config('siteadmins', 0);
// New config settings needed for course format refactoring in 2.4.
set_config('numsections', 15, 'moodlecourse');
set_config('hiddensections', 0, 'moodlecourse');
set_config('coursedisplay', 1, 'moodlecourse');
require_once $CFG->dirroot . '/cohort/lib.php';
require_once $CFG->dirroot . '/course/lib.php';
require_once $CFG->dirroot . '/group/lib.php';
require_once $CFG->dirroot . '/lib/enrollib.php';
require_once $CFG->dirroot . '/lib/gradelib.php';
// Create our test user, and determine their userid.
$this->run_core_user_import(array());
$userid = (int) $DB->get_field('user', 'id', array('username' => 'rlipusername', 'mnethostid' => $CFG->mnet_localhost_id));
// Create cohort.
$cohort = new stdClass();
$cohort->name = 'testcohort';
$cohort->contextid = context_system::instance()->id;
$cohortid = cohort_add_cohort($cohort);
// Add the user to the cohort.
cohort_add_member($cohortid, $userid);
// Create a course category - there is no API for doing this.
$category = new stdClass();
$category->name = 'testcategory';
$category->id = $DB->insert_record('course_categories', $category);
// Create a course.
set_config('defaultenrol', 1, 'enrol_manual');
set_config('status', ENROL_INSTANCE_ENABLED, 'enrol_manual');
$course = new stdClass();
$course->category = $category->id;
$course->fullname = 'testfullname';
$course = create_course($course);
// Create a grade.
$gradeitem = new grade_item(array('courseid' => $course->id, 'itemtype' => 'manual', 'itemname' => 'testitem'), false);
$gradeitem->insert();
$gradegrade = new grade_grade(array('itemid' => $gradeitem->id, 'userid' => $userid), false);
$gradegrade->insert();
// Send the user an unprocessed message.
set_config('noemailever', true);
// Set up a user tag.
tag_set('user', $userid, array('testtag'));
// Create a new course-level role.
$roleid = create_role('testrole', 'testrole', 'testrole');
set_role_contextlevels($roleid, array(CONTEXT_COURSE));
// Enrol the user in the course with the new role.
enrol_try_internal_enrol($course->id, $userid, $roleid);
// Create a group.
$group = new stdClass();
$group->name = 'testgroup';
$group->courseid = $course->id;
$groupid = groups_create_group($group);
// Add the user to the group.
groups_add_member($groupid, $userid);
set_user_preference('testname', 'testvalue', $userid);
// Create profile field data - don't both with the API here because it's a bit unwieldy.
$userinfodata = new stdClass();
$userinfodata->fieldid = 1;
$userinfodata->data = 'bogus';
$userinfodata->userid = $userid;
$DB->insert_record('user_info_data', $userinfodata);
// There is no easily accessible API for doing this.
$lastaccess = new stdClass();
$lastaccess->userid = $userid;
$lastaccess->courseid = $course->id;
$DB->insert_record('user_lastaccess', $lastaccess);
$data = array('action' => 'delete', 'username' => 'rlipusername');
$this->run_core_user_import($data, false);
// Assert data condition after delete.
$this->assertEquals($DB->count_records('message_read', array('useridto' => $userid)), 0);
$this->assertEquals($DB->count_records('grade_grades'), 0);
$this->assertEquals($DB->count_records('tag_instance'), 0);
$this->assertEquals($DB->count_records('cohort_members'), 0);
$this->assertEquals($DB->count_records('user_enrolments'), 0);
$this->assertEquals($DB->count_records('role_assignments'), 0);
$this->assertEquals($DB->count_records('groups_members'), 0);
$this->assertEquals($DB->count_records('user_preferences'), 0);
$this->assertEquals($DB->count_records('user_info_data'), 0);
$this->assertEquals($DB->count_records('user_lastaccess'), 0);
}
开发者ID:jamesmcq,项目名称:elis,代码行数:85,代码来源:version1_user_import_test.php
示例13: get_string
if (!$demostudentuser) {
// Test this by setting $demostudentuser to false.
print get_string('errorfailedtocreateuser', 'block_demostudent', $demostudentusername);
print get_string('returntocourse', 'block_demostudent', $url);
exit;
}
}
// Else DemoStudent user already exists for this instructor.
$demostudentid = $demostudentuser->id;
// Enrol DemoStudent in this course (as a demostudent).
$demostudentroleid = get_roleid_by_roleshortname('demostudent');
if (!$demostudentroleid) {
print get_string('warningmissingrole', 'block_demostudent');
}
if (!is_enrolled($coursecontext, $demostudentuser)) {
if (!enrol_try_internal_enrol($courseid, $demostudentid, $demostudentroleid)) {
// Enrolment failed. Haven't seen this happen yet.
trigger_error('DemoStudent user enrolment failed!<br>Parameters:<br>' . '<br> url=' . var_export($url, true) . '<br> viewrole=' . var_export($viewrole, true) . '<br> courseid=' . var_export($courseid, true) . '<br>Globals:' . '<br> userid=' . var_export($userid, true) . '<br> username=' . var_export($username, true) . '<br>Locals:' . '<br> demostudentid=' . var_export($demostudentid, true) . '<br> demostudentroleid=' . var_export($demostudentroleid, true) . '<br> coursecontext=' . var_export($coursecontext, true) . '<br> demostudentuser=' . var_export($demostudentuer, true));
// It's possible that the function failed, but that the user is nevertheless enrolled.
// If the user is not enrolled, a later check will take care of things.
}
}
// Aditionally, if we are switching from 'instructor' view (i.e., not in 'firstuse' mode), switch user.
if ($viewrole == 'instructor') {
if (is_siteadmin($demostudentid)) {
// This should never happen. Haven't seen it happen yet.
print_error('nologinas');
}
if (!is_enrolled($coursecontext, $demostudentid)) {
// This should never happen. Haven't seen it happen yet.
print_error('usernotincourse');
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:31,代码来源:switchview.php
示例14: test_version1importdeletecoursedeletesassociations
/**
* Validate that the version 1 plugin deletes appropriate associations when
* deleting a course
*/
public function test_version1importdeletecoursedeletesassociations()
{
global $DB, $CFG, $USER;
require_once $CFG->dirroot . '/user/lib.php';
require_once $CFG->dirroot . '/lib/gradelib.php';
require_once $CFG->dirroot . '/group/lib.php';
require_once $CFG->dirroot . '/lib/conditionlib.php';
require_once $CFG->dirroot . '/lib/enrollib.php';
require_once $CFG->dirroot . '/tag/lib.php';
require_once $CFG->dirroot . '/lib/questionlib.php';
// Setup.
$initialnumcontexts = $DB->count_records('context', array('contextlevel' => CONTEXT_COURSE));
$DB->delete_records('block_instances');
// Set up the course with one section, including default blocks.
set_config('defaultblocks_topics', 'search_forums');
set_config('maxsections', 10, 'moodlecourse');
$this->run_core_course_import(array('shortname' => 'deleteassociationsshortname', 'numsections' => 1));
// Create a user record.
$record = new stdClass();
$record->username = 'testuser';
$record->password = 'Testpass!0';
$userid = user_create_user($record);
// Create a course-level role.
$courseid = $DB->get_field('course', 'id', array('shortname' => 'deleteassociationsshortname'));
$coursecontext = context_course::instance($courseid);
$roleid = create_role('deleterole', 'deleterole', 'deleterole');
set_role_contextlevels($roleid, array(CONTEXT_COURSE));
$enrol = new stdClass();
$enrol->enrol = 'manual';
$enrol->courseid = $courseid;
$enrol->status = ENROL_INSTANCE_ENABLED;
if (!$DB->record_exists('enrol', (array) $enrol)) {
$DB->insert_record('enrol', $enrol);
}
// Assign the user to the course-level role.
enrol_try_internal_enrol($courseid, $userid, $roleid);
// Create a grade item.
$gradeitem = new grade_item(array('courseid' => $courseid, 'itemtype' => 'manual', 'itemname' => 'testitem'), false);
$gradeitem->insert();
$gradegrade = new grade_grade(array('itemid' => $gradeitem->id, 'userid' => $userid), false);
// Assign the user a grade.
$gradegrade->insert();
// Create a grade outcome.
$gradeoutcome = new grade_outcome(array('courseid' => $courseid, 'shortname' => 'bogusshortname', 'fullname' => 'bogusfullname'));
$gradeoutcome->insert();
// Create a grade scale.
$gradescale = new grade_scale(array('courseid' => $courseid, 'name' => 'bogusname', 'userid' => $userid, 'scale' => 'bogusscale', 'description' => 'bogusdescription'));
$gradescale->insert();
// Set a grade setting value.
grade_set_setting($courseid, 'bogus', 'bogus');
// Set up a grade letter.
$gradeletter = new stdClass();
$gradeletter->contextid = $coursecontext->id;
$gradeletter->lowerboundary = 80;
$gradeletter->letter = 'A';
$DB->insert_record('grade_letters', $gradeletter);
// Set up a forum instance.
$forum = new stdClass();
$forum->course = $courseid;
$forum->intro = 'intro';
$forum->id = $DB->insert_record('forum', $forum);
// Add it as a course module.
$forum->module = $DB->get_field('modules', 'id', array('name' => 'forum'));
$forum->instance = $forum->id;
$cmid = add_course_module($forum);
// Set up a completion record.
$completion = new stdClass();
$completion->coursemoduleid = $cmid;
$completion->completionstate = 0;
$completion->userid = 9999;
$completion->timemodified = time();
$DB->insert_record('course_modules_completion', $completion);
// Set up a completion condition.
$forum->id = $cmid;
$ci = new condition_info($forum, CONDITION_MISSING_EVERYTHING, false);
$ci->add_completion_condition($cmid, COMPLETION_ENABLED);
// Set the blocks position.
$instances = $DB->get_records('block_instances', array('parentcontextid' => $coursecontext->id));
$page = new stdClass();
$page->context = $coursecontext;
$page->pagetype = 'course-view-*';
$page->subpage = false;
foreach ($instances as $instance) {
blocks_set_visibility($instance, $page, 1);
}
// Create a group.
$group = new stdClass();
$group->name = 'testgroup';
$group->courseid = $courseid;
$groupid = groups_create_group($group);
// Add the user to the group.
groups_add_member($groupid, $userid);
// Create a grouping containing our group.
$grouping = new stdClass();
$grouping->name = 'testgrouping';
$grouping->courseid = $courseid;
//.........这里部分代码省略.........
开发者ID:jamesmcq,项目名称:elis,代码行数:101,代码来源:version1_course_import_test.php
示例15: facetoface_candidate_selector
$potentialuserselector = new facetoface_candidate_selector('addselect', array('sessionid' => $session->id));
$existinguserselector = new facetoface_existing_selector('removeselect', array('sessionid' => $session->id));
// Process incoming user assignments.
if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
require_capability('mod/facetoface:addattendees', $context);
$userstoassign = $potentialuserselector->get_selected_users();
if (!empty($userstoassign)) {
foreach ($userstoassign as $adduser) {
if (!($adduser = clean_param($adduser->id, PARAM_INT))) {
continue;
// Invalid userid.
}
// Make sure that the user is enroled in the course.
if (!has_capability('moodle/course:view', $context, $adduser)) {
$user = $DB->get_record('user', array('id' => $adduser));
if (!enrol_try_internal_enrol($course->id, $user->id, 5)) {
$errors[] = get_string('error:enrolmentfailed', 'facetoface', fullname($user));
$errors[] = get_string('error:addattendee', 'facetoface', fullname($user));
continue;
// Don't sign the user up.
}
}
$usernamefields = get_all_user_name_fields(true);
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.
开发者ID:eSrem,项目名称:facetoface-2.0,代码行数:31,代码来源:editattendees.php
示例16: stdClass
if (!($group = $DB->get_record("groups", array("name" => $v[1], "courseid" => $id)))) {
$newgroupdata = new stdClass();
$newgroupdata->name = $v[1];
$newgroupdata->courseid = $id;
$newgroupdata->description = '';
$gid = groups_create_group($newgroupdata);
if ($gid) {
$group = $DB->get_record("groups", array("id" => $gid));
}
$report['groupcreated'][$gid] = array($newgroupdata->name);
}
if (!$user) {
$report['studentnot
|
请发表评论