本文整理汇总了PHP中groups_get_grouping_by_name函数的典型用法代码示例。如果您正苦于以下问题:PHP groups_get_grouping_by_name函数的具体用法?PHP groups_get_grouping_by_name怎么用?PHP groups_get_grouping_by_name使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了groups_get_grouping_by_name函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validation
/**
* Form validation
*
* @param array $data
* @param array $files
* @return array $errors An array of validataion errors for the form.
*/
function validation($data, $files)
{
global $COURSE, $DB;
$errors = parent::validation($data, $files);
$name = trim($data['name']);
if ($data['id'] and $grouping = $DB->get_record('groupings', array('id' => $data['id']))) {
if (textlib::strtolower($grouping->name) != textlib::strtolower($name)) {
if (groups_get_grouping_by_name($COURSE->id, $name)) {
$errors['name'] = get_string('groupingnameexists', 'group', $name);
}
}
} else {
if (groups_get_grouping_by_name($COURSE->id, $name)) {
$errors['name'] = get_string('groupingnameexists', 'group', $name);
}
}
return $errors;
}
示例2: validation
function validation($data)
{
global $COURSE;
$errors = array();
$name = stripslashes($data['name']);
if ($data['id'] and $grouping = get_record('groupings', 'id', $data['id'])) {
if ($grouping->name != $name) {
if (groups_get_grouping_by_name($COURSE->id, $name)) {
$errors['name'] = get_string('groupingnameexists', 'group', $name);
}
}
} else {
if (groups_get_grouping_by_name($COURSE->id, $name)) {
$errors['name'] = get_string('groupingnameexists', 'group', $name);
}
}
if (count($errors) > 0) {
return $errors;
} else {
return true;
}
}
示例3: validation
/**
* Form validation
*
* @param array $data
* @param array $files
* @return array $errors An array of validataion errors for the form.
*/
function validation($data, $files)
{
global $COURSE, $DB;
$errors = parent::validation($data, $files);
$name = trim($data['name']);
if (isset($data['idnumber'])) {
$idnumber = trim($data['idnumber']);
} else {
$idnumber = '';
}
if ($data['id'] and $grouping = $DB->get_record('groupings', array('id' => $data['id']))) {
if (core_text::strtolower($grouping->name) != core_text::strtolower($name)) {
if (groups_get_grouping_by_name($COURSE->id, $name)) {
$errors['name'] = get_string('groupingnameexists', 'group', $name);
}
}
if (!empty($idnumber) && $grouping->idnumber != $idnumber) {
if (groups_get_grouping_by_idnumber($COURSE->id, $idnumber)) {
$errors['idnumber'] = get_string('idnumbertaken');
}
}
} else {
if (groups_get_grouping_by_name($COURSE->id, $name)) {
$errors['name'] = get_string('groupingnameexists', 'group', $name);
} else {
if (!empty($idnumber) && groups_get_grouping_by_idnumber($COURSE->id, $idnumber)) {
$errors['idnumber'] = get_string('idnumbertaken');
}
}
}
return $errors;
}
示例4: unset
unset($newgroup->groupidnumber);
}
if ($groupid = groups_get_group_by_name($newgroup->courseid, $groupname)) {
echo $OUTPUT->notification("{$groupname} :" . get_string('groupexistforcourse', 'error', $groupname));
} else {
if ($groupid = groups_create_group($newgroup)) {
echo $OUTPUT->notification(get_string('groupaddedsuccesfully', 'group', $groupname), 'notifysuccess');
} else {
echo $OUTPUT->notification(get_string('groupnotaddederror', 'error', $groupname));
continue;
}
}
// Add group to grouping
if (!empty($newgroup->groupingname) || is_numeric($newgroup->groupingname)) {
$groupingname = $newgroup->groupingname;
if (!($groupingid = groups_get_grouping_by_name($newgroup->courseid, $groupingname))) {
$data = new stdClass();
$data->courseid = $newgroup->courseid;
$data->name = $groupingname;
if ($groupingid = groups_create_grouping($data)) {
echo $OUTPUT->notification(get_string('groupingaddedsuccesfully', 'group', $groupingname), 'notifysuccess');
} else {
echo $OUTPUT->notification(get_string('groupingnotaddederror', 'error', $groupingname));
continue;
}
}
// if we have reached here we definitely have a groupingid
$a = array('groupname' => $groupname, 'groupingname' => $groupingname);
try {
groups_assign_grouping($groupingid, $groupid);
echo $OUTPUT->notification(get_string('groupaddedtogroupingsuccesfully', 'group', $a), 'notifysuccess');
示例5: validation
function validation($data, $files)
{
global $CFG, $COURSE;
$errors = parent::validation($data, $files);
if ($data['allocateby'] != 'no') {
if (!($users = groups_get_potential_members($data['courseid'], $data['roleid']))) {
$errors['roleid'] = get_string('nousersinrole', 'group');
}
/// Check the number entered is sane
if ($data['groupby'] == 'groups') {
$usercnt = count($users);
if ($data['number'] > $usercnt || $data['number'] < 1) {
$errors['number'] = get_string('toomanygroups', 'group', $usercnt);
}
}
}
//try to detect group name duplicates
$name = groups_parse_name(stripslashes(trim($data['namingscheme'])), 0);
if (groups_get_group_by_name($COURSE->id, $name)) {
$errors['namingscheme'] = get_string('groupnameexists', 'group', $name);
}
// check grouping name duplicates
if (isset($data['grouping']) && $data['grouping'] == '-1') {
$name = trim(stripslashes($data['groupingname']));
if (empty($name)) {
$errors['groupingname'] = get_string('required');
} else {
if (groups_get_grouping_by_name($COURSE->id, $name)) {
$errors['groupingname'] = get_string('groupingnameexists', 'group', $name);
}
}
}
/// Check the naming scheme
$matchcnt = preg_match_all('/[#@]{1,1}/', $data['namingscheme'], $matches);
if ($matchcnt != 1) {
$errors['namingscheme'] = get_string('badnamingscheme', 'group');
}
return $errors;
}
示例6: validate_end_result
/**
* Validate that our constant expect end result is reached
*/
private function validate_end_result()
{
global $CFG, $DB;
require_once $CFG->dirroot . '/lib/grouplib.php';
// Validate group creation.
$groupid = groups_get_group_by_name(SITEID, 'testusersetname');
$this->assertNotEquals(false, $groupid);
// Validate user-group assignment.
$userid = $DB->get_field('user', 'id', array('username' => 'testuserusername'));
$this->assertTrue(groups_is_member($groupid, $userid));
// Validate grouping creation.
$groupingid = groups_get_grouping_by_name(SITEID, 'testusersetname');
$this->assertNotEquals(false, $groupingid);
// Validate group-grouping assignment.
$this->assertTrue($DB->record_exists('groupings_groups', array('groupingid' => $groupingid, 'groupid' => $groupid)));
}
示例7: mass_enroll_grouping_exists
/**
* @param string $name group name
* @param int $courseid course
* @return string or false
*/
function mass_enroll_grouping_exists($name, $courseid) {
return groups_get_grouping_by_name($courseid, $name);
}
示例8: validation
/**
* Validation for administration-form
* If there are errors return array of errors ("fieldname"=>"error message"),
* otherwise true if ok.
*
* @param array $data array of ("fieldname"=>value) of submitted data
* @param array $files array of uploaded files "element_name"=>tmp_file_path
* @return array of "element_name"=>"error_description" if there are errors,
* or an empty array if everything is OK.
*/
public function validation($data, $files)
{
global $DB;
$parenterrors = parent::validation($data, $files);
$errors = array();
if ($data['target'] == -1 && empty($data['name'])) {
$errors['name'] = get_string('required');
}
if ($data['target'] == -1 && groups_get_grouping_by_name($data['courseid'], $data['name'])) {
$errors['name'] = get_string('groupingnameexists', 'group', $data['name']);
}
return array_merge($parenterrors, $errors);
}
示例9: test_groups_get_grouping
public function test_groups_get_grouping()
{
$this->resetAfterTest(true);
$generator = $this->getDataGenerator();
// Create a course category and course.
$cat = $generator->create_category(array('parent' => 0));
$course = $generator->create_course(array('category' => $cat->id));
$name1 = 'Grouping 1';
$name2 = 'Grouping 2';
// Test with an empty and a null idnumber.
$this->assertFalse(groups_get_grouping_by_name($course->id, ''));
$this->assertFalse(groups_get_grouping_by_name($course->id, null));
// Even when a group exists.
$generator->create_group(array('courseid' => $course->id));
$this->assertFalse(groups_get_grouping_by_name($course->id, ''));
$this->assertFalse(groups_get_grouping_by_name($course->id, null));
// Test with a valid name, but one that doesn't exist yet.
$this->assertFalse(groups_get_grouping_by_name($course->id, $name1));
$this->assertFalse(groups_get_grouping_by_name($course->id, $name2));
// We should now have a valid group returned by the name search.
$group1 = $generator->create_grouping(array('courseid' => $course->id, 'name' => $name1));
$this->assertEquals($group1->id, groups_get_grouping_by_name($course->id, $name1));
$this->assertFalse(groups_get_grouping_by_name($course->id, $name2));
// We should now have a two valid groups returned by the name search.
$group2 = $generator->create_grouping(array('courseid' => $course->id, 'name' => $name2));
$this->assertEquals($group1->id, groups_get_grouping_by_name($course->id, $name1));
$this->assertEquals($group2->id, groups_get_grouping_by_name($course->id, $name2));
// Delete a group.
$this->assertTrue(groups_delete_grouping($group1));
$this->assertFalse(groups_get_grouping_by_name($course->id, $name1));
$this->assertEquals($group2->id, groups_get_grouping_by_name($course->id, $name2));
/*
* Group idnumbers are unique within a course so test that we don't
* retrieve groups for the first course.
*/
// Create a second course.
$course = $generator->create_course(array('category' => $cat->id));
// An empty name should always return a false value.
$this->assertFalse(groups_get_grouping_by_name($course->id, ''));
$this->assertFalse(groups_get_grouping_by_name($course->id, null));
// Our existing names shouldn't be returned here as we're in a different course.
$this->assertFalse(groups_get_grouping_by_name($course->id, $name1));
$this->assertFalse(groups_get_grouping_by_name($course->id, $name2));
// We should be able to reuse the idnumbers again since this is a different course.
$group1 = $generator->create_grouping(array('courseid' => $course->id, 'name' => $name1));
$this->assertEquals($group1->id, groups_get_grouping_by_name($course->id, $name1));
$group2 = $generator->create_grouping(array('courseid' => $course->id, 'name' => $name2));
$this->assertEquals($group2->id, groups_get_grouping_by_name($course->id, $name2));
}
示例10: validation
/**
* Performs validation of the form information
*
* @param array $data
* @param array $files
* @return array $errors An array of $errors
*/
function validation($data, $files) {
global $CFG, $COURSE;
$errors = parent::validation($data, $files);
if ($data['allocateby'] != 'no') {
$source = array();
if ($data['cohortid']) {
$source['cohortid'] = $data['cohortid'];
}
if ($data['groupingid']) {
$source['groupingid'] = $data['groupingid'];
}
if ($data['groupid']) {
$source['groupid'] = $data['groupid'];
}
if (!$users = groups_get_potential_members($data['courseid'], $data['roleid'], $source)) {
$errors['roleid'] = get_string('nousersinrole', 'group');
}
/// Check the number entered is sane
if ($data['groupby'] == 'groups') {
$usercnt = count($users);
if ($data['number'] > $usercnt || $data['number'] < 1) {
$errors['number'] = get_string('toomanygroups', 'group', $usercnt);
}
}
}
//try to detect group name duplicates
$name = groups_parse_name(trim($data['namingscheme']), 0);
if (groups_get_group_by_name($COURSE->id, $name)) {
$errors['namingscheme'] = get_string('groupnameexists', 'group', $name);
}
// check grouping name duplicates
if ( isset($data['grouping']) && $data['grouping'] == '-1') {
$name = trim($data['groupingname']);
if (empty($name)) {
$errors['groupingname'] = get_string('required');
} else if (groups_get_grouping_by_name($COURSE->id, $name)) {
$errors['groupingname'] = get_string('groupingnameexists', 'group', $name);
}
}
/// Check the naming scheme
if ($data['groupby'] == 'groups' and $data['number'] == 1) {
// we can use the name as is because there will be only one group max
} else {
$matchcnt = preg_match_all('/[#@]{1,1}/', $data['namingscheme'], $matches);
if ($matchcnt != 1) {
$errors['namingscheme'] = get_string('badnamingscheme', 'group');
}
}
return $errors;
}
示例11: userset_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 userset_groups_update_grouping_closure($clusterid, $include_children = false)
{
global $CFG;
$enabled = get_config('elisprogram_usetgroups', 'userset_groupings');
if (empty($enabled) || !userset_groups_grouping_allowed($clusterid)) {
return true;
}
$cluster = new userset($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 userset($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 = userset_groups_get_child_usersets($cluster->id);
foreach ($child_cluster_ids as $child_cluster_id) {
//children only
if ($child_cluster_id != $cluster->id) {
$child_cluster = new userset($child_cluster_id);
//make sure the group exists
if ($child_groupid = groups_get_group_by_name(SITEID, $child_cluster->name) and userset_groups_userset_allows_groups($child_cluster->id)) {
groups_assign_grouping($grouping->id, $child_groupid);
}
}
}
}
}
}
}
return true;
}
示例12: view_administration
//.........这里部分代码省略.........
$continue = new moodle_url($PAGE->url, array('tab' => 'group_admin'));
echo $this->confirm('', $continue);
} else {
$cancel = new moodle_url($PAGE->url, array('tab' => 'group_admin'));
$params = array('confirm' => 1, 'bulkaction' => 'delete', 'start_bulkaction' => 1);
$text = get_string('confirm_delete', 'grouptool') . html_writer::start_tag('ul');
$groups = $DB->get_records_list('groups', 'id', $selected);
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);
}
}
示例13: 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;
}
示例14: blended_create_unique_grouping
function blended_create_unique_grouping($grouping_name, $course)
{
$data = new stdClass();
if ($grouping_name == '') {
$grouping_name = get_string('newgrouping', 'group');
}
$data->name = $grouping_name;
$data->courseid = $course->id;
$data->description_editor['text'] = ' ';
$data->description_editor['format'] = 1;
// Check existence of grouping name
$count = 1;
do {
$prev_grouping = groups_get_grouping_by_name($course->id, $data->name);
if ($prev_grouping !== 0) {
$data->name = $grouping_name . " ({$count})";
} else {
$data->name = $grouping_name;
}
$count++;
} while ($prev_grouping);
$groupingid = groups_create_grouping($data);
return $groupingid;
}
示例15: enrolment_create
//.........这里部分代码省略.........
$count = $DB->count_records('groups', array('name' => $record->group, 'courseid' => $context->instanceid));
$creategroups = get_config('dhimport_version1', 'creategroupsandgroupings');
if ($count > 1) {
//ambiguous
$identifier = $this->mappings['group'];
$this->fslogger->log_failure("{$identifier} value of \"{$record->group}\" refers to multiple " . "groups 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['group'];
$this->fslogger->log_failure("{$identifier} value of \"{$record->group}\" does not refer to " . "a valid group in course with shortname \"{$record->instance}\".", 0, $filename, $this->linenumber, $record, "enrolment");
return false;
} else {
//exact group exists
$groupid = groups_get_group_by_name($context->instanceid, $record->group);
}
}
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');