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


PHP groups_assign_grouping函数代码示例

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


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

示例1: test_usage

 /**
  * Tests constructing and using condition.
  */
 public function test_usage()
 {
     global $CFG, $USER;
     $this->resetAfterTest();
     $CFG->enableavailability = true;
     // Erase static cache before test.
     condition::wipe_static_cache();
     // Make a test course and user.
     $generator = $this->getDataGenerator();
     $course = $generator->create_course();
     $user = $generator->create_user();
     $generator->enrol_user($user->id, $course->id);
     $info = new \core_availability\mock_info($course, $user->id);
     // Make 2 test groups, one in a grouping and one not.
     $grouping = $generator->create_grouping(array('courseid' => $course->id));
     $group1 = $generator->create_group(array('courseid' => $course->id, 'name' => 'G1!'));
     groups_assign_grouping($grouping->id, $group1->id);
     $group2 = $generator->create_group(array('courseid' => $course->id, 'name' => 'G2!'));
     // Do test (not in group).
     $cond = new condition((object) array('id' => (int) $group1->id));
     // Check if available (when not available).
     $this->assertFalse($cond->is_available(false, $info, true, $user->id));
     $information = $cond->get_description(false, false, $info);
     $this->assertRegExp('~You belong to.*G1!~', $information);
     $this->assertTrue($cond->is_available(true, $info, true, $user->id));
     // Add user to groups and refresh cache.
     groups_add_member($group1, $user);
     groups_add_member($group2, $user);
     get_fast_modinfo($course->id, 0, true);
     // Recheck.
     $this->assertTrue($cond->is_available(false, $info, true, $user->id));
     $this->assertFalse($cond->is_available(true, $info, true, $user->id));
     $information = $cond->get_description(false, true, $info);
     $this->assertRegExp('~do not belong to.*G1!~', $information);
     // Check group 2 works also.
     $cond = new condition((object) array('id' => (int) $group2->id));
     $this->assertTrue($cond->is_available(false, $info, true, $user->id));
     // What about an 'any group' condition?
     $cond = new condition((object) array());
     $this->assertTrue($cond->is_available(false, $info, true, $user->id));
     $this->assertFalse($cond->is_available(true, $info, true, $user->id));
     $information = $cond->get_description(false, true, $info);
     $this->assertRegExp('~do not belong to any~', $information);
     // Admin user doesn't belong to a group, but they can access it
     // either way (positive or NOT).
     $this->setAdminUser();
     $this->assertTrue($cond->is_available(false, $info, true, $USER->id));
     $this->assertTrue($cond->is_available(true, $info, true, $USER->id));
     // Group that doesn't exist uses 'missing' text.
     $cond = new condition((object) array('id' => $group2->id + 1000));
     $this->assertFalse($cond->is_available(false, $info, true, $user->id));
     $information = $cond->get_description(false, false, $info);
     $this->assertRegExp('~You belong to.*\\(Missing group\\)~', $information);
 }
开发者ID:dg711,项目名称:moodle,代码行数:57,代码来源:condition_test.php

示例2: 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

示例3: test_version1importlogsduplicategroupingassignment

 /**
  * Validate log message for assigning a group to a grouping is already
  * belongs to
  */
 public function test_version1importlogsduplicategroupingassignment()
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/group/lib.php';
     $userid = $this->create_test_user();
     $courseid = $this->create_test_course();
     $context = context_course::instance($courseid);
     $roleid = $this->create_test_role();
     $group = new stdClass();
     $group->courseid = $courseid;
     $group->name = 'rlipname';
     $group->id = groups_create_group($group);
     $grouping = new stdClass();
     $grouping->courseid = $courseid;
     $grouping->name = 'rlipname';
     $grouping->id = groups_create_grouping($grouping);
     groups_assign_grouping($grouping->id, $group->id);
     // Make sure they already have a role assignment.
     role_assign($roleid, $userid, $context->id);
     // Base data used every time.
     $basedata = array('action' => 'create', 'context' => 'course', 'instance' => 'rlipshortname', 'role' => 'rlipshortname', 'group' => 'rlipname', 'grouping' => 'rlipname');
     // Username.
     $data = $basedata;
     $data['username'] = 'rlipusername';
     $expectedmessage = "[enrolment.csv line 2] User with username \"rlipusername\" enrolled in course with shortname ";
     $expectedmessage .= "\"rlipshortname\". Assigned user with username \"rlipusername\" to group with name \"rlipname\". ";
     $expectedmessage .= "Group with name \"rlipname\" is already assigned to grouping with name \"rlipname\".\n";
     $this->assert_data_produces_error($data, $expectedmessage, 'enrolment');
     $DB->delete_records('user_enrolments');
     $DB->delete_records('groups_members');
     // Email.
     $data = $basedata;
     $data['email'] = 'rlipuser@rlipdomain.com';
     $expectedmessage = "[enrolment.csv line 2] User with email \"rlipuser@rlipdomain.com\" enrolled in course with shortname ";
     $expectedmessage .= "\"rlipshortname\". Assigned user with email \"rlipuser@rlipdomain.com\" to group with name ";
     $expectedmessage .= "\"rlipname\". Group with name \"rlipname\" is already assigned to grouping with name \"rlipname\".\n";
     $this->assert_data_produces_error($data, $expectedmessage, 'enrolment');
     $DB->delete_records('user_enrolments');
     $DB->delete_records('groups_members');
     // Idnumber.
     $data = $basedata;
     $data['idnumber'] = 'rlipidnumber';
     $expectedmessage = "[enrolment.csv line 2] User with idnumber \"rlipidnumber\" enrolled in course with shortname ";
     $expectedmessage .= "\"rlipshortname\". Assigned user with idnumber \"rlipidnumber\" to group with name \"rlipname\". ";
     $expectedmessage .= "Group with name \"rlipname\" is already assigned to grouping with name \"rlipname\".\n";
     $this->assert_data_produces_error($data, $expectedmessage, 'enrolment');
     $DB->delete_records('user_enrolments');
     $DB->delete_records('groups_members');
     // Username, email.
     $data = $basedata;
     $data['username'] = 'rlipusername';
     $data['email'] = 'rlipuser@rlipdomain.com';
     $expectedmessage = "[enrolment.csv line 2] User with username \"rlipusername\", email \"rlipuser@rlipdomain.com\" ";
     $expectedmessage .= "enrolled in course with shortname \"rlipshortname\". Assigned user with username \"rlipusername\", ";
     $expectedmessage .= "email \"rlipuser@rlipdomain.com\" to group with name \"rlipname\". Group with name \"rlipname\" is ";
     $expectedmessage .= "already assigned to grouping with name \"rlipname\".\n";
     $this->assert_data_produces_error($data, $expectedmessage, 'enrolment');
     $DB->delete_records('user_enrolments');
     $DB->delete_records('groups_members');
     // Username, idnumber.
     $data = $basedata;
     $data['username'] = 'rlipusername';
     $data['idnumber'] = 'rlipidnumber';
     $expectedmessage = "[enrolment.csv line 2] User with username \"rlipusername\", idnumber \"rlipidnumber\" enrolled in ";
     $expectedmessage .= "course with shortname \"rlipshortname\". Assigned user with username \"rlipusername\", idnumber ";
     $expectedmessage .= "\"rlipidnumber\" to group with name \"rlipname\". Group with name \"rlipname\" is already assigned ";
     $expectedmessage .= "to grouping with name \"rlipname\".\n";
     $this->assert_data_produces_error($data, $expectedmessage, 'enrolment');
     $DB->delete_records('user_enrolments');
     $DB->delete_records('groups_members');
     // Email, idnumber.
     $data = $basedata;
     $data['email'] = 'rlipuser@rlipdomain.com';
     $data['idnumber'] = 'rlipidnumber';
     $expectedmessage = "[enrolment.csv line 2] User with email \"rlipuser@rlipdomain.com\", idnumber \"rlipidnumber\" ";
     $expectedmessage .= "enrolled in course with shortname \"rlipshortname\". Assigned user with email ";
     $expectedmessage .= "\"rlipuser@rlipdomain.com\", idnumber \"rlipidnumber\" to group with name \"rlipname\". Group with ";
     $expectedmessage .= "name \"rlipname\" is already assigned to grouping with name \"rlipname\".\n";
     $this->assert_data_produces_error($data, $expectedmessage, 'enrolment');
     $DB->delete_records('user_enrolments');
     $DB->delete_records('groups_members');
     // Username, email, idnumber.
     $data = $basedata;
     $data['username'] = 'rlipusername';
     $data['email'] = 'rlipuser@rlipdomain.com';
     $data['idnumber'] = 'rlipidnumber';
     $expectedmessage = "[enrolment.csv line 2] User with username \"rlipusername\", email \"rlipuser@rlipdomain.com\", ";
     $expectedmessage .= "idnumber \"rlipidnumber\" enrolled in course with shortname \"rlipshortname\". Assigned user with ";
     $expectedmessage .= "username \"rlipusername\", email \"rlipuser@rlipdomain.com\", idnumber \"rlipidnumber\" to group ";
     $expectedmessage .= "with name \"rlipname\". Group with name \"rlipname\" is already assigned to grouping with name ";
     $expectedmessage .= "\"rlipname\".\n";
     $this->assert_data_produces_error($data, $expectedmessage, 'enrolment');
     $DB->delete_records('user_enrolments');
     $DB->delete_records('groups_members');
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:99,代码来源:version1_filesystem_logging_test.php

示例4: print_error

}
if (!($course = get_record('course', 'id', $grouping->courseid))) {
    print_error('invalidcourse');
}
$courseid = $course->id;
require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $courseid);
require_capability('moodle/course:managegroups', $context);
$returnurl = $CFG->wwwroot . '/group/groupings.php?id=' . $courseid;
if ($frm = data_submitted() and confirm_sesskey()) {
    if (isset($frm->cancel)) {
        redirect($returnurl);
    } else {
        if (isset($frm->add) and !empty($frm->addselect)) {
            foreach ($frm->addselect as $groupid) {
                groups_assign_grouping($grouping->id, (int) $groupid);
            }
        } else {
            if (isset($frm->remove) and !empty($frm->removeselect)) {
                foreach ($frm->removeselect as $groupid) {
                    groups_unassign_grouping($grouping->id, (int) $groupid);
                }
            }
        }
    }
}
$currentmembers = array();
$potentialmembers = array();
if ($groups = get_records('groups', 'courseid', $courseid, 'name')) {
    if ($assignment = get_records('groupings_groups', 'groupingid', $grouping->id)) {
        foreach ($assignment as $ass) {
开发者ID:edwinphillips,项目名称:moodle-485cb39,代码行数:31,代码来源:assign.php

示例5: redirect

     redirect($PAGE->url);
 }
 if ($formdata = $mform->get_data()) {
     // Create a new group and add the creator as a member of it
     $params = array($course->id);
     $names = $DB->get_records_sql("SELECT g.name\n                   FROM {groups} g\n                  WHERE g.courseid = ?", $params);
     $max = 0;
     foreach ($names as $n) {
         if (intval($n->name) >= $max) {
             $max = intval($n->name);
         }
     }
     $data = (object) array('name' => strval($max + 1), 'description' => $formdata->description, 'courseid' => $course->id);
     $id = groups_create_group($data, false);
     if ($groupselect->targetgrouping != 0) {
         groups_assign_grouping($groupselect->targetgrouping, $id);
     }
     groups_add_member($id, $USER->id);
     //add_to_log ( $course->id, 'groupselect', 'select', 'view.php?id=' . $cm->id, $groupselect->id, $cm->id );
     if ($formdata->password !== '') {
         $passworddata = (object) array('groupid' => $id, 'password' => password_hash($formdata->password, PASSWORD_DEFAULT), 'instance_id' => $groupselect->id);
         $DB->insert_record('groupselect_passwords', $passworddata, false);
     }
     redirect($PAGE->url);
 } else {
     if ($create) {
         // If create button was clicked, show the form
         echo $OUTPUT->header();
         echo $OUTPUT->heading(get_string('creategroup', 'mod_groupselect'));
         $mform->display();
         echo $OUTPUT->footer();
开发者ID:nwp90,项目名称:moodle-mod_groupselect,代码行数:31,代码来源:view.php

示例6: test_groups_ordering

 /**
  * This unit test checks that groups_get_all_groups returns groups in
  * alphabetical order even if they are in a grouping.
  */
 public function test_groups_ordering()
 {
     $generator = $this->getDataGenerator();
     $this->resetAfterTest();
     // Create a course category and course.
     $cat = $generator->create_category(array('parent' => 0));
     $course = $generator->create_course(array('category' => $cat->id));
     $grouping = $generator->create_grouping(array('courseid' => $course->id, 'name' => 'Grouping'));
     // Create groups in reverse order.
     $group2 = $generator->create_group(array('courseid' => $course->id, 'name' => 'Group 2'));
     $group1 = $generator->create_group(array('courseid' => $course->id, 'name' => 'Group 1'));
     // Assign the groups to the grouping in reverse order.
     $this->assertTrue(groups_assign_grouping($grouping->id, $group2->id));
     $this->assertTrue(groups_assign_grouping($grouping->id, $group1->id));
     // Get all groups and check they are alphabetical.
     $groups = array_values(groups_get_all_groups($course->id, 0));
     $this->assertEquals('Group 1', $groups[0]->name);
     $this->assertEquals('Group 2', $groups[1]->name);
     // Now check the same is true when accessed by grouping.
     $groups = array_values(groups_get_all_groups($course->id, 0, $grouping->id));
     $this->assertEquals('Group 1', $groups[0]->name);
     $this->assertEquals('Group 2', $groups[1]->name);
 }
开发者ID:tyleung,项目名称:CMPUT401MoodleExams,代码行数:27,代码来源:grouplib_test.php

示例7: test_filter_users

 /**
  * Tests the filter_users (bulk checking) function.
  */
 public function test_filter_users()
 {
     global $DB, $CFG;
     $this->resetAfterTest();
     $CFG->enableavailability = true;
     // Erase static cache before test.
     condition::wipe_static_cache();
     // Make a test course and some users.
     $generator = $this->getDataGenerator();
     $course = $generator->create_course();
     $roleids = $DB->get_records_menu('role', null, '', 'shortname, id');
     $teacher = $generator->create_user();
     $generator->enrol_user($teacher->id, $course->id, $roleids['teacher']);
     $allusers = array($teacher->id => $teacher);
     $students = array();
     for ($i = 0; $i < 3; $i++) {
         $student = $generator->create_user();
         $students[$i] = $student;
         $generator->enrol_user($student->id, $course->id, $roleids['student']);
         $allusers[$student->id] = $student;
     }
     $info = new \core_availability\mock_info($course);
     $checker = new \core_availability\capability_checker($info->get_context());
     // Make test groups.
     $group1 = $generator->create_group(array('courseid' => $course->id));
     $group2 = $generator->create_group(array('courseid' => $course->id));
     $grouping1 = $generator->create_grouping(array('courseid' => $course->id));
     $grouping2 = $generator->create_grouping(array('courseid' => $course->id));
     groups_assign_grouping($grouping1->id, $group1->id);
     groups_assign_grouping($grouping2->id, $group2->id);
     // Make page in grouping 2.
     $pagegen = $generator->get_plugin_generator('mod_page');
     $page = $pagegen->create_instance(array('course' => $course->id, 'groupingid' => $grouping2->id, 'availability' => '{"op":"|","show":true,"c":[{"type":"grouping","activity":true}]}'));
     // Assign students to groups as follows (teacher is not in a group):
     // 0: no groups.
     // 1: in group 1/grouping 1.
     // 2: in group 2/grouping 2.
     groups_add_member($group1, $students[1]);
     groups_add_member($group2, $students[2]);
     // Test specific grouping.
     $cond = new condition((object) array('id' => (int) $grouping1->id));
     $result = array_keys($cond->filter_user_list($allusers, false, $info, $checker));
     ksort($result);
     $this->assertEquals(array($teacher->id, $students[1]->id), $result);
     $result = array_keys($cond->filter_user_list($allusers, true, $info, $checker));
     ksort($result);
     $this->assertEquals(array($teacher->id, $students[0]->id, $students[2]->id), $result);
     // Test course-module grouping.
     $modinfo = get_fast_modinfo($course);
     $cm = $modinfo->get_cm($page->cmid);
     $info = new \core_availability\info_module($cm);
     $result = array_keys($info->filter_user_list($allusers, $course));
     $this->assertEquals(array($teacher->id, $students[2]->id), $result);
 }
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:57,代码来源:condition_test.php

示例8: test_get_groupings

 /**
  * Test get_groupings
  */
 public function test_get_groupings()
 {
     global $DB;
     $this->resetAfterTest(true);
     $course = self::getDataGenerator()->create_course();
     $groupingdata = array();
     $groupingdata['courseid'] = $course->id;
     $groupingdata['name'] = 'Grouping Test';
     $groupingdata['description'] = 'Grouping Test description';
     $groupingdata['descriptionformat'] = FORMAT_MOODLE;
     $grouping = self::getDataGenerator()->create_grouping($groupingdata);
     // Set the required capabilities by the external function.
     $context = context_course::instance($course->id);
     $roleid = $this->assignUserCapability('moodle/course:managegroups', $context->id);
     $this->assignUserCapability('moodle/course:view', $context->id, $roleid);
     // Call the external function without specifying the optional parameter.
     $groupings = core_group_external::get_groupings(array($grouping->id));
     // We need to execute the return values cleaning process to simulate the web service server.
     $groupings = external_api::clean_returnvalue(core_group_external::get_groupings_returns(), $groupings);
     $this->assertEquals(1, count($groupings));
     $group1data = array();
     $group1data['courseid'] = $course->id;
     $group1data['name'] = 'Group Test 1';
     $group1data['description'] = 'Group Test 1 description';
     $group1data['descriptionformat'] = FORMAT_MOODLE;
     $group2data = array();
     $group2data['courseid'] = $course->id;
     $group2data['name'] = 'Group Test 2';
     $group2data['description'] = 'Group Test 2 description';
     $group2data['descriptionformat'] = FORMAT_MOODLE;
     $group1 = self::getDataGenerator()->create_group($group1data);
     $group2 = self::getDataGenerator()->create_group($group2data);
     groups_assign_grouping($grouping->id, $group1->id);
     groups_assign_grouping($grouping->id, $group2->id);
     // Call the external function specifying that groups are returned.
     $groupings = core_group_external::get_groupings(array($grouping->id), true);
     // We need to execute the return values cleaning process to simulate the web service server.
     $groupings = external_api::clean_returnvalue(core_group_external::get_groupings_returns(), $groupings);
     $this->assertEquals(1, count($groupings));
     $this->assertEquals(2, count($groupings[0]['groups']));
     foreach ($groupings[0]['groups'] as $group) {
         $dbgroup = $DB->get_record('groups', array('id' => $group['id']), '*', MUST_EXIST);
         $dbgroupinggroups = $DB->get_record('groupings_groups', array('groupingid' => $groupings[0]['id'], 'groupid' => $group['id']), '*', MUST_EXIST);
         switch ($dbgroup->name) {
             case $group1->name:
                 $groupdescription = $group1->description;
                 $groupcourseid = $group1->courseid;
                 break;
             case $group2->name:
                 $groupdescription = $group2->description;
                 $groupcourseid = $group2->courseid;
                 break;
             default:
                 throw new moodle_exception('unknowgroupname');
                 break;
         }
         $this->assertEquals($dbgroup->description, $groupdescription);
         $this->assertEquals($dbgroup->courseid, $groupcourseid);
     }
 }
开发者ID:masaterutakeno,项目名称:MoodleMobile,代码行数:63,代码来源:externallib_test.php

示例9: 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());
    }
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:81,代码来源:modinfolib_test.php

示例10: view_administration


//.........这里部分代码省略.........
                     foreach ($selected as $select) {
                         $params['selected[' . $select . ']'] = $select;
                         $text .= html_writer::tag('li', $groups[$select]->name);
                     }
                     $text .= html_writer::end_tag('ul');
                     $continue = new moodle_url($cancel, $params);
                     echo $this->confirm($text, $continue, $cancel);
                     echo $OUTPUT->footer();
                     die;
                 }
                 break;
             case 'grouping':
                 // Show grouping creation form!
                 $selected = optional_param_array('selected', array(), PARAM_INT);
                 $mform = new \mod_grouptool\groupings_creation_form(null, array('id' => $id, 'selected' => $selected));
                 $groups = $DB->get_records_list('groups', 'id', $selected);
                 if ($mform->is_cancelled()) {
                     $bulkaction = null;
                     $selected = array();
                 } else {
                     if ($fromform = $mform->get_data()) {
                         // Some groupings should be created...
                         if ($fromform->target == -2) {
                             // One new grouping per group!
                             foreach ($groups as $group) {
                                 $grouping = new stdClass();
                                 if (!($grouping->id = groups_get_grouping_by_name($this->course->id, $group->name))) {
                                     $grouping = new stdClass();
                                     $grouping->courseid = $this->course->id;
                                     $grouping->name = $group->name;
                                     $grouping->id = groups_create_grouping($grouping);
                                 }
                                 // Insert group!
                                 groups_assign_grouping($grouping->id, $group->id);
                             }
                         } else {
                             if ($fromform->target == -1) {
                                 // One new grouping!
                                 // Create grouping if it doesn't exist...
                                 $grouping = new stdClass();
                                 if (!($grouping->id = groups_get_grouping_by_name($this->course->id, $fromform->name))) {
                                     $grouping = new stdClass();
                                     $grouping->courseid = $this->course->id;
                                     $grouping->name = trim($fromform->name);
                                     $grouping->id = groups_create_grouping($grouping);
                                 }
                                 // Insert groups!
                                 foreach ($groups as $group) {
                                     groups_assign_grouping($grouping->id, $group->id);
                                 }
                             } else {
                                 if ($fromform->target > 0) {
                                     // Existing Grouping!
                                     $grouping = groups_get_grouping($fromform->target);
                                     if ($grouping) {
                                         foreach ($groups as $group) {
                                             groups_assign_grouping($grouping->id, $group->id);
                                         }
                                     }
                                 }
                             }
                         }
                         // ...redirect to show sortlist again!
                         $url = new moodle_url('/mod/grouptool/view.php', array('id' => $this->cm->id, 'tab' => 'group_admin', 'filter' => $filter));
                         $text = $OUTPUT->notification(get_string('groupings_created_and_groups_added', 'grouptool'), 'notifymessage');
                         echo $this->confirm($text, $url);
开发者ID:rimacher,项目名称:moodle-mod_grouptool,代码行数:67,代码来源:locallib.php

示例11: cluster_groups_update_grouping_closure

/**
 * Updates all parent cluster's groupings with the existence of a group for this cluster
 *
 * @param    int      $clusterid         The cluster to check the parents for
 * @param    boolean  $include_children  If true, make child cluster-groups trickle up the tree
 * @return   boolean                     Returns true to satisfy event handlers
 */
function cluster_groups_update_grouping_closure($clusterid, $include_children = false)
{
    global $CFG, $CURMAN;
    if (empty($CFG->enablegroupings) || empty($CURMAN->config->cluster_groupings) || !cluster_groups_grouping_allowed($clusterid)) {
        return true;
    }
    $cluster = new cluster($clusterid);
    //get the group id for this cluster
    if ($groupid = groups_get_group_by_name(SITEID, $cluster->name)) {
        //go through the chain of parent clusters
        while (!empty($cluster->parent)) {
            $cluster = new cluster($cluster->parent);
            //add this to grouping if applicable
            $grouping = groups_get_grouping_by_name(SITEID, $cluster->name);
            if ($grouping = groups_get_grouping($grouping)) {
                groups_assign_grouping($grouping->id, $groupid);
                //recurse into children if possible
                if ($include_children) {
                    //get all child clusters
                    $child_cluster_ids = cluster_groups_get_child_clusters($cluster->id);
                    foreach ($child_cluster_ids as $child_cluster_id) {
                        //children only
                        if ($child_cluster_id != $cluster->id) {
                            $child_cluster = new cluster($child_cluster_id);
                            //make sure the group exists
                            if ($child_groupid = groups_get_group_by_name(SITEID, $child_cluster->name) and cluster_groups_cluster_allows_groups($child_cluster->id)) {
                                groups_assign_grouping($grouping->id, $child_groupid);
                            }
                        }
                    }
                }
            }
        }
    }
    return true;
}
开发者ID:remotelearner,项目名称:elis.cm,代码行数:43,代码来源:lib.php

示例12: create_groups

 /**
  * This function creates the groups for testing.  We enroll the last users first, rather than
  * the ones at the start.  This way I can use user0 for testing.
  *
  */
 protected function create_groups()
 {
     for ($i = 0; $i < self::NUMBEROFGROUPS; $i++) {
         $group = $this->getDataGenerator()->create_group(array('courseid' => $this->courseid));
         groups_assign_grouping($this->groupingid, $group->id);
         $this->groupids[] = $group->id;
         groups_add_member($group->id, $this->users[self::NUMBEROFUSERS - 2 * $i - 1]->id);
         groups_add_member($group->id, $this->users[self::NUMBEROFUSERS - 2 * $i - 2]->id);
     }
 }
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:15,代码来源:skillsgroupunittest.php

示例13: foreach

            $grouping = $grouping->id;
        }
    }
    foreach ($teams as $k => $teamstr) {
        $name = $team_names[$k];
        $team = explode(",", $teamstr);
        $oname = !$nogrouping && $inherit_grouping_name ? "{$grouping_name} {$name}" : $name;
        $groupdata = new stdClass();
        $groupdata->courseid = $course->id;
        $groupdata->name = $oname;
        $group = groups_create_group($groupdata);
        foreach ($team as $user) {
            groups_add_member($group, $user);
        }
        if (!$nogrouping) {
            groups_assign_grouping($grouping, $group);
        }
    }
    $feedback = "Your groups were successfully created.";
} else {
    if ($teambuilder->groupid) {
        $group = $teambuilder->groupid;
    } else {
        $group = '';
    }
    $students = get_enrolled_users($ctxt, 'mod/teambuilder:respond', $group, 'u.id,u.firstname,u.lastname');
    $responses = teambuilder_get_responses($teambuilder->id);
    $questions = teambuilder_get_questions($teambuilder->id);
    echo '<script type="text/javascript">';
    echo 'var students = ' . json_encode($students) . ';';
    echo 'var responses = ' . json_encode($responses) . ';';
开发者ID:netspotau,项目名称:moodle-mod_teambuilder,代码行数:31,代码来源:build.php

示例14: test_unique_sql_parameter_behaviour

 /**
  * Tests the behaviour of the counter in unique_sql_parameter().
  *
  * There was a problem with static counters used to implement a sequence of
  * parameter placeholders (MDL-53481). As always with static variables, it
  * is a bit tricky to unit test the behaviour reliably as it depends on the
  * actual tests executed and also their order.
  *
  * To minimise risk of false expected behaviour, this test method should be
  * first one where {@link core_availability\tree::get_user_list_sql()} is
  * used. We also use higher number of condition instances to increase the
  * risk of the counter collision, should there remain a problem.
  */
 public function test_unique_sql_parameter_behaviour()
 {
     global $DB;
     $this->resetAfterTest();
     $generator = $this->getDataGenerator();
     // Create a test course with multiple groupings and groups and a student in each of them.
     $course = $generator->create_course();
     $user = $generator->create_user();
     $studentroleid = $DB->get_field('role', 'id', array('shortname' => 'student'));
     $generator->enrol_user($user->id, $course->id, $studentroleid);
     // The total number of groupings and groups must not be greater than 61.
     // There is a limit in MySQL on the max number of joined tables.
     $groups = [];
     for ($i = 0; $i < 25; $i++) {
         $group = $generator->create_group(array('courseid' => $course->id));
         groups_add_member($group, $user);
         $groups[] = $group;
     }
     $groupings = [];
     for ($i = 0; $i < 25; $i++) {
         $groupings[] = $generator->create_grouping(array('courseid' => $course->id));
     }
     foreach ($groupings as $grouping) {
         foreach ($groups as $group) {
             groups_assign_grouping($grouping->id, $group->id);
         }
     }
     $info = new \core_availability\mock_info($course);
     // Make a huge tree with 'AND' of all groups and groupings conditions.
     $conditions = [];
     foreach ($groups as $group) {
         $conditions[] = \availability_group\condition::get_json($group->id);
     }
     foreach ($groupings as $groupingid) {
         $conditions[] = \availability_grouping\condition::get_json($grouping->id);
     }
     shuffle($conditions);
     $tree = new tree(tree::get_root_json($conditions));
     list($sql, $params) = $tree->get_user_list_sql(false, $info, false);
     // This must not throw exception.
     $DB->fix_sql_params($sql, $params);
 }
开发者ID:EsdrasCaleb,项目名称:moodle,代码行数:55,代码来源:tree_test.php

示例15: test_version1importpreventsduplicategroupgroupingassignments

 /**
  * Validate that the import prevents assigning a user to the same grouping
  * twice
  */
 public function test_version1importpreventsduplicategroupgroupingassignments()
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/group/lib.php';
     // Set up the "pre-existing" group.
     $groupid = $this->create_test_group(self::$courseid);
     // Set up the "pre-existing" grouping.
     $groupingid = $this->create_test_grouping(self::$courseid);
     // Assign the group to the grouping.
     groups_assign_grouping($groupingid, $groupid);
     // Validate setup.
     $this->assertEquals($DB->count_records('groupings_groups'), 1);
     // Run the import.
     $data = $this->get_core_enrolment_data();
     $data['group'] = 'rlipgroup';
     $data['grouping'] = 'rlipgrouping';
     $this->run_core_enrolment_import($data, false);
     // Compare data.
     $this->assertEquals($DB->count_records('groupings_groups'), 1);
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:24,代码来源:version1_enrolment_import_test.php


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