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';
}
}