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


PHP groups_get_grouping_by_idnumber函数代码示例

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


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

示例1: process_grouping

 public function process_grouping($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 grouping 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_grouping_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 grouping
     // Search if the grouping 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 (!($groupingdb = $DB->get_record_sql("SELECT *\n                                                  FROM {groupings}\n                                                 WHERE courseid = :courseid\n                                                   AND name = :grname {$description_clause}", $params))) {
         // grouping doesn't exist, create
         $newitemid = $DB->insert_record('groupings', $data);
         $restorefiles = true;
         // We'll restore the files
     } else {
         // grouping exists, use it
         $newitemid = $groupingdb->id;
     }
     // Save the id mapping
     $this->set_mapping('grouping', $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

示例2: 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;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:39,代码来源:grouping_form.php

示例3: groups_update_grouping

/**
 * Update grouping
 *
 * @param stdClass $data grouping properties (with magic quotes)
 * @param array $editoroptions
 * @return bool true or exception
 */
function groups_update_grouping($data, $editoroptions = null)
{
    global $DB;
    $data->timemodified = time();
    $data->name = trim($data->name);
    if (isset($data->idnumber)) {
        $data->idnumber = trim($data->idnumber);
        if (($existing = groups_get_grouping_by_idnumber($data->courseid, $data->idnumber)) && $existing->id != $data->id) {
            throw new moodle_exception('idnumbertaken');
        }
    }
    if ($editoroptions !== null) {
        $data = file_postupdate_standard_editor($data, 'description', $editoroptions, $editoroptions['context'], 'grouping', 'description', $data->id);
    }
    $DB->update_record('groupings', $data);
    // Invalidate the group data.
    cache_helper::invalidate_by_definition('core', 'groupdata', array(), array($data->courseid));
    //trigger groups events
    events_trigger('groups_grouping_updated', $data);
    return true;
}
开发者ID:masaterutakeno,项目名称:MoodleMobile,代码行数:28,代码来源:lib.php

示例4: test_groups_get_grouping_by_idnumber

 public function test_groups_get_grouping_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_grouping_by_idnumber($course->id, ''));
     $this->assertFalse(groups_get_grouping_by_idnumber($course->id, null));
     // Even when a grouping exists which also has an empty idnumber.
     $generator->create_grouping(array('courseid' => $course->id));
     $this->assertFalse(groups_get_grouping_by_idnumber($course->id, ''));
     $this->assertFalse(groups_get_grouping_by_idnumber($course->id, null));
     /*
      * Test with a valid idnumber
      */
     // There is no matching idnumber at present.
     $this->assertFalse(groups_get_grouping_by_idnumber($course->id, $idnumber1));
     // We should now have a valid group returned by the idnumber search.
     $grouping = $generator->create_grouping(array('courseid' => $course->id, 'idnumber' => $idnumber1));
     $this->assertEquals($grouping, groups_get_grouping_by_idnumber($course->id, $idnumber1));
     // An empty idnumber should still return false.
     $this->assertFalse(groups_get_grouping_by_idnumber($course->id, ''));
     $this->assertFalse(groups_get_grouping_by_idnumber($course->id, null));
     /*
      * Test with another idnumber.
      */
     // There is no matching idnumber at present.
     $this->assertFalse(groups_get_grouping_by_idnumber($course->id, $idnumber2));
     // We should now have a valid grouping returned by the idnumber search.
     $grouping = $generator->create_grouping(array('courseid' => $course->id, 'idnumber' => $idnumber2));
     $this->assertEquals($grouping, groups_get_grouping_by_idnumber($course->id, $idnumber2));
     /*
      * Grouping idnumbers are unique within a course so test that we don't
      * retrieve groupings 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_grouping_by_idnumber($course->id, ''));
     $this->assertFalse(groups_get_grouping_by_idnumber($course->id, null));
     // Our existing idnumbers shouldn't be returned here as we're in a different course.
     $this->assertFalse(groups_get_grouping_by_idnumber($course->id, $idnumber1));
     $this->assertFalse(groups_get_grouping_by_idnumber($course->id, $idnumber2));
     // We should be able to reuse the idnumbers again since this is a different course.
     $grouping = $generator->create_grouping(array('courseid' => $course->id, 'idnumber' => $idnumber1));
     $this->assertEquals($grouping, groups_get_grouping_by_idnumber($course->id, $idnumber1));
     $grouping = $generator->create_grouping(array('courseid' => $course->id, 'idnumber' => $idnumber2));
     $this->assertEquals($grouping, groups_get_grouping_by_idnumber($course->id, $idnumber2));
 }
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:56,代码来源:grouplib_test.php

示例5: process_action_allocation_to_grouping

 private function process_action_allocation_to_grouping()
 {
     $now = time();
     if ($this->ratingallocate->accesstimestop < $now) {
         global $OUTPUT;
         $allgroupings = groups_get_all_groupings($this->course->id);
         $groupingidname = ratingallocate_MOD_NAME . '_instid_' . $this->ratingallocateid;
         // search if there is already a grouping from us
         $grouping = groups_get_grouping_by_idnumber($this->course->id, $groupingidname);
         $groupingid = null;
         if (!$grouping) {
             // create grouping
             $data = new stdClass();
             $data->name = get_string('groupingname', ratingallocate_MOD_NAME, $this->ratingallocate->name);
             $data->idnumber = $groupingidname;
             $data->courseid = $this->course->id;
             $groupingid = groups_create_grouping($data);
         } else {
             $groupingid = $grouping->id;
         }
         $group_identifier_from_choice_id = function ($choiceid) {
             return ratingallocate_MOD_NAME . '_c_' . $choiceid;
         };
         $choices = $this->get_choices_with_allocationcount();
         // make a new array containing only the identifiers of the choices
         $choice_identifiers = array();
         foreach ($choices as $id => $choice) {
             $choice_identifiers[$group_identifier_from_choice_id($choice->id)] = array('key' => $id);
         }
         // find all associated groups in this grouping
         $groups = groups_get_all_groups($this->course->id, 0, $groupingid);
         // loop through the groups in the grouping: if the choice does not exist anymore -> delete
         // otherwise mark it
         foreach ($groups as $group) {
             if (array_key_exists($group->idnumber, $choice_identifiers)) {
                 // group exists, mark
                 $choice_identifiers[$group->idnumber]['exists'] = true;
                 $choice_identifiers[$group->idnumber]['groupid'] = $group->id;
             } else {
                 // delete group $group->id
                 groups_delete_group($group->id);
             }
         }
         // create groups groups for new identifiers or empty group if it exists
         foreach ($choice_identifiers as $group_idnumber => $choice) {
             if (key_exists('exists', $choice)) {
                 // remove all members
                 groups_delete_group_members_by_group($choice['groupid']);
             } else {
                 $data = new stdClass();
                 $data->courseid = $this->course->id;
                 $data->name = $choices[$choice['key']]->title;
                 $data->idnumber = $group_idnumber;
                 $createdid = groups_create_group($data);
                 groups_assign_grouping($groupingid, $createdid);
                 $choice_identifiers[$group_idnumber]['groupid'] = $createdid;
             }
         }
         // add all participants in the correct group
         $allocations = $this->get_allocations();
         foreach ($allocations as $id => $allocation) {
             $choice_id = $allocation->choiceid;
             $user_id = $allocation->userid;
             $choiceidnumber = $group_identifier_from_choice_id($choice_id);
             groups_add_member($choice_identifiers[$choiceidnumber]['groupid'], $user_id);
         }
         // Invalidate the grouping cache for the course
         cache_helper::invalidate_by_definition('core', 'groupdata', array(), array($this->course->id));
         $renderer = $this->get_renderer();
         $renderer->add_notification(get_string('moodlegroups_created', ratingallocate_MOD_NAME), self::NOTIFY_SUCCESS);
     }
     return $this->process_default();
 }
开发者ID:Kathrin84,项目名称:moodle-mod_ratingallocate,代码行数:73,代码来源:locallib.php

示例6: groups_update_grouping

/**
 * Update grouping
 *
 * @param stdClass $data grouping properties (with magic quotes)
 * @param array $editoroptions
 * @return bool true or exception
 */
function groups_update_grouping($data, $editoroptions = null)
{
    global $DB;
    $data->timemodified = time();
    $data->name = trim($data->name);
    if (isset($data->idnumber)) {
        $data->idnumber = trim($data->idnumber);
        if (($existing = groups_get_grouping_by_idnumber($data->courseid, $data->idnumber)) && $existing->id != $data->id) {
            throw new moodle_exception('idnumbertaken');
        }
    }
    if ($editoroptions !== null) {
        $data = file_postupdate_standard_editor($data, 'description', $editoroptions, $editoroptions['context'], 'grouping', 'description', $data->id);
    }
    $DB->update_record('groupings', $data);
    // Invalidate the group data.
    cache_helper::invalidate_by_definition('core', 'groupdata', array(), array($data->courseid));
    // Trigger group event.
    $params = array('context' => context_course::instance($data->courseid), 'objectid' => $data->id);
    $event = \core\event\grouping_updated::create($params);
    $event->set_legacy_eventdata($data);
    $event->trigger();
    return true;
}
开发者ID:helenagarcia90,项目名称:moodle,代码行数:31,代码来源:lib.php


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