本文整理汇总了PHP中groups_remove_member函数的典型用法代码示例。如果您正苦于以下问题:PHP groups_remove_member函数的具体用法?PHP groups_remove_member怎么用?PHP groups_remove_member使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了groups_remove_member函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_create_group
/**
* This function tests to see if a user-named group is created correctly.
*/
public function test_create_group()
{
global $DB;
$this->configure_settings();
$sgrouping = new skills_grouping($this->courseid);
// Test 1: group creation with name specified.
$this->setUser($this->users[0]);
$testname = 'Test Skills Group';
$groupid = $sgrouping->create_group($testname);
$record = $DB->get_record('groups', array('id' => $groupid));
$this->assertEquals($record->name, $testname);
$memberrecord = $DB->get_record('groups_members', array('groupid' => $groupid));
$this->assertEquals($memberrecord->userid, $this->users[0]->id);
groups_remove_member($groupid, $this->users[0]->id);
// Test 2: auto-created group name.
$groupid = $sgrouping->create_group(null);
$record = $DB->get_record('groups', array('id' => $groupid));
$this->assertEquals($record->name, 'Team 03');
groups_remove_member($groupid, $this->users[0]->id);
$groupid = $sgrouping->create_group(null);
$record = $DB->get_record('groups', array('id' => $groupid));
$this->assertEquals($record->name, 'Team 04');
$groupid = $sgrouping->create_group(null);
$record = $DB->get_record('groups', array('id' => $groupid));
$this->assertEquals($record->name, 'Team 06');
}
示例2: destroy
/**
* Delete the fixture
*
* This method must be safe to call multiple times.
*
* @return void
* @throws moodle_exception
*/
public function destroy()
{
if ($this->exists() and $this->get_group()->exists() and $this->get_enrollment()->exists()) {
groups_remove_member($this->get_group()->get_results(), $this->get_user()->get_results());
}
$this->set_results(new stdClass());
}
示例3: local_syncgroups_do_sync
function local_syncgroups_do_sync($groups, $destinations, $trace)
{
global $DB;
foreach ($groups as $group) {
$trace->output('Grupo: ' . $group->name);
if (!($members = $DB->get_records_menu('groups_members', array('groupid' => $group->id), '', 'userid, id'))) {
$trace->output('group with no members, skipping');
continue;
}
foreach ($destinations as $dest) {
$trace->output("Curso: {$dest->shortname}");
if ($dgr = $DB->get_record('groups', array('courseid' => $dest->id, 'name' => $group->name), 'id, courseid, idnumber, name')) {
$trace->output('grupo existente');
} else {
$trace->output("criado grupo");
$dgr = new Stdclass();
$dgr->courseid = $dest->id;
$dgr->timecreated = time();
$dgr->timemodified = $dgr->timecreated;
$dgr->name = $group->name;
$dgr->description = $group->description;
$dgr->descriptionformat = $group->descriptionformat;
if (!($dgr->id = groups_create_group($dgr))) {
print_error("?? erro ao criar grupo");
}
}
$trace->output("inserindo membros: ");
foreach ($members as $userid => $memberid) {
if (!$DB->get_field('groups_members', 'id', array('groupid' => $dgr->id, 'userid' => $userid))) {
if ($DB->get_field('role_assignments', 'id', array('contextid' => $dest->context->id, 'userid' => $userid))) {
groups_add_member($dgr->id, $userid);
$trace->output('Usuário inserido no grupo: ' . $userid);
} else {
$trace->output("?? usuario id: {$userid} não inscrito no curso");
}
}
}
$trace->output("removendo membros: ");
$members_dest = $DB->get_records('groups_members', array('groupid' => $dgr->id), '', 'id, groupid, userid');
foreach ($members_dest as $id => $usum) {
if (!isset($members[$usum->userid])) {
groups_remove_member($dgr->id, $usum->userid);
$trace->output('Usuário removido do grupo: ' . $usum->userid);
}
}
}
}
$trace->output('Concluído.');
$trace->finished();
}
示例4: groups_leave_group
/**
* Remove a user from a group.
*
* @param int $group_id ID of the group.
* @param int $user_id Optional. ID of the user. Defaults to the currently
* logged-in user.
*
* @return bool True on success, false on failure.
*/
function groups_leave_group($group_id, $user_id = 0)
{
if (empty($user_id)) {
$user_id = bp_loggedin_user_id();
}
// Don't let single admins leave the group.
if (count(groups_get_group_admins($group_id)) < 2) {
if (groups_is_user_admin($user_id, $group_id)) {
bp_core_add_message(__('As the only admin, you cannot leave the group.', 'buddypress'), 'error');
return false;
}
}
if (!groups_remove_member($user_id, $group_id)) {
return false;
}
bp_core_add_message(__('You successfully left the group.', 'buddypress'));
/**
* Fires after a user leaves a group.
*
* @since 1.0.0
*
* @param int $group_id ID of the group.
* @param int $user_id ID of the user leaving the group.
*/
do_action('groups_leave_group', $group_id, $user_id);
return true;
}
示例5: process_course_cohort_membership_node
private function process_course_cohort_membership_node($membershipnode, $xpath, $role = '01')
{
global $DB, $CFG;
$idnumber = $xpath->evaluate("sourcedid/id", $membershipnode)->item(0);
$course = $DB->get_record('course', array('idnumber' => $idnumber->nodeValue), '*', MUST_EXIST);
$members = $xpath->evaluate("member", $membershipnode);
foreach ($members as $mmember) {
$midnumber = $xpath->evaluate("sourcedid/id", $mmember)->item(0);
$idtype = $xpath->evaluate("idtype", $mmember)->item(0);
if ($midnumber) {
$member = new stdClass();
$member->idnumber = $midnumber->nodeValue;
$cohortid = $DB->get_field('cohort', 'id', array('idnumber' => $member->idnumber));
$cohortname = $DB->get_field('cohort', 'name', array('idnumber' => $member->idnumber));
if ($idtype->nodeValue == 'Add' && $cohortid) {
if (!($cohortinstanceid = $DB->get_field('enrol', 'id', array('enrol' => 'cohort', 'customint1' => $cohortid, 'courseid' => $course->id)))) {
$enrol = enrol_get_plugin('cohort');
$enrol->add_instance($course, array('name' => $cohortname, 'status' => 0, 'customint1' => $cohortid, 'roleid' => 5, 'customint2' => 0));
$trace = new null_progress_trace();
enrol_cohort_sync($trace, $course->id);
$trace->finished();
}
if (substr($idnumber->nodeValue, 0, 8) == 'UOFAB-XL') {
$data = new stdClass();
if (!($data->id = $DB->get_field('groups', 'id', array('courseid' => $course->id, 'name' => $cohortname)))) {
$data->timecreated = time();
$data->timemodified = time();
$data->name = trim($cohortname);
$data->description = '';
$data->descriptionformat = '1';
$data->courseid = $course->id;
$data->id = groups_create_group($data);
}
$cohortrec = $DB->get_fieldset_select('cohort_members', 'userid', 'cohortid=' . $cohortid);
foreach ($cohortrec as $curmember) {
$latestlist[$curmember] = $curmember;
groups_add_member($data->id, $curmember);
}
$grouprec = $DB->get_fieldset_select('groups_members', 'userid', 'groupid=' . $data->id);
foreach ($grouprec as $grpmember) {
if (!isset($latestlist[$grpmember])) {
groups_remove_member($data->id, $grpmember);
}
}
}
} else {
if ($idtype->nodeValue == 'Delete') {
if ($cohortinstance = $DB->get_record('enrol', array('enrol' => 'cohort', 'customint1' => $cohortid, 'courseid' => $course->id))) {
$enrol = enrol_get_plugin('cohort');
$enrol->delete_instance($cohortinstance);
}
}
}
}
}
}
示例6: groups_get_members
$leavegroup = $my_groupid;
$members = groups_get_members($leavegroup);
if (count($members) == 1) {
groups_delete_group($leavegroup);
} else {
$member_group = $DB->get_records_sql('SELECT id,userid FROM {groups_members} WHERE groupid = ? and roleid = ? LIMIT 1', array($my_groupid, "2"));
foreach ($member_group as $member_leader) {
$member_new_leader = new stdClass();
$member_new_leader->id = $member_leader->id;
$member_new_leader->groupid = $leavegroup;
$member_new_leader->leader_group = $member_leader->userid;
}
//UAIOPEN - actualiza el líder
groups_update_leader($member_new_leader);
//UAIOPEN - remueve al participante
groups_remove_member($leavegroup, $USER->id);
}
redirect(new moodle_url('/group/index.php', array('id' => $courseid)));
break;
case 'updatemembers':
//Currently reloading.
break;
default:
//ERROR.
print_error('unknowaction', '', $returnurl);
break;
}
// Print the page and form
$strgroups = get_string('groups');
$strparticipants = get_string('participants');
/// Print header
示例7: delete_group_members
/**
* Delete group members
*
* @param array $members of arrays with keys userid, groupid
* @since Moodle 2.2
*/
public static function delete_group_members($members)
{
global $CFG, $DB;
require_once "{$CFG->dirroot}/group/lib.php";
$params = self::validate_parameters(self::delete_group_members_parameters(), array('members' => $members));
$transaction = $DB->start_delegated_transaction();
foreach ($params['members'] as $member) {
// validate params
$groupid = $member['groupid'];
$userid = $member['userid'];
$group = groups_get_group($groupid, 'id, courseid', MUST_EXIST);
$user = $DB->get_record('user', array('id' => $userid, 'deleted' => 0, 'mnethostid' => $CFG->mnet_localhost_id), '*', MUST_EXIST);
// now security checks
$context = context_course::instance($group->courseid, IGNORE_MISSING);
try {
self::validate_context($context);
} catch (Exception $e) {
$exceptionparam = new stdClass();
$exceptionparam->message = $e->getMessage();
$exceptionparam->courseid = $group->courseid;
throw new moodle_exception('errorcoursecontextnotvalid', 'webservice', '', $exceptionparam);
}
require_capability('moodle/course:managegroups', $context);
if (!groups_remove_member_allowed($group, $user)) {
throw new moodle_exception('errorremovenotpermitted', 'group', '', fullname($user));
}
groups_remove_member($group, $user);
}
$transaction->allow_commit();
}
示例8: elseif
} elseif (isset($frm->add) and !empty($frm->addselect)) {
foreach ($frm->addselect as $userid) {
if (!($userid = clean_param($userid, PARAM_INT))) {
continue;
}
$success = groups_add_member($groupid, $userid);
if (!$success) {
print_error('erroraddremoveuser', 'group', groups_home_url($courseid));
}
}
} elseif (isset($frm->remove) and !empty($frm->removeselect)) {
foreach ($frm->removeselect as $userid) {
if (!($userid = clean_param($userid, PARAM_INT))) {
continue;
}
$success = groups_remove_member($groupid, $userid);
if (!$success) {
print_error('erroraddremoveuser', 'group', groups_home_url($courseid));
}
}
}
}
$groupmembers = groups_get_members($groupid);
$groupmembersoptions = '';
$groupmemberscount = 0;
if ($groupmembers != false) {
// Put the groupings into a hash and sorts them
foreach ($groupmembers as $userid) {
$listmembers[$userid] = groups_get_user_displayname($userid, $courseid);
$groupmemberscount++;
}
示例9: cancelbatch
function cancelbatch($id){
global $DB;
$batchid=$id;
$newbatch=new stdClass();
$newbatch->id=$id;
$newbatch->active=2;
//updating the sbatch status
$DB->update_record('facetoface', $newbatch);
//used for unenrolling the users from course
$batch_courses=$DB->record_exists_sql("SELECT * FROM {local_batch_courses} WHERE batchid=$id AND courseid!=0");
$assigned_course=$DB->get_record_sql("SELECT * FROM {local_batch_courses} WHERE batchid=$id AND courseid!=0");
$email_log=simple_template_for_batches($id,1);
if($email_log){
if($batch_courses==1){
$batch_users=$DB->record_exists_sql("SELECT * FROM {local_batch_users} WHERE f2fid=$id");
if($batch_users==1){
$assigned_users=$DB->get_records_sql("SELECT * FROM {local_batch_users} WHERE f2fid=$id");
foreach($assigned_users as $assigned_user){
$manual = enrol_get_plugin('manual');
$studentrole = $DB->get_record('role', array('shortname'=>'student'));
$instance = $DB->get_record('enrol', array('courseid'=>$assigned_course->courseid, 'enrol'=>'manual'), '*', MUST_EXIST);
if($instance){
$timeend='';
if(!$DB->record_exists_sql("SELECT * FROM {course_completions} WHERE course=$assigned_course->courseid AND userid=$assigned_user->userid and timecompleted!=''")){
$local_batch_courses=$DB->get_records_sql("SELECT lbu.* FROM {local_batch_users} lbu
JOIN {facetoface} fa ON fa.id=lbu.f2fid and fa.active in (0,1,8,3)
where lbu.courseid=$assigned_course->courseid and lbu.userid=$assigned_user->userid
and fa.id!=$id");
if(count($local_batch_courses)==0){
$manual->unenrol_user($instance,$assigned_user->userid, $studentrole->id,time(),$timeend);
}
}
//$manual->unenrol_user($instance,$assigned_user->userid, $studentrole->id,time(),$timeend);
}
if($assigned_course->groupid!=0)
groups_remove_member($assigned_course->groupid, $assigned_user->userid);
}
}
$assigned_sessions=$DB->get_records_sql("SELECT * FROM {facetoface_sessions} WHERE facetoface=$id");
if($assigned_sessions){
foreach($assigned_sessions as $assigned_session){
$facetoface = $DB->get_record('facetoface', array('id' =>$id));
$signedupusers = $DB->get_records_sql("SELECT * FROM {local_batch_users} WHERE f2fid= $id");
if ($signedupusers and count($signedupusers) > 0) {
foreach ($signedupusers as $user) {
if (facetoface_user_cancel($assigned_session, $user->userid, true)) {
//facetoface_send_cancellation_notice($facetoface, $assigned_session, $user->userid);
} else {
return false; // Cannot rollback since we notified users already
}
}
}
if($facetoface->actualsessions){
$actual_sessions=$facetoface->actualsessions-1;
$DB->execute('update {facetoface} SET actualsessions='.$actual_sessions.' WHERE id='.$id.'');
}
}
}
}
return $email_log;
}
// unenrolling the users from course ends
//==========================Rajut // Cancel user signups (and notify users)==========================//
$facetoface = $DB->get_record('facetoface', array('id' =>$id));
$assigned_sessions=$DB->get_records_sql("SELECT * FROM {facetoface_sessions} WHERE facetoface=$id");
//print_object($assigned_sessions);
foreach($assigned_sessions as $assigned_session){
// Cancel user signups (and notify users)
$signedupusers = $DB->get_records_sql("SELECT * FROM {local_batch_users} WHERE f2fid=$id");
if ($signedupusers and count($signedupusers) > 0) {
foreach ($signedupusers as $user) {
if (facetoface_user_cancel($assigned_session, $user->userid, true)) {
//facetoface_send_cancellation_notice($facetoface, $assigned_session, $user->userid);
} else {
return false; // Cannot rollback since we notified users already
}
}
}
}
//return $id;
}
示例10: test_is_user_access_restricted_by_group
/**
* Test is_user_access_restricted_by_group()
*
* The underlying groups system is more thoroughly tested in lib/tests/grouplib_test.php
*/
public function test_is_user_access_restricted_by_group() {
global $DB, $CFG, $USER;
$this->resetAfterTest(true);
// Create a course
$course = $this->getDataGenerator()->create_course();
$coursecontext = context_course::instance($course->id);
// Create a mod_assign instance
$assign = $this->getDataGenerator()->create_module('assign', array('course'=>$course->id));
$cm_info = get_fast_modinfo($course)->instances['assign'][$assign->id];
// Create and enrol a student
// Enrolment is necessary for groups to work
$studentrole = $DB->get_record('role', array('shortname'=>'student'), '*', MUST_EXIST);
$student = $this->getDataGenerator()->create_user();
role_assign($studentrole->id, $student->id, $coursecontext);
$enrolplugin = enrol_get_plugin('manual');
$enrolplugin->add_instance($course);
$enrolinstances = enrol_get_instances($course->id, false);
foreach ($enrolinstances as $enrolinstance) {
if ($enrolinstance->enrol === 'manual') {
break;
}
}
$enrolplugin->enrol_user($enrolinstance, $student->id);
// Switch to a student and reload the context info
$this->setUser($student);
$cm_info = $this->refresh_cm_info($course, $assign);
// Create up a teacher
$teacherrole = $DB->get_record('role', array('shortname'=>'editingteacher'), '*', MUST_EXIST);
$teacher = $this->getDataGenerator()->create_user();
role_assign($teacherrole->id, $teacher->id, $coursecontext);
// Create 2 groupings
$grouping1 = $this->getDataGenerator()->create_grouping(array('courseid' => $course->id, 'name' => 'grouping1'));
$grouping2 = $this->getDataGenerator()->create_grouping(array('courseid' => $course->id, 'name' => 'grouping2'));
// Create 2 groups and put them in the groupings
$group1 = $this->getDataGenerator()->create_group(array('courseid' => $course->id, 'idnumber' => 'group1'));
groups_assign_grouping($grouping1->id, $group1->id);
$group2 = $this->getDataGenerator()->create_group(array('courseid' => $course->id, 'idnumber' => 'group2'));
groups_assign_grouping($grouping2->id, $group2->id);
// If groups are disabled, the activity isn't restricted.
$CFG->enablegroupmembersonly = false;
$this->assertFalse($cm_info->is_user_access_restricted_by_group());
// If groups are on but "group members only" is off, the activity isn't restricted.
$CFG->enablegroupmembersonly = true;
$cm_info->groupmembersonly = NOGROUPS;
$this->assertFalse($cm_info->is_user_access_restricted_by_group());
// If "group members only" is on but user is in the wrong group, the activity is restricted.
$cm_info->groupmembersonly = SEPARATEGROUPS;
$cm_info->groupingid = $grouping1->id;
$this->assertTrue(groups_add_member($group2, $USER));
$this->assertTrue($cm_info->is_user_access_restricted_by_group());
// If the user is in the required group, the activity isn't restricted.
groups_remove_member($group2, $USER);
$this->assertTrue(groups_add_member($group1, $USER));
$cm_info = $this->refresh_cm_info($course, $assign);
$this->assertFalse($cm_info->is_user_access_restricted_by_group());
// Switch to a teacher and reload the context info
$this->setUser($teacher);
$cm_info = $this->refresh_cm_info($course, $assign);
// If the user isn't in the required group but has 'moodle/site:accessallgroups', the activity isn't restricted.
$this->assertTrue(has_capability('moodle/site:accessallgroups', $coursecontext));
$this->assertFalse($cm_info->is_user_access_restricted_by_group());
}
示例11: blended_delete_sign_member_or_group
function blended_delete_sign_member_or_group($idteam, $member, $option)
{
global $DB;
$blended_teams = $DB->get_records('blended_team');
foreach ($blended_teams as $blended_team) {
if ($blended_team->id_team == $idteam) {
$f = $blended_team;
}
}
$g = $DB->get_record('groups', array('id' => $idteam));
$l = $DB->get_record('blended_assign_grouping', array('id_assign' => $f->id_assignment));
if ($option == 'member') {
$del = groups_remove_member($idteam, $member->userid);
blended_delete_team_member($idteam, $member->id);
}
if ($option == 'group') {
$del = groups_delete_group($idteam);
groups_unassign_grouping($l->id_grouping, $idteam);
blended_delete_team($idteam, $f->id_assignment);
blended_delete_team_member($idteam);
//Se debe realizar la comprobación de que si no hay mas equipos se borre el agrupamiento
if (!($teams = $DB->get_records('groupings_groups', array('groupingid' => $l->id_grouping)))) {
groups_delete_grouping($l->id_grouping);
$DB->delete_records('blended_assign_grouping', array('id_grouping' => $l->id_grouping));
}
}
}
示例12: moodle_group_add_groupmembers
function moodle_group_add_groupmembers($client) {
global $DB, $CFG;
//create category
$category = new stdClass();
$category->name = 'tmpcategoryfortest123';
$category->id = $DB->insert_record('course_categories', $category);
//create a course
$course = new stdClass();
$course->fullname = 'tmpcoursefortest123';
$course->shortname = 'tmpcoursefortest123';
$course->idnumber = 'tmpcoursefortest123';
$course->category = $category->id;
$course->id = $DB->insert_record('course', $course);
//create a role
$role1->id = create_role('role1thatshouldnotexist', 'role1thatshouldnotexist', '');
//create a user
$user = new stdClass();
$user->username = 'veryimprobabletestusername2';
$user->password = 'testpassword2';
$user->firstname = 'testfirstname2';
$user->lastname = 'testlastname2';
$user->email = 'testemail1@moodle.com';
$user->mnethostid = $CFG->mnet_localhost_id;
require_once($CFG->dirroot."/user/lib.php");
$user->id = user_create_user($user);
//create course context
$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
//enrol the user in the course with the created role
role_assign($role1->id, $user->id, $context->id);
$enrol = new stdClass();
$enrol->courseid = $course->id;
$enrol->roleid = $role1->id;
$enrol->id = $DB->insert_record('enrol', $enrol);
$enrolment = new stdClass();
$enrolment->userid = $user->id;
$enrolment->enrolid = $enrol->id;
$enrolment->id = $DB->insert_record('user_enrolments', $enrolment);
//create a group in the course
$group = new stdClass();
$group->courseid = $course->id;
$group->name = 'tmpgroufortest123';
$group->id = $DB->insert_record('groups', $group);
//WEBSERVICE CALL
$function = 'moodle_group_add_groupmembers';
$params = array('members' => array(array('groupid' => $group->id, 'userid' => $user->id)));
$groupsmembers = $client->call($function, $params);
//CHECK TEST RESULT
require_once($CFG->libdir . '/grouplib.php');
$groupmembers = groups_get_members($group->id);
$this->assertEqual(count($groupmembers), 1);
$this->assertEqual($groupmembers[$user->id]->id, $user->id);
//remove the members from the group
require_once($CFG->dirroot . "/group/lib.php");
groups_remove_member($group->id, $user->id);
//delete the group
$DB->delete_records('groups', array('id' => $group->id));
//unenrol the user
$DB->delete_records('user_enrolments', array('id' => $enrolment->id));
$DB->delete_records('enrol', array('id' => $enrol->id));
role_unassign($role1->id, $user->id, $context->id);
//delete course context
delete_context(CONTEXT_COURSE, $course->id);
//delete the user
$DB->delete_records('user', array('id' => $user->id));
//delete the role
delete_role($role1->id);
//delete the course
$DB->delete_records('course', array('id' => $course->id));
//delete the category
$DB->delete_records('course_categories', array('id' => $category->id));
}
示例13: groups_delete_group_members
/**
* Remove all users (or one user) from all groups in course
*
* @param int $courseid
* @param int $userid 0 means all users
* @param bool $showfeedback
* @return bool success
*/
function groups_delete_group_members($courseid, $userid = 0, $showfeedback = false)
{
global $DB, $OUTPUT;
if (is_bool($userid)) {
debugging('Incorrect userid function parameter');
return false;
}
// Select * so that the function groups_remove_member() gets the whole record.
$groups = $DB->get_recordset('groups', array('courseid' => $courseid));
foreach ($groups as $group) {
if ($userid) {
$userids = array($userid);
} else {
$userids = $DB->get_fieldset_select('groups_members', 'userid', 'groupid = :groupid', array('groupid' => $group->id));
}
foreach ($userids as $id) {
groups_remove_member($group, $id);
}
}
// TODO MDL-41312 Remove events_trigger_legacy('groups_members_removed').
// This event is kept here for backwards compatibility, because it cannot be
// translated to a new event as it is wrong.
$eventdata = new stdClass();
$eventdata->courseid = $courseid;
$eventdata->userid = $userid;
events_trigger_legacy('groups_members_removed', $eventdata);
if ($showfeedback) {
echo $OUTPUT->notification(get_string('deleted') . ' - ' . get_string('groupmembers', 'group'), 'notifysuccess');
}
return true;
}
示例14: adobeconnect_add_instance
/**
* Given an object containing all the necessary data,
* (defined by the form in mod_form.php) this function
* will create a new instance and return the id number
* of the new instance.
*
* @param object $adobeconnect An object from the form in mod_form.php
* @return int The id of the newly inserted adobeconnect record
*/
function adobeconnect_add_instance($adobeconnect)
{
global $COURSE, $USER, $DB;
$adobeconnect->timecreated = time();
$adobeconnect->meeturl = adobeconnect_clean_meet_url($adobeconnect->meeturl);
$adobeconnect->userid = $USER->id;
$name = empty($USER->idnumber) ? $USER->username : $USER->idnumber;
$username = set_username($name, $USER->email);
// Assign the current user with the Adobe Presenter role.
$context = context_course::instance($adobeconnect->course);
if (!has_capability('mod/adobeconnect:meetinghost', $context, $USER->id, false)) {
$param = array('shortname' => 'adobeconnecthost');
$roleid = $DB->get_field('role', 'id', $param);
if (!role_assign($roleid, $USER->id, $context->id, 'mod_adobeconnect')) {
debugging('role assignment failed', DEBUG_DEVELOPER);
return false;
}
}
$aconnect = aconnect_login();
if ($aconnect->get_connection() != 1) {
debugging('Unable to connect to the Adobe Connect server.', DEBUG_DEVELOPER);
return false;
}
$recid = $DB->insert_record('adobeconnect', $adobeconnect);
if (empty($recid)) {
debugging('creating adobeconnect module instance failed', DEBUG_DEVELOPER);
return false;
}
// Get the user's meeting folder location, if non exists then get the shared meeting folder location.
$meetfldscoid = aconnect_get_user_folder_sco_id($aconnect, $username);
if (empty($meetfldscoid)) {
$meetfldscoid = aconnect_get_folder($aconnect, 'meetings');
}
$meeting = clone $adobeconnect;
if (0 != $adobeconnect->groupmode) {
// Allow for multiple groups.
// Get all groups for the course.
$crsgroups = groups_get_all_groups($COURSE->id);
if (empty($crsgroups)) {
return 0;
}
require_once dirname(dirname(dirname(__FILE__))) . '/group/lib.php';
// Create the meeting for each group.
foreach ($crsgroups as $crsgroup) {
// The teacher role if they don't already have one and assign them to each group.
if (!groups_is_member($crsgroup->id, $USER->id)) {
groups_add_member($crsgroup->id, $USER->id);
}
$meeting->name = $adobeconnect->name . '_' . $crsgroup->name;
if (!empty($adobeconnect->meeturl)) {
$meeting->meeturl = adobeconnect_clean_meet_url($adobeconnect->meeturl . '_' . $crsgroup->name);
}
// If creating the meeting failed, then return false and revert the group role assignments.
if (!($meetingscoid = aconnect_create_meeting($aconnect, $meeting, $meetfldscoid))) {
groups_remove_member($crsgroup->id, $USER->id);
debugging('Error creating meeting', DEBUG_DEVELOPER);
return false;
}
// Update permissions for meeting.
if (empty($adobeconnect->meetingpublic)) {
aconnect_update_meeting_perm($aconnect, $meetingscoid, ADOBE_MEETPERM_PRIVATE);
} else {
aconnect_update_meeting_perm($aconnect, $meetingscoid, ADOBE_MEETPERM_PUBLIC);
}
// Insert record to activity instance in meeting_groups table.
$record = new stdClass();
$record->instanceid = $recid;
$record->meetingscoid = $meetingscoid;
$record->groupid = $crsgroup->id;
$record->id = $DB->insert_record('adobeconnect_meeting_groups', $record);
// Add event to calendar.
$event = new stdClass();
$event->name = $meeting->name;
$event->description = format_module_intro('adobeconnect', $adobeconnect, $adobeconnect->coursemodule);
$event->courseid = $adobeconnect->course;
$event->groupid = $crsgroup->id;
$event->userid = 0;
$event->instance = $recid;
$event->eventtype = 'group';
$event->timestart = $adobeconnect->starttime;
$event->timeduration = $adobeconnect->endtime - $adobeconnect->starttime;
$event->visible = 1;
$event->modulename = 'adobeconnect';
calendar_event::create($event);
}
} else {
// No groups support.
$meetingscoid = aconnect_create_meeting($aconnect, $meeting, $meetfldscoid);
// If creating the meeting failed, then return false and revert the group role assignments.
if (!$meetingscoid) {
debugging('error creating meeting', DEBUG_DEVELOPER);
//.........这里部分代码省略.........
示例15: group_member_removed
/**
* Group member removed
*
* @param \core\event\group_member_removed $event
* @return void
*/
public static function group_member_removed(\core\event\group_member_removed $event)
{
global $DB;
$group = $event->get_record_snapshot('groups', $event->objectid);
$user = \core_user::get_user($event->relateduserid, '*', MUST_EXIST);
$courseids = local_metagroups_parent_courses($group->courseid);
foreach ($courseids as $courseid) {
$course = get_course($courseid);
if ($metagroup = $DB->get_record('groups', array('courseid' => $course->id, 'idnumber' => $group->id))) {
groups_remove_member($metagroup, $user);
}
}
}