/** * Prints a nice side block with an optional header. The content can either * be a block of HTML or a list of text with optional icons. * * @todo Finish documenting this function. Show example of various attributes, etc. * * @static int $block_id Increments for each call to the function * @param string $heading HTML for the heading. Can include full HTML or just * plain text - plain text will automatically be enclosed in the appropriate * heading tags. * @param string $content HTML for the content * @param array $list an alternative to $content, it you want a list of things with optional icons. * @param array $icons optional icons for the things in $list. * @param string $footer Extra HTML content that gets output at the end, inside a <div class="footer"> * @param array $attributes an array of attribute => value pairs that are put on the * outer div of this block. If there is a class attribute ' sideblock' gets appended to it. If there isn't * already a class, class='sideblock' is used. * @param string $title Plain text title, as embedded in the $heading. * @deprecated */ function print_side_block($heading = '', $content = '', $list = NULL, $icons = NULL, $footer = '', $attributes = array(), $title = '') { global $OUTPUT; // We don't use $heading, becuse it often contains HTML that we don't want. // However, sometimes $title is not set, but $heading is. if (empty($title)) { $title = strip_tags($heading); } // Render list contents to HTML if required. if (empty($content) && $list) { $content = $OUTPUT->list_block_contents($icons, $list); } $bc = new block_contents(); $bc->content = $content; $bc->footer = $footer; $bc->title = $title; if (isset($attributes['id'])) { $bc->id = $attributes['id']; unset($attributes['id']); } if (isset($attributes['class'])) { $bc->set_classes($attributes['class']); unset($attributes['class']); } $bc->attributes = $attributes; echo $OUTPUT->block($bc, BLOCK_POS_LEFT); // POS LEFT may be wrong, but no way to get a better guess here. }
/** * If left menu is turned on, then this will * print the menu in a block * * @param int $cmid Course Module ID for this lesson * @param object $lesson Full lesson record object * @return void **/ function lesson_menu_block_contents($cmid, $lesson) { global $CFG, $DB; if (!$lesson->displayleft) { return null; } $pageid = $DB->get_field('lesson_pages', 'id', array('lessonid' => $lesson->id, 'prevpageid' => 0)); $params = array("lessonid" => $lesson->id); $pages = $DB->get_records_select('lesson_pages', "lessonid = :lessonid", $params); $currentpageid = optional_param('pageid', $pageid, PARAM_INT); if (!$pageid || !$pages) { return null; } $content = '<a href="#maincontent" class="skip">' . get_string('skip', 'lesson') . "</a>\n<div class=\"menuwrapper\">\n<ul>\n"; while ($pageid != 0) { $page = $pages[$pageid]; // Only process branch tables with display turned on if ($page->qtype == LESSON_BRANCHTABLE and $page->display) { if ($page->id == $currentpageid) { $content .= '<li class="selected">' . format_string($page->title, true) . "</li>\n"; } else { $content .= "<li class=\"notselected\"><a href=\"{$CFG->wwwroot}/mod/lesson/view.php?id={$cmid}&pageid={$page->id}\">" . format_string($page->title, true) . "</a></li>\n"; } } $pageid = $page->nextpageid; } $content .= "</ul>\n</div>\n"; $bc = new block_contents(); $bc->title = get_string('lessonmenu', 'lesson'); $bc->set_classes('menu'); $bc->content = $content; return $bc; }
/** * Return a block_contents oject representing the full contents of this block. * * This internally calls ->get_content(), and then adds the editing controls etc. * * You probably should not override this method, but instead override * {@link html_attributes()}, {@link formatted_contents()} or {@link get_content()}, * {@link hide_header()}, {@link (get_edit_controls)}, etc. * * @return block_contents a represntation of the block, for rendering. * @since Moodle 2.0. */ public function get_content_for_output($output) { global $CFG; $bc = new block_contents(); $bc->blockinstanceid = $this->instance->id; $bc->blockpositionid = $this->instance->blockpositionid; if ($this->instance->visible) { $bc->content = $this->formatted_contents($output); if (!empty($this->content->footer)) { $bc->footer = $this->content->footer; } } else { $bc->add_class('invisible'); } $attributes = $this->html_attributes(); if (isset($attributes['id'])) { $bc->id = $attributes['id']; unset($attributes['id']); } if (isset($attributes['class'])) { $bc->set_classes($attributes['class']); unset($attributes['class']); } $bc->attributes = $attributes; if (!$this->hide_header()) { $bc->title = $this->title; } if ($this->page->user_is_editing()) { $bc->controls = $this->page->blocks->edit_controls($this); } if ($this->is_empty() && !$bc->controls) { return null; } if (empty($CFG->allowuserblockhiding) || empty($bc->content) && empty($bc->footer)) { $bc->collapsible = block_contents::NOT_HIDEABLE; } else { if (get_user_preferences('block' . $bc->blockinstanceid . 'hidden', false)) { $bc->collapsible = block_contents::HIDDEN; } else { $bc->collapsible = block_contents::VISIBLE; } } $bc->annotation = ''; // TODO MDL-19398 need to work out what to say here. return $bc; }