mirror of
https://github.com/moodle/moodle.git
synced 2025-03-22 16:40:07 +01:00
Merge branch 'wip-MDL-40907-master' of git://github.com/marinaglancy/moodle
This commit is contained in:
commit
48395a9cdb
@ -660,10 +660,6 @@ class dndupload_ajax_processor {
|
||||
));
|
||||
$event->trigger();
|
||||
|
||||
add_to_log($this->course->id, $mod->modname, "add",
|
||||
"view.php?id=$mod->id",
|
||||
"$instanceid", $mod->id);
|
||||
|
||||
$this->send_response($mod);
|
||||
}
|
||||
|
||||
|
@ -160,10 +160,6 @@ function add_moduleinfo($moduleinfo, $course, $mform = null) {
|
||||
));
|
||||
$event->trigger();
|
||||
|
||||
add_to_log($course->id, $moduleinfo->modulename, "add",
|
||||
"view.php?id=$moduleinfo->coursemodule",
|
||||
"$moduleinfo->instance", $moduleinfo->coursemodule);
|
||||
|
||||
$moduleinfo = edit_module_post_actions($moduleinfo, $course);
|
||||
$transaction->allow_commit();
|
||||
|
||||
@ -541,10 +537,6 @@ function update_moduleinfo($cm, $moduleinfo, $course, $mform = null) {
|
||||
));
|
||||
$event->trigger();
|
||||
|
||||
add_to_log($course->id, $moduleinfo->modulename, "update",
|
||||
"view.php?id=$moduleinfo->coursemodule",
|
||||
"$moduleinfo->instance", $moduleinfo->coursemodule);
|
||||
|
||||
$moduleinfo = edit_module_post_actions($moduleinfo, $course);
|
||||
|
||||
return array($cm, $moduleinfo);
|
||||
|
@ -34,7 +34,7 @@ require_course_login($course, true);
|
||||
|
||||
// get list of all resource-like modules
|
||||
$allmodules = $DB->get_records('modules', array('visible'=>1));
|
||||
$modules = array();
|
||||
$availableresources = array();
|
||||
foreach ($allmodules as $key=>$module) {
|
||||
$modname = $module->name;
|
||||
$libfile = "$CFG->dirroot/mod/$modname/lib.php";
|
||||
@ -46,11 +46,15 @@ foreach ($allmodules as $key=>$module) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$modules[$modname] = get_string('modulename', $modname);
|
||||
//some hacky nasic logging
|
||||
add_to_log($course->id, $modname, 'view all', "index.php?id=$course->id", '');
|
||||
$availableresources[] = $modname;
|
||||
}
|
||||
|
||||
// Triger view event.
|
||||
$event = \core\event\course_resources_list_viewed::create(array('context' => context_course::instance($course->id)));
|
||||
$event->set_legacy_logdata($availableresources);
|
||||
$event->add_record_snapshot('course', $course);
|
||||
$event->trigger();
|
||||
|
||||
$strresources = get_string('resources');
|
||||
$strname = get_string('name');
|
||||
$strintro = get_string('moduleintro');
|
||||
@ -67,10 +71,10 @@ $usesections = course_format_uses_sections($course->format);
|
||||
$cms = array();
|
||||
$resources = array();
|
||||
foreach ($modinfo->cms as $cm) {
|
||||
if (!$cm->uservisible) {
|
||||
if (!in_array($cm->modname, $availableresources)) {
|
||||
continue;
|
||||
}
|
||||
if (!array_key_exists($cm->modname, $modules)) {
|
||||
if (!$cm->uservisible) {
|
||||
continue;
|
||||
}
|
||||
if (!$cm->has_view()) {
|
||||
@ -127,11 +131,7 @@ foreach ($cms as $cm) {
|
||||
}
|
||||
|
||||
$extra = empty($cm->extra) ? '' : $cm->extra;
|
||||
if (!empty($cm->icon)) {
|
||||
$icon = '<img src="'.$OUTPUT->pix_url($cm->icon).'" class="activityicon" alt="'.get_string('modulename', $cm->modname).'" /> ';
|
||||
} else {
|
||||
$icon = '<img src="'.$OUTPUT->pix_url('icon', $cm->modname).'" class="activityicon" alt="'.get_string('modulename', $cm->modname).'" /> ';
|
||||
}
|
||||
$icon = '<img src="'.$cm->get_icon_url().'" class="activityicon" alt="'.$cm->get_module_type_name().'" /> ';
|
||||
|
||||
if (isset($resource->intro) && isset($resource->introformat)) {
|
||||
$intro = format_module_intro('resource', $resource, $cm->id);
|
||||
@ -142,7 +142,7 @@ foreach ($cms as $cm) {
|
||||
$class = $cm->visible ? '' : 'class="dimmed"'; // hidden modules are dimmed
|
||||
$table->data[] = array (
|
||||
$printsection,
|
||||
"<a $class $extra href=\"$CFG->wwwroot/mod/$cm->modname/view.php?id=$cm->id\">".$icon.format_string($resource->name)."</a>",
|
||||
"<a $class $extra href=\"".$cm->url."\">".$icon.$cm->get_formatted_name()."</a>",
|
||||
$intro);
|
||||
}
|
||||
|
||||
|
@ -1943,7 +1943,10 @@ class core_course_courselib_testcase extends advanced_testcase {
|
||||
$eventdata->userid = $USER->id;
|
||||
$this->assertEventLegacyData($eventdata, $event);
|
||||
|
||||
$arr = array($cm->course, "course", "add mod", "../mod/assign/view.php?id=$cm->id", "assign $cm->instance");
|
||||
$arr = array(
|
||||
array($cm->course, "course", "add mod", "../mod/assign/view.php?id=$cm->id", "assign $cm->instance"),
|
||||
array($cm->course, "assign", "add", "view.php?id=$cm->id", $cm->instance, $cm->id)
|
||||
);
|
||||
$this->assertEventLegacyLogData($arr, $event);
|
||||
$this->assertEventContextNotUsed($event);
|
||||
|
||||
@ -2049,7 +2052,10 @@ class core_course_courselib_testcase extends advanced_testcase {
|
||||
$eventdata->userid = $USER->id;
|
||||
$this->assertEventLegacyData($eventdata, $event);
|
||||
|
||||
$arr = array($cm->course, "course", "update mod", "../mod/forum/view.php?id=$cm->id", "forum $cm->instance");
|
||||
$arr = array(
|
||||
array($cm->course, "course", "update mod", "../mod/forum/view.php?id=$cm->id", "forum $cm->instance"),
|
||||
array($cm->course, "forum", "update", "view.php?id=$cm->id", $cm->instance, $cm->id)
|
||||
);
|
||||
$this->assertEventLegacyLogData($arr, $event);
|
||||
$this->assertEventContextNotUsed($event);
|
||||
}
|
||||
@ -2360,4 +2366,35 @@ class core_course_courselib_testcase extends advanced_testcase {
|
||||
$dbcourses = $DB->get_records('course', array('category' => $category->id), 'sortorder', 'id');
|
||||
$this->assertEquals(array_keys($dbcourses), array_keys($courses));
|
||||
}
|
||||
|
||||
public function test_view_resources_list() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$course = self::getDataGenerator()->create_course();
|
||||
$coursecontext = context_course::instance($course->id);
|
||||
|
||||
$event = \core\event\course_resources_list_viewed::create(array('context' => context_course::instance($course->id)));
|
||||
$event->set_legacy_logdata(array('book', 'page', 'resource'));
|
||||
$sink = $this->redirectEvents();
|
||||
$event->trigger();
|
||||
$events = $sink->get_events();
|
||||
$sink->close();
|
||||
|
||||
// Validate the event.
|
||||
$event = $events[0];
|
||||
$this->assertInstanceOf('\core\event\course_resources_list_viewed', $event);
|
||||
$this->assertEquals(null, $event->objecttable);
|
||||
$this->assertEquals(null, $event->objectid);
|
||||
$this->assertEquals($course->id, $event->courseid);
|
||||
$this->assertEquals($coursecontext->id, $event->contextid);
|
||||
$expecteddesc = "User with id '$event->userid' viewed list of resources in course with id '$event->courseid'";
|
||||
$this->assertEquals($expecteddesc, $event->get_description());
|
||||
$expectedlegacydata = array(
|
||||
array($course->id, "book", "view all", 'index.php?id=' . $course->id, ''),
|
||||
array($course->id, "page", "view all", 'index.php?id=' . $course->id, ''),
|
||||
array($course->id, "resource", "view all", 'index.php?id=' . $course->id, ''),
|
||||
);
|
||||
$this->assertEventLegacyLogData($expectedlegacydata, $event);
|
||||
$this->assertEventContextNotUsed($event);
|
||||
}
|
||||
}
|
||||
|
@ -615,7 +615,14 @@ abstract class base implements \IteratorAggregate {
|
||||
if ($data = $this->get_legacy_logdata()) {
|
||||
$manager = get_log_manager();
|
||||
if (method_exists($manager, 'legacy_add_to_log')) {
|
||||
call_user_func_array(array($manager, 'legacy_add_to_log'), $data);
|
||||
if (is_array($data[0])) {
|
||||
// Some events require several entries in 'log' table.
|
||||
foreach ($data as $d) {
|
||||
call_user_func_array(array($manager, 'legacy_add_to_log'), $d);
|
||||
}
|
||||
} else {
|
||||
call_user_func_array(array($manager, 'legacy_add_to_log'), $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -110,8 +110,12 @@ class course_module_created extends base {
|
||||
* @return array of parameters to be passed to legacy add_to_log() function.
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
return array ($this->courseid, "course", "add mod", "../mod/" . $this->other['modulename'] . "/view.php?id=" .
|
||||
$log1 = array($this->courseid, "course", "add mod", "../mod/" . $this->other['modulename'] . "/view.php?id=" .
|
||||
$this->objectid, $this->other['modulename'] . " " . $this->other['instanceid']);
|
||||
$log2 = array($this->courseid, $this->other['modulename'], "add",
|
||||
"view.php?id={$this->objectid}",
|
||||
"{$this->other['instanceid']}", $this->objectid);
|
||||
return array($log1, $log2);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -110,8 +110,12 @@ class course_module_updated extends base {
|
||||
* @return array of parameters to be passed to legacy add_to_log() function.
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
return array ($this->courseid, "course", "update mod", "../mod/" . $this->other['modulename'] . "/view.php?id=" .
|
||||
$log1 = array($this->courseid, "course", "update mod", "../mod/" . $this->other['modulename'] . "/view.php?id=" .
|
||||
$this->objectid, $this->other['modulename'] . " " . $this->other['instanceid']);
|
||||
$log2 = array($this->courseid, $this->other['modulename'], "update",
|
||||
"view.php?id={$this->objectid}",
|
||||
"{$this->other['instanceid']}", $this->objectid);
|
||||
return array($log1, $log2);
|
||||
}
|
||||
|
||||
/**
|
||||
|
119
lib/classes/event/course_resources_list_viewed.php
Normal file
119
lib/classes/event/course_resources_list_viewed.php
Normal file
@ -0,0 +1,119 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Event for viewing the list of course resources.
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2014 Marina Glancy
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core\event;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Event for viewing the list of course resources.
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2014 Marina Glancy
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class course_resources_list_viewed extends base {
|
||||
|
||||
/** @var array list of resource types for legacy logging */
|
||||
private $resourceslist = null;
|
||||
|
||||
/**
|
||||
* 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 "User with id '$this->userid' viewed list of resources in course with id '$this->courseid'";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('eventcoursemoduleinstancelistviewed', 'core');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL related to the action.
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url("/course/resources.php", array('id' => $this->courseid));
|
||||
}
|
||||
|
||||
/**
|
||||
* List of resource types enabled in the system. This is used for legacy logging to log one record for each resource type.
|
||||
*
|
||||
* There is no public getter for this data because it does not depend on the
|
||||
* course. It always includes the list of all resource types in the system
|
||||
* even when some of them are not present in the course.
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function set_legacy_logdata($data) {
|
||||
$this->resourceslist = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the legacy event log data.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
if (empty($this->resourceslist)) {
|
||||
return null;
|
||||
}
|
||||
$logs = array();
|
||||
foreach ($this->resourceslist as $resourcename) {
|
||||
$logs[] = array($this->courseid, $resourcename, 'view all', 'index.php?id=' . $this->courseid, '');
|
||||
}
|
||||
return $logs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Custom validation.
|
||||
*
|
||||
* @throws \coding_exception
|
||||
* @return void
|
||||
*/
|
||||
protected function validate_data() {
|
||||
if ($this->contextlevel != CONTEXT_COURSE) {
|
||||
throw new \coding_exception('Context passed must be course context.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user