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


PHP groups_get_group_by_idnumber函数代码示例

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


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

示例1: test_groups_get_group_by_idnumber

 public function test_groups_get_group_by_idnumber()
 {
     $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));
     $idnumber1 = 'idnumber1';
     $idnumber2 = 'idnumber2';
     /*
      * Test with an empty and a null idnumber.
      */
     // An empty idnumber should always return a false value.
     $this->assertFalse(groups_get_group_by_idnumber($course->id, ''));
     $this->assertFalse(groups_get_group_by_idnumber($course->id, null));
     // Even when a group exists which also has an empty idnumber.
     $generator->create_group(array('courseid' => $course->id));
     $this->assertFalse(groups_get_group_by_idnumber($course->id, ''));
     $this->assertFalse(groups_get_group_by_idnumber($course->id, null));
     /*
      * Test with a valid idnumber.
      */
     // There is no matching idnumber at present.
     $this->assertFalse(groups_get_group_by_idnumber($course->id, $idnumber1));
     // We should now have a valid group returned by the idnumber search.
     $group = $generator->create_group(array('courseid' => $course->id, 'idnumber' => $idnumber1));
     $this->assertEquals($group, groups_get_group_by_idnumber($course->id, $idnumber1));
     // An empty idnumber should still return false.
     $this->assertFalse(groups_get_group_by_idnumber($course->id, ''));
     $this->assertFalse(groups_get_group_by_idnumber($course->id, null));
     /*
      * Test with another idnumber.
      */
     // There is no matching idnumber at present.
     $this->assertFalse(groups_get_group_by_idnumber($course->id, $idnumber2));
     // We should now have a valid group returned by the idnumber search.
     $group = $generator->create_group(array('courseid' => $course->id, 'idnumber' => $idnumber2));
     $this->assertEquals($group, groups_get_group_by_idnumber($course->id, $idnumber2));
     /*
      * 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 idnumber should always return a false value.
     $this->assertFalse(groups_get_group_by_idnumber($course->id, ''));
     $this->assertFalse(groups_get_group_by_idnumber($course->id, null));
     // Our existing idnumbers shouldn't be returned here as we're in a different course.
     $this->assertFalse(groups_get_group_by_idnumber($course->id, $idnumber1));
     $this->assertFalse(groups_get_group_by_idnumber($course->id, $idnumber2));
     // We should be able to reuse the idnumbers again since this is a different course.
     $group = $generator->create_group(array('courseid' => $course->id, 'idnumber' => $idnumber1));
     $this->assertEquals($group, groups_get_group_by_idnumber($course->id, $idnumber1));
     $group = $generator->create_group(array('courseid' => $course->id, 'idnumber' => $idnumber2));
     $this->assertEquals($group, groups_get_group_by_idnumber($course->id, $idnumber2));
 }
开发者ID:eamador,项目名称:moodle-course-custom-fields,代码行数:56,代码来源:grouplib_test.php

示例2: process_group

 public function process_group($data)
 {
     global $DB;
     $data = (object) $data;
     // handy
     $data->courseid = $this->get_courseid();
     // Only allow the idnumber to be set if the user has permission and the idnumber is not already in use by
     // another a group in the same course
     $context = context_course::instance($data->courseid);
     if (isset($data->idnumber) and has_capability('moodle/course:changeidnumber', $context, $this->task->get_userid())) {
         if (groups_get_group_by_idnumber($data->courseid, $data->idnumber)) {
             unset($data->idnumber);
         }
     } else {
         unset($data->idnumber);
     }
     $oldid = $data->id;
     // need this saved for later
     $restorefiles = false;
     // Only if we end creating the group
     // Search if the group already exists (by name & description) in the target course
     $description_clause = '';
     $params = array('courseid' => $this->get_courseid(), 'grname' => $data->name);
     if (!empty($data->description)) {
         $description_clause = ' AND ' . $DB->sql_compare_text('description') . ' = ' . $DB->sql_compare_text(':description');
         $params['description'] = $data->description;
     }
     if (!($groupdb = $DB->get_record_sql("SELECT *\n                                               FROM {groups}\n                                              WHERE courseid = :courseid\n                                                AND name = :grname {$description_clause}", $params))) {
         // group doesn't exist, create
         $newitemid = $DB->insert_record('groups', $data);
         $restorefiles = true;
         // We'll restore the files
     } else {
         // group exists, use it
         $newitemid = $groupdb->id;
     }
     // Save the id mapping
     $this->set_mapping('group', $oldid, $newitemid, $restorefiles);
     // Invalidate the course group data cache just in case.
     cache_helper::invalidate_by_definition('core', 'groupdata', array(), array($data->courseid));
 }
开发者ID:Jinelle,项目名称:moodle,代码行数:41,代码来源:restore_stepslib.php

示例3: trim

 //if courseid is set
 if (isset($newgroup->courseid)) {
     $linenum++;
     $groupname = $newgroup->name;
     $newgrpcoursecontext = context_course::instance($newgroup->courseid);
     ///Users cannot upload groups in courses they cannot update.
     if (!has_capability('moodle/course:managegroups', $newgrpcoursecontext) or !is_enrolled($newgrpcoursecontext) and !has_capability('moodle/course:view', $newgrpcoursecontext)) {
         echo $OUTPUT->notification(get_string('nopermissionforcreation', 'group', $groupname));
     } else {
         if (isset($newgroup->groupidnumber)) {
             // The CSV field for the group idnumber is groupidnumber rather than
             // idnumber as that field is already in use for the course idnumber.
             $newgroup->groupidnumber = trim($newgroup->groupidnumber);
             if (has_capability('moodle/course:changeidnumber', $newgrpcoursecontext)) {
                 $newgroup->idnumber = $newgroup->groupidnumber;
                 if ($existing = groups_get_group_by_idnumber($newgroup->courseid, $newgroup->idnumber)) {
                     // idnumbers must be unique to a course but we shouldn't ignore group creation for duplicates
                     $existing->name = s($existing->name);
                     $existing->idnumber = s($existing->idnumber);
                     $existing->problemgroup = $groupname;
                     echo $OUTPUT->notification(get_string('groupexistforcoursewithidnumber', 'error', $existing));
                     unset($newgroup->idnumber);
                 }
             }
             // Always drop the groupidnumber key. It's not a valid database field
             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)) {
开发者ID:evltuma,项目名称:moodle,代码行数:31,代码来源:import.php

示例4: groups_update_group

/**
 * Update group
 *
 * @param stdClass $data group properties (with magic quotes)
 * @param stdClass $editform
 * @param array $editoroptions
 * @return bool true or exception
 */
function groups_update_group($data, $editform = false, $editoroptions = false)
{
    global $CFG, $DB;
    $context = context_course::instance($data->courseid);
    $data->timemodified = time();
    $data->name = trim($data->name);
    if (isset($data->idnumber)) {
        $data->idnumber = trim($data->idnumber);
        if (($existing = groups_get_group_by_idnumber($data->courseid, $data->idnumber)) && $existing->id != $data->id) {
            throw new moodle_exception('idnumbertaken');
        }
    }
    if ($editform and $editoroptions) {
        $data = file_postupdate_standard_editor($data, 'description', $editoroptions, $context, 'group', 'description', $data->id);
    }
    $DB->update_record('groups', $data);
    // Invalidate the group data.
    cache_helper::invalidate_by_definition('core', 'groupdata', array(), array($data->courseid));
    $group = $DB->get_record('groups', array('id' => $data->id));
    if ($editform) {
        groups_update_group_icon($group, $data, $editform);
    }
    //trigger groups events
    events_trigger('groups_group_updated', $group);
    return true;
}
开发者ID:masaterutakeno,项目名称:MoodleMobile,代码行数:34,代码来源:lib.php

示例5: validation

 /**
  * Form validation
  *
  * @param array $data
  * @param array $files
  * @return array $errors An array of errors
  */
 function validation($data, $files)
 {
     global $COURSE, $DB, $CFG;
     $errors = parent::validation($data, $files);
     $name = trim($data['name']);
     if (isset($data['idnumber'])) {
         $idnumber = trim($data['idnumber']);
     } else {
         $idnumber = '';
     }
     if ($data['id'] and $group = $DB->get_record('groups', array('id' => $data['id']))) {
         if (textlib::strtolower($group->name) != textlib::strtolower($name)) {
             if (groups_get_group_by_name($COURSE->id, $name)) {
                 $errors['name'] = get_string('groupnameexists', 'group', $name);
             }
         }
         if (!empty($idnumber) && $group->idnumber != $idnumber) {
             if (groups_get_group_by_idnumber($COURSE->id, $idnumber)) {
                 $errors['idnumber'] = get_string('idnumbertaken');
             }
         }
         if (!empty($CFG->groupenrolmentkeypolicy) and $data['enrolmentkey'] != '' and $group->enrolmentkey !== $data['enrolmentkey']) {
             // enforce password policy only if changing password
             $errmsg = '';
             if (!check_password_policy($data['enrolmentkey'], $errmsg)) {
                 $errors['enrolmentkey'] = $errmsg;
             }
         }
     } else {
         if (groups_get_group_by_name($COURSE->id, $name)) {
             $errors['name'] = get_string('groupnameexists', 'group', $name);
         } else {
             if (!empty($idnumber) && groups_get_group_by_idnumber($COURSE->id, $idnumber)) {
                 $errors['idnumber'] = get_string('idnumbertaken');
             }
         }
     }
     return $errors;
 }
开发者ID:JP-Git,项目名称:moodle,代码行数:46,代码来源:group_form.php

示例6: validation

 /**
  * Form validation
  *
  * @param array $data
  * @param array $files
  * @return array $errors An array of errors
  */
 function validation($data, $files)
 {
     global $COURSE, $DB, $CFG;
     $errors = parent::validation($data, $files);
     $name = trim($data['name']);
     if (isset($data['idnumber'])) {
         $idnumber = trim($data['idnumber']);
     } else {
         $idnumber = '';
     }
     if ($data['id'] and $group = $DB->get_record('groups', array('id' => $data['id']))) {
         if (core_text::strtolower($group->name) != core_text::strtolower($name)) {
             if (groups_get_group_by_name($COURSE->id, $name)) {
                 $errors['name'] = get_string('groupnameexists', 'group', $name);
             }
         }
         if (!empty($idnumber) && $group->idnumber != $idnumber) {
             if (groups_get_group_by_idnumber($COURSE->id, $idnumber)) {
                 $errors['idnumber'] = get_string('idnumbertaken');
             }
         }
         if ($data['enrolmentkey'] != '') {
             $errmsg = '';
             if (!empty($CFG->groupenrolmentkeypolicy) && $group->enrolmentkey !== $data['enrolmentkey'] && !check_password_policy($data['enrolmentkey'], $errmsg)) {
                 // Enforce password policy when the password is changed.
                 $errors['enrolmentkey'] = $errmsg;
             } else {
                 // Prevent twice the same enrolment key in course groups.
                 $sql = "SELECT id FROM {groups} WHERE id <> :groupid AND courseid = :courseid AND enrolmentkey = :key";
                 $params = array('groupid' => $data['id'], 'courseid' => $COURSE->id, 'key' => $data['enrolmentkey']);
                 if ($DB->record_exists_sql($sql, $params)) {
                     $errors['enrolmentkey'] = get_string('enrolmentkeyalreadyinuse', 'group');
                 }
             }
         }
     } else {
         if (groups_get_group_by_name($COURSE->id, $name)) {
             $errors['name'] = get_string('groupnameexists', 'group', $name);
         } else {
             if (!empty($idnumber) && groups_get_group_by_idnumber($COURSE->id, $idnumber)) {
                 $errors['idnumber'] = get_string('idnumbertaken');
             } else {
                 if ($data['enrolmentkey'] != '') {
                     $errmsg = '';
                     if (!empty($CFG->groupenrolmentkeypolicy) && !check_password_policy($data['enrolmentkey'], $errmsg)) {
                         // Enforce password policy.
                         $errors['enrolmentkey'] = $errmsg;
                     } else {
                         if ($DB->record_exists('groups', array('courseid' => $COURSE->id, 'enrolmentkey' => $data['enrolmentkey']))) {
                             // Prevent the same enrolment key from being used multiple times in course groups.
                             $errors['enrolmentkey'] = get_string('enrolmentkeyalreadyinuse', 'group');
                         }
                     }
                 }
             }
         }
     }
     return $errors;
 }
开发者ID:edmiranda,项目名称:group,代码行数:66,代码来源:group_form.php


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