Exemplo n.º 1
0
/**
 * Add the book TOC sticky block to the default region
 *
 * @param array $chapters
 * @param stdClass $chapter
 * @param stdClass $book
 * @param stdClass $cm
 * @param bool $edit
 */
function book_add_fake_block($chapters, $chapter, $book, $cm, $edit)
{
    global $OUTPUT, $PAGE;
    $toc = book_get_toc($chapters, $chapter, $book, $cm, $edit, 0);
    $bc = new block_contents();
    $bc->title = get_string('toc', 'mod_book');
    $bc->attributes['class'] = 'block block_book_toc';
    $bc->content = $toc;
    $defaultregion = $PAGE->blocks->get_default_region();
    $PAGE->blocks->add_fake_block($bc, $defaultregion);
}
Exemplo n.º 2
0
/**
 * Add the book TOC sticky block to the 1st region available
 *
 * @param array $chapters
 * @param stdClass $chapter
 * @param stdClass $book
 * @param stdClass $cm
 * @param bool $edit
 */
function book_add_fake_block($chapters, $chapter, $book, $cm, $edit)
{
    global $OUTPUT, $PAGE;
    $toc = book_get_toc($chapters, $chapter, $book, $cm, $edit, 0);
    if ($edit) {
        $toc .= '<div class="book_faq">';
        $toc .= $OUTPUT->help_icon('faq', 'mod_book', get_string('faq', 'mod_book'));
        $toc .= '</div>';
    }
    $bc = new block_contents();
    $bc->title = get_string('toc', 'mod_book');
    $bc->attributes['class'] = 'block';
    $bc->content = $toc;
    $regions = $PAGE->blocks->get_regions();
    $firstregion = reset($regions);
    $PAGE->blocks->add_fake_block($bc, $firstregion);
}
Exemplo n.º 3
0
/**
 * Add the book TOC sticky block to the default region.
 *
 * @param   array       $chapters   The Chapters in the book
 * @param   stdClass    $chapter    The current chapter
 * @param   stdClass    $book       The book
 * @param   stdClass    $cm         The course module
 * @param   bool        $edit       Whether the user is editing
 */
function book_add_fake_block($chapters, $chapter, $book, $cm, $edit = null)
{
    global $PAGE, $USER;
    if ($edit === null) {
        if (has_capability('mod/book:edit', context_module::instance($cm->id))) {
            if (isset($USER->editing)) {
                $edit = $USER->editing;
            } else {
                $edit = 0;
            }
        } else {
            $edit = 0;
        }
    }
    $toc = book_get_toc($chapters, $chapter, $book, $cm, $edit, 0);
    $bc = new block_contents();
    $bc->title = get_string('toc', 'mod_book');
    $bc->attributes['class'] = 'block block_book_toc';
    $bc->content = $toc;
    $defaultregion = $PAGE->blocks->get_default_region();
    $PAGE->blocks->add_fake_block($bc, $defaultregion);
}