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


PHP condition_info::add_completion_condition方法代码示例

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


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

示例1: update_cm_from_form

 /**
  * Utility function called by modedit.php; updates the 
  * course_modules_availability table based on the module form data.
  *
  * @param object $cm Course-module with as much data as necessary, min id
  * @param object $fromform
  * @param bool $wipefirst Defaults to true
  */
 public static function update_cm_from_form($cm, $fromform, $wipefirst = true)
 {
     $ci = new condition_info($cm, CONDITION_MISSING_EVERYTHING, false);
     if ($wipefirst) {
         $ci->wipe_conditions();
     }
     foreach ($fromform->conditiongradegroup as $record) {
         if ($record['conditiongradeitemid']) {
             $ci->add_grade_condition($record['conditiongradeitemid'], $record['conditiongrademin'], $record['conditiongrademax']);
         }
     }
     if (isset($fromform->conditioncompletiongroup)) {
         foreach ($fromform->conditioncompletiongroup as $record) {
             if ($record['conditionsourcecmid']) {
                 $ci->add_completion_condition($record['conditionsourcecmid'], $record['conditionrequiredcompletion']);
             }
         }
     }
 }
开发者ID:ajv,项目名称:Offline-Caching,代码行数:27,代码来源:conditionlib.php

示例2: array

 function test_is_available()
 {
     global $DB, $USER;
     $courseid = $this->make_course();
     // No conditions
     $cmid = $this->make_course_module($courseid);
     $ci = new condition_info((object) array('id' => $cmid), CONDITION_MISSING_EVERYTHING);
     $this->assertTrue($ci->is_available($text, false, 0));
     $this->assertEqual('', $text);
     // Time (from)
     $time = time() + 100;
     $cmid = $this->make_course_module($courseid, array('availablefrom' => $time));
     $ci = new condition_info((object) array('id' => $cmid), CONDITION_MISSING_EVERYTHING);
     $this->assertFalse($ci->is_available($text));
     $this->assert(new PatternExpectation('/' . preg_quote(userdate($time, get_string('strftimedate', 'langconfig'))) . '/'), $text);
     $time = time() - 100;
     $cmid = $this->make_course_module($courseid, array('availablefrom' => $time));
     $ci = new condition_info((object) array('id' => $cmid), CONDITION_MISSING_EVERYTHING);
     $this->assertTrue($ci->is_available($text));
     $this->assertEqual('', $text);
     $this->assert(new PatternExpectation('/' . preg_quote(userdate($time, get_string('strftimedate', 'langconfig'))) . '/'), $ci->get_full_information());
     // Time (until)
     $cmid = $this->make_course_module($courseid, array('availableuntil' => time() - 100));
     $ci = new condition_info((object) array('id' => $cmid), CONDITION_MISSING_EVERYTHING);
     $this->assertFalse($ci->is_available($text));
     $this->assertEqual('', $text);
     // Completion
     $oldid = $cmid;
     $cmid = $this->make_course_module($courseid);
     $this->make_section($courseid, array($oldid, $cmid));
     $oldcm = $DB->get_record('course_modules', array('id' => $oldid));
     $oldcm->completion = COMPLETION_TRACKING_MANUAL;
     $DB->update_record('course_modules', $oldcm);
     $ci = new condition_info((object) array('id' => $cmid), CONDITION_MISSING_EVERYTHING);
     $ci->add_completion_condition($oldid, COMPLETION_COMPLETE);
     $this->assertFalse($ci->is_available($text, false));
     $this->assertEqual(get_string('requires_completion_1', 'condition', 'xxx'), $text);
     $completion = new completion_info($DB->get_record('course', array('id' => $courseid)));
     $completion->update_state($oldcm, COMPLETION_COMPLETE);
     completion_info::wipe_session_cache();
     condition_info::wipe_session_cache();
     $this->assertTrue($ci->is_available($text));
     $this->assertFalse($ci->is_available($text, false, $USER->id + 1));
     completion_info::wipe_session_cache();
     condition_info::wipe_session_cache();
     $completion = new completion_info($DB->get_record('course', array('id' => $courseid)));
     $completion->update_state($oldcm, COMPLETION_INCOMPLETE);
     $this->assertFalse($ci->is_available($text));
     $ci->wipe_conditions();
     $ci->add_completion_condition($oldid, COMPLETION_INCOMPLETE);
     condition_info::wipe_session_cache();
     $this->assertTrue($ci->is_available($text));
     $this->assertTrue($ci->is_available($text, false, $USER->id + 1));
     condition_info::wipe_session_cache();
     $this->assertTrue($ci->is_available($text, true));
     // Grade
     $ci->wipe_conditions();
     // Add a fake grade item
     $gradeitemid = $DB->insert_record('grade_items', (object) array('courseid' => $courseid, 'itemname' => 'frog'));
     // Add a condition on a value existing...
     $ci->add_grade_condition($gradeitemid, null, null, true);
     $this->assertFalse($ci->is_available($text));
     $this->assertEqual(get_string('requires_grade_any', 'condition', 'frog'), $text);
     // Fake it existing
     $DB->insert_record('grade_grades', (object) array('itemid' => $gradeitemid, 'userid' => $USER->id, 'finalgrade' => 3.78));
     condition_info::wipe_session_cache();
     $this->assertTrue($ci->is_available($text));
     condition_info::wipe_session_cache();
     $this->assertTrue($ci->is_available($text, true));
     // Now require that user gets more than 3.78001
     $ci->wipe_conditions();
     $ci->add_grade_condition($gradeitemid, 3.78001, null, true);
     condition_info::wipe_session_cache();
     $this->assertFalse($ci->is_available($text));
     $this->assertEqual(get_string('requires_grade_min', 'condition', 'frog'), $text);
     // ...just on 3.78...
     $ci->wipe_conditions();
     $ci->add_grade_condition($gradeitemid, 3.78, null, true);
     condition_info::wipe_session_cache();
     $this->assertTrue($ci->is_available($text));
     // ...less than 3.78
     $ci->wipe_conditions();
     $ci->add_grade_condition($gradeitemid, null, 3.78, true);
     condition_info::wipe_session_cache();
     $this->assertFalse($ci->is_available($text));
     $this->assertEqual(get_string('requires_grade_max', 'condition', 'frog'), $text);
     // ...less than 3.78001
     $ci->wipe_conditions();
     $ci->add_grade_condition($gradeitemid, null, 3.78001, true);
     condition_info::wipe_session_cache();
     $this->assertTrue($ci->is_available($text));
     // ...in a range that includes it
     $ci->wipe_conditions();
     $ci->add_grade_condition($gradeitemid, 3, 4, true);
     condition_info::wipe_session_cache();
     $this->assertTrue($ci->is_available($text));
     // ...in a range that doesn't include it
     $ci->wipe_conditions();
     $ci->add_grade_condition($gradeitemid, 4, 5, true);
     condition_info::wipe_session_cache();
//.........这里部分代码省略.........
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:101,代码来源:testconditionlib.php

示例3: test_cm_info_properties

 public function test_cm_info_properties()
 {
     global $DB, $CFG;
     $this->resetAfterTest();
     $oldcfgenableavailability = $CFG->enableavailability;
     $oldcfgenablecompletion = $CFG->enablecompletion;
     set_config('enableavailability', 1);
     set_config('enablecompletion', 1);
     $this->setAdminUser();
     // Generate the course and pre-requisite module.
     $course = $this->getDataGenerator()->create_course(array('format' => 'topics', 'numsections' => 3, 'enablecompletion' => 1, 'groupmode' => SEPARATEGROUPS, 'forcegroupmode' => 0), array('createsections' => true));
     $coursecontext = context_course::instance($course->id);
     $prereqforum = $this->getDataGenerator()->create_module('forum', array('course' => $course->id), array('completion' => 1));
     // Generate the module and add availability conditions.
     $conditionscompletion = array($prereqforum->cmid => COMPLETION_COMPLETE);
     $conditionsgrade = array(666 => (object) array('min' => 0.4, 'max' => null, 'name' => '!missing'));
     $conditionsfield = array('email' => (object) array('fieldname' => 'email', 'operator' => 'contains', 'value' => 'test'));
     $assign = $this->getDataGenerator()->create_module('assign', array('course' => $course->id), array('idnumber' => 123, 'groupmode' => VISIBLEGROUPS, 'availablefrom' => time() + 3600, 'availableuntil' => time() + 5 * 3600));
     $ci = new condition_info((object) array('id' => $assign->cmid), CONDITION_MISSING_EVERYTHING);
     foreach ($conditionscompletion as $cmid => $requiredcompletion) {
         $ci->add_completion_condition($cmid, $requiredcompletion);
     }
     foreach ($conditionsgrade as $gradeid => $conditiongrade) {
         $ci->add_grade_condition($gradeid, $conditiongrade->min, $conditiongrade->max, true);
     }
     foreach ($conditionsfield as $conditionfield) {
         $ci->add_user_field_condition($conditionfield->fieldname, $conditionfield->operator, $conditionfield->value);
     }
     // Direct access to condition_info functions does not reset course cache, do it manually.
     rebuild_course_cache($course->id, true);
     // Retrieve all related records from DB.
     $assigndb = $DB->get_record('assign', array('id' => $assign->id));
     $moduletypedb = $DB->get_record('modules', array('name' => 'assign'));
     $moduledb = $DB->get_record('course_modules', array('module' => $moduletypedb->id, 'instance' => $assign->id));
     $sectiondb = $DB->get_record('course_sections', array('id' => $moduledb->section));
     $modnamessingular = get_module_types_names(false);
     $modnamesplural = get_module_types_names(true);
     // Create and enrol a student.
     $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');
     $enrolinstance = $DB->get_record('enrol', array('courseid' => $course->id, 'enrol' => 'manual'));
     $enrolplugin->enrol_user($enrolinstance, $student->id);
     $this->setUser($student);
     // Emulate data used in building course cache to receive the same instance of cached_cm_info as was used in building modinfo.
     $rawmods = get_course_mods($course->id);
     $cachedcminfo = assign_get_coursemodule_info($rawmods[$moduledb->id]);
     // Get modinfo.
     $modinfo = get_fast_modinfo($course->id);
     $cm = $modinfo->instances['assign'][$assign->id];
     $this->assertEquals($moduledb->id, $cm->id);
     $this->assertEquals($assigndb->id, $cm->instance);
     $this->assertEquals($moduledb->course, $cm->course);
     $this->assertEquals($moduledb->idnumber, $cm->idnumber);
     $this->assertEquals($moduledb->added, $cm->added);
     $this->assertEquals($moduledb->visible, $cm->visible);
     $this->assertEquals($moduledb->visibleold, $cm->visibleold);
     $this->assertEquals($moduledb->groupmode, $cm->groupmode);
     $this->assertEquals(VISIBLEGROUPS, $cm->groupmode);
     $this->assertEquals($moduledb->groupingid, $cm->groupingid);
     $this->assertEquals($moduledb->groupmembersonly, $cm->groupmembersonly);
     $this->assertEquals($course->groupmodeforce, $cm->coursegroupmodeforce);
     $this->assertEquals($course->groupmode, $cm->coursegroupmode);
     $this->assertEquals(SEPARATEGROUPS, $cm->coursegroupmode);
     $this->assertEquals($course->groupmodeforce ? $course->groupmode : $moduledb->groupmode, $cm->effectivegroupmode);
     // (since mod_assign supports groups).
     $this->assertEquals(VISIBLEGROUPS, $cm->effectivegroupmode);
     $this->assertEquals($moduledb->indent, $cm->indent);
     $this->assertEquals($moduledb->completion, $cm->completion);
     $this->assertEquals($moduledb->completiongradeitemnumber, $cm->completiongradeitemnumber);
     $this->assertEquals($moduledb->completionview, $cm->completionview);
     $this->assertEquals($moduledb->completionexpected, $cm->completionexpected);
     $this->assertEquals($moduledb->availablefrom, $cm->availablefrom);
     $this->assertEquals($moduledb->availableuntil, $cm->availableuntil);
     $this->assertEquals($moduledb->showavailability, $cm->showavailability);
     $this->assertEquals($moduledb->showdescription, $cm->showdescription);
     $this->assertEquals(null, $cm->extra);
     // Deprecated field. Used in module types that don't return cached_cm_info.
     $this->assertEquals($cachedcminfo->icon, $cm->icon);
     $this->assertEquals($cachedcminfo->iconcomponent, $cm->iconcomponent);
     $this->assertEquals('assign', $cm->modname);
     $this->assertEquals($moduledb->module, $cm->module);
     $this->assertEquals($cachedcminfo->name, $cm->name);
     $this->assertEquals($sectiondb->section, $cm->sectionnum);
     $this->assertEquals($moduledb->section, $cm->section);
     $this->assertEquals($conditionscompletion, $cm->conditionscompletion);
     $this->assertEquals($conditionsgrade, $cm->conditionsgrade);
     $this->assertEquals($conditionsfield, $cm->conditionsfield);
     $this->assertEquals(context_module::instance($moduledb->id), $cm->context);
     $this->assertEquals($modnamessingular['assign'], $cm->modfullname);
     $this->assertEquals($modnamesplural['assign'], $cm->modplural);
     $this->assertEquals(new moodle_url('/mod/assign/view.php', array('id' => $moduledb->id)), $cm->url);
     $this->assertEquals($cachedcminfo->customdata, $cm->customdata);
     // Dynamic fields, just test that they can be retrieved (must be carefully tested in each activity type).
     $this->assertNotEmpty($cm->availableinfo);
     // Lists all unmet availability conditions.
     $this->assertEquals(0, $cm->uservisible);
     $this->assertEquals('', $cm->extraclasses);
     $this->assertEquals('', $cm->onclick);
//.........这里部分代码省略.........
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:101,代码来源:modinfolib_test.php

示例4: test_version1importdeletecoursedeletesassociations

 /**
  * Validate that the version 1 plugin deletes appropriate associations when
  * deleting a course
  */
 public function test_version1importdeletecoursedeletesassociations()
 {
     global $DB, $CFG, $USER;
     require_once $CFG->dirroot . '/user/lib.php';
     require_once $CFG->dirroot . '/lib/gradelib.php';
     require_once $CFG->dirroot . '/group/lib.php';
     require_once $CFG->dirroot . '/lib/conditionlib.php';
     require_once $CFG->dirroot . '/lib/enrollib.php';
     require_once $CFG->dirroot . '/tag/lib.php';
     require_once $CFG->dirroot . '/lib/questionlib.php';
     // Setup.
     $initialnumcontexts = $DB->count_records('context', array('contextlevel' => CONTEXT_COURSE));
     $DB->delete_records('block_instances');
     // Set up the course with one section, including default blocks.
     set_config('defaultblocks_topics', 'search_forums');
     set_config('maxsections', 10, 'moodlecourse');
     $this->run_core_course_import(array('shortname' => 'deleteassociationsshortname', 'numsections' => 1));
     // Create a user record.
     $record = new stdClass();
     $record->username = 'testuser';
     $record->password = 'Testpass!0';
     $userid = user_create_user($record);
     // Create a course-level role.
     $courseid = $DB->get_field('course', 'id', array('shortname' => 'deleteassociationsshortname'));
     $coursecontext = context_course::instance($courseid);
     $roleid = create_role('deleterole', 'deleterole', 'deleterole');
     set_role_contextlevels($roleid, array(CONTEXT_COURSE));
     $enrol = new stdClass();
     $enrol->enrol = 'manual';
     $enrol->courseid = $courseid;
     $enrol->status = ENROL_INSTANCE_ENABLED;
     if (!$DB->record_exists('enrol', (array) $enrol)) {
         $DB->insert_record('enrol', $enrol);
     }
     // Assign the user to the course-level role.
     enrol_try_internal_enrol($courseid, $userid, $roleid);
     // Create a grade item.
     $gradeitem = new grade_item(array('courseid' => $courseid, 'itemtype' => 'manual', 'itemname' => 'testitem'), false);
     $gradeitem->insert();
     $gradegrade = new grade_grade(array('itemid' => $gradeitem->id, 'userid' => $userid), false);
     // Assign the user a grade.
     $gradegrade->insert();
     // Create a grade outcome.
     $gradeoutcome = new grade_outcome(array('courseid' => $courseid, 'shortname' => 'bogusshortname', 'fullname' => 'bogusfullname'));
     $gradeoutcome->insert();
     // Create a grade scale.
     $gradescale = new grade_scale(array('courseid' => $courseid, 'name' => 'bogusname', 'userid' => $userid, 'scale' => 'bogusscale', 'description' => 'bogusdescription'));
     $gradescale->insert();
     // Set a grade setting value.
     grade_set_setting($courseid, 'bogus', 'bogus');
     // Set up a grade letter.
     $gradeletter = new stdClass();
     $gradeletter->contextid = $coursecontext->id;
     $gradeletter->lowerboundary = 80;
     $gradeletter->letter = 'A';
     $DB->insert_record('grade_letters', $gradeletter);
     // Set up a forum instance.
     $forum = new stdClass();
     $forum->course = $courseid;
     $forum->intro = 'intro';
     $forum->id = $DB->insert_record('forum', $forum);
     // Add it as a course module.
     $forum->module = $DB->get_field('modules', 'id', array('name' => 'forum'));
     $forum->instance = $forum->id;
     $cmid = add_course_module($forum);
     // Set up a completion record.
     $completion = new stdClass();
     $completion->coursemoduleid = $cmid;
     $completion->completionstate = 0;
     $completion->userid = 9999;
     $completion->timemodified = time();
     $DB->insert_record('course_modules_completion', $completion);
     // Set up a completion condition.
     $forum->id = $cmid;
     $ci = new condition_info($forum, CONDITION_MISSING_EVERYTHING, false);
     $ci->add_completion_condition($cmid, COMPLETION_ENABLED);
     // Set the blocks position.
     $instances = $DB->get_records('block_instances', array('parentcontextid' => $coursecontext->id));
     $page = new stdClass();
     $page->context = $coursecontext;
     $page->pagetype = 'course-view-*';
     $page->subpage = false;
     foreach ($instances as $instance) {
         blocks_set_visibility($instance, $page, 1);
     }
     // Create a group.
     $group = new stdClass();
     $group->name = 'testgroup';
     $group->courseid = $courseid;
     $groupid = groups_create_group($group);
     // Add the user to the group.
     groups_add_member($groupid, $userid);
     // Create a grouping containing our group.
     $grouping = new stdClass();
     $grouping->name = 'testgrouping';
     $grouping->courseid = $courseid;
//.........这里部分代码省略.........
开发者ID:jamesmcq,项目名称:elis,代码行数:101,代码来源:version1_course_import_test.php


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