first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,98 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* booktool_print book printed event.
*
* @package booktool_print
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace booktool_print\event;
defined('MOODLE_INTERNAL') || die();
/**
* booktool_print book printed event class.
*
* @package booktool_print
* @since Moodle 2.6
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class book_printed extends \core\event\base {
/**
* Create instance of event.
*
* @since Moodle 2.7
*
* @param \stdClass $book
* @param \context_module $context
* @return book_printed
*/
public static function create_from_book(\stdClass $book, \context_module $context) {
$data = array(
'context' => $context,
'objectid' => $book->id
);
/** @var book_printed $event */
$event = self::create($data);
$event->add_record_snapshot('book', $book);
return $event;
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' has printed the book with course module id '$this->contextinstanceid'.";
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventbookprinted', 'booktool_print');
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/book/tool/print/index.php', array('id' => $this->contextinstanceid));
}
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
$this->data['objecttable'] = 'book';
}
public static function get_objectid_mapping() {
return array('db' => 'book', 'restore' => 'book');
}
}
@@ -0,0 +1,101 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* booktool_print chapter printed event.
*
* @package booktool_print
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace booktool_print\event;
defined('MOODLE_INTERNAL') || die();
/**
* booktool_print chapter printed event class.
*
* @package booktool_print
* @since Moodle 2.6
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class chapter_printed extends \core\event\base {
/**
* Create instance of event.
*
* @since Moodle 2.7
*
* @param \stdClass $book
* @param \context_module $context
* @param \stdClass $chapter
* @return chapter_printed
*/
public static function create_from_chapter(\stdClass $book, \context_module $context, \stdClass $chapter) {
$data = array(
'context' => $context,
'objectid' => $chapter->id,
);
/** @var chapter_printed $event */
$event = self::create($data);
$event->add_record_snapshot('book', $book);
$event->add_record_snapshot('book_chapters', $chapter);
return $event;
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' has printed the chapter with id '$this->objectid' of the book with " .
"course module id '$this->contextinstanceid'.";
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventchapterprinted', 'booktool_print');
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/book/tool/print/index.php', array('id' => $this->contextinstanceid));
}
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
$this->data['objecttable'] = 'book_chapters';
}
public static function get_objectid_mapping() {
return array('db' => 'book_chapters', 'restore' => 'book_chapter');
}
}
@@ -0,0 +1,106 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Class containing data for the view book page.
*
* @package booktool_print
* @copyright 2019 Mihail Geshoski
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace booktool_print\output;
defined('MOODLE_INTERNAL') || die();
use renderable;
use renderer_base;
use stdClass;
use templatable;
use context_module;
/**
* Class containing data for the print book page.
*
* @copyright 2019 Mihail Geshoski
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class print_book_chapter_page implements renderable, templatable {
/**
* @var object $book The book object.
*/
protected $book;
/**
* @var object $cm The course module object.
*/
protected $cm;
/**
* @var object $chapter The book chapter object.
*/
protected $chapter;
/**
* Construct this renderable.
*
* @param object $book The book
* @param object $cm The course module
* @param object $chapter The book chapter
*/
public function __construct($book, $cm, $chapter) {
$this->book = $book;
$this->cm = $cm;
$this->chapter = $chapter;
}
/**
* Export this data so it can be used as the context for a mustache template.
*
* @param renderer_base $output
* @return stdClass
*/
public function export_for_template(renderer_base $output) {
global $OUTPUT;
$context = context_module::instance($this->cm->id);
$chapters = book_preload_chapters($this->book);
$data = new stdClass();
// Print dialog link.
$data->printdialoglink = $output->render_print_book_chapter_dialog_link();
$data->booktitle = $OUTPUT->heading(format_string($this->book->name, true,
array('context' => $context)), 1);
if (!$this->book->customtitles) {
// If the current chapter is a subchapter, get the title of the parent chapter.
if ($this->chapter->subchapter) {
$parentchaptertitle = book_get_chapter_title($chapters[$this->chapter->id]->parent, $chapters,
$this->book, $context);
$data->parentchaptertitle = $OUTPUT->heading(format_string($parentchaptertitle, true,
array('context' => $context)), 2);
}
}
list($chaptercontent, $chaptervisible) = $output->render_print_book_chapter($this->chapter, $chapters,
$this->book, $this->cm);
$chapter = new stdClass();
$chapter->content = $chaptercontent;
$chapter->visible = $chaptervisible;
$data->chapter = $chapter;
return $data;
}
}
@@ -0,0 +1,103 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Class containing data for the view book page.
*
* @package booktool_print
* @copyright 2019 Mihail Geshoski
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace booktool_print\output;
defined('MOODLE_INTERNAL') || die();
use moodle_url;
use renderable;
use renderer_base;
use stdClass;
use templatable;
use context_module;
/**
* Class containing data for the print book page.
*
* @copyright 2019 Mihail Geshoski
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class print_book_page implements renderable, templatable {
/**
* @var object $book The book object.
*/
protected $book;
/**
* @var object $cm The course module object.
*/
protected $cm;
/**
* Construct this renderable.
*
* @param object $book The book
* @param object $cm The course module
*/
public function __construct($book, $cm) {
$this->book = $book;
$this->cm = $cm;
}
/**
* Export this data so it can be used as the context for a mustache template.
*
* @param renderer_base $output
* @return stdClass
*/
public function export_for_template(renderer_base $output) {
global $OUTPUT, $CFG, $SITE, $USER;
$context = context_module::instance($this->cm->id);
$chapters = book_preload_chapters($this->book);
$course = get_course($this->book->course);
$data = new stdClass();
// Print dialog link.
$data->printdialoglink = $output->render_print_book_dialog_link();
$data->booktitle = $OUTPUT->heading(format_string($this->book->name, true,
array('context' => $context)), 1);
$introtext = file_rewrite_pluginfile_urls($this->book->intro, 'pluginfile.php', $context->id, 'mod_book', 'intro', null);
$data->bookintro = format_text($introtext, $this->book->introformat,
array('noclean' => true, 'context' => $context));
$data->sitelink = \html_writer::link(new moodle_url($CFG->wwwroot),
format_string($SITE->fullname, true, array('context' => $context)));
$data->coursename = format_string($course->fullname, true, array('context' => $context));
$data->modulename = format_string($this->book->name, true, array('context' => $context));
$data->username = fullname($USER, true);
$data->printdate = userdate(time());
$data->toc = $output->render_print_book_toc($chapters, $this->book, $this->cm);
foreach ($chapters as $ch) {
list($chaptercontent, $chaptervisible) = $output->render_print_book_chapter($ch, $chapters, $this->book,
$this->cm);
$chapter = new stdClass();
$chapter->content = $chaptercontent;
$chapter->visible = $chaptervisible;
$data->chapters[] = $chapter;
}
return $data;
}
}
@@ -0,0 +1,208 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Defines the renderer for the book print tool.
*
* @package booktool_print
* @copyright 2019 Mihail Geshoski
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace booktool_print\output;
defined('MOODLE_INTERNAL') || die();
use plugin_renderer_base;
use html_writer;
use context_module;
use moodle_url;
use moodle_exception;
/**
* The renderer for the book print tool.
*
* @copyright 2019 Mihail Geshoski
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class renderer extends plugin_renderer_base {
/**
* Render the print book page.
*
* @param print_book_page $page
* @return string html for the page
* @throws moodle_exception
*/
public function render_print_book_page(print_book_page $page) {
$data = $page->export_for_template($this);
return parent::render_from_template('booktool_print/print_book', $data);
}
/**
* Render the print book chapter page.
*
* @param print_book_chapter_page $page
* @return string html for the page
* @throws moodle_exception
*/
public function render_print_book_chapter_page(print_book_chapter_page $page) {
$data = $page->export_for_template($this);
return parent::render_from_template('booktool_print/print_book_chapter', $data);
}
/**
* Render the print book chapter link.
*
* @return string html for the link
*/
public function render_print_book_chapter_dialog_link() {
$printtext = get_string('printchapter', 'booktool_print');
$printicon = $this->output->pix_icon('chapter', $printtext, 'booktool_print',
array('class' => 'icon'));
$printlinkatt = array('onclick' => 'window.print();return false;', 'class' => 'hidden-print');
return html_writer::link('#', $printicon . $printtext, $printlinkatt);
}
/**
* Render the print book link.
*
* @return string html for the link
*/
public function render_print_book_dialog_link() {
$printtext = get_string('printbook', 'booktool_print');
$printicon = $this->output->pix_icon('book', $printtext, 'booktool_print',
array('class' => 'icon'));
$printlinkatt = array('onclick' => 'window.print();return false;', 'class' => 'hidden-print');
return html_writer::link('#', $printicon . $printtext, $printlinkatt);
}
/**
* Render the print book table of contents.
*
* @param array $chapters Array of book chapters
* @param object $book The book object
* @param object $cm The curse module object
* @return string html for the TOC
*/
public function render_print_book_toc($chapters, $book, $cm) {
$first = true;
$context = context_module::instance($cm->id);
$toc = ''; // Representation of toc (HTML).
switch ($book->numbering) {
case BOOK_NUM_NONE:
$toc .= html_writer::start_tag('div', array('class' => 'book_toc_none'));
break;
case BOOK_NUM_NUMBERS:
$toc .= html_writer::start_tag('div', array('class' => 'book_toc_numbered'));
break;
case BOOK_NUM_BULLETS:
$toc .= html_writer::start_tag('div', array('class' => 'book_toc_bullets'));
break;
case BOOK_NUM_INDENTED:
$toc .= html_writer::start_tag('div', array('class' => 'book_toc_indented'));
break;
}
$toc .= html_writer::tag('a', '', array('name' => 'toc')); // Representation of toc (HTML).
$toc .= html_writer::tag('h2', get_string('toc', 'mod_book'), ['class' => 'text-center pb-5']);
$toc .= html_writer::start_tag('ul');
foreach ($chapters as $ch) {
if (!$ch->hidden) {
$title = book_get_chapter_title($ch->id, $chapters, $book, $context);
if (!$ch->subchapter) {
if ($first) {
$toc .= html_writer::start_tag('li');
} else {
$toc .= html_writer::end_tag('ul');
$toc .= html_writer::end_tag('li');
$toc .= html_writer::start_tag('li');
}
} else {
if ($first) {
$toc .= html_writer::start_tag('li');
$toc .= html_writer::start_tag('ul');
$toc .= html_writer::start_tag('li');
} else {
$toc .= html_writer::start_tag('li');
}
}
if (!$ch->subchapter) {
$toc .= html_writer::link(new moodle_url('#ch' . $ch->id), $title,
array('title' => s($title), 'class' => 'font-weight-bold text-decoration-none'));
$toc .= html_writer::start_tag('ul');
} else {
$toc .= html_writer::link(new moodle_url('#ch' . $ch->id), $title,
array('title' => s($title), 'class' => 'text-decoration-none'));
$toc .= html_writer::end_tag('li');
}
$first = false;
}
}
$toc .= html_writer::end_tag('ul');
$toc .= html_writer::end_tag('li');
$toc .= html_writer::end_tag('ul');
$toc .= html_writer::end_tag('div');
$toc = str_replace('<ul></ul>', '', $toc); // Cleanup of invalid structures.
return $toc;
}
/**
* Render the print book chapter.
*
* @param object $chapter The book chapter object
* @param array $chapters The array of book chapters
* @param object $book The book object
* @param object $cm The course module object
* @return array The array containing the content of the book chapter and visibility information
*/
public function render_print_book_chapter($chapter, $chapters, $book, $cm) {
$context = context_module::instance($cm->id);
$title = book_get_chapter_title($chapter->id, $chapters, $book, $context);
$chaptervisible = $chapter->hidden ? false : true;
$bookchapter = '';
$bookchapter .= html_writer::start_div('book_chapter pt-3', ['id' => 'ch' . $chapter->id]);
if (!$book->customtitles) {
if (!$chapter->subchapter) {
$bookchapter .= $this->output->heading($title, 2, 'text-center pb-5');
} else {
$bookchapter .= $this->output->heading($title, 3, 'text-center pb-5');
}
}
$chaptertext = file_rewrite_pluginfile_urls($chapter->content, 'pluginfile.php', $context->id,
'mod_book', 'chapter', $chapter->id);
$bookchapter .= format_text($chaptertext, $chapter->contentformat, array('noclean' => true, 'context' => $context));
$bookchapter .= html_writer::end_div();
return array($bookchapter, $chaptervisible);
}
}
@@ -0,0 +1,46 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Privacy provider implementation for booktool_print.
*
* @package booktool_print
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace booktool_print\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy provider implementation for booktool_print.
*
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}
+40
View File
@@ -0,0 +1,40 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Book module capability definition
*
* @package booktool_print
* @copyright 2011 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
$capabilities = array(
'booktool/print:print' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => array(
'guest' => CAP_ALLOW,
'frontpage' => CAP_ALLOW,
'student' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW,
)
),
);
+30
View File
@@ -0,0 +1,30 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Print booktool log events definition
*
* @package booktool_print
* @copyright 2012 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$logs = array(
array('module' => 'book', 'action' => 'print', 'mtable' => 'book', 'field' => 'name'),
array('module' => 'book', 'action' => 'print chapter', 'mtable' => 'book_chapters', 'field' => 'title')
);
+97
View File
@@ -0,0 +1,97 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Book printing
*
* @package booktool_print
* @copyright 2004-2011 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require(__DIR__.'/../../../../config.php');
require_once(__DIR__.'/locallib.php');
$id = required_param('id', PARAM_INT); // Course Module ID
$chapterid = optional_param('chapterid', 0, PARAM_INT); // Chapter ID
// =========================================================================
// security checks START - teachers and students view
// =========================================================================
$cm = get_coursemodule_from_id('book', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$book = $DB->get_record('book', array('id' => $cm->instance), '*', MUST_EXIST);
require_course_login($course, true, $cm);
$context = context_module::instance($cm->id);
require_capability('mod/book:read', $context);
require_capability('booktool/print:print', $context);
// Check all variables.
if ($chapterid) {
// Single chapter printing - only visible!
$chapter = $DB->get_record('book_chapters', array('id' => $chapterid, 'bookid' => $book->id), '*',
MUST_EXIST);
} else {
// Complete book.
$chapter = false;
}
$PAGE->set_url('/mod/book/print.php', array('id' => $id, 'chapterid' => $chapterid));
$PAGE->activityheader->disable();
$PAGE->set_pagelayout("embedded");
unset($id);
unset($chapterid);
// Security checks END.
// read chapters
$chapters = book_preload_chapters($book);
$strbooks = get_string('modulenameplural', 'mod_book');
$strbook = get_string('modulename', 'mod_book');
$strtop = get_string('top', 'mod_book');
// Page header.
$strtitle = format_string($book->name, true, array('context' => $context));
$PAGE->set_title($strtitle);
$PAGE->set_heading($strtitle);
$PAGE->requires->css('/mod/book/tool/print/print.css');
$renderer = $PAGE->get_renderer('booktool_print');
// Begin page output.
echo $OUTPUT->header();
if ($chapter) {
if ($chapter->hidden) {
require_capability('mod/book:viewhiddenchapters', $context);
}
\booktool_print\event\chapter_printed::create_from_chapter($book, $context, $chapter)->trigger();
$page = new booktool_print\output\print_book_chapter_page($book, $cm, $chapter);
} else {
\booktool_print\event\book_printed::create_from_book($book, $context)->trigger();
$page = new booktool_print\output\print_book_page($book, $cm);
}
echo $renderer->render($page);
// Finish page output.
echo $OUTPUT->footer();
@@ -0,0 +1,35 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Book module language strings
*
* @package booktool_print
* @copyright 2011 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
$string['eventbookprinted'] = 'Book printed';
$string['eventchapterprinted'] = 'Chapter printed';
$string['pluginname'] = 'Book printing';
$string['printbook'] = 'Print book';
$string['printchapter'] = 'Print this chapter';
$string['printdate'] = 'Date';
$string['printedby'] = 'Printed by';
$string['print:print'] = 'Print book';
$string['privacy:metadata'] = 'The Book printing plugin does not store any personal data.';
+64
View File
@@ -0,0 +1,64 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Print lib
*
* @package booktool_print
* @copyright 2004-2011 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
/**
* Adds module specific settings to the settings block
*
* @param settings_navigation $settings The settings navigation object
* @param navigation_node $node The node to add module settings to
*/
function booktool_print_extend_settings_navigation(settings_navigation $settings, navigation_node $node) {
$params = $settings->get_page()->url->params();
if (empty($params['id']) or empty($params['chapterid'])) {
return;
}
if (has_capability('booktool/print:print', $settings->get_page()->cm->context)) {
$url1 = new moodle_url('/mod/book/tool/print/index.php', array('id'=>$params['id']));
$url2 = new moodle_url('/mod/book/tool/print/index.php', array('id'=>$params['id'], 'chapterid'=>$params['chapterid']));
$action = new action_link($url1, get_string('printbook', 'booktool_print'), new popup_action('click', $url1));
$booknode = $node->add(get_string('printbook', 'booktool_print'), $action, navigation_node::TYPE_SETTING, null, 'printbook',
new pix_icon('book', '', 'booktool_print', array('class' => 'icon')));
$booknode->set_force_into_more_menu(true);
$action = new action_link($url2, get_string('printchapter', 'booktool_print'), new popup_action('click', $url2));
$chapternode = $node->add(get_string('printchapter', 'booktool_print'), $action, navigation_node::TYPE_SETTING, null,
'printchapter', new pix_icon('chapter', '', 'booktool_print', array('class' => 'icon')));
$chapternode->set_force_into_more_menu(true);
}
}
/**
* Return read actions.
*
* Note: This is not used by new logging system. Event with
* crud = 'r' and edulevel = LEVEL_PARTICIPATING will
* be considered as view action.
*
* @return array
*/
function booktool_print_get_view_actions() {
return array('print');
}
+36
View File
@@ -0,0 +1,36 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Book print lib
*
* @package booktool_print
* @copyright 2011 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
require_once(__DIR__.'/lib.php');
require_once($CFG->dirroot.'/mod/book/locallib.php');
/**
* @deprecated since Moodle 3.7
*/
function booktool_print_get_toc() {
throw new coding_exception(__FUNCTION__ . ' can not be used any more. Please use booktool_print renderer
function render_print_book_toc().');
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 307 B

+3
View File
@@ -0,0 +1,3 @@
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [
<!ENTITY ns_flows "http://ns.adobe.com/Flows/1.0/">
]><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" preserveAspectRatio="xMinYMid meet" overflow="visible"><path d="M4 16H0V2l2-2h8.5c.8 0 1.5.7 1.5 1.5V4h-1V2.5c0-.8-.7-1.5-1.5-1.5H3.1l-1 1h6.4c.8 0 1.5.7 1.5 1.5V4H8.6L6 6.6v3.6c-1.2.4-2 1.5-2 2.8v3zm12 0v-3c0-1.1-.9-2-2-2H7c-1.1 0-2 .9-2 2v3h11zm-2-1H7v-1h7v1zM9 5L7 7v3h7V5H9zm4 4H8V8h2V6h3v3z" fill="#888"/></svg>

After

Width:  |  Height:  |  Size: 554 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 446 B

+3
View File
@@ -0,0 +1,3 @@
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [
<!ENTITY ns_flows "http://ns.adobe.com/Flows/1.0/">
]><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" preserveAspectRatio="xMinYMid meet" overflow="visible"><path d="M4 12c-2 0-4 1.2-4 1.2V1.1S2 0 4 0s3.1.5 4 1c.9-.5 2-1 4-1s4 1.1 4 1.1v9.6c-.3-.3-.6-.5-1-.6V1.8S12.9 1 11.4 1c-1.3 0-2.6.7-3.4 1.1C7.2 1.7 5.9 1 4.6 1 3.1 1 1 1.8 1 1.8v9.9s2-.8 3.6-.8h.1c-.3.3-.5.6-.6 1 0 .1 0 .1-.1.1zm1.9-1.8s.1 0 0 0L6 6.6 8.6 4H14V2.5S12.8 2 11.4 2C9.8 2 8 3.3 8 3.3S6.2 2 4.6 2C3.2 2 2 2.5 2 2.5v7.9s1.2-.4 2.6-.4c.5 0 .9.1 1.3.2zM16 16v-3c0-1.1-.9-2-2-2H7c-1.1 0-2 .9-2 2v3h11zm-2-1H7v-1h7v1zM9 5L7 7v3h7V5H9zm4 4H8V8h2V6h3v3z" fill="#888"/></svg>

After

Width:  |  Height:  |  Size: 773 B

+111
View File
@@ -0,0 +1,111 @@
/* ===== TOC numbering styles ===== */
/* numbering == NONE */
#page-mod-book-print .book_toc_none {
page-break-before: always;
}
#page-mod-book-print .book_toc_none ul,
#page-mod-book-print .book_toc_none ul ul {
margin-left: 0;
padding-left: 0;
}
#page-mod-book-print .book_toc_none li {
margin-top: 10px;
list-style: none;
}
#page-mod-book-print .book_toc_none li li {
margin-top: 0;
list-style: none;
}
/* numbering == NUMBERED */
#page-mod-book-print .book_toc_numbered {
page-break-before: always;
}
#page-mod-book-print .book_toc_numbered li {
margin-top: 10px;
list-style: none;
}
#page-mod-book-print .book_toc_numbered li li {
margin-top: 0;
list-style: none;
}
#page-mod-book-print .book_toc_numbered ul,
#page-mod-book-print .book_toc_numbered ul ul {
margin-left: 0;
padding-left: 0;
}
/* numbering == BULLETS */
#page-mod-book-print .book_toc_bullets {
page-break-before: always;
}
#page-mod-book-print .book_toc_bullets li {
margin-top: 10px;
list-style: none;
}
#page-mod-book-print .book_toc_bullets li li {
margin-top: 0;
list-style: circle;
}
#page-mod-book-print .book_toc_bullets ul {
margin-left: 0;
padding-left: 0;
}
#page-mod-book-print .book_toc_bullets ul ul {
margin-left: 20px;
padding-left: 0;
}
/* numbering == INDENTED */
#page-mod-book-print .book_toc_indented {
page-break-before: always;
}
#page-mod-book-print .book_toc_indented li {
margin-top: 10px;
list-style: none;
}
#page-mod-book-print .book_toc_indented li li {
margin-top: 0;
list-style: none;
}
#page-mod-book-print .book_toc_indented ul {
margin-left: 0;
padding-left: 0;
}
#page-mod-book-print .book_toc_indented ul ul {
margin-left: 20px;
padding-left: 0;
}
#page-mod-book-print .book .book_chapter,
#page-mod-book-print .book .book_description {
page-break-before: always;
}
#page-mod-book-print {
padding-top: 0;
}
/* Exclude elements from printing. */
@media print {
.hidden-print {
display: none !important; /* stylelint-disable-line declaration-no-important */
}
.book .book_title {
margin-top: 45%;
}
}
@@ -0,0 +1,137 @@
{{!
This file is part of Moodle - http://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more comments.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template booktool_print/print_book
Print book page.
Classes required for JS:
* none
Data attributes required for JS:
* none
* printdialoglink string The URL pointing to the print book chapter popup window.
* booktitle string The HTML of the book title.
* bookintro string The book description.
* sitelink string The HTML link pointing to the site's dashboard.
* coursename string The name of the course.
* modulename string The name of the module.
* username string The user name.
* printdate string The print date.
* chaptertitle string The title of the chapter.
* toc object The HTML of the table of contents.
* chapters array The array of book chapters, their content and visibility information.
Example context (json):
{
"printdialoglink": "<a>Print book</a>",
"booktitle": "<h2>Book title</h2>",
"bookintro": "Book description",
"sitelink" : "<a>Site title</a>",
"coursename" : "Course name",
"modulename" : "Module name",
"username" : "User name",
"printdate" : "Tuesday, 22 January 2019, 10:17 AM",
"chaptertitle": "Chapter title",
"toc" : "<div>Table of contents</div>",
"chapters": [
{
"content": "<div>Chapter1 content</div>",
"visible": "true"
},
{
"content": "<div>Chapter2 content</div>",
"visible": "false"
}
]
}
}}
<div class="book p-4">
<div class="text-right">{{{ printdialoglink }}}</div>
<div class="text-center pb-3 book_title">{{{ booktitle }}}</div>
<div class="book_info w-100 pt-6 d-inline-block">
<div class="w-50 float-left">
<table>
<tr>
<td>
{{# str }} site {{/ str }}:
</td>
<td class="pl-3">
{{{ sitelink }}}
</td>
</tr>
<tr>
<td>
{{# str }} course {{/ str }}:
</td>
<td class="pl-3">
{{{ coursename }}}
</td>
</tr>
<tr>
<td>
{{# str }} modulename, mod_book {{/ str }}:
</td>
<td class="pl-3">
{{{ modulename }}}
</td>
</tr>
</table>
</div>
<div class="w-50 float-left">
<table class="float-right">
<tr>
<td>
{{# str }} printedby, booktool_print {{/ str }}:
</td>
<td class="pl-3">
{{{ username }}}
</td>
</tr>
<tr>
<td>
{{# str }} printdate, booktool_print {{/ str }}:
</td>
<td class="pl-3">
{{{ printdate }}}
</td>
</tr>
</table>
</div>
</div>
{{#bookintro}}
<div class="w-100 book_description">
<div class="py-5">
<h2 class="text-center pb-5">{{#str}} description {{/str}}</h2>
<p class="book_summary">{{{ bookintro }}}</p>
</div>
</div>
{{/bookintro}}
<div class="w-100">
<div class="py-5">{{{ toc }}}</div>
</div>
<div class="w-100">
{{#chapters}}
{{#visible }}
<div class="pb-5">
{{{ content }}}
</div>
{{/visible}}
{{/chapters}}
</div>
</div>
@@ -0,0 +1,56 @@
{{!
This file is part of Moodle - http://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more comments.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template booktool_print/print_book_chapter
Print book chapter page.
Classes required for JS:
* none
Data attributes required for JS:
* none
Context variables required for this template:
* printdialoglink string The URL pointing to the print book chapter popup window.
* booktitle string The HTML of the book title.
* parentchaptertitle string The HTML of the parent chapter title (if exists).
* chapter object The object containing the HTML of the chapter content and chapter's visibility.
Example context (json):
{
"printdialoglink": "<a>Print book</a>",
"booktitle": "<h2>Book title</h2>",
"parentchaptertitle": "<h2>Parent chapter title</h2>",
"chapter": {
"content": "<div>Chapter content</div>",
"visible": "true"
}
}
}}
<div class="chapter col-12 p-4">
<div class="text-right">{{{ printdialoglink }}}</div>
<div class="text-center pb-5">{{{ booktitle }}}</div>
<div class="chapter">
{{#parentchaptertitle}}
<div class="text-center">
{{{parentchaptertitle}}}
</div>
{{/parentchaptertitle}}
{{{chapter.content}}}
</div>
</div>
@@ -0,0 +1,91 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Events tests.
*
* @package booktool_print
* @category phpunit
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace booktool_print\event;
/**
* Events tests class.
*
* @package booktool_print
* @category phpunit
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class events_test extends \advanced_testcase {
public function setUp(): void {
$this->resetAfterTest();
}
public function test_book_printed(): void {
// There is no proper API to call to test the event, so what we are
// doing here is simply making sure that the events returns the right information.
$course = $this->getDataGenerator()->create_course();
$book = $this->getDataGenerator()->create_module('book', array('course' => $course->id));
$context = \context_module::instance($book->cmid);
$event = \booktool_print\event\book_printed::create_from_book($book, $context);
// Triggering and capturing the event.
$sink = $this->redirectEvents();
$event->trigger();
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
// Checking that the event contains the expected values.
$this->assertInstanceOf('\booktool_print\event\book_printed', $event);
$this->assertEquals(\context_module::instance($book->cmid), $event->get_context());
$this->assertEquals($book->id, $event->objectid);
}
public function test_chapter_printed(): void {
// There is no proper API to call to test the event, so what we are
// doing here is simply making sure that the events returns the right information.
$course = $this->getDataGenerator()->create_course();
$book = $this->getDataGenerator()->create_module('book', array('course' => $course->id));
$bookgenerator = $this->getDataGenerator()->get_plugin_generator('mod_book');
$chapter = $bookgenerator->create_chapter(array('bookid' => $book->id));
$context = \context_module::instance($book->cmid);
$event = \booktool_print\event\chapter_printed::create_from_chapter($book, $context, $chapter);
// Triggering and capturing the event.
$sink = $this->redirectEvents();
$event->trigger();
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
// Checking that the event contains the expected values.
$this->assertInstanceOf('\booktool_print\event\chapter_printed', $event);
$this->assertEquals(\context_module::instance($book->cmid), $event->get_context());
$this->assertEquals($chapter->id, $event->objectid);
}
}
+29
View File
@@ -0,0 +1,29 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Book print plugin version info
*
* @package booktool_print
* @copyright 2004-2011 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
$plugin->component = 'booktool_print'; // Full name of the plugin (used for diagnostics)
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.