当前位置: 首页>>代码示例>>PHP>>正文


PHP book_preload_chapters函数代码示例

本文整理汇总了PHP中book_preload_chapters函数的典型用法代码示例。如果您正苦于以下问题:PHP book_preload_chapters函数的具体用法?PHP book_preload_chapters怎么用?PHP book_preload_chapters使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了book_preload_chapters函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: booktool_exportimscp_build_package

/**
 * Export one book as IMSCP package
 *
 * @param stdClass $book book instance
 * @param context_module $context
 * @return bool|stored_file
 */
function booktool_exportimscp_build_package($book, $context)
{
    global $DB;
    $fs = get_file_storage();
    if ($packagefile = $fs->get_file($context->id, 'booktool_exportimscp', 'package', $book->revision, '/', 'imscp.zip')) {
        return $packagefile;
    }
    // fix structure and test if chapters present
    if (!book_preload_chapters($book)) {
        print_error('nochapters', 'booktool_exportimscp');
    }
    // prepare temp area with package contents
    booktool_exportimscp_prepare_files($book, $context);
    $packer = get_file_packer('application/zip');
    $areafiles = $fs->get_area_files($context->id, 'booktool_exportimscp', 'temp', $book->revision, "sortorder, itemid, filepath, filename", false);
    $files = array();
    foreach ($areafiles as $file) {
        $path = $file->get_filepath() . $file->get_filename();
        $path = ltrim($path, '/');
        $files[$path] = $file;
    }
    unset($areafiles);
    $packagefile = $packer->archive_to_storage($files, $context->id, 'booktool_exportimscp', 'package', $book->revision, '/', 'imscp.zip');
    // drop temp area
    $fs->delete_area_files($context->id, 'booktool_exportimscp', 'temp', $book->revision);
    // delete older versions
    $sql = "SELECT DISTINCT itemid\n              FROM {files}\n             WHERE contextid = :contextid AND component = 'booktool_exportimscp' AND itemid < :revision";
    $params = array('contextid' => $context->id, 'revision' => $book->revision);
    $revisions = $DB->get_records_sql($sql, $params);
    foreach ($revisions as $rev => $unused) {
        $fs->delete_area_files($context->id, 'booktool_exportimscp', 'temp', $rev);
        $fs->delete_area_files($context->id, 'booktool_exportimscp', 'package', $rev);
    }
    return $packagefile;
}
开发者ID:evltuma,项目名称:moodle,代码行数:42,代码来源:locallib.php

示例2: view_book

 /**
  * Simulate the book/view.php web interface page: trigger events, completion, etc...
  *
  * @param int $bookid the book instance id
  * @param int $chapterid the book chapter id
  * @return array of warnings and status result
  * @since Moodle 3.0
  * @throws moodle_exception
  */
 public static function view_book($bookid, $chapterid = 0)
 {
     global $DB, $CFG;
     require_once $CFG->dirroot . "/mod/book/lib.php";
     require_once $CFG->dirroot . "/mod/book/locallib.php";
     $params = self::validate_parameters(self::view_book_parameters(), array('bookid' => $bookid, 'chapterid' => $chapterid));
     $bookid = $params['bookid'];
     $chapterid = $params['chapterid'];
     $warnings = array();
     // Request and permission validation.
     $book = $DB->get_record('book', array('id' => $bookid), '*', MUST_EXIST);
     list($course, $cm) = get_course_and_cm_from_instance($book, 'book');
     $context = context_module::instance($cm->id);
     self::validate_context($context);
     require_capability('mod/book:read', $context);
     $chapters = book_preload_chapters($book);
     $firstchapterid = 0;
     $lastchapterid = 0;
     foreach ($chapters as $ch) {
         if ($ch->hidden) {
             continue;
         }
         if (!$firstchapterid) {
             $firstchapterid = $ch->id;
         }
         $lastchapterid = $ch->id;
     }
     if (!$chapterid) {
         // Trigger the module viewed events since we are displaying the book.
         book_view($book, null, false, $course, $cm, $context);
         $chapterid = $firstchapterid;
     }
     // Check if book is empty (warning).
     if (!$chapterid) {
         $warnings[] = array('item' => 'book', 'itemid' => $book->id, 'warningcode' => '1', 'message' => get_string('nocontent', 'mod_book'));
     } else {
         $chapter = $DB->get_record('book_chapters', array('id' => $chapterid, 'bookid' => $book->id));
         $viewhidden = has_capability('mod/book:viewhiddenchapters', $context);
         if (!$chapter or $chapter->hidden and !$viewhidden) {
             throw new moodle_exception('errorchapter', 'mod_book');
         }
         // Trigger the chapter viewed event.
         $islastchapter = $chapter->id == $lastchapterid ? true : false;
         book_view($book, $chapter, $islastchapter, $course, $cm, $context);
     }
     $result = array();
     $result['status'] = true;
     $result['warnings'] = $warnings;
     return $result;
 }
开发者ID:pzhu2004,项目名称:moodle,代码行数:59,代码来源:external.php

示例3: array

// Switch hidden state.
$chapter->hidden = $chapter->hidden ? 0 : 1;

// Update record.
$DB->update_record('book_chapters', $chapter);

// Change visibility of subchapters too.
if (!$chapter->subchapter) {
    $chapters = $DB->get_records('book_chapters', array('bookid'=>$book->id), 'pagenum', 'id, subchapter, hidden');
    $found = 0;
    foreach ($chapters as $ch) {
        if ($ch->id == $chapter->id) {
            $found = 1;
        } else if ($found and $ch->subchapter) {
            $ch->hidden = $chapter->hidden;
            $DB->update_record('book_chapters', $ch);
        } else if ($found) {
            break;
        }
    }
}

add_to_log($course->id, 'course', 'update mod', '../mod/book/view.php?id='.$cm->id, 'book '.$book->id);
add_to_log($course->id, 'book', 'update', 'view.php?id='.$cm->id, $book->id, $cm->id);

book_preload_chapters($book); // fix structure
$DB->set_field('book', 'revision', $book->revision+1, array('id'=>$book->id));

redirect('view.php?id='.$cm->id.'&chapterid='.$chapter->id);

开发者ID:nicusX,项目名称:moodle,代码行数:29,代码来源:show.php

示例4: array

                    $fs->delete_area_files($context->id, 'mod_book', 'chapter', $ch->id);
                    $DB->delete_records('book_chapters', array('id' => $ch->id));
                    \mod_book\event\chapter_deleted::create_from_chapter($book, $context, $ch)->trigger();
                } else {
                    if ($found) {
                        break;
                    }
                }
            }
        }
        $chapters->close();
    }
    $fs->delete_area_files($context->id, 'mod_book', 'chapter', $chapter->id);
    $DB->delete_records('book_chapters', array('id' => $chapter->id));
    \mod_book\event\chapter_deleted::create_from_chapter($book, $context, $chapter)->trigger();
    book_preload_chapters($book);
    // Fix structure.
    $DB->set_field('book', 'revision', $book->revision + 1, array('id' => $book->id));
    redirect('view.php?id=' . $cm->id);
}
echo $OUTPUT->header();
echo $OUTPUT->heading($book->name);
// The operation has not been confirmed yet so ask the user to do so.
if ($chapter->subchapter) {
    $strconfirm = get_string('confchapterdelete', 'mod_book');
} else {
    $strconfirm = get_string('confchapterdeleteall', 'mod_book');
}
echo '<br />';
$continue = new moodle_url('/mod/book/delete.php', array('id' => $cm->id, 'chapterid' => $chapter->id, 'confirm' => 1));
$cancel = new moodle_url('/mod/book/view.php', array('id' => $cm->id, 'chapterid' => $chapter->id));
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:31,代码来源:delete.php

示例5: book_pluginfile

/**
 * Serves the book attachments. Implements needed access control ;-)
 *
 * @param stdClass $course course object
 * @param cm_info $cm course module object
 * @param context $context context object
 * @param string $filearea file area
 * @param array $args extra arguments
 * @param bool $forcedownload whether or not force download
 * @param array $options additional options affecting the file serving
 * @return bool false if file not found, does not return if found - just send the file
 */
function book_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array())
{
    global $CFG, $DB;
    if ($context->contextlevel != CONTEXT_MODULE) {
        return false;
    }
    require_course_login($course, true, $cm);
    if ($filearea !== 'chapter') {
        return false;
    }
    if (!has_capability('mod/book:read', $context)) {
        return false;
    }
    $chid = (int) array_shift($args);
    if (!($book = $DB->get_record('book', array('id' => $cm->instance)))) {
        return false;
    }
    if (!($chapter = $DB->get_record('book_chapters', array('id' => $chid, 'bookid' => $book->id)))) {
        return false;
    }
    if ($chapter->hidden and !has_capability('mod/book:viewhiddenchapters', $context)) {
        return false;
    }
    // Download the contents of a chapter as an html file.
    if ($args[0] == 'index.html') {
        $filename = "index.html";
        // We need to rewrite the pluginfile URLs so the media filters can work.
        $content = file_rewrite_pluginfile_urls($chapter->content, 'webservice/pluginfile.php', $context->id, 'mod_book', 'chapter', $chapter->id);
        $formatoptions = new stdClass();
        $formatoptions->noclean = true;
        $formatoptions->overflowdiv = true;
        $formatoptions->context = $context;
        $content = format_text($content, $chapter->contentformat, $formatoptions);
        // Remove @@PLUGINFILE@@/.
        $options = array('reverse' => true);
        $content = file_rewrite_pluginfile_urls($content, 'webservice/pluginfile.php', $context->id, 'mod_book', 'chapter', $chapter->id, $options);
        $content = str_replace('@@PLUGINFILE@@/', '', $content);
        $titles = "";
        // Format the chapter titles.
        if (!$book->customtitles) {
            require_once __DIR__ . '/locallib.php';
            $chapters = book_preload_chapters($book);
            if (!$chapter->subchapter) {
                $currtitle = book_get_chapter_title($chapter->id, $chapters, $book, $context);
                // Note that we can't use the $OUTPUT->heading() in WS_SERVER mode.
                $titles = "<h3>{$currtitle}</h3>";
            } else {
                $currtitle = book_get_chapter_title($chapters[$chapter->id]->parent, $chapters, $book, $context);
                $currsubtitle = book_get_chapter_title($chapter->id, $chapters, $book, $context);
                // Note that we can't use the $OUTPUT->heading() in WS_SERVER mode.
                $titles = "<h3>{$currtitle}</h3>";
                $titles .= "<h4>{$currsubtitle}</h4>";
            }
        }
        $content = $titles . $content;
        send_file($content, $filename, 0, 0, true, true);
    } else {
        $fs = get_file_storage();
        $relativepath = implode('/', $args);
        $fullpath = "/{$context->id}/mod_book/chapter/{$chid}/{$relativepath}";
        if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
            return false;
        }
        // Nasty hack because we do not have file revisions in book yet.
        $lifetime = $CFG->filelifetime;
        if ($lifetime > 60 * 10) {
            $lifetime = 60 * 10;
        }
        // Finally send the file.
        send_stored_file($file, $lifetime, 0, $forcedownload, $options);
    }
}
开发者ID:evltuma,项目名称:moodle,代码行数:84,代码来源:lib.php

示例6: mod_book_html

 protected function mod_book_html($mod)
 {
     if (!$mod->uservisible) {
         return "";
     }
     global $DB;
     $cm = get_coursemodule_from_id('book', $mod->id, 0, false, MUST_EXIST);
     $book = $DB->get_record('book', array('id' => $cm->instance), '*', MUST_EXIST);
     $chapters = book_preload_chapters($book);
     if ($book->intro) {
         $context = context_module::instance($mod->id);
         $content = file_rewrite_pluginfile_urls($book->intro, 'pluginfile.php', $context->id, 'mod_book', 'intro', null);
         $formatoptions = new stdClass();
         $formatoptions->noclean = true;
         $formatoptions->overflowdiv = true;
         $formatoptions->context = $context;
         $content = format_text($content, $book->introformat, $formatoptions);
         return "<div class=summary-text>\n                    {$content}</div>" . $this->book_get_toc($chapters, $book, $cm);
     }
     return $this->book_get_toc($chapters, $book, $cm);
 }
开发者ID:nadavkav,项目名称:moodle-theme_snap,代码行数:21,代码来源:course_renderer.php

示例7: array

            $data->importsrc = '';
            $data->content = '';
            // updated later
            $data->contentformat = FORMAT_HTML;
            // updated later
            // make room for new page
            $sql = "UPDATE {book_chapters}\n                   SET pagenum = pagenum + 1\n                 WHERE bookid = ? AND pagenum >= ?";
            $DB->execute($sql, array($book->id, $data->pagenum));
            $data->id = $DB->insert_record('book_chapters', $data);
            // store the files
            $data = file_postupdate_standard_editor($data, 'content', $options, $context, 'mod_book', 'chapter', $data->id);
            $DB->update_record('book_chapters', $data);
            $DB->set_field('book', 'revision', $book->revision + 1, array('id' => $book->id));
            $chapter = $DB->get_record('book_chapters', array('id' => $data->id));
            \mod_book\event\chapter_created::create_from_chapter($book, $context, $chapter)->trigger();
        }
        book_preload_chapters($book);
        // fix structure
        redirect("view.php?id={$cm->id}&chapterid={$data->id}");
    }
}
// Otherwise fill and print the form.
$PAGE->set_title($book->name);
$PAGE->set_heading($course->fullname);
if ($chapters = book_preload_chapters($book)) {
    book_add_fake_block($chapters, $chapter, $book, $cm);
}
echo $OUTPUT->header();
echo $OUTPUT->heading($book->name);
$mform->display();
echo $OUTPUT->footer();
开发者ID:dg711,项目名称:moodle,代码行数:31,代码来源:edit.php


注:本文中的book_preload_chapters函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。