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


PHP format_base::instance方法代码示例

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


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

示例1: test_course_format_options_restore_new_format

 /**
  * Tests that all section options are copied when the course format is changed.
  * None of the data is copied.
  *
  * It is a future enhancement to copy;
  * 1. Only the relevant options.
  * 2. Only the data associated with relevant options.
  */
 public function test_course_format_options_restore_new_format()
 {
     global $DB, $CFG;
     $this->resetAfterTest(true);
     $this->setAdminUser();
     $CFG->enableavailability = true;
     $CFG->enablecompletion = true;
     // Create a course with some availability data set.
     $generator = $this->getDataGenerator();
     $course = $generator->create_course(array('format' => 'test_cs2_options', 'numsections' => 3, 'enablecompletion' => COMPLETION_ENABLED), array('createsections' => true));
     $newcourse = $generator->create_course(array('format' => 'test_cs_options', 'numsections' => 3, 'enablecompletion' => COMPLETION_ENABLED), array('createsections' => true));
     $courseobject = format_base::instance($course->id);
     $section = $DB->get_record('course_sections', array('course' => $course->id, 'section' => 1), '*', MUST_EXIST);
     $data = array('id' => $section->id, 'numdaystocomplete' => 2, 'secondparameter' => 8);
     $courseobject->update_section_format_options($data);
     // Backup and restore it.
     $this->backup_and_restore($course, $newcourse);
     $newcourseobject = format_base::instance($newcourse->id);
     $sectionoptions = $newcourseobject->get_format_options(1);
     $this->assertArrayHasKey('numdaystocomplete', $sectionoptions);
     $this->assertArrayHasKey('secondparameter', $sectionoptions);
     $this->assertEquals(0, $sectionoptions['numdaystocomplete']);
     $this->assertEquals(0, $sectionoptions['secondparameter']);
 }
开发者ID:Keneth1212,项目名称:moodle,代码行数:32,代码来源:moodle2_course_format_test.php

示例2: course_get_format

/**
 * Returns an instance of format class (extending format_base) for given course
 *
 * @param int|stdClass $courseorid either course id or
 *     an object that has the property 'format' and may contain property 'id'
 * @return format_base
 */
function course_get_format($courseorid)
{
    return format_base::instance($courseorid);
}
开发者ID:EsdrasCaleb,项目名称:moodle,代码行数:11,代码来源:lib.php

示例3: test_course_format_options_restore_new_format

 /**
  * Tests that all section options are copied when the course format is changed.
  * None of the data is copied.
  *
  * It is a future enhancement to copy;
  * 1. Only the relevant options.
  * 2. Only the data associated with relevant options.
  */
 public function test_course_format_options_restore_new_format()
 {
     global $DB, $CFG;
     $this->resetAfterTest(true);
     $this->setAdminUser();
     // Create a source course using the test_cs2_options format.
     $generator = $this->getDataGenerator();
     $course = $generator->create_course(array('format' => 'test_cs2_options', 'numsections' => 3, 'enablecompletion' => COMPLETION_ENABLED), array('createsections' => true));
     // Create a target course using test_cs_options format.
     $newcourse = $generator->create_course(array('format' => 'test_cs_options', 'numsections' => 3, 'enablecompletion' => COMPLETION_ENABLED), array('createsections' => true));
     // Set section 2 to have both options, and a name.
     $courseobject = format_base::instance($course->id);
     $section = $DB->get_record('course_sections', array('course' => $course->id, 'section' => 2), '*', MUST_EXIST);
     $data = array('id' => $section->id, 'numdaystocomplete' => 2, 'secondparameter' => 8);
     $courseobject->update_section_format_options($data);
     $DB->set_field('course_sections', 'name', 'Frogs', array('id' => $section->id));
     // Backup and restore to the new course using 'add to existing' so it
     // keeps the current (test_cs_options) format.
     $this->backup_and_restore($course, $newcourse, backup::TARGET_EXISTING_ADDING);
     // Check that the section contains the options suitable for the new
     // format and that even the one with the same name as from the old format
     // has NOT been set.
     $newcourseobject = format_base::instance($newcourse->id);
     $sectionoptions = $newcourseobject->get_format_options(2);
     $this->assertArrayHasKey('numdaystocomplete', $sectionoptions);
     $this->assertArrayNotHasKey('secondparameter', $sectionoptions);
     $this->assertEquals(0, $sectionoptions['numdaystocomplete']);
     // However, the name should have been changed, as this does not depend
     // on the format.
     $modinfo = get_fast_modinfo($newcourse->id);
     $section = $modinfo->get_section_info(2);
     $this->assertEquals('Frogs', $section->name);
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:41,代码来源:moodle2_course_format_test.php


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