当前位置: 首页>>代码示例>>PHP>>正文


PHP groups_add_member函数代码示例

本文整理汇总了PHP中groups_add_member函数的典型用法代码示例。如果您正苦于以下问题:PHP groups_add_member函数的具体用法?PHP groups_add_member怎么用?PHP groups_add_member使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了groups_add_member函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: test_member_added_event

 public function test_member_added_event()
 {
     $this->resetAfterTest();
     $this->setAdminUser();
     $course = $this->getDataGenerator()->create_course();
     $user = $this->getDataGenerator()->create_user();
     $group = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
     $this->getDataGenerator()->enrol_user($user->id, $course->id);
     $sink = $this->redirectEvents();
     groups_add_member($group->id, $user->id, 'mod_workshop', '123');
     $events = $sink->get_events();
     $this->assertCount(1, $events);
     $event = reset($events);
     $expected = new stdClass();
     $expected->groupid = $group->id;
     $expected->userid = $user->id;
     $expected->component = 'mod_workshop';
     $expected->itemid = '123';
     $this->assertEventLegacyData($expected, $event);
     $this->assertSame('groups_member_added', $event->get_legacy_eventname());
     $this->assertInstanceOf('\\core\\event\\group_member_added', $event);
     $this->assertEquals($user->id, $event->relateduserid);
     $this->assertEquals(context_course::instance($course->id), $event->get_context());
     $this->assertEquals($group->id, $event->objectid);
     $url = new moodle_url('/group/members.php', array('group' => $event->objectid));
     $this->assertEquals($url, $event->get_url());
 }
开发者ID:evltuma,项目名称:moodle,代码行数:27,代码来源:lib_test.php

示例2: load_data

 /**
  * Loads some data to be used by the different tests
  * @param  int $s1grade Student 1 grade
  * @param  int $s2grade Student 2 grade
  * @return array          Course and users instances
  */
 private function load_data($s1grade, $s2grade)
 {
     global $DB;
     $course = $this->getDataGenerator()->create_course(array('groupmode' => SEPARATEGROUPS, 'groupmodeforce' => 1));
     $studentrole = $DB->get_record('role', array('shortname' => 'student'));
     $student1 = $this->getDataGenerator()->create_user();
     $this->getDataGenerator()->enrol_user($student1->id, $course->id, $studentrole->id);
     $student2 = $this->getDataGenerator()->create_user();
     $this->getDataGenerator()->enrol_user($student2->id, $course->id, $studentrole->id);
     $teacherrole = $DB->get_record('role', array('shortname' => 'teacher'));
     $teacher = $this->getDataGenerator()->create_user();
     $this->getDataGenerator()->enrol_user($teacher->id, $course->id, $teacherrole->id);
     $context = context_course::instance($course->id);
     assign_capability('moodle/site:accessallgroups', CAP_PROHIBIT, $teacherrole->id, $context);
     accesslib_clear_all_caches_for_unit_testing();
     $group1 = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
     $group2 = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
     groups_add_member($group1->id, $student1->id);
     groups_add_member($group1->id, $teacher->id);
     groups_add_member($group2->id, $student2->id);
     $assignment = $this->getDataGenerator()->create_module('assign', array('name' => "Test assign", 'course' => $course->id));
     $modcontext = get_coursemodule_from_instance('assign', $assignment->id, $course->id);
     $assignment->cmidnumber = $modcontext->id;
     $student1grade = array('userid' => $student1->id, 'rawgrade' => $s1grade);
     $student2grade = array('userid' => $student2->id, 'rawgrade' => $s2grade);
     $studentgrades = array($student1->id => $student1grade, $student2->id => $student2grade);
     assign_grade_item_update($assignment, $studentgrades);
     return array($course, $teacher, $student1, $student2, $assignment);
 }
开发者ID:janeklb,项目名称:moodle,代码行数:35,代码来源:externallib_test.php

示例3: _addUserToGroup

 private function _addUserToGroup($userId, $groupId)
 {
     global $CFG;
     require_once $CFG->dirroot . '/group/lib.php';
     groups_add_member($groupId, $userId);
     /* group/lib.php */
 }
开发者ID:frapersan,项目名称:group-magic,代码行数:7,代码来源:GroupMagic.php

示例4: build

 /**
  * Create the fixture
  *
  * This method must be safe to call multiple times.
  *
  * @return void
  * @throws moodle_exception
  */
 public function build()
 {
     global $DB;
     if (!$this->exists()) {
         // Dependents
         $this->get_group()->build();
         $this->get_enrollment()->build();
         groups_add_member($this->get_group()->get_results(), $this->get_user()->get_results());
         $conditions = array('groupid' => $this->get_group()->get('id'), 'userid' => $this->get_user()->get('id'));
         $this->set_results($DB->get_record('groups_members', $conditions, '*', MUST_EXIST));
     }
 }
开发者ID:bgao-ca,项目名称:moodle-local_mr,代码行数:20,代码来源:member.php

示例5: test_add_member

 function test_add_member()
 {
     // NOTE, interface change on add_member, remove_member.
     $this->assertTrue(groups_add_member($this->groupid, $this->userid));
     $this->assertTrue(groups_is_member($this->groupid, $this->userid));
     $this->assertTrue($userids = groups_get_members($this->groupid));
     //...
     $this->assertTrue($groupids = groups_get_groups_for_user($this->userid, $this->courseid));
     //...
     $this->assertTrue(1 == groups_count_group_members($this->groupid));
     //Utillib.
 }
开发者ID:veritech,项目名称:pare-project,代码行数:12,代码来源:test_basicgrouplib.php

示例6: 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();
}
开发者ID:danielneis,项目名称:moodle-local_syncgroups,代码行数:50,代码来源:lib.php

示例7: create_group

 /**
  * This function creates a group with a particular name, adds it to the grouping,
  * and then adds the current user to that group.
  *
  * @param string $name The name to assign to the newly created group.
  * @return int The ID of the group that was group that was created.
  *
  */
 public function create_group($name)
 {
     global $DB, $USER;
     $sgs = new skills_group_setting($this->courseid);
     $group = new stdClass();
     if ($name === null || trim($name) == '') {
         $name = $this->name_empty_group();
     }
     $group->name = $name;
     $group->courseid = $this->courseid;
     $groupid = groups_create_group($group);
     groups_assign_grouping($sgs->get_grouping_id(), $groupid);
     groups_add_member($groupid, $USER->id);
     return $groupid;
 }
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:23,代码来源:skills_grouping.class.php

示例8: setUp

 /**
  * setUp/tearDown: Better in a constructor/destructor, but PHP4 doesn't do destructors :(
  */
 function setUp()
 {
     parent::setUp();
     if ($course = groups_get_course_info(1)) {
         $this->courseid = $course->id;
     }
     if ($user = groups_get_user(2)) {
         //Primary admin.
         $this->userid = $user->id;
     }
     $this->groupid = groups_create_group($this->courseid);
     $groupinfo = groups_set_default_group_settings();
     $bok = groups_set_group_settings($this->groupid, $groupinfo);
     $bok = groups_add_member($this->groupid, $this->userid);
 }
开发者ID:veritech,项目名称:pare-project,代码行数:18,代码来源:test_groupinglib.php

示例9: member_added

 /**
  * Event processor - cohort member added.
  * @param \core\event\cohort_member_added $event
  * @return bool
  */
 public static function member_added(\core\event\cohort_member_added $event)
 {
     global $DB, $CFG;
     require_once "{$CFG->dirroot}/group/lib.php";
     if (!enrol_is_enabled('cohort')) {
         return true;
     }
     // Does any enabled cohort instance want to sync with this cohort?
     $sql = "SELECT e.*, r.id as roleexists\n                  FROM {enrol} e\n             LEFT JOIN {role} r ON (r.id = e.roleid)\n                 WHERE e.customint1 = :cohortid AND e.enrol = 'cohort' AND e.status = :enrolstatus\n              ORDER BY e.id ASC";
     $params['cohortid'] = $event->objectid;
     $params['enrolstatus'] = ENROL_INSTANCE_ENABLED;
     if (!($instances = $DB->get_records_sql($sql, $params))) {
         return true;
     }
     $plugin = enrol_get_plugin('cohort');
     foreach ($instances as $instance) {
         if ($instance->status != ENROL_INSTANCE_ENABLED) {
             // No roles for disabled instances.
             $instance->roleid = 0;
         } else {
             if ($instance->roleid and !$instance->roleexists) {
                 // Invalid role - let's just enrol, they will have to create new sync and delete this one.
                 $instance->roleid = 0;
             }
         }
         unset($instance->roleexists);
         // No problem if already enrolled.
         $plugin->enrol_user($instance, $event->relateduserid, $instance->roleid, 0, 0, ENROL_USER_ACTIVE);
         // Sync groups.
         if ($instance->customint2) {
             if (!groups_is_member($instance->customint2, $event->relateduserid)) {
                 if ($group = $DB->get_record('groups', array('id' => $instance->customint2, 'courseid' => $instance->courseid))) {
                     groups_add_member($group->id, $event->relateduserid, 'enrol_cohort', $instance->id);
                 }
             }
         }
     }
     return true;
 }
开发者ID:stronk7,项目名称:moodle,代码行数:44,代码来源:locallib.php

示例10: stdClass

             if (!array_key_exists($addgroup, $ccache[$shortname]->groups)) {
                 // if group doesn't exist,  create it
                 $newgroupdata = new stdClass();
                 $newgroupdata->name = $addgroup;
                 $newgroupdata->courseid = $ccache[$shortname]->id;
                 if ($ccache[$shortname]->groups[$addgroup]->id = groups_create_group($newgroupdata)) {
                     $ccache[$shortname]->groups[$addgroup]->name = $newgroupdata->name;
                 } else {
                     $upt->track('enrolments', get_string('unknowngroup', 'error', s($addgroup)), 'error');
                     continue;
                 }
             }
             $gid = $ccache[$shortname]->groups[$addgroup]->id;
             $gname = $ccache[$shortname]->groups[$addgroup]->name;
             try {
                 if (groups_add_member($gid, $user->id)) {
                     $upt->track('enrolments', get_string('addedtogroup', '', s($gname)));
                 } else {
                     $upt->track('enrolments', get_string('addedtogroupnot', '', s($gname)), 'error');
                 }
             } catch (moodle_exception $e) {
                 $upt->track('enrolments', get_string('addedtogroupnot', '', s($gname)), 'error');
                 continue;
             }
         }
     }
 }
 $upt->close();
 // close table
 $cir->close();
 $cir->cleanup(true);
开发者ID:richheath,项目名称:moodle,代码行数:31,代码来源:uploaduser.php

示例11: add_to_group

 function add_to_group($groupid, $userid)
 {
     groups_add_member($groupid, $userid);
 }
开发者ID:sirromas,项目名称:lms,代码行数:4,代码来源:Utils.php

示例12: restore_group_member

 /**
  * Restore user group membership.
  * @param stdClass $instance
  * @param int $groupid
  * @param int $userid
  */
 public function restore_group_member($instance, $groupid, $userid)
 {
     global $CFG;
     require_once "{$CFG->dirroot}/group/lib.php";
     // This might be called when forcing restore as manual enrolments.
     groups_add_member($groupid, $userid);
 }
开发者ID:masaterutakeno,项目名称:MoodleMobile,代码行数:13,代码来源:lib.php

示例13: 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);
                     }
                 }
             }
         }
     }
 }
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:56,代码来源:lib.php

示例14: test_mod_data_rating_can_see_item_ratings

 /**
  * Tests for mod_data_rating_can_see_item_ratings().
  *
  * @throws coding_exception
  * @throws rating_exception
  */
 public function test_mod_data_rating_can_see_item_ratings()
 {
     global $DB;
     $this->resetAfterTest();
     // Setup test data.
     $course = new stdClass();
     $course->groupmode = SEPARATEGROUPS;
     $course->groupmodeforce = true;
     $course = $this->getDataGenerator()->create_course($course);
     $data = $this->getDataGenerator()->create_module('data', array('course' => $course->id));
     $cm = get_coursemodule_from_instance('data', $data->id);
     $context = context_module::instance($cm->id);
     // Create users.
     $user1 = $this->getDataGenerator()->create_user();
     $user2 = $this->getDataGenerator()->create_user();
     $user3 = $this->getDataGenerator()->create_user();
     $user4 = $this->getDataGenerator()->create_user();
     // Groups and stuff.
     $role = $DB->get_record('role', array('shortname' => 'teacher'), '*', MUST_EXIST);
     $this->getDataGenerator()->enrol_user($user1->id, $course->id, $role->id);
     $this->getDataGenerator()->enrol_user($user2->id, $course->id, $role->id);
     $this->getDataGenerator()->enrol_user($user3->id, $course->id, $role->id);
     $this->getDataGenerator()->enrol_user($user4->id, $course->id, $role->id);
     $group1 = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
     $group2 = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
     groups_add_member($group1, $user1);
     groups_add_member($group1, $user2);
     groups_add_member($group2, $user3);
     groups_add_member($group2, $user4);
     // Add data.
     $field = data_get_field_new('text', $data);
     $fielddetail = new stdClass();
     $fielddetail->name = 'Name';
     $fielddetail->description = 'Some name';
     $field->define_field($fielddetail);
     $field->insert_field();
     // Add a record with a group id of zero (all participants).
     $recordid1 = data_add_record($data, 0);
     $datacontent = array();
     $datacontent['fieldid'] = $field->field->id;
     $datacontent['recordid'] = $recordid1;
     $datacontent['content'] = 'Obelix';
     $DB->insert_record('data_content', $datacontent);
     $recordid = data_add_record($data, $group1->id);
     $datacontent = array();
     $datacontent['fieldid'] = $field->field->id;
     $datacontent['recordid'] = $recordid;
     $datacontent['content'] = 'Asterix';
     $DB->insert_record('data_content', $datacontent);
     // Now try to access it as various users.
     unassign_capability('moodle/site:accessallgroups', $role->id);
     // Eveyone should have access to the record with the group id of zero.
     $params1 = array('contextid' => 2, 'component' => 'mod_data', 'ratingarea' => 'entry', 'itemid' => $recordid1, 'scaleid' => 2);
     $params = array('contextid' => 2, 'component' => 'mod_data', 'ratingarea' => 'entry', 'itemid' => $recordid, 'scaleid' => 2);
     $this->setUser($user1);
     $this->assertTrue(mod_data_rating_can_see_item_ratings($params));
     $this->assertTrue(mod_data_rating_can_see_item_ratings($params1));
     $this->setUser($user2);
     $this->assertTrue(mod_data_rating_can_see_item_ratings($params));
     $this->assertTrue(mod_data_rating_can_see_item_ratings($params1));
     $this->setUser($user3);
     $this->assertFalse(mod_data_rating_can_see_item_ratings($params));
     $this->assertTrue(mod_data_rating_can_see_item_ratings($params1));
     $this->setUser($user4);
     $this->assertFalse(mod_data_rating_can_see_item_ratings($params));
     $this->assertTrue(mod_data_rating_can_see_item_ratings($params1));
     // Now try with accessallgroups cap and make sure everything is visible.
     assign_capability('moodle/site:accessallgroups', CAP_ALLOW, $role->id, $context->id);
     $this->setUser($user1);
     $this->assertTrue(mod_data_rating_can_see_item_ratings($params));
     $this->assertTrue(mod_data_rating_can_see_item_ratings($params1));
     $this->setUser($user2);
     $this->assertTrue(mod_data_rating_can_see_item_ratings($params));
     $this->assertTrue(mod_data_rating_can_see_item_ratings($params1));
     $this->setUser($user3);
     $this->assertTrue(mod_data_rating_can_see_item_ratings($params));
     $this->assertTrue(mod_data_rating_can_see_item_ratings($params1));
     $this->setUser($user4);
     $this->assertTrue(mod_data_rating_can_see_item_ratings($params));
     $this->assertTrue(mod_data_rating_can_see_item_ratings($params1));
     // Change group mode and verify visibility.
     $course->groupmode = VISIBLEGROUPS;
     $DB->update_record('course', $course);
     unassign_capability('moodle/site:accessallgroups', $role->id);
     $this->setUser($user1);
     $this->assertTrue(mod_data_rating_can_see_item_ratings($params));
     $this->assertTrue(mod_data_rating_can_see_item_ratings($params1));
     $this->setUser($user2);
     $this->assertTrue(mod_data_rating_can_see_item_ratings($params));
     $this->assertTrue(mod_data_rating_can_see_item_ratings($params1));
     $this->setUser($user3);
     $this->assertTrue(mod_data_rating_can_see_item_ratings($params));
     $this->assertTrue(mod_data_rating_can_see_item_ratings($params1));
     $this->setUser($user4);
//.........这里部分代码省略.........
开发者ID:antoniorodrigues,项目名称:redes-digitais,代码行数:101,代码来源:lib_test.php

示例15: test_forum_user_can_post_discussion

 /**
  * Test forum_user_can_post_discussion
  */
 public function test_forum_user_can_post_discussion()
 {
     global $CFG, $DB;
     $this->resetAfterTest(true);
     // Create course to add the module.
     $course = self::getDataGenerator()->create_course(array('groupmode' => SEPARATEGROUPS, 'groupmodeforce' => 1));
     $user = self::getDataGenerator()->create_user();
     $this->getDataGenerator()->enrol_user($user->id, $course->id);
     // Forum forcing separate gropus.
     $record = new stdClass();
     $record->course = $course->id;
     $forum = self::getDataGenerator()->create_module('forum', $record, array('groupmode' => SEPARATEGROUPS));
     $cm = get_coursemodule_from_instance('forum', $forum->id);
     $context = context_module::instance($cm->id);
     self::setUser($user);
     // The user is not enroled in any group, try to post in a forum with separate groups.
     $can = forum_user_can_post_discussion($forum, null, -1, $cm, $context);
     $this->assertFalse($can);
     // Create a group.
     $group = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
     // Try to post in a group the user is not enrolled.
     $can = forum_user_can_post_discussion($forum, $group->id, -1, $cm, $context);
     $this->assertFalse($can);
     // Add the user to a group.
     groups_add_member($group->id, $user->id);
     // Try to post in a group the user is not enrolled.
     $can = forum_user_can_post_discussion($forum, $group->id + 1, -1, $cm, $context);
     $this->assertFalse($can);
     // Now try to post in the user group. (null means it will guess the group).
     $can = forum_user_can_post_discussion($forum, null, -1, $cm, $context);
     $this->assertTrue($can);
     $can = forum_user_can_post_discussion($forum, $group->id, -1, $cm, $context);
     $this->assertTrue($can);
     // Test all groups.
     $can = forum_user_can_post_discussion($forum, -1, -1, $cm, $context);
     $this->assertFalse($can);
     $this->setAdminUser();
     $can = forum_user_can_post_discussion($forum, -1, -1, $cm, $context);
     $this->assertTrue($can);
     // Change forum type.
     $forum->type = 'news';
     $DB->update_record('forum', $forum);
     // Admin can post news.
     $can = forum_user_can_post_discussion($forum, null, -1, $cm, $context);
     $this->assertTrue($can);
     // Normal users don't.
     self::setUser($user);
     $can = forum_user_can_post_discussion($forum, null, -1, $cm, $context);
     $this->assertFalse($can);
     // Change forum type.
     $forum->type = 'eachuser';
     $DB->update_record('forum', $forum);
     // I didn't post yet, so I should be able to post.
     $can = forum_user_can_post_discussion($forum, null, -1, $cm, $context);
     $this->assertTrue($can);
     // Post now.
     $record = new stdClass();
     $record->course = $course->id;
     $record->userid = $user->id;
     $record->forum = $forum->id;
     $discussion = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
     // I already posted, I shouldn't be able to post.
     $can = forum_user_can_post_discussion($forum, null, -1, $cm, $context);
     $this->assertFalse($can);
     // Last check with no groups, normal forum and course.
     $course->groupmode = NOGROUPS;
     $course->groupmodeforce = 0;
     $DB->update_record('course', $course);
     $forum->type = 'general';
     $forum->groupmode = NOGROUPS;
     $DB->update_record('forum', $forum);
     $can = forum_user_can_post_discussion($forum, null, -1, $cm, $context);
     $this->assertTrue($can);
 }
开发者ID:rushi963,项目名称:moodle,代码行数:77,代码来源:lib_test.php


注:本文中的groups_add_member函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。