本文整理汇总了PHP中course_get_format函数的典型用法代码示例。如果您正苦于以下问题:PHP course_get_format函数的具体用法?PHP course_get_format怎么用?PHP course_get_format使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了course_get_format函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: moodleform_mod
function moodleform_mod($current, $section, $cm, $course)
{
global $CFG;
$this->current = $current;
$this->_instance = $current->instance;
$this->_section = $section;
$this->_cm = $cm;
if ($this->_cm) {
$this->context = context_module::instance($this->_cm->id);
} else {
$this->context = context_course::instance($course->id);
}
// Set the course format.
require_once $CFG->dirroot . '/course/format/lib.php';
$this->courseformat = course_get_format($course);
// Guess module name
$matches = array();
if (!preg_match('/^mod_([^_]+)_mod_form$/', get_class($this), $matches)) {
debugging('Use $modname parameter or rename form to mod_xx_mod_form, where xx is name of your module');
print_error('unknownmodulename');
}
$this->_modname = $matches[1];
$this->init_features();
parent::moodleform('modedit.php');
}
示例2: __construct
/**
* Constructor method, calls the parent constructor - MDL-21097
*
* @param moodle_page $page
* @param string $target one of rendering target constants
*/
public function __construct(moodle_page $page, $target)
{
parent::__construct($page, $target);
$this->courseformat = course_get_format($page->course);
$this->settings = $this->courseformat->get_settings();
/* Since format_grid_renderer::section_edit_controls() only displays the 'Set current section' control when editing
mode is on we need to be sure that the link 'Turn editing mode on' is available for a user who does not have any
other managing capability. */
$page->set_other_editing_capability('moodle/course:setcurrentsection');
}
示例3: section_left_content
/**
* Generate the content to displayed on the left part of a section
* before course modules are included
*
* @param stdClass $section The course_section entry from DB
* @param stdClass $course The course entry from DB
* @param bool $onsectionpage true if being printed on a section page
* @return string HTML to output.
*/
protected function section_left_content($section, $course, $onsectionpage)
{
$o = $this->output->spacer();
if ($section->section != 0) {
// Only in the non-general sections.
if (course_get_format($course)->is_section_current($section)) {
$o .= get_accesshide(get_string('currentsection', 'format_' . $course->format));
}
}
return $o;
}
示例4: course_format
/**
* Contructor
* @param $course object The pre-defined course object.
* Passed by reference, so that extended info can be added.
*
*/
function course_format(&$course)
{
if (empty($this->course) && is_object($course)) {
$this->course = clone $course;
}
$courseformatoptions = course_get_format($course)->get_format_options();
$this->course->numsections = $courseformatoptions['numsections'];
//$course->hiddensections = $courseformatoptions['hiddensections'];
//$course->coursedisplay = $courseformatoptions['coursedisplay'];
/// Method should load any other course data into the course property.
$this->get_course();
}
示例5: __construct
/**
* Constructor method, calls the parent constructor - MDL-21097
*
* @param moodle_page $page
* @param string $target one of rendering target constants
*/
public function __construct(moodle_page $page, $target)
{
parent::__construct($page, $target);
$this->togglelib = new topcoll_togglelib();
$this->courseformat = course_get_format($page->course);
// Needed for collapsed topics settings retrieval.
/* Since format_topcoll_renderer::section_edit_controls() only displays the 'Set current section' control when editing
mode is on we need to be sure that the link 'Turn editing mode on' is available for a user who does not have any
other managing capability. */
$page->set_other_editing_capability('moodle/course:setcurrentsection');
global $PAGE;
$this->userisediting = $PAGE->user_is_editing();
$this->tctoggleiconsize = clean_param(get_config('format_topcoll', 'defaulttoggleiconsize'), PARAM_TEXT);
}
示例6: test_update_course_numsections
public function test_update_course_numsections()
{
global $DB;
$this->resetAfterTest(true);
$generator = $this->getDataGenerator();
$course = $generator->create_course(array('numsections' => 10, 'format' => 'topics'), array('createsections' => true));
$generator->create_module('assign', array('course' => $course, 'section' => 7));
$this->setAdminUser();
$this->assertEquals(11, $DB->count_records('course_sections', array('course' => $course->id)));
// Change the numsections to 8, last two sections did not have any activities, they should be deleted.
update_course((object) array('id' => $course->id, 'numsections' => 8));
$this->assertEquals(9, $DB->count_records('course_sections', array('course' => $course->id)));
$this->assertEquals(9, count(get_fast_modinfo($course)->get_section_info_all()));
// Change the numsections to 5, section 8 should be deleted but section 7 should remain as it has activities.
update_course((object) array('id' => $course->id, 'numsections' => 6));
$this->assertEquals(8, $DB->count_records('course_sections', array('course' => $course->id)));
$this->assertEquals(8, count(get_fast_modinfo($course)->get_section_info_all()));
$this->assertEquals(6, course_get_format($course)->get_course()->numsections);
}
示例7: get_form
/**
* Returns a form element for this rule.
*
* @param string $basename The form element base name.
* @return string
*/
public function get_form($basename)
{
global $COURSE;
$options = array();
$modinfo = get_fast_modinfo($this->courseid);
$courseformat = course_get_format($this->courseid);
foreach ($modinfo->get_sections() as $sectionnum => $cmids) {
$modules = array();
foreach ($cmids as $cmid) {
$cm = $modinfo->get_cm($cmid);
$modules[$cm->context->id] = $cm->name;
}
$options[] = array($courseformat->get_section_name($sectionnum) => $modules);
}
$o = block_xp_rule::get_form($basename);
$modules = html_writer::select($options, $basename . '[value]', $this->value, '', array('id' => '', 'class' => ''));
$o .= get_string('activityoresourceis', 'block_xp', $modules);
return $o;
}
示例8: __construct
/**
* course_toc constructor.
* @param null $course
*/
function __construct($course = null)
{
global $COURSE;
if (empty($course)) {
$course = $COURSE;
}
$supportedformats = ['weeks', 'topics'];
if (!in_array($course->format, $supportedformats)) {
return;
} else {
$this->formatsupportstoc = true;
}
$this->format = course_get_format($course);
$this->course = $this->format->get_course();
// Has additional fields.
course_create_sections_if_missing($course, range(0, $this->course->numsections));
$this->set_modules();
$this->set_chapters();
$this->set_footer();
}
示例9: delete_displayed_images
private function delete_displayed_images()
{
global $CFG, $DB;
/* We only process this information if the course we are backing up is in the
'grid' format (target format can change depending of restore options).
Note: This appears to be a bit silly as this code is executed even if the
course is not in the 'grid' format.
*/
$courseid = $this->task->get_courseid();
$format = $DB->get_field('course', 'format', array('id' => $courseid));
if ($format != 'grid') {
return;
}
require_once $CFG->dirroot . '/course/format/lib.php';
// For format_base.
require_once $CFG->dirroot . '/course/format/grid/lib.php';
// For format_grid.
$courseformat = course_get_format($courseid);
$courseformat->delete_displayed_images();
}
示例10: addsection_action
/**
* Add a new section with the provided title and (optional) summary
*
* @return string
*/
public function addsection_action()
{
global $CFG, $PAGE, $DB;
require_once $CFG->dirroot . '/course/lib.php';
$sectioname = required_param('newsection', PARAM_TEXT);
$summary = optional_param('summary', '', PARAM_RAW);
require_sesskey();
$courseid = $PAGE->context->get_course_context()->instanceid;
$course = course_get_format($courseid)->get_course();
$course->numsections++;
course_get_format($course)->update_course_format_options(array('numsections' => $course->numsections));
course_create_sections_if_missing($course, range(0, $course->numsections));
$modinfo = get_fast_modinfo($course);
$section = $modinfo->get_section_info($course->numsections, MUST_EXIST);
$DB->set_field('course_sections', 'name', $sectioname, array('id' => $section->id));
$DB->set_field('course_sections', 'summary', $summary, array('id' => $section->id));
$DB->set_field('course_sections', 'summaryformat', FORMAT_HTML, array('id' => $section->id));
rebuild_course_cache($course->id);
redirect(course_get_url($course, $section->section));
}
示例11: display
/**
* Displays the activities list in cases when course view page is not
* redirected to the activity page.
*
* @param stdClass $course record from table course
* @param bool $orphaned if false displays the main activity (if present)
* if true displays all other activities
*/
public function display($course, $orphaned)
{
$courserenderer = $this->page->get_renderer('core', 'course');
$output = '';
$modinfo = get_fast_modinfo($course);
if ($orphaned) {
if (!empty($modinfo->sections[1])) {
$output .= $this->output->heading(get_string('orphaned', 'format_singleactivity'), 3, 'sectionname');
$output .= $this->output->box(get_string('orphanedwarning', 'format_singleactivity'));
$output .= $courserenderer->course_section_cm_list($course, 1, 1);
}
} else {
$output .= $courserenderer->course_section_cm_list($course, 0, 0);
if (empty($modinfo->sections[0]) && course_get_format($course)->activity_has_subtypes()) {
// Course format was unable to automatically redirect to add module page.
$output .= $courserenderer->course_section_add_cm_control($course, 0, 0);
}
}
return $output;
}
示例12: process_topcoll
/**
* Process the 'plugin_format_topcoll_course' element within the 'course' element in the 'course.xml' file in the
* '/course' folder of the zipped backup 'mbz' file.
*/
public function process_topcoll($data)
{
global $DB;
$data = (object) $data;
// We only process this information if the course we are restoring to
// has 'topcoll' format (target format can change depending of restore options).
$format = $DB->get_field('course', 'format', array('id' => $this->task->get_courseid()));
if ($format != 'topcoll') {
return;
}
$data->courseid = $this->task->get_courseid();
if (!($course = $DB->get_record('course', array('id' => $data->courseid)))) {
print_error('invalidcourseid', 'error');
}
// From /course/view.php.
$courseformat = course_get_format($course);
if (empty($data->layoutcolumns)) {
// Cope with backups from Moodle 2.0, 2.1 and 2.2 versions.
$data->layoutcolumns = get_config('format_topcoll', 'defaultlayoutcolumns');
}
$courseformat->restore_topcoll_setting($data->courseid, $data->layoutelement, $data->layoutstructure, $data->layoutcolumns, $data->tgfgcolour, $data->tgbgcolour, $data->tgbghvrcolour);
// No need to annotate anything here.
}
示例13: get_fast_modinfo
// Must set layout before gettting section info. See MDL-47555.
$PAGE->set_pagelayout('course');
if ($section and $section > 0) {
// Get section details and check it exists.
$modinfo = get_fast_modinfo($course);
$coursesections = $modinfo->get_section_info($section, MUST_EXIST);
// Check user is allowed to see it.
if (!$coursesections->uservisible) {
// Note: We actually already know they don't have this capability
// or uservisible would have been true; this is just to get the
// correct error message shown.
require_capability('moodle/course:viewhiddensections', $context);
}
}
// Fix course format if it is no longer installed
$course->format = course_get_format($course)->get_format();
$PAGE->set_pagetype('course-view-' . $course->format);
$PAGE->set_other_editing_capability('moodle/course:update');
$PAGE->set_other_editing_capability('moodle/course:manageactivities');
$PAGE->set_other_editing_capability('moodle/course:activityvisibility');
if (course_format_uses_sections($course->format)) {
$PAGE->set_other_editing_capability('moodle/course:sectionvisibility');
$PAGE->set_other_editing_capability('moodle/course:movesections');
}
// Preload course format renderer before output starts.
// This is a little hacky but necessary since
// format.php is not included until after output starts
if (file_exists($CFG->dirroot . '/course/format/' . $course->format . '/renderer.php')) {
require_once $CFG->dirroot . '/course/format/' . $course->format . '/renderer.php';
if (class_exists('format_' . $course->format . '_renderer')) {
// call get_renderer only if renderer is defined in format plugin
示例14: generate_sections_and_activities
/**
* Generates an array of sections and an array of activities for the given course.
*
* This method uses the cache to improve performance and avoid the get_fast_modinfo call
*
* @param stdClass $course
* @return array Array($sections, $activities)
*/
protected function generate_sections_and_activities(stdClass $course)
{
global $CFG;
require_once $CFG->dirroot . '/course/lib.php';
$modinfo = get_fast_modinfo($course);
$sections = $modinfo->get_section_info_all();
// For course formats using 'numsections' trim the sections list
$courseformatoptions = course_get_format($course)->get_format_options();
if (isset($courseformatoptions['numsections'])) {
$sections = array_slice($sections, 0, $courseformatoptions['numsections'] + 1, true);
}
$activities = array();
foreach ($sections as $key => $section) {
// Clone and unset summary to prevent $SESSION bloat (MDL-31802).
$sections[$key] = clone $section;
unset($sections[$key]->summary);
$sections[$key]->hasactivites = false;
if (!array_key_exists($section->section, $modinfo->sections)) {
continue;
}
foreach ($modinfo->sections[$section->section] as $cmid) {
$cm = $modinfo->cms[$cmid];
$activity = new stdClass();
$activity->id = $cm->id;
$activity->course = $course->id;
$activity->section = $section->section;
$activity->name = $cm->name;
$activity->icon = $cm->icon;
$activity->iconcomponent = $cm->iconcomponent;
$activity->hidden = !$cm->visible;
$activity->modname = $cm->modname;
$activity->nodetype = navigation_node::NODETYPE_LEAF;
$activity->onclick = $cm->onclick;
$url = $cm->url;
if (!$url) {
$activity->url = null;
$activity->display = false;
} else {
$activity->url = $url->out();
$activity->display = $cm->uservisible ? true : false;
if (self::module_extends_navigation($cm->modname)) {
$activity->nodetype = navigation_node::NODETYPE_BRANCH;
}
}
$activities[$cmid] = $activity;
if ($activity->display) {
$sections[$key]->hasactivites = true;
}
}
}
return array($sections, $activities);
}
示例15: update_courses
/**
* Update courses
*
* @param array $courses
* @since Moodle 2.5
*/
public static function update_courses($courses) {
global $CFG, $DB;
require_once($CFG->dirroot . "/course/lib.php");
$warnings = array();
$params = self::validate_parameters(self::update_courses_parameters(),
array('courses' => $courses));
$availablethemes = core_component::get_plugin_list('theme');
$availablelangs = get_string_manager()->get_list_of_translations();
foreach ($params['courses'] as $course) {
// Catch any exception while updating course and return as warning to user.
try {
// Ensure the current user is allowed to run this function.
$context = context_course::instance($course['id'], MUST_EXIST);
self::validate_context($context);
$oldcourse = course_get_format($course['id'])->get_course();
require_capability('moodle/course:update', $context);
// Check if user can change category.
if (array_key_exists('categoryid', $course) && ($oldcourse->category != $course['categoryid'])) {
require_capability('moodle/course:changecategory', $context);
$course['category'] = $course['categoryid'];
}
// Check if the user can change fullname.
if (array_key_exists('fullname', $course) && ($oldcourse->fullname != $course['fullname'])) {
require_capability('moodle/course:changefullname', $context);
}
// Check if the user can change shortname.
if (array_key_exists('shortname', $course) && ($oldcourse->shortname != $course['shortname'])) {
require_capability('moodle/course:changeshortname', $context);
}
// Check if the user can change the idnumber.
if (array_key_exists('idnumber', $course) && ($oldcourse->idnumber != $course['idnumber'])) {
require_capability('moodle/course:changeidnumber', $context);
}
// Check if user can change summary.
if (array_key_exists('summary', $course) && ($oldcourse->summary != $course['summary'])) {
require_capability('moodle/course:changesummary', $context);
}
// Summary format.
if (array_key_exists('summaryformat', $course) && ($oldcourse->summaryformat != $course['summaryformat'])) {
require_capability('moodle/course:changesummary', $context);
$course['summaryformat'] = external_validate_format($course['summaryformat']);
}
// Check if user can change visibility.
if (array_key_exists('visible', $course) && ($oldcourse->visible != $course['visible'])) {
require_capability('moodle/course:visibility', $context);
}
// Make sure lang is valid.
if (array_key_exists('lang', $course) && empty($availablelangs[$course['lang']])) {
throw new moodle_exception('errorinvalidparam', 'webservice', '', 'lang');
}
// Make sure theme is valid.
if (array_key_exists('forcetheme', $course)) {
if (!empty($CFG->allowcoursethemes)) {
if (empty($availablethemes[$course['forcetheme']])) {
throw new moodle_exception('errorinvalidparam', 'webservice', '', 'forcetheme');
} else {
$course['theme'] = $course['forcetheme'];
}
}
}
// Make sure completion is enabled before setting it.
if (array_key_exists('enabledcompletion', $course) && !completion_info::is_enabled_for_site()) {
$course['enabledcompletion'] = 0;
}
// Make sure maxbytes are less then CFG->maxbytes.
if (array_key_exists('maxbytes', $course)) {
$course['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $course['maxbytes']);
}
if (!empty($course['courseformatoptions'])) {
foreach ($course['courseformatoptions'] as $option) {
if (isset($option['name']) && isset($option['value'])) {
$course[$option['name']] = $option['value'];
}
}
}
// Update course if user has all required capabilities.
//.........这里部分代码省略.........