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


PHP condition_info::get_full_course_module方法代码示例

本文整理汇总了PHP中condition_info::get_full_course_module方法的典型用法代码示例。如果您正苦于以下问题:PHP condition_info::get_full_course_module方法的具体用法?PHP condition_info::get_full_course_module怎么用?PHP condition_info::get_full_course_module使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在condition_info的用法示例。


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

示例1: test_constructor

 public function test_constructor()
 {
     $generator = $this->getDataGenerator();
     $course = $generator->create_course();
     $page = $generator->get_plugin_generator('mod_page')->create_instance(array('course' => $course));
     $modinfo = get_fast_modinfo($course);
     // No ID.
     try {
         $test = new condition_info((object) array());
         $this->fail();
     } catch (coding_exception $e) {
         // Do nothing.
         $this->assertDebuggingCalled();
     }
     // Get actual cm_info for comparison.
     $realcm = $modinfo->get_cm($page->cmid);
     // No other data.
     $test = new condition_info((object) array('id' => $page->cmid));
     $this->assertDebuggingCalled();
     $this->assertEquals($realcm, $test->get_full_course_module());
     $this->assertDebuggingCalled();
     // Course id.
     $test = new condition_info((object) array('id' => $page->cmid, 'course' => $course->id));
     $this->assertDebuggingCalled();
     $this->assertEquals($realcm, $test->get_full_course_module());
     $this->assertDebuggingCalled();
     // Full cm.
     $test = new condition_info($realcm);
     $this->assertDebuggingCalled();
     $this->assertEquals($realcm, $test->get_full_course_module());
     $this->assertDebuggingCalled();
 }
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:32,代码来源:conditionlib_test.php

示例2: foreach


//.........这里部分代码省略.........
         // shows only the date and not time).
         $date = usergetdate(time());
         $midnight = make_timestamp($date['year'], $date['mon'], $date['mday']);
         // From/until controls
         $mform->addElement('header', 'availabilityconditionsheader', get_string('availabilityconditions', 'condition'));
         $mform->addElement('date_time_selector', 'availablefrom', get_string('availablefrom', 'condition'), array('optional' => true, 'defaulttime' => $midnight));
         $mform->addHelpButton('availablefrom', 'availablefrom', 'condition');
         $mform->addElement('date_time_selector', 'availableuntil', get_string('availableuntil', 'condition'), array('optional' => true, 'defaulttime' => $midnight));
         // Conditions based on grades
         $gradeoptions = array();
         $items = grade_item::fetch_all(array('courseid' => $COURSE->id));
         $items = $items ? $items : array();
         foreach ($items as $id => $item) {
             // Do not include grades for current item
             if (!empty($this->_cm) && $this->_cm->instance == $item->iteminstance && $this->_cm->modname == $item->itemmodule && $item->itemtype == 'mod') {
                 continue;
             }
             $gradeoptions[$id] = $item->get_name();
         }
         asort($gradeoptions);
         $gradeoptions = array(0 => $strnone) + $gradeoptions;
         $grouparray = array();
         $grouparray[] =& $mform->createElement('select', 'conditiongradeitemid', '', $gradeoptions);
         $grouparray[] =& $mform->createElement('static', '', '', ' ' . get_string('grade_atleast', 'condition') . ' ');
         $grouparray[] =& $mform->createElement('text', 'conditiongrademin', '', array('size' => 3));
         $grouparray[] =& $mform->createElement('static', '', '', '% ' . get_string('grade_upto', 'condition') . ' ');
         $grouparray[] =& $mform->createElement('text', 'conditiongrademax', '', array('size' => 3));
         $grouparray[] =& $mform->createElement('static', '', '', '%');
         $group = $mform->createElement('group', 'conditiongradegroup', get_string('gradecondition', 'condition'), $grouparray);
         // Get version with condition info and store it so we don't ask
         // twice
         if (!empty($this->_cm)) {
             $ci = new condition_info($this->_cm, CONDITION_MISSING_EXTRATABLE);
             $this->_cm = $ci->get_full_course_module();
             $count = count($this->_cm->conditionsgrade) + 1;
             $fieldcount = count($this->_cm->conditionsfield) + 1;
         } else {
             $count = 1;
             $fieldcount = 1;
         }
         $this->repeat_elements(array($group), $count, array(), 'conditiongraderepeats', 'conditiongradeadds', 2, get_string('addgrades', 'condition'), true);
         $mform->addHelpButton('conditiongradegroup[0]', 'gradecondition', 'condition');
         // Conditions based on user fields
         $operators = condition_info::get_condition_user_field_operators();
         $useroptions = condition_info::get_condition_user_fields();
         asort($useroptions);
         $useroptions = array(0 => $strnone) + $useroptions;
         $grouparray = array();
         $grouparray[] =& $mform->createElement('select', 'conditionfield', '', $useroptions);
         $grouparray[] =& $mform->createElement('select', 'conditionfieldoperator', '', $operators);
         $grouparray[] =& $mform->createElement('text', 'conditionfieldvalue');
         $mform->setType('conditionfieldvalue', PARAM_RAW);
         $group = $mform->createElement('group', 'conditionfieldgroup', get_string('userfield', 'condition'), $grouparray);
         $this->repeat_elements(array($group), $fieldcount, array(), 'conditionfieldrepeats', 'conditionfieldadds', 2, get_string('adduserfields', 'condition'), true);
         $mform->addHelpButton('conditionfieldgroup[0]', 'userfield', 'condition');
         // Conditions based on completion
         $completion = new completion_info($COURSE);
         if ($completion->is_enabled()) {
             $completionoptions = array();
             $modinfo = get_fast_modinfo($COURSE);
             foreach ($modinfo->cms as $id => $cm) {
                 // Add each course-module if it:
                 // (a) has completion turned on
                 // (b) is not the same as current course-module
                 if ($cm->completion && (empty($this->_cm) || $this->_cm->id != $id)) {
                     $completionoptions[$id] = $cm->name;
开发者ID:Burick,项目名称:moodle,代码行数:67,代码来源:moodleform_mod.php

示例3: test_inject_rowspans

 /**
  * Tests grade_report_user::inject_rowspans()
  *
  * inject_rowspans() returns the count of the number of elements, sets maxdepth on the
  *  report object and sets the rowspan property on any element that has children.
  */
 public function test_inject_rowspans()
 {
     global $CFG, $USER, $DB;
     parent::setUp();
     $this->resetAfterTest(true);
     $CFG->enableavailability = 1;
     $CFG->enablecompletion = 1;
     // Create a course.
     $course = $this->getDataGenerator()->create_course();
     $coursecategory = grade_category::fetch_course_category($course->id);
     $coursecontext = context_course::instance($course->id);
     // Create and enrol test users.
     $student = $this->getDataGenerator()->create_user(array('username' => 'Student Sam'));
     $role = $DB->get_record('role', array('shortname' => 'student'), '*', MUST_EXIST);
     $this->getDataGenerator()->enrol_user($student->id, $course->id, $role->id);
     $teacher = $this->getDataGenerator()->create_user(array('username' => 'Teacher T'));
     $role = $DB->get_record('role', array('shortname' => 'editingteacher'), '*', MUST_EXIST);
     $this->getDataGenerator()->enrol_user($teacher->id, $course->id, $role->id);
     // An array so we can test with both users in a loop.
     $users = array($student, $teacher);
     // Make the student the current user.
     $this->setUser($student);
     // Test an empty course.
     $report = $this->create_report($course, $student, $coursecontext);
     // a lead column that spans all children + course grade item = 2
     $this->assertEquals(2, $report->inject_rowspans($report->gtree->top_element));
     $this->assertEquals(2, $report->gtree->top_element['rowspan']);
     $this->assertEquals(2, $report->maxdepth);
     // Only elements with children should have rowspan set.
     if (array_key_exists('rowspan', $report->gtree->top_element['children'][1])) {
         $this->fail('Elements without children should not have rowspan set');
     }
     // Add 2 activities.
     $data1 = $this->getDataGenerator()->create_module('data', array('assessed' => 1, 'scale' => 100, 'course' => $course->id));
     $forum1 = $this->getDataGenerator()->create_module('forum', array('assessed' => 1, 'scale' => 100, 'course' => $course->id));
     $forum1cm = get_coursemodule_from_id('forum', $forum1->cmid);
     // Switch the stdClass instance for a grade item instance so grade_item::set_parent() is available.
     $forum1 = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'forum', 'iteminstance' => $forum1->id, 'courseid' => $course->id));
     $report = $this->create_report($course, $student, $coursecontext);
     // Lead column + course + (2 x activity) = 4
     $this->assertEquals(4, $report->inject_rowspans($report->gtree->top_element));
     $this->assertEquals(4, $report->gtree->top_element['rowspan']);
     // Lead column + 1 level (course + 2 activities) = 2
     $this->assertEquals(2, $report->maxdepth);
     // Only elements with children should have rowspan set.
     if (array_key_exists('rowspan', $report->gtree->top_element['children'][1])) {
         $this->fail('Elements without children should not have rowspan set');
     }
     // Hide the forum activity.
     set_coursemodule_visible($forum1cm->id, 0);
     foreach ($users as $user) {
         $this->setUser($user);
         $message = 'Testing with ' . $user->username;
         accesslib_clear_all_caches_for_unit_testing();
         $report = $this->create_report($course, $user, $coursecontext);
         // Lead column + course + (2 x activity) = 4 (element count isn't affected by hiding)
         $this->assertEquals(4, $report->inject_rowspans($report->gtree->top_element), $message);
         $this->assertEquals(4, $report->gtree->top_element['rowspan'], $message);
         // Lead column -> 1 level containing the course + 2 activities = 2
         $this->assertEquals(2, $report->maxdepth, $message);
     }
     // Unhide the forum activity.
     set_coursemodule_visible($forum1cm->id, 1);
     // Create a category and put the forum in it.
     $params = new stdClass();
     $params->courseid = $course->id;
     $params->fullname = 'unittestcategory';
     $params->parent = $coursecategory->id;
     $gradecategory = new grade_category($params, false);
     $gradecategory->insert();
     $forum1->set_parent($gradecategory->id);
     $report = $this->create_report($course, $student, $coursecontext);
     // Lead column + course + (category + category grade item) + (2 x activity) = 6
     $this->assertEquals(6, $report->inject_rowspans($report->gtree->top_element));
     $this->assertEquals(6, $report->gtree->top_element['rowspan']);
     // Lead column -> the category -> the forum activity = 3
     $this->assertEquals(3, $report->maxdepth);
     // Check rowspan on the category. The category itself + category grade item + forum = 3
     $this->assertEquals(3, $report->gtree->top_element['children'][4]['rowspan']);
     // check the forum doesn't have rowspan set
     if (array_key_exists('rowspan', $report->gtree->top_element['children'][4]['children'][3])) {
         $this->fail('The forum has no children so should not have rowspan set');
     }
     // Conditional activity tests.
     $DB->insert_record('course_modules_availability', (object) array('coursemoduleid' => $forum1cm->id, 'gradeitemid' => 37, 'grademin' => 5.5));
     $cm = (object) array('id' => $forum1cm->id);
     $test = new condition_info($cm, CONDITION_MISSING_EVERYTHING);
     $fullcm = $test->get_full_course_module();
     foreach ($users as $user) {
         $this->setUser($user);
         $message = 'Testing with ' . $user->username;
         accesslib_clear_all_caches_for_unit_testing();
         $report = $this->create_report($course, $user, $coursecontext);
         // Lead column + course + (category + category grade item) + (2 x activity) = 6
//.........这里部分代码省略.........
开发者ID:masaterutakeno,项目名称:MoodleMobile,代码行数:101,代码来源:reportuser_test.php

示例4: array

 function test_add_and_remove()
 {
     global $DB;
     // Make course and module
     $courseid = $this->make_course();
     $cmid = $this->make_course_module($courseid, array('showavailability' => 0, 'availablefrom' => 0, 'availableuntil' => 0));
     $this->make_section($courseid, array($cmid));
     // Check it has no conditions
     $test1 = new condition_info((object) array('id' => $cmid), CONDITION_MISSING_EVERYTHING);
     $cm = $test1->get_full_course_module();
     $this->assertEqual(array(), $cm->conditionscompletion);
     $this->assertEqual(array(), $cm->conditionsgrade);
     // Add conditions of each type
     $test1->add_completion_condition(13, 3);
     $this->assertEqual(array(13 => 3), $cm->conditionscompletion);
     $test1->add_grade_condition(666, 0.4, null, true);
     $this->assertEqual(array(666 => (object) array('min' => 0.4, 'max' => null, 'name' => '!missing')), $cm->conditionsgrade);
     // Check they were really added in db
     $test2 = new condition_info((object) array('id' => $cmid), CONDITION_MISSING_EVERYTHING);
     $cm = $test2->get_full_course_module();
     $this->assertEqual(array(13 => 3), $cm->conditionscompletion);
     $this->assertEqual(array(666 => (object) array('min' => 0.4, 'max' => null, 'name' => '!missing')), $cm->conditionsgrade);
     // Wipe conditions
     $test2->wipe_conditions();
     $this->assertEqual(array(), $cm->conditionscompletion);
     $this->assertEqual(array(), $cm->conditionsgrade);
     // Check they were really wiped
     $test3 = new condition_info((object) array('id' => $cmid), CONDITION_MISSING_EVERYTHING);
     $cm = $test3->get_full_course_module();
     $this->assertEqual(array(), $cm->conditionscompletion);
     $this->assertEqual(array(), $cm->conditionsgrade);
 }
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:32,代码来源:testconditionlib.php

示例5: foreach

 /**
  * Adds all the standard elements to a form to edit the settings for an activity module.
  */
 function standard_coursemodule_elements()
 {
     global $COURSE, $CFG, $DB;
     $mform =& $this->_form;
     $outcomesused = false;
     if ($this->_features->outcomes) {
         if ($outcomes = grade_outcome::fetch_all_available($COURSE->id)) {
             $outcomesused = true;
             $mform->addElement('header', 'modoutcomes', get_string('outcomes', 'grades'));
             foreach ($outcomes as $outcome) {
                 $mform->addElement('advcheckbox', 'outcome_' . $outcome->id, $outcome->get_name());
             }
         }
     }
     $mform->addElement('header', 'modstandardelshdr', get_string('modstandardels', 'form'));
     if ($this->_features->groups) {
         $options = array(NOGROUPS => get_string('groupsnone'), SEPARATEGROUPS => get_string('groupsseparate'), VISIBLEGROUPS => get_string('groupsvisible'));
         $mform->addElement('select', 'groupmode', get_string('groupmode'), $options, NOGROUPS);
         $mform->setHelpButton('groupmode', array('groupmode', get_string('groupmode')));
     }
     if (!empty($CFG->enablegroupings)) {
         if ($this->_features->groupings or $this->_features->groupmembersonly) {
             //groupings selector - used for normal grouping mode or also when restricting access with groupmembersonly
             $options = array();
             $options[0] = get_string('none');
             if ($groupings = $DB->get_records('groupings', array('courseid' => $COURSE->id))) {
                 foreach ($groupings as $grouping) {
                     $options[$grouping->id] = format_string($grouping->name);
                 }
             }
             $mform->addElement('select', 'groupingid', get_string('grouping', 'group'), $options);
             $mform->setHelpButton('groupingid', array('grouping', get_string('grouping', 'group')));
             $mform->setAdvanced('groupingid');
         }
         if ($this->_features->groupmembersonly) {
             $mform->addElement('checkbox', 'groupmembersonly', get_string('groupmembersonly', 'group'));
             $mform->setHelpButton('groupmembersonly', array('groupmembersonly', get_string('groupmembersonly', 'group')));
             $mform->setAdvanced('groupmembersonly');
         }
     }
     $mform->addElement('modvisible', 'visible', get_string('visible'));
     if ($this->_features->idnumber) {
         $mform->addElement('text', 'cmidnumber', get_string('idnumbermod'));
         $mform->setHelpButton('cmidnumber', array('cmidnumber', get_string('idnumbermod')), true);
     }
     if ($this->_features->gradecat) {
         $categories = grade_get_categories_menu($COURSE->id, $outcomesused);
         $mform->addElement('select', 'gradecat', get_string('gradecategory', 'grades'), $categories);
     }
     if (!empty($CFG->enableavailability)) {
         // Conditional availability
         $mform->addElement('header', '', get_string('availabilityconditions', 'condition'));
         $mform->addElement('date_selector', 'availablefrom', get_string('availablefrom', 'condition'), array('optional' => true));
         $mform->setHelpButton('availablefrom', array('conditiondates', get_string('help_conditiondates', 'condition'), 'condition'));
         $mform->addElement('date_selector', 'availableuntil', get_string('availableuntil', 'condition'), array('optional' => true));
         $mform->setHelpButton('availableuntil', array('conditiondates', get_string('help_conditiondates', 'condition'), 'condition'));
         // Conditions based on grades
         $gradeoptions = array();
         $items = grade_item::fetch_all(array('courseid' => $COURSE->id));
         $items = $items ? $items : array();
         foreach ($items as $id => $item) {
             // Do not include grades for current item
             if (!empty($this->_cm) && $this->_cm->instance == $item->iteminstance && $this->_cm->modname == $item->itemmodule && $item->itemtype == 'mod') {
                 continue;
             }
             $gradeoptions[$id] = $item->get_name();
         }
         asort($gradeoptions);
         $gradeoptions = array(0 => get_string('none', 'condition')) + $gradeoptions;
         $grouparray = array();
         $grouparray[] =& $mform->createElement('select', 'conditiongradeitemid', '', $gradeoptions);
         $grouparray[] =& $mform->createElement('static', '', '', ' ' . get_string('grade_atleast', 'condition') . ' ');
         $grouparray[] =& $mform->createElement('text', 'conditiongrademin', '', array('size' => 3));
         $grouparray[] =& $mform->createElement('static', '', '', '% ' . get_string('grade_upto', 'condition') . ' ');
         $grouparray[] =& $mform->createElement('text', 'conditiongrademax', '', array('size' => 3));
         $grouparray[] =& $mform->createElement('static', '', '', '%');
         $mform->setType('conditiongrademin', PARAM_FLOAT);
         $mform->setType('conditiongrademax', PARAM_FLOAT);
         $group = $mform->createElement('group', 'conditiongradegroup', get_string('gradecondition', 'condition'), $grouparray);
         // Get version with condition info and store it so we don't ask
         // twice
         if (!empty($this->_cm)) {
             $ci = new condition_info($this->_cm, CONDITION_MISSING_EXTRATABLE);
             $this->_cm = $ci->get_full_course_module();
             $count = count($this->_cm->conditionsgrade) + 1;
         } else {
             $count = 1;
         }
         $this->repeat_elements(array($group), $count, array(), 'conditiongraderepeats', 'conditiongradeadds', 2, get_string('addgrades', 'condition'), true);
         $mform->setHelpButton('conditiongradegroup[0]', array('gradecondition', get_string('help_gradecondition', 'condition'), 'condition'));
         // Conditions based on completion
         $completion = new completion_info($COURSE);
         if ($completion->is_enabled()) {
             $completionoptions = array();
             $modinfo = get_fast_modinfo($COURSE);
             foreach ($modinfo->cms as $id => $cm) {
                 // Add each course-module if it:
//.........这里部分代码省略.........
开发者ID:ajv,项目名称:Offline-Caching,代码行数:101,代码来源:moodleform_mod.php


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