mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 04:30:15 +01:00
MDL-40060 mod_book: Replace add_to_log with events
This commit is contained in:
parent
7abaa052b4
commit
7f6e3eefd1
88
mod/book/classes/event/chapter_created.php
Normal file
88
mod/book/classes/event/chapter_created.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* mod_book chapter created event.
|
||||
*
|
||||
* @package mod_book
|
||||
* @copyright 2013 Frédéric Massart
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_book\event;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* mod_book chapter created event class.
|
||||
*
|
||||
* @package mod_book
|
||||
* @copyright 2013 Frédéric Massart
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class chapter_created extends \core\event\base {
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The chapter $this->objectid of the book $this->context->instanceid has been created.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the legacy event log data.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
return array($this->courseid, 'book', 'add chapter', 'view.php?id=' . $this->context->instanceid . '&chapterid=' .
|
||||
$this->objectid, $this->objectid, $this->context->instanceid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('event_chapter_created', 'mod_book');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL related to the action.
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url('/mod/book/view.php', array(
|
||||
'id' => $this->context->instanceid,
|
||||
'chapterid' => $this->objectid
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Init method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'c';
|
||||
$this->data['level'] = self::LEVEL_TEACHING;
|
||||
$this->data['objecttable'] = 'book_chapters';
|
||||
}
|
||||
|
||||
}
|
100
mod/book/classes/event/chapter_deleted.php
Normal file
100
mod/book/classes/event/chapter_deleted.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* mod_book chapter deleted event.
|
||||
*
|
||||
* @package mod_book
|
||||
* @copyright 2013 Frédéric Massart
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_book\event;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* mod_book chapter deleted event class.
|
||||
*
|
||||
* @package mod_book
|
||||
* @copyright 2013 Frédéric Massart
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class chapter_deleted extends \core\event\base {
|
||||
|
||||
/**
|
||||
* Legacy log data.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $legacylogdata;
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The chapter $this->objectid of the book $this->context->instanceid has been deleted.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the legacy event log data.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
return $this->legacylogdata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('event_chapter_deleted', 'mod_book');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL related to the action.
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url('/mod/book/view.php', array('id' => $this->context->instanceid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Init method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'd';
|
||||
$this->data['level'] = self::LEVEL_TEACHING;
|
||||
$this->data['objecttable'] = 'book_chapters';
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the legacy event log data.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function set_legacy_logdata($legacydata) {
|
||||
$this->legacylogdata = $legacydata;
|
||||
}
|
||||
|
||||
}
|
88
mod/book/classes/event/chapter_updated.php
Normal file
88
mod/book/classes/event/chapter_updated.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* mod_book chapter updated event.
|
||||
*
|
||||
* @package mod_book
|
||||
* @copyright 2013 Frédéric Massart
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_book\event;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* mod_book chapter updated event class.
|
||||
*
|
||||
* @package mod_book
|
||||
* @copyright 2013 Frédéric Massart
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class chapter_updated extends \core\event\base {
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The chapter $this->objectid of the book $this->context->instanceid has been updated.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the legacy event log data.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
return array($this->courseid, 'book', 'update chapter', 'view.php?id=' . $this->context->instanceid . '&chapterid=' .
|
||||
$this->objectid, $this->objectid, $this->context->instanceid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('event_chapter_updated', 'mod_book');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL related to the action.
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url('/mod/book/view.php', array(
|
||||
'id' => $this->context->instanceid,
|
||||
'chapterid' => $this->objectid
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Init method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'u';
|
||||
$this->data['level'] = self::LEVEL_TEACHING;
|
||||
$this->data['objecttable'] = 'book_chapters';
|
||||
}
|
||||
|
||||
}
|
97
mod/book/classes/event/chapter_viewed.php
Normal file
97
mod/book/classes/event/chapter_viewed.php
Normal 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/>.
|
||||
|
||||
/**
|
||||
* mod_book chapter viewed event.
|
||||
*
|
||||
* @package mod_book
|
||||
* @copyright 2013 Frédéric Massart
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_book\event;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* mod_book chapter viewed event class.
|
||||
*
|
||||
* @package mod_book
|
||||
* @copyright 2013 Frédéric Massart
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class chapter_viewed extends \core\event\content_viewed {
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user $this->userid has viewed the chapter $this->objectid of book module $this->context->instanceid";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the legacy event log data.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
return array($this->courseid, 'book', 'view chapter', 'view.php?id=' . $this->context->instanceid .
|
||||
'&chapterid=' . $this->objectid, $this->objectid, $this->context->instanceid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('event_chapter_viewed', 'mod_book');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL related to the action.
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url('/mod/book/view.php', array('id' => $this->context->instanceid, 'chapterid' => $this->objectid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Init method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'r';
|
||||
$this->data['level'] = self::LEVEL_PARTICIPATING;
|
||||
$this->data['objecttable'] = 'book_chapters';
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom validation.
|
||||
*
|
||||
* @throws \coding_exception
|
||||
* @return void
|
||||
*/
|
||||
protected function validate_data() {
|
||||
// Hack to please the parent class. 'view chapter' was the key used in old add_to_log().
|
||||
$this->data['other']['content'] = 'view chapter';
|
||||
parent::validate_data();
|
||||
}
|
||||
|
||||
}
|
97
mod/book/classes/event/course_module_viewed.php
Normal file
97
mod/book/classes/event/course_module_viewed.php
Normal 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/>.
|
||||
|
||||
/**
|
||||
* mod_book course module viewed event.
|
||||
*
|
||||
* @package mod_book
|
||||
* @copyright 2013 Frédéric Massart
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_book\event;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* mod_book course module viewed event class.
|
||||
*
|
||||
* @package mod_book
|
||||
* @copyright 2013 Frédéric Massart
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class course_module_viewed extends \core\event\content_viewed {
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user $this->userid has viewed the book $this->objectid.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the legacy event log data.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
return array($this->courseid, 'book', 'view', 'view.php?id=' . $this->context->instanceid, $this->objectid,
|
||||
$this->context->instanceid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('event_course_module_viewed', 'mod_book');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL related to the action.
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url('/mod/book/view.php', array('id' => $this->context->instanceid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Init method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'r';
|
||||
$this->data['level'] = self::LEVEL_PARTICIPATING;
|
||||
$this->data['objecttable'] = 'book';
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom validation.
|
||||
*
|
||||
* @throws \coding_exception
|
||||
* @return void
|
||||
*/
|
||||
protected function validate_data() {
|
||||
// Hack to please the parent class. 'view' was the key used in old add_to_log().
|
||||
$this->data['other']['content'] = 'view';
|
||||
parent::validate_data();
|
||||
}
|
||||
|
||||
}
|
73
mod/book/classes/event/instances_list_viewed.php
Normal file
73
mod/book/classes/event/instances_list_viewed.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* mod_book instances list viewed event.
|
||||
*
|
||||
* @package mod_book
|
||||
* @copyright 2013 Frédéric Massart
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_book\event;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* mod_book instances list viewed event class.
|
||||
*
|
||||
* @package mod_book
|
||||
* @copyright 2013 Frédéric Massart
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class instances_list_viewed extends \core\event\course_module_instances_list_viewed {
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "User $this->userid viewed the list of book activities in the course $this->courseid.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the legacy event log data.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
return array($this->courseid, 'book', 'view all', 'index.php?id=' . $this->courseid, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('event_instances_list_viewed', 'mod_book');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL related to the action
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url('/mod/book/index.php', array('id' => $this->courseid));
|
||||
}
|
||||
|
||||
}
|
@ -52,7 +52,7 @@ $PAGE->set_heading($course->fullname);
|
||||
if ($confirm) { // the operation was confirmed.
|
||||
$fs = get_file_storage();
|
||||
if (!$chapter->subchapter) { // Delete all its sub-chapters if any
|
||||
$chapters = $DB->get_records('book_chapters', array('bookid'=>$book->id), 'pagenum', 'id, subchapter');
|
||||
$chapters = $DB->get_recordset('book_chapters', array('bookid'=>$book->id), 'pagenum');
|
||||
$found = false;
|
||||
foreach ($chapters as $ch) {
|
||||
if ($ch->id == $chapter->id) {
|
||||
@ -60,16 +60,32 @@ if ($confirm) { // the operation was confirmed.
|
||||
} else if ($found and $ch->subchapter) {
|
||||
$fs->delete_area_files($context->id, 'mod_book', 'chapter', $ch->id);
|
||||
$DB->delete_records('book_chapters', array('id'=>$ch->id));
|
||||
|
||||
$params = array(
|
||||
'context' => $context,
|
||||
'objectid' => $ch->id
|
||||
);
|
||||
$event = \mod_book\event\chapter_deleted::create($params);
|
||||
$event->add_record_snapshot('book_chapters', $ch);
|
||||
$event->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));
|
||||
|
||||
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);
|
||||
$params = array(
|
||||
'context' => $context,
|
||||
'objectid' => $chapter->id
|
||||
);
|
||||
$event = \mod_book\event\chapter_deleted::create($params);
|
||||
$event->add_record_snapshot('book_chapters', $chapter);
|
||||
$event->set_legacy_logdata(array($course->id, 'book', 'update', 'view.php?id='.$cm->id, $book->id, $cm->id));
|
||||
$event->trigger();
|
||||
|
||||
book_preload_chapters($book); // Fix structure.
|
||||
$DB->set_field('book', 'revision', $book->revision+1, array('id'=>$book->id));
|
||||
|
@ -76,7 +76,13 @@ if ($mform->is_cancelled()) {
|
||||
$DB->set_field('book', 'revision', $book->revision+1, array('id'=>$book->id));
|
||||
|
||||
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 chapter', 'view.php?id='.$cm->id.'&chapterid='.$data->id, $data->id, $cm->id);
|
||||
$params = array(
|
||||
'context' => $context,
|
||||
'objectid' => $data->id
|
||||
);
|
||||
$event = \mod_book\event\chapter_updated::create($params);
|
||||
$event->add_record_snapshot('book_chapters', $data);
|
||||
$event->trigger();
|
||||
|
||||
} else {
|
||||
// adding new chapter
|
||||
@ -102,7 +108,13 @@ if ($mform->is_cancelled()) {
|
||||
$DB->set_field('book', 'revision', $book->revision+1, array('id'=>$book->id));
|
||||
|
||||
add_to_log($course->id, 'course', 'update mod', '../mod/book/view.php?id='.$cm->id, 'book '.$book->id);
|
||||
add_to_log($course->id, 'book', 'add chapter', 'view.php?id='.$cm->id.'&chapterid='.$data->id, $data->id, $cm->id);
|
||||
$params = array(
|
||||
'context' => $context,
|
||||
'objectid' => $data->id
|
||||
);
|
||||
$event = \mod_book\event\chapter_created::create($params);
|
||||
$event->add_record_snapshot('book_chapters', $data);
|
||||
$event->trigger();
|
||||
}
|
||||
|
||||
book_preload_chapters($book); // fix structure
|
||||
|
@ -48,7 +48,11 @@ $PAGE->set_heading($course->fullname);
|
||||
$PAGE->navbar->add($strbooks);
|
||||
echo $OUTPUT->header();
|
||||
|
||||
add_to_log($course->id, 'book', 'view all', 'index.php?id='.$course->id, '');
|
||||
$params = array(
|
||||
'context' => context_course::instance($course->id)
|
||||
);
|
||||
$event = \mod_book\event\instances_list_viewed::create($params);
|
||||
$event->trigger();
|
||||
|
||||
// Get all the appropriate data
|
||||
if (!$books = get_all_instances_in_course('book', $course)) {
|
||||
|
@ -43,9 +43,15 @@ $string['customtitles_help'] = 'Normally the chapter title is displayed in the t
|
||||
|
||||
If the custom titles checkbox is ticked, the chapter title is NOT displayed as a heading above the content. A different title (perhaps longer than the chapter title) may be entered as part of the content.';
|
||||
$string['chapters'] = 'Chapters';
|
||||
$string['editingchapter'] = 'Editing chapter';
|
||||
$string['chaptertitle'] = 'Chapter title';
|
||||
$string['content'] = 'Content';
|
||||
$string['editingchapter'] = 'Editing chapter';
|
||||
$string['event_chapter_created'] = 'Chapter created';
|
||||
$string['event_chapter_deleted'] = 'Chapter deleted';
|
||||
$string['event_chapter_updated'] = 'Chapter updated';
|
||||
$string['event_chapter_viewed'] = 'Chapter viewed';
|
||||
$string['event_instances_list_viewed'] = 'Instances list viewed';
|
||||
$string['event_course_module_viewed'] = 'Course module viewed';
|
||||
$string['subchapter'] = 'Subchapter';
|
||||
$string['nocontent'] = 'No content has been added to this book yet.';
|
||||
$string['numbering'] = 'Chapter formatting';
|
||||
|
@ -173,10 +173,19 @@ if (!$nothing) {
|
||||
foreach ($newchapters as $ch) {
|
||||
$ch->pagenum = $i;
|
||||
$DB->update_record('book_chapters', $ch);
|
||||
|
||||
$params = array(
|
||||
'context' => $context,
|
||||
'objectid' => $ch->id
|
||||
);
|
||||
$event = \mod_book\event\chapter_updated::create($params);
|
||||
$event->trigger();
|
||||
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
// MDL-39963 Decide what to do with those logs.
|
||||
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);
|
||||
|
||||
|
@ -47,6 +47,13 @@ $chapter->hidden = $chapter->hidden ? 0 : 1;
|
||||
|
||||
// Update record.
|
||||
$DB->update_record('book_chapters', $chapter);
|
||||
$params = array(
|
||||
'context' => $context,
|
||||
'objectid' => $chapter->id
|
||||
);
|
||||
$event = \mod_book\event\chapter_updated::create($params);
|
||||
$event->add_record_snapshot('book_chapters', $chapter);
|
||||
$event->trigger();
|
||||
|
||||
// Change visibility of subchapters too.
|
||||
if (!$chapter->subchapter) {
|
||||
@ -58,12 +65,21 @@ if (!$chapter->subchapter) {
|
||||
} else if ($found and $ch->subchapter) {
|
||||
$ch->hidden = $chapter->hidden;
|
||||
$DB->update_record('book_chapters', $ch);
|
||||
|
||||
$params = array(
|
||||
'context' => $context,
|
||||
'objectid' => $ch->id
|
||||
);
|
||||
$event = \mod_book\event\chapter_updated::create($params);
|
||||
$event->trigger();
|
||||
|
||||
} else if ($found) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MDL-39963 Decide what to do with those logs.
|
||||
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);
|
||||
|
||||
|
224
mod/book/tests/events_test.php
Normal file
224
mod/book/tests/events_test.php
Normal file
@ -0,0 +1,224 @@
|
||||
<?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 mod_book
|
||||
* @category phpunit
|
||||
* @copyright 2013 Frédéric Massart
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
global $CFG;
|
||||
|
||||
/**
|
||||
* Events tests class.
|
||||
*
|
||||
* @package mod_book
|
||||
* @category phpunit
|
||||
* @copyright 2013 Frédéric Massart
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class mod_book_events_testcase extends advanced_testcase {
|
||||
|
||||
public function setUp() {
|
||||
$this->resetAfterTest();
|
||||
}
|
||||
|
||||
public function test_chapter_created() {
|
||||
// There is no proper API to call to generate chapters for a book, 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));
|
||||
|
||||
$params = array(
|
||||
'context' => context_module::instance($book->cmid),
|
||||
'objectid' => $chapter->id
|
||||
);
|
||||
$event = \mod_book\event\chapter_created::create($params);
|
||||
|
||||
// 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('\mod_book\event\chapter_created', $event);
|
||||
$this->assertEquals(context_module::instance($book->id), $event->get_context());
|
||||
$this->assertEquals($chapter->id, $event->objectid);
|
||||
$expected = array($course->id, 'book', 'add chapter', 'view.php?id='.$book->cmid.'&chapterid='.$chapter->id,
|
||||
$chapter->id, $book->cmid);
|
||||
$this->assertEventLegacyLogData($expected, $event);
|
||||
}
|
||||
|
||||
public function test_chapter_updated() {
|
||||
// There is no proper API to call to generate chapters for a book, 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));
|
||||
|
||||
$params = array(
|
||||
'context' => context_module::instance($book->cmid),
|
||||
'objectid' => $chapter->id
|
||||
);
|
||||
$event = \mod_book\event\chapter_updated::create($params);
|
||||
|
||||
// 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('\mod_book\event\chapter_updated', $event);
|
||||
$this->assertEquals(context_module::instance($book->id), $event->get_context());
|
||||
$this->assertEquals($chapter->id, $event->objectid);
|
||||
$expected = array($course->id, 'book', 'update chapter', 'view.php?id='.$book->cmid.'&chapterid='.$chapter->id,
|
||||
$chapter->id, $book->cmid);
|
||||
$this->assertEventLegacyLogData($expected, $event);
|
||||
}
|
||||
|
||||
public function test_chapter_deleted() {
|
||||
// There is no proper API to call to delete chapters for a book, 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));
|
||||
|
||||
$params = array(
|
||||
'context' => context_module::instance($book->cmid),
|
||||
'objectid' => $chapter->id
|
||||
);
|
||||
$event = \mod_book\event\chapter_deleted::create($params);
|
||||
$event->add_record_snapshot('book_chapters', $chapter);
|
||||
$event->set_legacy_logdata(array('1', 2, false));
|
||||
|
||||
// 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('\mod_book\event\chapter_deleted', $event);
|
||||
$this->assertEquals(context_module::instance($book->id), $event->get_context());
|
||||
$this->assertEquals($chapter->id, $event->objectid);
|
||||
$this->assertEquals($chapter, $event->get_record_snapshot('book_chapters', $chapter->id));
|
||||
$this->assertEventLegacyLogData(array('1', 2, false), $event);
|
||||
}
|
||||
|
||||
public function test_instances_list_viewed() {
|
||||
// There is no proper API to call to trigger this event, so what we are
|
||||
// doing here is simply making sure that the events returns the right information.
|
||||
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$params = array(
|
||||
'context' => context_course::instance($course->id)
|
||||
);
|
||||
$event = \mod_book\event\instances_list_viewed::create($params);
|
||||
|
||||
// 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('\mod_book\event\instances_list_viewed', $event);
|
||||
$this->assertEquals(context_course::instance($course->id), $event->get_context());
|
||||
$expected = array($course->id, 'book', 'view all', 'index.php?id='.$course->id, '');
|
||||
$this->assertEventLegacyLogData($expected, $event);
|
||||
}
|
||||
|
||||
public function test_course_module_viewed() {
|
||||
// There is no proper API to call to trigger this 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));
|
||||
|
||||
$params = array(
|
||||
'context' => context_module::instance($book->cmid),
|
||||
'objectid' => $book->id
|
||||
);
|
||||
$event = \mod_book\event\course_module_viewed::create($params);
|
||||
|
||||
// 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('\mod_book\event\course_module_viewed', $event);
|
||||
$this->assertEquals(context_module::instance($book->cmid), $event->get_context());
|
||||
$this->assertEquals($book->id, $event->objectid);
|
||||
$expected = array($course->id, 'book', 'view', 'view.php?id=' . $book->cmid, $book->id, $book->cmid);
|
||||
$this->assertEventLegacyLogData($expected, $event);
|
||||
}
|
||||
|
||||
public function test_chapter_viewed() {
|
||||
// There is no proper API to call to trigger this 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));
|
||||
|
||||
$params = array(
|
||||
'context' => context_module::instance($book->cmid),
|
||||
'objectid' => $chapter->id
|
||||
);
|
||||
$event = \mod_book\event\chapter_viewed::create($params);
|
||||
|
||||
// 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('\mod_book\event\chapter_viewed', $event);
|
||||
$this->assertEquals(context_module::instance($book->cmid), $event->get_context());
|
||||
$this->assertEquals($chapter->id, $event->objectid);
|
||||
$expected = array($course->id, 'book', 'view chapter', 'view.php?id=' . $book->cmid . '&chapterid=' .
|
||||
$chapter->id, $chapter->id, $book->cmid);
|
||||
$this->assertEventLegacyLogData($expected, $event);
|
||||
}
|
||||
|
||||
}
|
85
mod/book/tool/exportimscp/classes/event/book_exported.php
Normal file
85
mod/book/tool/exportimscp/classes/event/book_exported.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?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_exportimscp book exported event.
|
||||
*
|
||||
* @package booktool_exportimscp
|
||||
* @copyright 2013 Frédéric Massart
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace booktool_exportimscp\event;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* booktool_exportimscp book exported event class.
|
||||
*
|
||||
* @package booktool_exportimscp
|
||||
* @copyright 2013 Frédéric Massart
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class book_exported extends \core\event\base {
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user $this->userid has exported the book $this->objectid.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the legacy event log data.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
return array($this->courseid, 'book', 'exportimscp', 'tool/exportimscp/index.php?id=' . $this->context->instanceid,
|
||||
$this->objectid, $this->context->instanceid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('event_book_exported', 'booktool_exportimscp');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL related to the action.
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url('/mod/book/view.php', array('id' => $this->context->instanceid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Init method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'r';
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
$this->data['objecttable'] = 'book';
|
||||
}
|
||||
|
||||
}
|
@ -43,7 +43,13 @@ $context = context_module::instance($cm->id);
|
||||
require_capability('mod/book:read', $context);
|
||||
require_capability('booktool/exportimscp:export', $context);
|
||||
|
||||
add_to_log($course->id, 'book', 'exportimscp', 'tool/exportimscp/index.php?id='.$cm->id, $book->id, $cm->id);
|
||||
$params = array(
|
||||
'context' => $context,
|
||||
'objectid' => $book->id
|
||||
);
|
||||
$event = \booktool_exportimscp\event\book_exported::create($params);
|
||||
$event->add_record_snapshot('book', $book);
|
||||
$event->trigger();
|
||||
|
||||
$file = booktool_exportimscp_build_package($book, $context);
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
$string['event_book_exported'] = 'Book exported';
|
||||
$string['exportimscp:export'] = 'Export book as IMS content package';
|
||||
$string['generateimscp'] = 'Generate IMS CP';
|
||||
$string['nochapters'] = 'No book chapters found, so unable to export to IMS CP.';
|
||||
|
72
mod/book/tool/exportimscp/tests/events_test.php
Normal file
72
mod/book/tool/exportimscp/tests/events_test.php
Normal file
@ -0,0 +1,72 @@
|
||||
<?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_exportimscp
|
||||
* @category phpunit
|
||||
* @copyright 2013 Frédéric Massart
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
global $CFG;
|
||||
|
||||
/**
|
||||
* Events tests class.
|
||||
*
|
||||
* @package booktool_exportimscp
|
||||
* @category phpunit
|
||||
* @copyright 2013 Frédéric Massart
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class booktool_exportimscp_events_testcase extends advanced_testcase {
|
||||
|
||||
public function setUp() {
|
||||
$this->resetAfterTest();
|
||||
}
|
||||
|
||||
public function test_book_exported() {
|
||||
// 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));
|
||||
|
||||
$params = array(
|
||||
'context' => context_module::instance($book->cmid),
|
||||
'objectid' => $book->id
|
||||
);
|
||||
$event = \booktool_exportimscp\event\book_exported::create($params);
|
||||
|
||||
// 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_exportimscp\event\book_exported', $event);
|
||||
$this->assertEquals(context_module::instance($book->cmid), $event->get_context());
|
||||
$this->assertEquals($book->id, $event->objectid);
|
||||
$expected = array($course->id, 'book', 'exportimscp', 'tool/exportimscp/index.php?id=' . $book->cmid,
|
||||
$book->id, $book->cmid);
|
||||
$this->assertEventLegacyLogData($expected, $event);
|
||||
}
|
||||
|
||||
}
|
@ -84,7 +84,13 @@ function toolbook_importhtml_import_chapters($package, $type, $book, $context, $
|
||||
$chapter->id = $DB->insert_record('book_chapters', $chapter);
|
||||
$chapters[$chapter->id] = $chapter;
|
||||
|
||||
add_to_log($book->course, 'book', 'add chapter', 'view.php?id='.$context->instanceid.'&chapterid='.$chapter->id, $chapter->id, $context->instanceid);
|
||||
$params = array(
|
||||
'context' => $context,
|
||||
'objectid' => $chapter->id
|
||||
);
|
||||
$event = \mod_book\event\chapter_created::create($params);
|
||||
$event->add_record_snapshot('book_chapters', $chapter);
|
||||
$event->trigger();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
BIN
mod/book/tool/importhtml/tests/fixtures/chapters.zip
vendored
Normal file
BIN
mod/book/tool/importhtml/tests/fixtures/chapters.zip
vendored
Normal file
Binary file not shown.
76
mod/book/tool/importhtml/tests/locallib_test.php
Normal file
76
mod/book/tool/importhtml/tests/locallib_test.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?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_importhtml tests.
|
||||
*
|
||||
* @package booktool_importhtml
|
||||
* @category phpunit
|
||||
* @copyright 2013 Frédéric Massart
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
global $CFG;
|
||||
|
||||
require_once($CFG->dirroot.'/mod/book/tool/importhtml/locallib.php');
|
||||
|
||||
/**
|
||||
* booktool_importhtml tests class.
|
||||
*
|
||||
* @package booktool_importhtml
|
||||
* @category phpunit
|
||||
* @copyright 2013 Frédéric Massart
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class booktool_importhtml_locallib_testcase extends advanced_testcase {
|
||||
|
||||
public function setUp() {
|
||||
$this->resetAfterTest();
|
||||
}
|
||||
|
||||
public function test_import_chapters_events() {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$book = $this->getDataGenerator()->create_module('book', array('course' => $course->id));
|
||||
$context = context_module::instance($book->cmid);
|
||||
|
||||
$record = new stdClass();
|
||||
$record->contextid = $context->id;
|
||||
$record->component = 'phpunit';
|
||||
$record->filearea = 'test';
|
||||
$record->itemid = 0;
|
||||
$record->filepath = '/';
|
||||
$record->filename = 'chapters.zip';
|
||||
|
||||
$fs = get_file_storage();
|
||||
$file = $fs->create_file_from_pathname($record, __DIR__ . '/fixtures/chapters.zip');
|
||||
|
||||
// Importing the chapters.
|
||||
$sink = $this->redirectEvents();
|
||||
toolbook_importhtml_import_chapters($file, 2, $book, $context, false);
|
||||
$events = $sink->get_events();
|
||||
|
||||
// Checking the results.
|
||||
$this->assertCount(5, $events);
|
||||
foreach ($events as $event) {
|
||||
$this->assertInstanceOf('\mod_book\event\chapter_created', $event);
|
||||
$this->assertEquals($context, $event->get_context());
|
||||
$chapter = $event->get_record_snapshot('book_chapters', $event->objectid);
|
||||
$this->assertNotEmpty($chapter);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
85
mod/book/tool/print/classes/event/book_printed.php
Normal file
85
mod/book/tool/print/classes/event/book_printed.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?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
|
||||
* @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 {
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user $this->userid has printed the book $this->objectid.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the legacy event log data.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
return array($this->courseid, 'book', 'print', 'tool/print/index.php?id=' . $this->context->instanceid,
|
||||
$this->objectid, $this->context->instanceid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('event_book_printed', '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->context->instanceid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Init method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'r';
|
||||
$this->data['level'] = self::LEVEL_PARTICIPATING;
|
||||
$this->data['objecttable'] = 'book';
|
||||
}
|
||||
|
||||
}
|
85
mod/book/tool/print/classes/event/chapter_printed.php
Normal file
85
mod/book/tool/print/classes/event/chapter_printed.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?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
|
||||
* @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 {
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user $this->userid has printed the chapter $this->objectid of the book module $this->context->instanceid.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the legacy event log data.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
return array($this->courseid, 'book', 'print chapter', 'tool/print/index.php?id=' . $this->context->instanceid .
|
||||
'&chapterid=' . $this->objectid, $this->objectid, $this->context->instanceid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('event_chapter_printed', '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->context->instanceid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Init method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'r';
|
||||
$this->data['level'] = self::LEVEL_PARTICIPATING;
|
||||
$this->data['objecttable'] = 'book';
|
||||
}
|
||||
|
||||
}
|
@ -77,7 +77,13 @@ if ($chapter) {
|
||||
require_capability('mod/book:viewhiddenchapters', $context);
|
||||
}
|
||||
|
||||
add_to_log($course->id, 'book', 'print chapter', 'tool/print/index.php?id='.$cm->id.'&chapterid='.$chapter->id, $chapter->id, $cm->id);
|
||||
$params = array(
|
||||
'context' => $context,
|
||||
'objectid' => $chapter->id
|
||||
);
|
||||
$event = \booktool_print\event\chapter_printed::create($params);
|
||||
$event->add_record_snapshot('book_chapters', $chapter);
|
||||
$event->trigger();
|
||||
|
||||
// page header
|
||||
?>
|
||||
@ -123,7 +129,14 @@ if ($chapter) {
|
||||
echo '</body> </html>';
|
||||
|
||||
} else {
|
||||
add_to_log($course->id, 'book', 'print', 'tool/print/index.php?id='.$cm->id, $book->id, $cm->id);
|
||||
$params = array(
|
||||
'context' => $context,
|
||||
'objectid' => $book->id
|
||||
);
|
||||
$event = \booktool_print\event\book_printed::create($params);
|
||||
$event->add_record_snapshot('book', $book);
|
||||
$event->trigger();
|
||||
|
||||
$allchapters = $DB->get_records('book_chapters', array('bookid'=>$book->id), 'pagenum');
|
||||
$book->intro = file_rewrite_pluginfile_urls($book->intro, 'pluginfile.php', $context->id, 'mod_book', 'intro', null);
|
||||
|
||||
|
@ -24,6 +24,8 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
$string['event_book_printed'] = 'Book printed';
|
||||
$string['event_chapter_printed'] = 'Chapter printed';
|
||||
$string['pluginname'] = 'Book printing';
|
||||
$string['printbook'] = 'Print book';
|
||||
$string['printchapter'] = 'Print this chapter';
|
||||
|
103
mod/book/tool/print/tests/events_test.php
Normal file
103
mod/book/tool/print/tests/events_test.php
Normal file
@ -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/>.
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
global $CFG;
|
||||
|
||||
/**
|
||||
* 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 booktool_print_events_testcase extends advanced_testcase {
|
||||
|
||||
public function setUp() {
|
||||
$this->resetAfterTest();
|
||||
}
|
||||
|
||||
public function test_book_printed() {
|
||||
// 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));
|
||||
|
||||
$params = array(
|
||||
'context' => context_module::instance($book->cmid),
|
||||
'objectid' => $book->id
|
||||
);
|
||||
$event = \booktool_print\event\book_printed::create($params);
|
||||
|
||||
// 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);
|
||||
$expected = array($course->id, 'book', 'print', 'tool/print/index.php?id=' . $book->cmid, $book->id, $book->cmid);
|
||||
$this->assertEventLegacyLogData($expected, $event);
|
||||
}
|
||||
|
||||
|
||||
public function test_chapter_printed() {
|
||||
// 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));
|
||||
|
||||
$params = array(
|
||||
'context' => context_module::instance($book->cmid),
|
||||
'objectid' => $chapter->id
|
||||
);
|
||||
$event = \booktool_print\event\chapter_printed::create($params);
|
||||
|
||||
// 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);
|
||||
$expected = array($course->id, 'book', 'print chapter', 'tool/print/index.php?id=' . $book->cmid .
|
||||
'&chapterid=' . $chapter->id, $chapter->id, $book->cmid);
|
||||
$this->assertEventLegacyLogData($expected, $event);
|
||||
}
|
||||
|
||||
}
|
@ -75,7 +75,14 @@ if ($allowedit and !$chapters) {
|
||||
}
|
||||
// Check chapterid and read chapter data
|
||||
if ($chapterid == '0') { // Go to first chapter if no given.
|
||||
add_to_log($course->id, 'book', 'view', 'view.php?id='.$cm->id, $book->id, $cm->id);
|
||||
$params = array(
|
||||
'context' => $context,
|
||||
'objectid' => $book->id
|
||||
);
|
||||
$event = \mod_book\event\course_module_viewed::create($params);
|
||||
$event->add_record_snapshot('book', $book);
|
||||
$event->trigger();
|
||||
|
||||
foreach ($chapters as $ch) {
|
||||
if ($edit) {
|
||||
$chapterid = $ch->id;
|
||||
@ -110,7 +117,13 @@ unset($chapterid);
|
||||
|
||||
// Security checks END.
|
||||
|
||||
add_to_log($course->id, 'book', 'view chapter', 'view.php?id='.$cm->id.'&chapterid='.$chapter->id, $chapter->id, $cm->id);
|
||||
$params = array(
|
||||
'context' => $context,
|
||||
'objectid' => $chapter->id
|
||||
);
|
||||
$event = \mod_book\event\chapter_viewed::create($params);
|
||||
$event->add_record_snapshot('book_chapters', $chapter);
|
||||
$event->trigger();
|
||||
|
||||
// Read standard strings.
|
||||
$strbooks = get_string('modulenameplural', 'mod_book');
|
||||
|
Loading…
x
Reference in New Issue
Block a user