mirror of
https://github.com/moodle/moodle.git
synced 2025-08-08 02:16:41 +02:00
Merge branch 'w16_MDL-45144_m27_booklog' of git://github.com/skodak/moodle
This commit is contained in:
commit
c18c7869fa
22 changed files with 218 additions and 171 deletions
|
@ -34,6 +34,27 @@ defined('MOODLE_INTERNAL') || die();
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
class chapter_created extends \core\event\base {
|
class chapter_created extends \core\event\base {
|
||||||
|
/**
|
||||||
|
* Create instance of event.
|
||||||
|
*
|
||||||
|
* @since Moodle 2.7
|
||||||
|
*
|
||||||
|
* @param \stdClass $book
|
||||||
|
* @param \context_module $context
|
||||||
|
* @param \stdClass $chapter
|
||||||
|
* @return chapter_created
|
||||||
|
*/
|
||||||
|
public static function create_from_chapter(\stdClass $book, \context_module $context, \stdClass $chapter) {
|
||||||
|
$data = array(
|
||||||
|
'context' => $context,
|
||||||
|
'objectid' => $chapter->id,
|
||||||
|
);
|
||||||
|
/** @var chapter_created $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.
|
* Returns description of what happened.
|
||||||
|
|
|
@ -34,13 +34,27 @@ defined('MOODLE_INTERNAL') || die();
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
class chapter_deleted extends \core\event\base {
|
class chapter_deleted extends \core\event\base {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Legacy log data.
|
* Create instance of event.
|
||||||
*
|
*
|
||||||
* @var array
|
* @since Moodle 2.7
|
||||||
|
*
|
||||||
|
* @param \stdClass $book
|
||||||
|
* @param \context_module $context
|
||||||
|
* @param \stdClass $chapter
|
||||||
|
* @return chapter_deleted
|
||||||
*/
|
*/
|
||||||
protected $legacylogdata;
|
public static function create_from_chapter(\stdClass $book, \context_module $context, \stdClass $chapter) {
|
||||||
|
$data = array(
|
||||||
|
'context' => $context,
|
||||||
|
'objectid' => $chapter->id,
|
||||||
|
);
|
||||||
|
/** @var chapter_deleted $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.
|
* Returns description of what happened.
|
||||||
|
@ -57,7 +71,8 @@ class chapter_deleted extends \core\event\base {
|
||||||
* @return array|null
|
* @return array|null
|
||||||
*/
|
*/
|
||||||
protected function get_legacy_logdata() {
|
protected function get_legacy_logdata() {
|
||||||
return $this->legacylogdata;
|
$chapter = $this->get_record_snapshot('book_chapters', $this->objectid);
|
||||||
|
return array($this->courseid, 'book', 'update', 'view.php?id='.$this->contextinstanceid, $chapter->bookid, $this->contextinstanceid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -88,14 +103,4 @@ class chapter_deleted extends \core\event\base {
|
||||||
$this->data['edulevel'] = self::LEVEL_TEACHING;
|
$this->data['edulevel'] = self::LEVEL_TEACHING;
|
||||||
$this->data['objecttable'] = 'book_chapters';
|
$this->data['objecttable'] = 'book_chapters';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the legacy event log data.
|
|
||||||
*
|
|
||||||
* @return array|null
|
|
||||||
*/
|
|
||||||
public function set_legacy_logdata($legacydata) {
|
|
||||||
$this->legacylogdata = $legacydata;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,27 @@ defined('MOODLE_INTERNAL') || die();
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
class chapter_updated extends \core\event\base {
|
class chapter_updated extends \core\event\base {
|
||||||
|
/**
|
||||||
|
* Create instance of event.
|
||||||
|
*
|
||||||
|
* @since Moodle 2.7
|
||||||
|
*
|
||||||
|
* @param \stdClass $book
|
||||||
|
* @param \context_module $context
|
||||||
|
* @param \stdClass $chapter
|
||||||
|
* @return chapter_updated
|
||||||
|
*/
|
||||||
|
public static function create_from_chapter(\stdClass $book, \context_module $context, \stdClass $chapter) {
|
||||||
|
$data = array(
|
||||||
|
'context' => $context,
|
||||||
|
'objectid' => $chapter->id,
|
||||||
|
);
|
||||||
|
/** @var chapter_updated $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.
|
* Returns description of what happened.
|
||||||
|
|
|
@ -34,6 +34,27 @@ defined('MOODLE_INTERNAL') || die();
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
class chapter_viewed extends \core\event\base {
|
class chapter_viewed extends \core\event\base {
|
||||||
|
/**
|
||||||
|
* Create instance of event.
|
||||||
|
*
|
||||||
|
* @since Moodle 2.7
|
||||||
|
*
|
||||||
|
* @param \stdClass $book
|
||||||
|
* @param \context_module $context
|
||||||
|
* @param \stdClass $chapter
|
||||||
|
* @return chapter_viewed
|
||||||
|
*/
|
||||||
|
public static function create_from_chapter(\stdClass $book, \context_module $context, \stdClass $chapter) {
|
||||||
|
$data = array(
|
||||||
|
'context' => $context,
|
||||||
|
'objectid' => $chapter->id,
|
||||||
|
);
|
||||||
|
/** @var chapter_viewed $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.
|
* Returns description of what happened.
|
||||||
|
|
|
@ -34,5 +34,18 @@ defined('MOODLE_INTERNAL') || die();
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
class course_module_instance_list_viewed extends \core\event\course_module_instance_list_viewed {
|
class course_module_instance_list_viewed extends \core\event\course_module_instance_list_viewed {
|
||||||
}
|
/**
|
||||||
|
* Create the event from course record.
|
||||||
|
*
|
||||||
|
* @param \stdClass $course
|
||||||
|
* @return course_module_instance_list_viewed
|
||||||
|
*/
|
||||||
|
public static function create_from_course(\stdClass $course) {
|
||||||
|
$params = array(
|
||||||
|
'context' => \context_course::instance($course->id)
|
||||||
|
);
|
||||||
|
$event = \mod_book\event\course_module_instance_list_viewed::create($params);
|
||||||
|
$event->add_record_snapshot('course', $course);
|
||||||
|
return $event;
|
||||||
|
}}
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,25 @@ defined('MOODLE_INTERNAL') || die();
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
class course_module_viewed extends \core\event\course_module_viewed {
|
class course_module_viewed extends \core\event\course_module_viewed {
|
||||||
|
/**
|
||||||
|
* Create instance of event.
|
||||||
|
*
|
||||||
|
* @since Moodle 2.7
|
||||||
|
*
|
||||||
|
* @param \stdClass $book
|
||||||
|
* @param \context_module $context
|
||||||
|
* @return course_module_viewed
|
||||||
|
*/
|
||||||
|
public static function create_from_book(\stdClass $book, \context_module $context) {
|
||||||
|
$data = array(
|
||||||
|
'context' => $context,
|
||||||
|
'objectid' => $book->id
|
||||||
|
);
|
||||||
|
/** @var course_module_viewed $event */
|
||||||
|
$event = self::create($data);
|
||||||
|
$event->add_record_snapshot('book', $book);
|
||||||
|
return $event;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init method.
|
* Init method.
|
||||||
|
|
|
@ -60,14 +60,7 @@ if ($confirm) { // the operation was confirmed.
|
||||||
} else if ($found and $ch->subchapter) {
|
} else if ($found and $ch->subchapter) {
|
||||||
$fs->delete_area_files($context->id, 'mod_book', 'chapter', $ch->id);
|
$fs->delete_area_files($context->id, 'mod_book', 'chapter', $ch->id);
|
||||||
$DB->delete_records('book_chapters', array('id'=>$ch->id));
|
$DB->delete_records('book_chapters', array('id'=>$ch->id));
|
||||||
|
\mod_book\event\chapter_deleted::create_from_chapter($book, $context, $ch)->trigger();
|
||||||
$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) {
|
} else if ($found) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -77,15 +70,7 @@ if ($confirm) { // the operation was confirmed.
|
||||||
$fs->delete_area_files($context->id, 'mod_book', 'chapter', $chapter->id);
|
$fs->delete_area_files($context->id, 'mod_book', 'chapter', $chapter->id);
|
||||||
$DB->delete_records('book_chapters', array('id'=>$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);
|
\mod_book\event\chapter_deleted::create_from_chapter($book, $context, $chapter)->trigger();
|
||||||
$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.
|
book_preload_chapters($book); // Fix structure.
|
||||||
$DB->set_field('book', 'revision', $book->revision+1, array('id'=>$book->id));
|
$DB->set_field('book', 'revision', $book->revision+1, array('id'=>$book->id));
|
||||||
|
|
|
@ -74,18 +74,9 @@ if ($mform->is_cancelled()) {
|
||||||
$data = file_postupdate_standard_editor($data, 'content', $options, $context, 'mod_book', 'chapter', $data->id);
|
$data = file_postupdate_standard_editor($data, 'content', $options, $context, 'mod_book', 'chapter', $data->id);
|
||||||
$DB->update_record('book_chapters', $data);
|
$DB->update_record('book_chapters', $data);
|
||||||
$DB->set_field('book', 'revision', $book->revision+1, array('id'=>$book->id));
|
$DB->set_field('book', 'revision', $book->revision+1, array('id'=>$book->id));
|
||||||
|
$chapter = $DB->get_record('book_chapters', array('id' => $data->id));
|
||||||
|
|
||||||
add_to_log($course->id, 'course', 'update mod', '../mod/book/view.php?id='.$cm->id, 'book '.$book->id);
|
\mod_book\event\chapter_updated::create_from_chapter($book, $context, $chapter)->trigger();
|
||||||
$params = array(
|
|
||||||
'context' => $context,
|
|
||||||
'objectid' => $data->id
|
|
||||||
);
|
|
||||||
$event = \mod_book\event\chapter_updated::create($params);
|
|
||||||
foreach ($data as $key => $value) {
|
|
||||||
$chapter->$key = $value;
|
|
||||||
}
|
|
||||||
$event->add_record_snapshot('book_chapters', $chapter);
|
|
||||||
$event->trigger();
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// adding new chapter
|
// adding new chapter
|
||||||
|
@ -109,15 +100,9 @@ if ($mform->is_cancelled()) {
|
||||||
$data = file_postupdate_standard_editor($data, 'content', $options, $context, 'mod_book', 'chapter', $data->id);
|
$data = file_postupdate_standard_editor($data, 'content', $options, $context, 'mod_book', 'chapter', $data->id);
|
||||||
$DB->update_record('book_chapters', $data);
|
$DB->update_record('book_chapters', $data);
|
||||||
$DB->set_field('book', 'revision', $book->revision+1, array('id'=>$book->id));
|
$DB->set_field('book', 'revision', $book->revision+1, array('id'=>$book->id));
|
||||||
|
$chapter = $DB->get_record('book_chapters', array('id' => $data->id));
|
||||||
|
|
||||||
add_to_log($course->id, 'course', 'update mod', '../mod/book/view.php?id='.$cm->id, 'book '.$book->id);
|
\mod_book\event\chapter_created::create_from_chapter($book, $context, $chapter)->trigger();
|
||||||
$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
|
book_preload_chapters($book); // fix structure
|
||||||
|
|
|
@ -47,12 +47,7 @@ $PAGE->set_heading($course->fullname);
|
||||||
$PAGE->navbar->add($strbooks);
|
$PAGE->navbar->add($strbooks);
|
||||||
echo $OUTPUT->header();
|
echo $OUTPUT->header();
|
||||||
|
|
||||||
$params = array(
|
\mod_book\event\course_module_instance_list_viewed::create_from_course($course)->trigger();
|
||||||
'context' => context_course::instance($course->id)
|
|
||||||
);
|
|
||||||
$event = \mod_book\event\course_module_instance_list_viewed::create($params);
|
|
||||||
$event->add_record_snapshot('course', $course);
|
|
||||||
$event->trigger();
|
|
||||||
|
|
||||||
// Get all the appropriate data
|
// Get all the appropriate data
|
||||||
if (!$books = get_all_instances_in_course('book', $course)) {
|
if (!$books = get_all_instances_in_course('book', $course)) {
|
||||||
|
|
|
@ -173,22 +173,14 @@ if (!$nothing) {
|
||||||
foreach ($newchapters as $ch) {
|
foreach ($newchapters as $ch) {
|
||||||
$ch->pagenum = $i;
|
$ch->pagenum = $i;
|
||||||
$DB->update_record('book_chapters', $ch);
|
$DB->update_record('book_chapters', $ch);
|
||||||
|
$ch = $DB->get_record('book_chapters', array('id' => $ch->id));
|
||||||
|
|
||||||
$params = array(
|
\mod_book\event\chapter_updated::create_from_chapter($book, $context, $ch)->trigger();
|
||||||
'context' => $context,
|
|
||||||
'objectid' => $ch->id
|
|
||||||
);
|
|
||||||
$event = \mod_book\event\chapter_updated::create($params);
|
|
||||||
$event->trigger();
|
|
||||||
|
|
||||||
$i++;
|
$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);
|
|
||||||
|
|
||||||
book_preload_chapters($book); // fix structure
|
book_preload_chapters($book); // fix structure
|
||||||
$DB->set_field('book', 'revision', $book->revision+1, array('id'=>$book->id));
|
$DB->set_field('book', 'revision', $book->revision+1, array('id'=>$book->id));
|
||||||
|
|
||||||
|
|
|
@ -47,42 +47,28 @@ $chapter->hidden = $chapter->hidden ? 0 : 1;
|
||||||
|
|
||||||
// Update record.
|
// Update record.
|
||||||
$DB->update_record('book_chapters', $chapter);
|
$DB->update_record('book_chapters', $chapter);
|
||||||
$params = array(
|
\mod_book\event\chapter_updated::create_from_chapter($book, $context, $chapter)->trigger();
|
||||||
'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.
|
// Change visibility of subchapters too.
|
||||||
if (!$chapter->subchapter) {
|
if (!$chapter->subchapter) {
|
||||||
$chapters = $DB->get_records('book_chapters', array('bookid'=>$book->id), 'pagenum', 'id, subchapter, hidden');
|
$chapters = $DB->get_recordset('book_chapters', array('bookid'=>$book->id), 'pagenum ASC');
|
||||||
$found = 0;
|
$found = 0;
|
||||||
foreach ($chapters as $ch) {
|
foreach ($chapters as $ch) {
|
||||||
if ($ch->id == $chapter->id) {
|
if ($ch->id == $chapter->id) {
|
||||||
$found = 1;
|
$found = 1;
|
||||||
|
|
||||||
} else if ($found and $ch->subchapter) {
|
} else if ($found and $ch->subchapter) {
|
||||||
$ch->hidden = $chapter->hidden;
|
$ch->hidden = $chapter->hidden;
|
||||||
$DB->update_record('book_chapters', $ch);
|
$DB->update_record('book_chapters', $ch);
|
||||||
|
\mod_book\event\chapter_updated::create_from_chapter($book, $context, $ch)->trigger();
|
||||||
$params = array(
|
|
||||||
'context' => $context,
|
|
||||||
'objectid' => $ch->id
|
|
||||||
);
|
|
||||||
$event = \mod_book\event\chapter_updated::create($params);
|
|
||||||
$event->trigger();
|
|
||||||
|
|
||||||
} else if ($found) {
|
} else if ($found) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$chapters->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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);
|
|
||||||
|
|
||||||
book_preload_chapters($book); // fix structure
|
book_preload_chapters($book); // fix structure
|
||||||
$DB->set_field('book', 'revision', $book->revision+1, array('id'=>$book->id));
|
$DB->set_field('book', 'revision', $book->revision+1, array('id'=>$book->id));
|
||||||
|
|
||||||
|
|
|
@ -47,14 +47,11 @@ class mod_book_events_testcase extends advanced_testcase {
|
||||||
$course = $this->getDataGenerator()->create_course();
|
$course = $this->getDataGenerator()->create_course();
|
||||||
$book = $this->getDataGenerator()->create_module('book', array('course' => $course->id));
|
$book = $this->getDataGenerator()->create_module('book', array('course' => $course->id));
|
||||||
$bookgenerator = $this->getDataGenerator()->get_plugin_generator('mod_book');
|
$bookgenerator = $this->getDataGenerator()->get_plugin_generator('mod_book');
|
||||||
|
$context = context_module::instance($book->cmid);
|
||||||
|
|
||||||
$chapter = $bookgenerator->create_chapter(array('bookid' => $book->id));
|
$chapter = $bookgenerator->create_chapter(array('bookid' => $book->id));
|
||||||
|
|
||||||
$params = array(
|
$event = \mod_book\event\chapter_created::create_from_chapter($book, $context, $chapter);
|
||||||
'context' => context_module::instance($book->cmid),
|
|
||||||
'objectid' => $chapter->id
|
|
||||||
);
|
|
||||||
$event = \mod_book\event\chapter_created::create($params);
|
|
||||||
|
|
||||||
// Triggering and capturing the event.
|
// Triggering and capturing the event.
|
||||||
$sink = $this->redirectEvents();
|
$sink = $this->redirectEvents();
|
||||||
|
@ -80,14 +77,11 @@ class mod_book_events_testcase extends advanced_testcase {
|
||||||
$course = $this->getDataGenerator()->create_course();
|
$course = $this->getDataGenerator()->create_course();
|
||||||
$book = $this->getDataGenerator()->create_module('book', array('course' => $course->id));
|
$book = $this->getDataGenerator()->create_module('book', array('course' => $course->id));
|
||||||
$bookgenerator = $this->getDataGenerator()->get_plugin_generator('mod_book');
|
$bookgenerator = $this->getDataGenerator()->get_plugin_generator('mod_book');
|
||||||
|
$context = context_module::instance($book->cmid);
|
||||||
|
|
||||||
$chapter = $bookgenerator->create_chapter(array('bookid' => $book->id));
|
$chapter = $bookgenerator->create_chapter(array('bookid' => $book->id));
|
||||||
|
|
||||||
$params = array(
|
$event = \mod_book\event\chapter_updated::create_from_chapter($book, $context, $chapter);
|
||||||
'context' => context_module::instance($book->cmid),
|
|
||||||
'objectid' => $chapter->id
|
|
||||||
);
|
|
||||||
$event = \mod_book\event\chapter_updated::create($params);
|
|
||||||
|
|
||||||
// Triggering and capturing the event.
|
// Triggering and capturing the event.
|
||||||
$sink = $this->redirectEvents();
|
$sink = $this->redirectEvents();
|
||||||
|
@ -113,16 +107,12 @@ class mod_book_events_testcase extends advanced_testcase {
|
||||||
$course = $this->getDataGenerator()->create_course();
|
$course = $this->getDataGenerator()->create_course();
|
||||||
$book = $this->getDataGenerator()->create_module('book', array('course' => $course->id));
|
$book = $this->getDataGenerator()->create_module('book', array('course' => $course->id));
|
||||||
$bookgenerator = $this->getDataGenerator()->get_plugin_generator('mod_book');
|
$bookgenerator = $this->getDataGenerator()->get_plugin_generator('mod_book');
|
||||||
|
$context = context_module::instance($book->cmid);
|
||||||
|
|
||||||
$chapter = $bookgenerator->create_chapter(array('bookid' => $book->id));
|
$chapter = $bookgenerator->create_chapter(array('bookid' => $book->id));
|
||||||
|
|
||||||
$params = array(
|
$event = \mod_book\event\chapter_deleted::create_from_chapter($book, $context, $chapter);
|
||||||
'context' => context_module::instance($book->cmid),
|
$legacy = array($course->id, 'book', 'update', 'view.php?id='.$book->cmid, $book->id, $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.
|
// Triggering and capturing the event.
|
||||||
$sink = $this->redirectEvents();
|
$sink = $this->redirectEvents();
|
||||||
|
@ -136,7 +126,7 @@ class mod_book_events_testcase extends advanced_testcase {
|
||||||
$this->assertEquals(context_module::instance($book->cmid), $event->get_context());
|
$this->assertEquals(context_module::instance($book->cmid), $event->get_context());
|
||||||
$this->assertEquals($chapter->id, $event->objectid);
|
$this->assertEquals($chapter->id, $event->objectid);
|
||||||
$this->assertEquals($chapter, $event->get_record_snapshot('book_chapters', $chapter->id));
|
$this->assertEquals($chapter, $event->get_record_snapshot('book_chapters', $chapter->id));
|
||||||
$this->assertEventLegacyLogData(array('1', 2, false), $event);
|
$this->assertEventLegacyLogData($legacy, $event);
|
||||||
$this->assertEventContextNotUsed($event);
|
$this->assertEventContextNotUsed($event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,14 +191,11 @@ class mod_book_events_testcase extends advanced_testcase {
|
||||||
$course = $this->getDataGenerator()->create_course();
|
$course = $this->getDataGenerator()->create_course();
|
||||||
$book = $this->getDataGenerator()->create_module('book', array('course' => $course->id));
|
$book = $this->getDataGenerator()->create_module('book', array('course' => $course->id));
|
||||||
$bookgenerator = $this->getDataGenerator()->get_plugin_generator('mod_book');
|
$bookgenerator = $this->getDataGenerator()->get_plugin_generator('mod_book');
|
||||||
|
$context = context_module::instance($book->cmid);
|
||||||
|
|
||||||
$chapter = $bookgenerator->create_chapter(array('bookid' => $book->id));
|
$chapter = $bookgenerator->create_chapter(array('bookid' => $book->id));
|
||||||
|
|
||||||
$params = array(
|
$event = \mod_book\event\chapter_viewed::create_from_chapter($book, $context, $chapter);
|
||||||
'context' => context_module::instance($book->cmid),
|
|
||||||
'objectid' => $chapter->id
|
|
||||||
);
|
|
||||||
$event = \mod_book\event\chapter_viewed::create($params);
|
|
||||||
|
|
||||||
// Triggering and capturing the event.
|
// Triggering and capturing the event.
|
||||||
$sink = $this->redirectEvents();
|
$sink = $this->redirectEvents();
|
||||||
|
|
|
@ -34,6 +34,25 @@ defined('MOODLE_INTERNAL') || die();
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
class book_exported extends \core\event\base {
|
class book_exported extends \core\event\base {
|
||||||
|
/**
|
||||||
|
* Create instance of event.
|
||||||
|
*
|
||||||
|
* @since Moodle 2.7
|
||||||
|
*
|
||||||
|
* @param \stdClass $book
|
||||||
|
* @param \context_module $context
|
||||||
|
* @return book_exported
|
||||||
|
*/
|
||||||
|
public static function create_from_book(\stdClass $book, \context_module $context) {
|
||||||
|
$data = array(
|
||||||
|
'context' => $context,
|
||||||
|
'objectid' => $book->id
|
||||||
|
);
|
||||||
|
/** @var book_exported $event */
|
||||||
|
$event = self::create($data);
|
||||||
|
$event->add_record_snapshot('book', $book);
|
||||||
|
return $event;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns description of what happened.
|
* Returns description of what happened.
|
||||||
|
|
|
@ -43,13 +43,7 @@ $context = context_module::instance($cm->id);
|
||||||
require_capability('mod/book:read', $context);
|
require_capability('mod/book:read', $context);
|
||||||
require_capability('booktool/exportimscp:export', $context);
|
require_capability('booktool/exportimscp:export', $context);
|
||||||
|
|
||||||
$params = array(
|
\booktool_exportimscp\event\book_exported::create_from_book($book, $context)->trigger();
|
||||||
'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);
|
$file = booktool_exportimscp_build_package($book, $context);
|
||||||
|
|
||||||
|
|
|
@ -46,12 +46,9 @@ class booktool_exportimscp_events_testcase extends advanced_testcase {
|
||||||
|
|
||||||
$course = $this->getDataGenerator()->create_course();
|
$course = $this->getDataGenerator()->create_course();
|
||||||
$book = $this->getDataGenerator()->create_module('book', array('course' => $course->id));
|
$book = $this->getDataGenerator()->create_module('book', array('course' => $course->id));
|
||||||
|
$context = context_module::instance($book->cmid);
|
||||||
|
|
||||||
$params = array(
|
$event = \booktool_exportimscp\event\book_exported::create_from_book($book, $context);
|
||||||
'context' => context_module::instance($book->cmid),
|
|
||||||
'objectid' => $book->id
|
|
||||||
);
|
|
||||||
$event = \booktool_exportimscp\event\book_exported::create($params);
|
|
||||||
|
|
||||||
// Triggering and capturing the event.
|
// Triggering and capturing the event.
|
||||||
$sink = $this->redirectEvents();
|
$sink = $this->redirectEvents();
|
||||||
|
|
|
@ -82,15 +82,10 @@ function toolbook_importhtml_import_chapters($package, $type, $book, $context, $
|
||||||
}
|
}
|
||||||
|
|
||||||
$chapter->id = $DB->insert_record('book_chapters', $chapter);
|
$chapter->id = $DB->insert_record('book_chapters', $chapter);
|
||||||
|
$chapter = $DB->get_record('book_chapters', array('id' => $chapter->id));
|
||||||
$chapters[$chapter->id] = $chapter;
|
$chapters[$chapter->id] = $chapter;
|
||||||
|
|
||||||
$params = array(
|
\mod_book\event\chapter_created::create_from_chapter($book, $context, $chapter)->trigger();
|
||||||
'context' => $context,
|
|
||||||
'objectid' => $chapter->id
|
|
||||||
);
|
|
||||||
$event = \mod_book\event\chapter_created::create($params);
|
|
||||||
$event->add_record_snapshot('book_chapters', $chapter);
|
|
||||||
$event->trigger();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -154,7 +149,6 @@ function toolbook_importhtml_import_chapters($package, $type, $book, $context, $
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
add_to_log($book->course, 'course', 'update mod', '../mod/book/view.php?id='.$context->instanceid, 'book '.$book->id);
|
|
||||||
$fs->delete_area_files($context->id, 'mod_book', 'importhtmltemp', 0);
|
$fs->delete_area_files($context->id, 'mod_book', 'importhtmltemp', 0);
|
||||||
|
|
||||||
// update the revision flag - this takes a long time, better to refetch the current value
|
// update the revision flag - this takes a long time, better to refetch the current value
|
||||||
|
|
|
@ -34,6 +34,25 @@ defined('MOODLE_INTERNAL') || die();
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
class book_printed extends \core\event\base {
|
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.
|
* Returns description of what happened.
|
||||||
|
|
|
@ -34,6 +34,27 @@ defined('MOODLE_INTERNAL') || die();
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
class chapter_printed extends \core\event\base {
|
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.
|
* Returns description of what happened.
|
||||||
|
|
|
@ -76,14 +76,7 @@ if ($chapter) {
|
||||||
if ($chapter->hidden) {
|
if ($chapter->hidden) {
|
||||||
require_capability('mod/book:viewhiddenchapters', $context);
|
require_capability('mod/book:viewhiddenchapters', $context);
|
||||||
}
|
}
|
||||||
|
\booktool_print\event\chapter_printed::create_from_chapter($book, $context, $chapter)->trigger();
|
||||||
$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
|
// page header
|
||||||
?>
|
?>
|
||||||
|
@ -129,13 +122,7 @@ if ($chapter) {
|
||||||
echo '</body> </html>';
|
echo '</body> </html>';
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$params = array(
|
\booktool_print\event\book_printed::create_from_book($book, $context)->trigger();
|
||||||
'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');
|
$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);
|
$book->intro = file_rewrite_pluginfile_urls($book->intro, 'pluginfile.php', $context->id, 'mod_book', 'intro', null);
|
||||||
|
|
|
@ -46,12 +46,9 @@ class booktool_print_events_testcase extends advanced_testcase {
|
||||||
|
|
||||||
$course = $this->getDataGenerator()->create_course();
|
$course = $this->getDataGenerator()->create_course();
|
||||||
$book = $this->getDataGenerator()->create_module('book', array('course' => $course->id));
|
$book = $this->getDataGenerator()->create_module('book', array('course' => $course->id));
|
||||||
|
$context = context_module::instance($book->cmid);
|
||||||
|
|
||||||
$params = array(
|
$event = \booktool_print\event\book_printed::create_from_book($book, $context);
|
||||||
'context' => context_module::instance($book->cmid),
|
|
||||||
'objectid' => $book->id
|
|
||||||
);
|
|
||||||
$event = \booktool_print\event\book_printed::create($params);
|
|
||||||
|
|
||||||
// Triggering and capturing the event.
|
// Triggering and capturing the event.
|
||||||
$sink = $this->redirectEvents();
|
$sink = $this->redirectEvents();
|
||||||
|
@ -78,12 +75,9 @@ class booktool_print_events_testcase extends advanced_testcase {
|
||||||
$book = $this->getDataGenerator()->create_module('book', array('course' => $course->id));
|
$book = $this->getDataGenerator()->create_module('book', array('course' => $course->id));
|
||||||
$bookgenerator = $this->getDataGenerator()->get_plugin_generator('mod_book');
|
$bookgenerator = $this->getDataGenerator()->get_plugin_generator('mod_book');
|
||||||
$chapter = $bookgenerator->create_chapter(array('bookid' => $book->id));
|
$chapter = $bookgenerator->create_chapter(array('bookid' => $book->id));
|
||||||
|
$context = context_module::instance($book->cmid);
|
||||||
|
|
||||||
$params = array(
|
$event = \booktool_print\event\chapter_printed::create_from_chapter($book, $context, $chapter);
|
||||||
'context' => context_module::instance($book->cmid),
|
|
||||||
'objectid' => $chapter->id
|
|
||||||
);
|
|
||||||
$event = \booktool_print\event\chapter_printed::create($params);
|
|
||||||
|
|
||||||
// Triggering and capturing the event.
|
// Triggering and capturing the event.
|
||||||
$sink = $this->redirectEvents();
|
$sink = $this->redirectEvents();
|
||||||
|
|
6
mod/book/upgrade.txt
Normal file
6
mod/book/upgrade.txt
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
This files describes API changes in the book code.
|
||||||
|
|
||||||
|
=== 2.7 ===
|
||||||
|
|
||||||
|
* bogus legacy log calls were removed
|
||||||
|
* \mod_book\event\chapter_deleted::set_legacy_logdata() was removed
|
|
@ -75,15 +75,7 @@ if ($allowedit and !$chapters) {
|
||||||
}
|
}
|
||||||
// Check chapterid and read chapter data
|
// Check chapterid and read chapter data
|
||||||
if ($chapterid == '0') { // Go to first chapter if no given.
|
if ($chapterid == '0') { // Go to first chapter if no given.
|
||||||
$params = array(
|
\mod_book\event\course_module_viewed::create_from_book($book, $context)->trigger();
|
||||||
'context' => $context,
|
|
||||||
'objectid' => $book->id
|
|
||||||
);
|
|
||||||
$event = \mod_book\event\course_module_viewed::create($params);
|
|
||||||
$event->add_record_snapshot('course_modules', $cm);
|
|
||||||
$event->add_record_snapshot('course', $course);
|
|
||||||
$event->add_record_snapshot('book', $book);
|
|
||||||
$event->trigger();
|
|
||||||
|
|
||||||
foreach ($chapters as $ch) {
|
foreach ($chapters as $ch) {
|
||||||
if ($edit) {
|
if ($edit) {
|
||||||
|
@ -119,13 +111,7 @@ unset($chapterid);
|
||||||
|
|
||||||
// Security checks END.
|
// Security checks END.
|
||||||
|
|
||||||
$params = array(
|
\mod_book\event\chapter_viewed::create_from_chapter($book, $context, $chapter)->trigger();
|
||||||
'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.
|
// Read standard strings.
|
||||||
$strbooks = get_string('modulenameplural', 'mod_book');
|
$strbooks = get_string('modulenameplural', 'mod_book');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue