MDL-52710 tool_lp: Create event for framework viewed
This commit is contained in:
committed by
Frederic Massart
parent
20e7509522
commit
f73a29c181
@@ -553,6 +553,24 @@ class api {
|
||||
return $framework;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logg the competency framework viewed event.
|
||||
*
|
||||
* @param competency_framework|int $frameworkorid The competency_framework object or competency framework id
|
||||
* @return bool
|
||||
*/
|
||||
public static function competency_framework_viewed($frameworkorid) {
|
||||
$framework = $frameworkorid;
|
||||
if (!is_object($framework)) {
|
||||
$framework = new competency_framework($framework);
|
||||
}
|
||||
if (!has_any_capability(array('tool/lp:competencyread', 'tool/lp:competencymanage'), $framework->get_context())) {
|
||||
throw new required_capability_exception($framework->get_context(), 'tool/lp:competencyread', 'nopermissions', '');
|
||||
}
|
||||
\tool_lp\event\competency_framework_viewed::create_from_framework($framework)->trigger();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a search based on the provided filters and return a paginated list of records.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Competency framework viewed event.
|
||||
*
|
||||
* @package tool_lp
|
||||
* @copyright 2016 Issam Taboubi <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace tool_lp\event;
|
||||
|
||||
use core\event\base;
|
||||
use tool_lp\competency_framework;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Competency framework viewed event class.
|
||||
*
|
||||
* @package tool_lp
|
||||
* @since Moodle 3.1
|
||||
* @copyright 2016 Issam Taboubi <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class competency_framework_viewed extends base {
|
||||
|
||||
/**
|
||||
* Convenience method to instantiate the event.
|
||||
*
|
||||
* @param competency_framework $framework The framework.
|
||||
* @return self
|
||||
*/
|
||||
public static function create_from_framework(competency_framework $framework) {
|
||||
if (!$framework->get_id()) {
|
||||
throw new \coding_exception('The competency framework ID must be set.');
|
||||
}
|
||||
$event = static::create(array(
|
||||
'contextid' => $framework->get_contextid(),
|
||||
'objectid' => $framework->get_id()
|
||||
));
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user with id '$this->userid' viewed the competency framework with id '$this->objectid'";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('eventcompetencyframeworkviewed', 'tool_lp');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns relevant URL.
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url('/admin/tool/lp/competencies.php', array(
|
||||
'competencyframeworkid' => $this->objectid,
|
||||
'pagecontextid' => $this->contextid
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Init method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'r';
|
||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
||||
$this->data['objecttable'] = competency_framework::TABLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get_objectid_mapping method.
|
||||
*
|
||||
* @return string the name of the restore mapping the objectid links to
|
||||
*/
|
||||
public static function get_objectid_mapping() {
|
||||
return base::NOT_MAPPED;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -567,6 +567,48 @@ class external extends external_api {
|
||||
return new external_value(PARAM_INT, 'The number of competency frameworks found.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of competency_framework_viewed() parameters.
|
||||
*
|
||||
* @return \external_function_parameters
|
||||
*/
|
||||
public static function competency_framework_viewed_parameters() {
|
||||
$id = new external_value(
|
||||
PARAM_INT,
|
||||
'The competency framework id',
|
||||
VALUE_REQUIRED
|
||||
);
|
||||
|
||||
$params = array(
|
||||
'id' => $id
|
||||
);
|
||||
return new external_function_parameters($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log event competency framework viewed.
|
||||
*
|
||||
* @param int $id The competency framework ID.
|
||||
* @return boolean
|
||||
*/
|
||||
public static function competency_framework_viewed($id) {
|
||||
$params = self::validate_parameters(self::competency_framework_viewed_parameters(),
|
||||
array(
|
||||
'id' => $id
|
||||
));
|
||||
return api::competency_framework_viewed($params['id']);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of competency_framework_viewed() result value.
|
||||
*
|
||||
* @return \external_description
|
||||
*/
|
||||
public static function competency_framework_viewed_returns() {
|
||||
return new external_value(PARAM_BOOL, 'True if the event competency framework was logged');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of data_for_competency_frameworks_manage_page() parameters.
|
||||
*
|
||||
|
||||
@@ -58,4 +58,7 @@ echo $output->heading($pagetitle);
|
||||
$page = new \tool_lp\output\manage_competencies_page($framework, $search, $pagecontext);
|
||||
echo $output->render($page);
|
||||
|
||||
// Log the framework viewed event after rendering the page.
|
||||
\tool_lp\api::competency_framework_viewed($framework);
|
||||
|
||||
echo $output->footer();
|
||||
|
||||
@@ -93,6 +93,15 @@ $functions = array(
|
||||
'capabilities' => 'tool/lp:competencyview',
|
||||
'ajax' => true,
|
||||
),
|
||||
'tool_lp_competency_framework_viewed' => array(
|
||||
'classname' => 'tool_lp\external',
|
||||
'methodname' => 'competency_framework_viewed',
|
||||
'classpath' => '',
|
||||
'description' => 'Log event competency framework viewed',
|
||||
'type' => 'read',
|
||||
'capabilities' => 'tool/lp:competencyread',
|
||||
'ajax' => true,
|
||||
),
|
||||
'tool_lp_data_for_competency_frameworks_manage_page' => array(
|
||||
'classname' => 'tool_lp\external',
|
||||
'methodname' => 'data_for_competency_frameworks_manage_page',
|
||||
|
||||
@@ -97,6 +97,7 @@ $string['edituserevidence'] = 'Edit evidence';
|
||||
$string['eventcompetencyframeworkcreated'] = 'Competency framework created.';
|
||||
$string['eventcompetencyframeworkdeleted'] = 'Competency framework deleted.';
|
||||
$string['eventcompetencyframeworkupdated'] = 'Competency framework updated.';
|
||||
$string['eventcompetencyframeworkviewed'] = 'Competency framework viewed.';
|
||||
$string['evidence'] = 'Evidence';
|
||||
$string['evidence_competencyrule'] = 'The rule of the competency was met.';
|
||||
$string['evidence_coursecompleted'] = 'The course \'{$a}\' was completed.';
|
||||
|
||||
@@ -122,4 +122,31 @@ class tool_lp_event_testcase extends advanced_testcase {
|
||||
$this->assertDebuggingNotCalled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the competency framework viewed event.
|
||||
*
|
||||
*/
|
||||
public function test_competency_framework_viewed() {
|
||||
$this->resetAfterTest(true);
|
||||
$this->setAdminUser();
|
||||
$lpg = $this->getDataGenerator()->get_plugin_generator('tool_lp');
|
||||
|
||||
$framework = $lpg->create_framework();
|
||||
|
||||
// Trigger and capture the event.
|
||||
$sink = $this->redirectEvents();
|
||||
api::competency_framework_viewed($framework);
|
||||
|
||||
// Get our event event.
|
||||
$events = $sink->get_events();
|
||||
$event = reset($events);
|
||||
|
||||
// Check that the event data is valid.
|
||||
$this->assertInstanceOf('\tool_lp\event\competency_framework_viewed', $event);
|
||||
$this->assertEquals($framework->get_id(), $event->objectid);
|
||||
$this->assertEquals($framework->get_contextid(), $event->contextid);
|
||||
$this->assertEventContextNotUsed($event);
|
||||
$this->assertDebuggingNotCalled();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,6 +25,6 @@
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
|
||||
$plugin->version = 2015111045; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->version = 2015111046; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2014110400; // Requires this Moodle version.
|
||||
$plugin->component = 'tool_lp'; // Full name of the plugin (used for diagnostics).
|
||||
|
||||
Reference in New Issue
Block a user