/** * Returns the list of blocks to be automatically added for the newly created course * * @see blocks_add_default_course_blocks() * * @return array of default blocks, must contain two keys BLOCK_POS_LEFT and BLOCK_POS_RIGHT * each of values is an array of block names (for left and right side columns) */ public function get_default_blocks() { global $CFG; if (isset($CFG->defaultblocks)) { return blocks_parse_default_blocks_list($CFG->defaultblocks); } $blocknames = array(BLOCK_POS_LEFT => array(), BLOCK_POS_RIGHT => array()); return $blocknames; }
/** * Add the default blocks to a course. * * @param object $course a course object. */ function blocks_add_default_course_blocks($course) { global $CFG; if (!empty($CFG->defaultblocks_override)) { $blocknames = blocks_parse_default_blocks_list($CFG->defaultblocks_override); } else { if ($course->id == SITEID) { $blocknames = blocks_get_default_site_course_blocks(); } else { if (!empty($CFG->{'defaultblocks_' . $course->format})) { $blocknames = blocks_parse_default_blocks_list($CFG->{'defaultblocks_' . $course->format}); } else { $blocknames = course_get_format($course)->get_default_blocks(); } } } if ($course->id == SITEID) { $pagetypepattern = 'site-index'; } else { $pagetypepattern = 'course-view-*'; } $page = new moodle_page(); $page->set_course($course); $page->blocks->add_blocks($blocknames, $pagetypepattern); }
/** * Add the default blocks to a course. * * @param object $course a course object. */ function blocks_add_default_course_blocks($course) { global $CFG; if (!empty($CFG->defaultblocks_override)) { $blocknames = blocks_parse_default_blocks_list($CFG->defaultblocks_override); } else { if ($course->id == SITEID) { $blocknames = blocks_get_default_site_course_blocks(); } else { $defaultblocks = 'defaultblocks_' . $course->format; if (!empty($CFG->{$defaultblocks})) { $blocknames = blocks_parse_default_blocks_list($CFG->{$defaultblocks}); } else { $formatconfig = $CFG->dirroot . '/course/format/' . $course->format . '/config.php'; $format = array(); // initialize array in external file if (is_readable($formatconfig)) { include $formatconfig; } if (!empty($format['defaultblocks'])) { $blocknames = blocks_parse_default_blocks_list($format['defaultblocks']); } else { if (!empty($CFG->defaultblocks)) { $blocknames = blocks_parse_default_blocks_list($CFG->defaultblocks); } else { $blocknames = array(BLOCK_POS_LEFT => array(), BLOCK_POS_RIGHT => array('search_forums', 'news_items', 'calendar_upcoming', 'recent_activity')); } } } } } if ($course->id == SITEID) { $pagetypepattern = 'site-index'; } else { $pagetypepattern = 'course-view-*'; } $page = new moodle_page(); $page->set_course($course); $page->blocks->add_blocks($blocknames, $pagetypepattern); }
/** * Returns the list of blocks to be automatically added for the newly created course * * This function checks the existence of the file config.php in the course format folder. * If file exists and contains the code * $format['defaultblocks'] = 'leftblock1,leftblock2:rightblock1,rightblock2'; * these blocks are used, otherwise parent function is called * * @return array of default blocks, must contain two keys BLOCK_POS_LEFT and BLOCK_POS_RIGHT * each of values is an array of block names (for left and right side columns) */ public function get_default_blocks() { global $CFG; $formatconfig = $CFG->dirroot . '/course/format/' . $this->format . '/config.php'; $format = array(); // initialize array in external file if (is_readable($formatconfig)) { include $formatconfig; } if (!empty($format['defaultblocks'])) { return blocks_parse_default_blocks_list($format['defaultblocks']); } return parent::get_default_blocks(); }
/** * Returns the list of blocks to be automatically added for the newly created course * * @see blocks_add_default_course_blocks() * * @return array of default blocks, must contain two keys BLOCK_POS_LEFT and BLOCK_POS_RIGHT * each of values is an array of block names (for left and right side columns) */ public function get_default_blocks() { global $CFG; if (!empty($CFG->defaultblocks)) { return blocks_parse_default_blocks_list($CFG->defaultblocks); } $blocknames = array(BLOCK_POS_LEFT => array(), BLOCK_POS_RIGHT => array('search_forums', 'news_items', 'calendar_upcoming', 'recent_activity')); return $blocknames; }
/** * @deprecated since 2.0 * Dispite what this function is called, it seems to be mostly used to populate * the default blocks when a new course (or whatever) is created. * @param object $page the page to add default blocks to. * @return boolean success or failure. */ function blocks_repopulate_page($page) { global $CFG; debugging('Call to deprecated function blocks_repopulate_page. ' . 'Use a more specific method like blocks_add_default_course_blocks, ' . 'or just call $PAGE->blocks->add_blocks()', DEBUG_DEVELOPER); /// If the site override has been defined, it is the only valid one. if (!empty($CFG->defaultblocks_override)) { $blocknames = $CFG->defaultblocks_override; } else { $blocknames = $page->blocks_get_default(); } $blocks = blocks_parse_default_blocks_list($blocknames); $page->blocks->add_blocks($blocks); return true; }