mirror of
https://github.com/moodle/moodle.git
synced 2025-04-07 17:33:18 +02:00
MDL-40062 mod_forum: convert viewed events
* course_module_instance_list_viewed * forum_viewed * course_searched * userreport_viewed
This commit is contained in:
parent
33c40cc633
commit
2288139207
@ -0,0 +1,38 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* The mod_forum instance list viewed event.
|
||||
*
|
||||
* @package mod_forum
|
||||
* @copyright 2014 Dan Poltawski <dan@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_forum\event;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* The mod_forum instance list viewed event.
|
||||
*
|
||||
* @package mod_forum
|
||||
* @copyright 2014 Dan Poltawski <dan@moodle.com>
|
||||
* @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.
|
||||
}
|
111
mod/forum/classes/event/course_searched.php
Normal file
111
mod/forum/classes/event/course_searched.php
Normal file
@ -0,0 +1,111 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* The mod_forum course searched event.
|
||||
*
|
||||
* @package mod_forum
|
||||
* @copyright 2014 Dan Poltawski <dan@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_forum\event;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* The mod_forum course searched event.
|
||||
*
|
||||
* @property-read array $other Extra information about the event.
|
||||
* -string searchterm: The searchterm used on forum search
|
||||
*
|
||||
* @package mod_forum
|
||||
* @copyright 2014 Dan Poltawski <dan@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class course_searched extends \core\event\base {
|
||||
|
||||
/**
|
||||
* Init method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'r';
|
||||
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
$searchterm = s($this->other['searchterm']);
|
||||
return "The user {$this->userid} has searched the course {$this->courseid} for ".
|
||||
"forum posts containing '{$searchterm}''";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('eventcoursesearched', 'mod_forum');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL related to the action
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url('/mod/forum/search.php',
|
||||
array('id' => $this->courseid, 'search' => $this->other['searchterm']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the legacy event log data.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
// The legacy log table expects a relative path to /mod/forum/.
|
||||
$logurl = substr($this->get_url()->out_as_local_url(), strlen('/mod/forum/'));
|
||||
|
||||
return array($this->courseid, 'forum', 'search', $logurl, $this->other['searchterm']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom validation.
|
||||
*
|
||||
* @throws \coding_exception
|
||||
* @return void
|
||||
*/
|
||||
protected function validate_data() {
|
||||
parent::validate_data();
|
||||
if (!isset($this->other['searchterm'])) {
|
||||
throw new \coding_exception('searchterm must be set in $other.');
|
||||
}
|
||||
|
||||
if ($this->contextlevel != CONTEXT_COURSE) {
|
||||
throw new \coding_exception('Context passed must be course.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
106
mod/forum/classes/event/forum_viewed.php
Normal file
106
mod/forum/classes/event/forum_viewed.php
Normal file
@ -0,0 +1,106 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* The mod_forum forum viewed event.
|
||||
*
|
||||
* @package mod_forum
|
||||
* @copyright 2014 Dan Poltawski <dan@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_forum\event;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* The mod_forum forum viewed event.
|
||||
*
|
||||
* @package mod_forum
|
||||
* @copyright 2014 Dan Poltawski <dan@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class forum_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'] = 'forum';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user {$this->userid} has viewed the forum {$this->objectid}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('eventforumviewed', 'mod_forum');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL related to the action
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url('/mod/forum/view.php', array('d' => $this->objectid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the legacy event log data.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
return array($this->courseid, 'forum', 'view forum', 'view.php?f=' . $this->objectid,
|
||||
$this->objectid, $this->contextinstanceid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom validation.
|
||||
*
|
||||
* @throws \coding_exception
|
||||
* @return void
|
||||
*/
|
||||
protected function validate_data() {
|
||||
parent::validate_data();
|
||||
|
||||
if ($this->contextlevel != CONTEXT_MODULE) {
|
||||
throw new \coding_exception('Context passed must be module context.');
|
||||
}
|
||||
|
||||
if (!isset($this->objectid)) {
|
||||
throw new \coding_exception('objectid must be set to the forumid.');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
127
mod/forum/classes/event/userreport_viewed.php
Normal file
127
mod/forum/classes/event/userreport_viewed.php
Normal file
@ -0,0 +1,127 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* The mod_forum userreport viewed event.
|
||||
*
|
||||
* @package mod_forum
|
||||
* @copyright 2014 Dan Poltawski <dan@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_forum\event;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* The mod_forum userreport viewed event.
|
||||
*
|
||||
* @property-read array $other Extra information about the event.
|
||||
* - string reportmode: The mode the report has been viewed in (posts or discussions).
|
||||
*
|
||||
* @package mod_forum
|
||||
* @copyright 2014 Dan Poltawski <dan@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class userreport_viewed extends \core\event\base {
|
||||
|
||||
/**
|
||||
* Init method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'r';
|
||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user {$this->userid} has viewed the userreport for user {$this->relateduserid} in ".
|
||||
"course {$this->courseid} with viewing mode {$this->other['reportmode']}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('eventuserreportviewed', 'mod_forum');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL related to the action
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
|
||||
$url = new \moodle_url('/mod/forum/user.php', array('id' => $this->relateduserid,
|
||||
'mode' => $this->other['reportmode']));
|
||||
|
||||
if ($this->courseid != SITEID) {
|
||||
$url->param('course', $this->courseid);
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the legacy event log data.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
// The legacy log table expects a relative path to /mod/forum/.
|
||||
$logurl = substr($this->get_url()->out_as_local_url(), strlen('/mod/forum/'));
|
||||
|
||||
return array($this->courseid, 'forum', 'user report', $logurl, $this->relateduserid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom validation.
|
||||
*
|
||||
* @throws \coding_exception
|
||||
* @return void
|
||||
*/
|
||||
protected function validate_data() {
|
||||
parent::validate_data();
|
||||
if (!isset($this->relateduserid)) {
|
||||
throw new \coding_exception('relateduserid must be set.');
|
||||
}
|
||||
if (!isset($this->other['reportmode'])) {
|
||||
throw new \coding_exception('reportmode must be set in other.');
|
||||
}
|
||||
|
||||
switch ($this->contextlevel)
|
||||
{
|
||||
case CONTEXT_COURSE:
|
||||
case CONTEXT_SYSTEM:
|
||||
// OK, expected context level.
|
||||
break;
|
||||
default:
|
||||
// Unexpected contextlevel.
|
||||
throw new \coding_exception('Context passed must be system or course.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -51,7 +51,11 @@ $coursecontext = context_course::instance($course->id);
|
||||
|
||||
unset($SESSION->fromdiscussion);
|
||||
|
||||
add_to_log($course->id, 'forum', 'view forums', "index.php?id=$course->id");
|
||||
$params = array(
|
||||
'context' => context_course::instance($course->id)
|
||||
);
|
||||
$event = \mod_forum\event\course_module_instance_list_viewed::create($params);
|
||||
$event->trigger();
|
||||
|
||||
$strforums = get_string('forums', 'forum');
|
||||
$strforum = get_string('forum', 'forum');
|
||||
|
@ -144,6 +144,9 @@ $string['edit'] = 'Edit';
|
||||
$string['editedby'] = 'Edited by {$a->name} - original submission {$a->date}';
|
||||
$string['editedpostupdated'] = '{$a}\'s post was updated';
|
||||
$string['editing'] = 'Editing';
|
||||
$string['eventcoursesearched'] = 'Course searched';
|
||||
$string['eventforumviewed'] = 'Forum viewed';
|
||||
$string['eventuserreportviewed'] = 'User report viewed';
|
||||
$string['emaildigestcompleteshort'] = 'Complete posts';
|
||||
$string['emaildigestdefault'] = 'Default ({$a})';
|
||||
$string['emaildigestoffshort'] = 'No digest';
|
||||
|
@ -112,7 +112,13 @@ if (!$course = $DB->get_record('course', array('id'=>$id))) {
|
||||
|
||||
require_course_login($course);
|
||||
|
||||
add_to_log($course->id, "forum", "search", "search.php?id=$course->id&search=".urlencode($search), $search);
|
||||
$params = array(
|
||||
'context' => $PAGE->context,
|
||||
'other' => array('searchterm' => $search)
|
||||
);
|
||||
|
||||
$event = \mod_forum\event\course_searched::create($params);
|
||||
$event->trigger();
|
||||
|
||||
$strforums = get_string("modulenameplural", "forum");
|
||||
$strsearch = get_string("search", "forum");
|
||||
|
@ -62,8 +62,6 @@ if ($perpage != 5) {
|
||||
$url->param('perpage', $perpage);
|
||||
}
|
||||
|
||||
add_to_log(($isspecificcourse)?$courseid:SITEID, "forum", "user report", 'user.php?'.$url->get_query_string(), $userid);
|
||||
|
||||
$user = $DB->get_record("user", array("id" => $userid), '*', MUST_EXIST);
|
||||
$usercontext = context_user::instance($user->id, MUST_EXIST);
|
||||
// Check if the requested user is the guest user
|
||||
@ -117,6 +115,15 @@ if ($isspecificcourse) {
|
||||
$courses = forum_get_courses_user_posted_in($user, $discussionsonly);
|
||||
}
|
||||
|
||||
|
||||
$params = array(
|
||||
'context' => $PAGE->context,
|
||||
'relateduserid' => $user->id,
|
||||
'other' => array('reportmode' => $mode),
|
||||
);
|
||||
$event = \mod_forum\event\userreport_viewed::create($params);
|
||||
$event->trigger();
|
||||
|
||||
// Get the posts by the requested user that the current user can access.
|
||||
$result = forum_get_posts_by_user($user, $courses, $isspecificcourse, $discussionsonly, ($page * $perpage), $perpage);
|
||||
|
||||
|
@ -129,12 +129,13 @@
|
||||
/// find out current groups mode
|
||||
groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/forum/view.php?id=' . $cm->id);
|
||||
|
||||
/// Okay, we can show the discussions. Log the forum view.
|
||||
if ($cm->id) {
|
||||
add_to_log($course->id, "forum", "view forum", "view.php?id=$cm->id", "$forum->id", $cm->id);
|
||||
} else {
|
||||
add_to_log($course->id, "forum", "view forum", "view.php?f=$forum->id", "$forum->id");
|
||||
}
|
||||
$params = array(
|
||||
'context' => $context,
|
||||
'objectid' => $forum->id
|
||||
);
|
||||
$event = \mod_forum\event\forum_viewed::create($params);
|
||||
$event->add_record_snapshot('forum', $forum);
|
||||
$event->trigger();
|
||||
|
||||
$SESSION->fromdiscussion = qualified_me(); // Return here if we post or set subscription etc
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user