diff --git a/classes/event/course_module_instance_list_viewed.php b/classes/event/course_module_instance_list_viewed.php new file mode 100644 index 0000000..84c5056 --- /dev/null +++ b/classes/event/course_module_instance_list_viewed.php @@ -0,0 +1,39 @@ +. + +/** + * The mod_forumng instance list viewed event. + * + * @package mod_forumng + * @copyright 2014 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_ouwiki\event; + +defined('MOODLE_INTERNAL') || die(); + +/** + * The mod_forumng instance list viewed event class. + * + * @package mod_ouwiki + * @since Moodle 2.7 + * @copyright 2014 The Open University + * @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 { + // No need for any code here as everything is handled by the parent class. +} diff --git a/classes/event/ouwiki_viewed.php b/classes/event/ouwiki_viewed.php new file mode 100644 index 0000000..6210fe6 --- /dev/null +++ b/classes/event/ouwiki_viewed.php @@ -0,0 +1,120 @@ +. + +/** + * The mod_ouwiki view ouwiki event. + * + * @package mod_ouwiki + * @copyright 2014 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_ouwiki\event; + +defined('MOODLE_INTERNAL') || die(); + +/** + * The mod_ouwiki view ouwiki event class. + * + * @package mod_ouwiki + * @since Moodle 2.7 + * @copyright 2014 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class ouwiki_viewed extends \core\event\base { + + /** + * Init method. + * + * @return void + */ + protected function init() { + $this->data['crud'] = 'r'; + $this->data['edulevel'] = self::LEVEL_PARTICIPATING; + $this->data['objecttable'] = 'ouwiki'; + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + $str1 = "The user with id '$this->userid' viewed ouwiki page {$this->other['info']} + with the course module id of '$this->contextinstanceid'."; + $str2 = "Action was {$this->other['action']}"; + return $str1.$str2; + } + + /** + * Return localised event name. + * + * @return string + */ + public static function get_name() { + return get_string('event:ouwikiviewed', 'mod_ouwiki'); + } + + /** + * Get URL related to the action + * + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url('\\mod\\ouwiki\\' . $this->other['logurl']); + } + + /** + * Return the legacy event log data. + * + * @return array|null + */ + protected function get_legacy_logdata() { + return array($this->courseid, 'ouwiki', $this->other['action'], $this->other['logurl'], + $this->other['info'], $this->contextinstanceid); + } + + /** + * Custom validation. + * + * @throws \coding_exception + * @return void + */ + protected function validate_data() { + parent::validate_data(); + + if (!isset($this->objectid)) { + throw new \coding_exception('The \'ouwikiid\' value must be set in the object.'); + } + + if (!isset($this->other['info'])) { + throw new \coding_exception('The \'info\' value must be set in other.'); + } + + if (!isset($this->other['action'])) { + throw new \coding_exception('The \'action\' value must be set in other.'); + } + + if (!isset($this->other['logurl'])) { + throw new \coding_exception('The \'logurl\' value must be set in other.'); + } + + if ($this->contextlevel != CONTEXT_MODULE) { + throw new \coding_exception('Context level must be CONTEXT_MODULE.'); + } + } + +} diff --git a/classes/event/page_created.php b/classes/event/page_created.php new file mode 100644 index 0000000..231e4f8 --- /dev/null +++ b/classes/event/page_created.php @@ -0,0 +1,115 @@ +. + +/** + * The mod_ouwiki view ouwiki event. + * + * @package mod_ouwiki + * @copyright 2014 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_ouwiki\event; + +defined('MOODLE_INTERNAL') || die(); + +/** + * The mod_ouwiki view ouwiki event class. + * + * @package mod_ouwiki + * @since Moodle 2.7 + * @copyright 2014 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +class page_created extends \core\event\base { + /** + * Init method. + * + * @return void + */ + protected function init() { + $this->data['crud'] = 'c'; + $this->data['edulevel'] = self::LEVEL_PARTICIPATING; + $this->data['objecttable'] = 'ouwiki_pages'; + } + + /** + * Return localised event name. + * + * @return string + */ + public static function get_name() { + return get_string('event:ouwikipagecreated', 'mod_ouwiki'); + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return "The user with id '$this->userid' created the page {$this->other['info']} with id '$this->objectid' + for the ouwiki with course module id of '$this->contextinstanceid'."; + } + + /** + * Get URL related to the action + * + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url($this->other['logurl']); + } + + /** + * Return the legacy event log data. + * + * @return array|null + */ + protected function get_legacy_logdata() { + $logurl = substr($this->other['logurl'], strlen('/mod/ouwiki/')); + return array($this->courseid, 'ouwiki', 'page created', $logurl, + $this->other['info'], $this->contextinstanceid); + } + + /** + * Custom validation. + * + * @throws \coding_exception + * @return void + */ + protected function validate_data() { + parent::validate_data(); + + if (!isset($this->objectid)) { + throw new \coding_exception('The \'ouwikiid\' value must be set in the object.'); + } + + if (!isset($this->other['info'])) { + throw new \coding_exception('The \'info\' value must be set in other.'); + } + + if (!isset($this->other['logurl'])) { + throw new \coding_exception('The \'logurl\' value must be set in other.'); + } + + if ($this->contextlevel != CONTEXT_MODULE) { + throw new \coding_exception('Context level must be CONTEXT_MODULE.'); + } + } + +} diff --git a/classes/event/page_lock.php b/classes/event/page_lock.php new file mode 100644 index 0000000..739acc6 --- /dev/null +++ b/classes/event/page_lock.php @@ -0,0 +1,114 @@ +. + +/** + * The mod_ouwiki view ouwiki event. + * + * @package mod_ouwiki + * @copyright 2014 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_ouwiki\event; + +defined('MOODLE_INTERNAL') || die(); + +/** + * The mod_ouwiki view ouwiki event class. + * + * @package mod_ouwiki + * @since Moodle 2.7 + * @copyright 2014 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class page_lock extends \core\event\base { + + /** + * Init method. + * + * @return void + */ + protected function init() { + $this->data['crud'] = 'u'; + $this->data['edulevel'] = self::LEVEL_PARTICIPATING; + $this->data['objecttable'] = 'ouwiki_pages'; + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return "The user with id '$this->userid' locked ouwiki page {$this->other['info']} + with the course module id '$this->contextinstanceid' "; + } + + /** + * Return localised event name. + * + * @return string + */ + public static function get_name() { + return get_string('event:pagelock', 'mod_ouwiki'); + } + + /** + * Get URL related to the action + * + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url('\\mod\\ouwiki\\' . $this->other['logurl']); + } + + /** + * Return the legacy event log data. + * + * @return array|null + */ + protected function get_legacy_logdata() { + return array($this->courseid, 'ouwiki', 'lock', $this->other['logurl'], + $this->other['info'], $this->contextinstanceid); + } + + /** + * Custom validation. + * + * @throws \coding_exception + * @return void + */ + protected function validate_data() { + parent::validate_data(); + + if (!isset($this->objectid)) { + throw new \coding_exception('The \'ouwikiid\' value must be set in the object.'); + } + + if (!isset($this->other['info'])) { + throw new \coding_exception('The \'info\' value must be set in other.'); + } + + if (!isset($this->other['logurl'])) { + throw new \coding_exception('The \'logurl\' value must be set in other.'); + } + + if ($this->contextlevel != CONTEXT_MODULE) { + throw new \coding_exception('Context level must be CONTEXT_MODULE.'); + } + } + +} diff --git a/classes/event/page_unlock.php b/classes/event/page_unlock.php new file mode 100644 index 0000000..74f9d77 --- /dev/null +++ b/classes/event/page_unlock.php @@ -0,0 +1,114 @@ +. + +/** + * The mod_ouwiki view ouwiki event. + * + * @package mod_ouwiki + * @copyright 2014 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_ouwiki\event; + +defined('MOODLE_INTERNAL') || die(); + +/** + * The mod_ouwiki view ouwiki event class. + * + * @package mod_ouwiki + * @since Moodle 2.7 + * @copyright 2014 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class page_unlock extends \core\event\base { + + /** + * Init method. + * + * @return void + */ + protected function init() { + $this->data['crud'] = 'u'; + $this->data['edulevel'] = self::LEVEL_PARTICIPATING; + $this->data['objecttable'] = 'ouwiki_pages'; + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return "The user with id '$this->userid' unlocked ouwiki page {$this->other['info']} + with the course module id '$this->contextinstanceid' "; + } + + /** + * Return localised event name. + * + * @return string + */ + public static function get_name() { + return get_string('event:pageunlock', 'mod_ouwiki'); + } + + /** + * Get URL related to the action + * + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url('\\mod\\ouwiki\\' . $this->other['logurl']); + } + + /** + * Return the legacy event log data. + * + * @return array|null + */ + protected function get_legacy_logdata() { + return array($this->courseid, 'ouwiki', 'unlock', $this->other['logurl'], + $this->other['info'], $this->contextinstanceid); + } + + /** + * Custom validation. + * + * @throws \coding_exception + * @return void + */ + protected function validate_data() { + parent::validate_data(); + + if (!isset($this->objectid)) { + throw new \coding_exception('The \'ouwikiid\' value must be set in the object.'); + } + + if (!isset($this->other['info'])) { + throw new \coding_exception('The \'info\' value must be set in other.'); + } + + if (!isset($this->other['logurl'])) { + throw new \coding_exception('The \'logurl\' value must be set in other.'); + } + + if ($this->contextlevel != CONTEXT_MODULE) { + throw new \coding_exception('Context level must be CONTEXT_MODULE.'); + } + } + +} diff --git a/classes/event/page_updated.php b/classes/event/page_updated.php new file mode 100644 index 0000000..189ba17 --- /dev/null +++ b/classes/event/page_updated.php @@ -0,0 +1,113 @@ +. +/** + * The mod_ouwiki view ouwiki event. + * + * @package mod_ouwiki + * @copyright 2014 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_ouwiki\event; + +defined('MOODLE_INTERNAL') || die(); + +/** + * The mod_ouwiki view ouwiki event class. + * + * @package mod_ouwiki + * @since Moodle 2.7 + * @copyright 2014 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +class page_updated extends \core\event\base { + /** + * Init method. + * + * @return void + */ + protected function init() { + $this->data['crud'] = 'u'; + $this->data['edulevel'] = self::LEVEL_PARTICIPATING; + $this->data['objecttable'] = 'ouwiki_pages'; + } + + /** + * Return localised event name. + * + * @return string + */ + public static function get_name() { + return get_string('event:ouwikipageupdated', 'mod_ouwiki'); + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return "The user with id '$this->userid' updated the page {$this->other['info']} with id '$this->objectid' + for the ouwiki with the course module id '$this->contextinstanceid'."; + } + + /** + * Get URL related to the action + * + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url( $this->other['logurl']); + } + + /** + * Return the legacy event log data. + * + * @return array|null + */ + protected function get_legacy_logdata() { + $logurl = substr($this->other['logurl'], strlen('/mod/ouwiki/')); + return array($this->courseid, 'ouwiki', 'page updated', $logurl, + $this->other['info'], $this->contextinstanceid); + } + + /** + * Custom validation. + * + * @throws \coding_exception + * @return void + */ + protected function validate_data() { + parent::validate_data(); + + if (!isset($this->objectid)) { + throw new \coding_exception('The \'ouwikiid\' value must be set in the object.'); + } + + if (!isset($this->other['info'])) { + throw new \coding_exception('The \'info\' value must be set in other.'); + } + + if (!isset($this->other['logurl'])) { + throw new \coding_exception('The \'logurl\' value must be set in other.'); + } + + if ($this->contextlevel != CONTEXT_MODULE) { + throw new \coding_exception('Context level must be CONTEXT_MODULE.'); + } + } +} diff --git a/classes/event/page_version_deleted.php b/classes/event/page_version_deleted.php new file mode 100644 index 0000000..8e68728 --- /dev/null +++ b/classes/event/page_version_deleted.php @@ -0,0 +1,110 @@ +. + +/** + * The mod_ouwiki delete ouwiki event. + * + * @package mod_ouwiki + * @copyright 2014 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_ouwiki\event; + +defined('MOODLE_INTERNAL') || die(); + +/** + * The mod_ouwiki delete ouwiki event class. + * + * @package mod_ouwiki + * @since Moodle 2.7 + * @copyright 2014 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class page_version_deleted extends \core\event\base { + + /** + * Init method. + * + * @return void + */ + protected function init() { + $this->data['crud'] = 'd'; + $this->data['edulevel'] = self::LEVEL_PARTICIPATING; + $this->data['objecttable'] = 'page_version'; + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return "The user with id '$this->userid' deleted ouwiki with the course module id '$this->contextinstanceid' + delete version action"; + } + + /** + * Return localised event name. + * + * @return string + */ + public static function get_name() { + return get_string('event:ouwikidelete', 'mod_ouwiki'); + } + + /** + * Get URL related to the action + * + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url('\\mod\\ouwiki\\' . $this->other['logurl']); + } + + /** + * Return the legacy event log data. + * + * @return array|null + */ + protected function get_legacy_logdata() { + return array($this->courseid, 'ouwiki', 'version delete', $this->other['logurl'], + '', $this->contextinstanceid); + } + + /** + * Custom validation. + * + * @throws \coding_exception + * @return void + */ + protected function validate_data() { + parent::validate_data(); + + if (!isset($this->objectid)) { + throw new \coding_exception('The \'ouwikiid\' value must be set in the object.'); + } + + if (!isset($this->other['logurl'])) { + throw new \coding_exception('The \'logurl\' value must be set in other.'); + } + + if ($this->contextlevel != CONTEXT_MODULE) { + throw new \coding_exception('Context level must be CONTEXT_MODULE.'); + } + } + +} diff --git a/classes/event/page_version_undeleted.php b/classes/event/page_version_undeleted.php new file mode 100644 index 0000000..d59043c --- /dev/null +++ b/classes/event/page_version_undeleted.php @@ -0,0 +1,110 @@ +. + +/** + * The mod_ouwiki delete ouwiki event. + * + * @package mod_ouwiki + * @copyright 2014 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_ouwiki\event; + +defined('MOODLE_INTERNAL') || die(); + +/** + * The mod_ouwiki delete ouwiki event class. + * + * @package mod_ouwiki + * @since Moodle 2.7 + * @copyright 2014 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class page_version_undeleted extends \core\event\base { + + /** + * Init method. + * + * @return void + */ + protected function init() { + $this->data['crud'] = 'u'; + $this->data['edulevel'] = self::LEVEL_PARTICIPATING; + $this->data['objecttable'] = 'page_version'; + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return "The user with id '$this->userid' undeleted ouwiki page with the course module id '$this->contextinstanceid' + delete version action"; + } + + /** + * Return localised event name. + * + * @return string + */ + public static function get_name() { + return get_string('event:ouwikidelete', 'mod_ouwiki'); + } + + /** + * Get URL related to the action + * + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url('\\mod\\ouwiki\\' . $this->other['logurl']); + } + + /** + * Return the legacy event log data. + * + * @return array|null + */ + protected function get_legacy_logdata() { + return array($this->courseid, 'ouwiki', 'version delete', $this->other['logurl'], + '', $this->contextinstanceid); + } + + /** + * Custom validation. + * + * @throws \coding_exception + * @return void + */ + protected function validate_data() { + parent::validate_data(); + + if (!isset($this->objectid)) { + throw new \coding_exception('The \'ouwikiid\' value must be set in the object.'); + } + + if (!isset($this->other['logurl'])) { + throw new \coding_exception('The \'logurl\' value must be set in other.'); + } + + if ($this->contextlevel != CONTEXT_MODULE) { + throw new \coding_exception('Context level must be CONTEXT_MODULE.'); + } + } + +} diff --git a/db/log.php b/db/log.php index 361d1f6..78eaaff 100644 --- a/db/log.php +++ b/db/log.php @@ -47,5 +47,7 @@ array('module' => 'ouwiki', 'action' => 'view all', 'mtable' => 'ouwiki', 'field' => 'name'), array('module' => 'ouwiki', 'action' => 'viewold', 'mtable' => 'ouwiki', 'field' => 'name'), array('module' => 'ouwiki', 'action' => 'wikihistory', 'mtable' => 'ouwiki', 'field' => 'name'), - array('module' => 'ouwiki', 'action' => 'wikiindex', 'mtable' => 'ouwiki', 'field' => 'name') + array('module' => 'ouwiki', 'action' => 'wikiindex', 'mtable' => 'ouwiki', 'field' => 'name'), + array('module' => 'ouwiki', 'action' => 'page created', 'mtable' => 'ouwiki', 'field' => 'name'), + array('module' => 'ouwiki', 'action' => 'page updated', 'mtable' => 'ouwiki', 'field' => 'name') ); \ No newline at end of file diff --git a/delete.php b/delete.php index 9956672..ab8dcc7 100644 --- a/delete.php +++ b/delete.php @@ -129,12 +129,31 @@ // Unlock page ouwiki_release_lock($pageversion->pageid); -// Log delete or undelete action +// Log delete or undelete action. $ouwikiparamsurl = ouwiki_display_wiki_parameters($pagename, $subwiki, $cm, OUWIKI_PARAMS_URL); -add_to_log($course->id, 'ouwiki', 'version'.$action, 'delete.php?'.$ouwikiparamsurl.'&version='.$versionid, '', $cm->id); -$redirecturl = new moodle_url('/mod/ouwiki/history.php'); +$logurl = 'delete.php?' . $ouwikiparamsurl . '&version=' . $versionid; + +// Add to log. +$params = array( + 'context' => $context, + 'objectid' => $pageversion->pageid, + 'other' => array('logurl' => $logurl) +); + +$event = null; +if ($action == 'delete') { + $event = \mod_ouwiki\event\page_version_deleted::create($params); +} else { + // Undeleting. + $event = \mod_ouwiki\event\page_version_undeleted::create($params); +} +$event->add_record_snapshot('course_modules', $cm); +$event->add_record_snapshot('course', $course); +$event->add_record_snapshot('ouwiki', $ouwiki); +$event->trigger(); -// Redirect to view what is now the current version +// Redirect to view what is now the current version. +$redirecturl = new moodle_url('/mod/ouwiki/history.php'); redirect($redirecturl.'?'.$ouwikiparamsurl); exit; diff --git a/edit.php b/edit.php index ece757b..5a838f9 100644 --- a/edit.php +++ b/edit.php @@ -42,9 +42,15 @@ $urlparams = array(); $urlparams['id'] = $cm->id; -$urlparams['page'] = $pagename; -$urlparams['newsection'] = $newsection; -$urlparams['section'] = $section; +if (!empty($pagename)) { + $urlparams['page'] = $pagename; +} +if (!empty($newsection)) { + $urlparams['newsection'] = $newsection; +} +if (!empty($section)) { + $urlparams['section'] = $section; +} // sort out if the action was save or cancel $save = $action === get_string('savechanges') ? true : false; @@ -222,6 +228,7 @@ exit; } + $event = null; if ($section) { ouwiki_save_new_version_section($course, $cm, $ouwiki, $subwiki, $pagename, $pageversion->xhtml, $formdata->content['text'], $sectiondetails, $formdata); } else { @@ -243,9 +250,33 @@ $completion->update_state($cm, COMPLETION_COMPLETE); } - // release lock and redirect + // Release lock, log and redirect. ouwiki_release_lock($pageversion->pageid); + // Log. + $info = ''; + if ($pagename) { + $info = $pagename; + } + + // Log usage edit. + $params = array( + 'context' => $context, + 'objectid' => $pageversion->pageid, + 'other' => array('info' => $info, 'logurl' => $url->out_as_local_url()) + ); + + if ($addpage) { + $event = \mod_ouwiki\event\page_created::create($params); + } else { + $event = \mod_ouwiki\event\page_updated::create($params); + } + $event->add_record_snapshot('course_modules', $cm); + $event->add_record_snapshot('course', $course); + $event->add_record_snapshot('ouwiki', $ouwiki); + $event->trigger(); + + // Redirect. redirect($returnurl); exit; } diff --git a/index.php b/index.php index e7e06f1..49815b7 100644 --- a/index.php +++ b/index.php @@ -45,8 +45,6 @@ $PAGE->set_pagelayout('incourse'); $context = context_course::instance($course->id); -add_to_log($course->id, 'ouwiki', 'view all', "index.php?id=$course->id", ''); - // Get all required strings. $strname = get_string('name'); $strsectionname = get_string('sectionname', 'format_' . $course->format); @@ -99,5 +97,14 @@ echo html_writer::table($table); +// Log usage view. +$params = array( + 'context' => $context, +); + +$event = \mod_ouwiki\event\course_module_instance_list_viewed::create($params); +$event->add_record_snapshot('course', $course); +$event->trigger(); + // Finish the page. echo $OUTPUT->footer(); diff --git a/lang/en/ouwiki.php b/lang/en/ouwiki.php index 5ca946e..796c6d9 100644 --- a/lang/en/ouwiki.php +++ b/lang/en/ouwiki.php @@ -575,3 +575,10 @@ $string['importedfrom'] = 'Imported from:'; $string['pagesimported'] = 'Pages imported'; $string['unabletoimport'] = 'No wiki\'s available to import from.'; +$string['event:ouwikiviewed'] = 'ouwiki view'; +$string['event:pageunlock'] = 'ouwiki unlock'; +$string['event:pagelock'] = 'ouwiki lock'; +$string['event:ouwikiundelete'] = 'ouwiki version undelete'; +$string['event:ouwikidelete'] = 'ouwiki version delete'; +$string['event:ouwikipagecreated'] = 'ouwiki page created'; +$string['event:ouwikipageupdated'] = 'ouwiki page updated'; diff --git a/locallib.php b/locallib.php index 11d8264..be1ed9b 100644 --- a/locallib.php +++ b/locallib.php @@ -1084,11 +1084,12 @@ function ouwiki_print_header($ouwiki, $cm, $subwiki, $pagename, $afterpage = nul function ouwiki_print_footer($course, $cm, $subwiki, $pagename = null, $logurl = null, $logaction = null, $loginfo = null) { global $PAGE, $OUTPUT; + $info = ''; echo ''; echo $OUTPUT->footer(); - // Log + // Log. $url = $logurl ? $logurl : preg_replace('~^.*/ouwiki/~', '', $_SERVER['PHP_SELF']); $url .= (strpos($url, '?') === false ? '?' : '&').'id='.$cm->id; @@ -1098,11 +1099,9 @@ function ouwiki_print_footer($course, $cm, $subwiki, $pagename = null, $logurl = if ($subwiki->userid) { $url .= '&user='.$subwiki->userid; } - if ($pagename !== null) { + if (!empty($pagename)) { $url .= '&page='.urlencode($pagename); $info = $pagename; - } else { - $info = ''; } if ($loginfo) { if ($info) { @@ -1110,8 +1109,21 @@ function ouwiki_print_footer($course, $cm, $subwiki, $pagename = null, $logurl = } $info .= $loginfo; } + $action = $logaction ? $logaction : preg_replace('~\..*$~', '', $url); - add_to_log($course->id, 'ouwiki', $action, $url, $info, $cm->id); + + // Log usage view. + $params = array( + 'context' => context_module::instance($cm->id), + 'objectid' => $subwiki->wikiid, + 'other' => array('info' => $info, 'action' => $action, 'logurl' => $url) + ); + + $event = \mod_ouwiki\event\ouwiki_viewed::create($params); + $event->add_record_snapshot('course_modules', $cm); + $event->add_record_snapshot('course', $course); + $event->trigger(); + } function ouwiki_nice_date($time, $insentence = null, $showrecent = null) { @@ -2682,15 +2694,19 @@ function ouwiki_is_page_editing_locked($pageid) { * * @param object $pageversion Page/version object * @param int $cmid Course module id + * @param string pagename * @return string $result Contains the html for the form */ -function ouwiki_display_lock_page_form($pageversion, $cmid) { +function ouwiki_display_lock_page_form($pageversion, $cmid, $pagename) { $result=''; $genericformdetails ='