/**
  * Return a block_contents object 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 representation of the block, for rendering.
  * @since Moodle 2.0.
  */
 public function get_content_for_output($output)
 {
     global $CFG;
     $bc = new block_contents($this->html_attributes());
     $bc->attributes['data-block'] = $this->name();
     $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');
     }
     if (!$this->hide_header()) {
         $bc->title = $this->title;
     }
     if (empty($bc->title)) {
         $bc->arialabel = new lang_string('pluginname', get_class($this));
         $this->arialabel = $bc->arialabel;
     }
     if ($this->page->user_is_editing()) {
         $bc->controls = $this->page->blocks->edit_controls($this);
     } else {
         // we must not use is_empty on hidden blocks
         if ($this->is_empty() && !$bc->controls) {
             return null;
         }
     }
     if (empty($CFG->allowuserblockhiding) || empty($bc->content) && empty($bc->footer) || !$this->instance_can_be_collapsed()) {
         $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;
         }
     }
     if ($this->instance_can_be_docked() && !$this->hide_header()) {
         $bc->dockable = true;
     }
     $bc->annotation = '';
     // TODO MDL-19398 need to work out what to say here.
     return $bc;
 }
示例#2
0
/**
 * Return a {@link block_contents} representing the add a new block UI, if
 * this user is allowed to see it.
 *
 * @return block_contents an appropriate block_contents, or null if the user
 * cannot add any blocks here.
 */
function block_add_block_ui($page, $output)
{
    global $CFG, $OUTPUT;
    if (!$page->user_is_editing() || !$page->user_can_edit_blocks()) {
        return null;
    }
    $bc = new block_contents();
    $bc->title = get_string('addblock');
    $bc->add_class('block_adminblock');
    $missingblocks = $page->blocks->get_addable_blocks();
    if (empty($missingblocks)) {
        $bc->content = get_string('noblockstoaddhere');
        return $bc;
    }
    $menu = array();
    foreach ($missingblocks as $block) {
        $blockobject = block_instance($block->name);
        if ($blockobject !== false && $blockobject->user_can_addto($page)) {
            $menu[$block->name] = $blockobject->get_title();
        }
    }
    collatorlib::asort($menu);
    $actionurl = new moodle_url($page->url, array('sesskey' => sesskey()));
    $select = new single_select($actionurl, 'bui_addblock', $menu, null, array('' => get_string('adddots')), 'add_block');
    $select->set_label(get_string('addblock'), array('class' => 'accesshide'));
    $bc->content = $OUTPUT->render($select);
    return $bc;
}
示例#3
0
 /**
  * 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($this->html_attributes());
     $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');
     }
     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;
 }
示例#4
0
/**
 * 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}&amp;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;
}
示例#5
0
/**
 * Return a {@link block_contents} representing the add a new block UI, if
 * this user is allowed to see it.
 *
 * @return block_contents an appropriate block_contents, or null if the user
 * cannot add any blocks here.
 */
function block_add_block_ui($page, $output)
{
    global $CFG, $OUTPUT;
    if (!$page->user_is_editing() || !$page->user_can_edit_blocks()) {
        return null;
    }
    $bc = new block_contents();
    $bc->title = get_string('addblock');
    $bc->add_class('block_adminblock');
    $missingblocks = $page->blocks->get_addable_blocks();
    if (empty($missingblocks)) {
        $bc->content = get_string('noblockstoaddhere');
        return $bc;
    }
    $menu = array();
    foreach ($missingblocks as $block) {
        $blockobject = block_instance($block->name);
        if ($blockobject !== false && $blockobject->user_can_addto($page)) {
            $menu[$block->name] = $blockobject->get_title();
        }
    }
    asort($menu, SORT_LOCALE_STRING);
    $actionurl = $page->url->out_action();
    $select = html_select::make_popup_form($actionurl, 'bui_addblock', $menu, 'add_block');
    $select->nothinglabel = get_string('adddots');
    $bc->content = $OUTPUT->select($select);
    return $bc;
}
示例#6
0
/**
 * 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 &lt;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.
}