mirror of
https://github.com/moodle/moodle.git
synced 2025-01-29 19:50:14 +01:00
MDL-68076 core: log user's click on feedback links
This commit is contained in:
parent
a3a9539bd7
commit
363aaf6eaa
@ -805,6 +805,8 @@ $string['eventsearchresultsviewed'] = 'Search results viewed';
|
||||
$string['eventunknownlogged'] = 'Unknown event';
|
||||
$string['eventusercreated'] = 'User created';
|
||||
$string['eventuserdeleted'] = 'User deleted';
|
||||
$string['eventuserfeedbackgiven'] = 'Feedback link clicked';
|
||||
$string['eventuserfeedbackremind'] = 'Remind me later feedback link clicked';
|
||||
$string['eventuserlistviewed'] = 'User list viewed';
|
||||
$string['eventuserloggedout'] = 'User logged out';
|
||||
$string['eventuserpasswordpolicyfailed'] = 'User password failed password policy';
|
||||
|
2
lib/amd/build/userfeedback.min.js
vendored
2
lib/amd/build/userfeedback.min.js
vendored
@ -1,2 +1,2 @@
|
||||
define ("core/userfeedback",["exports","core/ajax","core/notification"],function(a,b,c){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.registerEventListeners=void 0;b=d(b);c=d(c);function d(a){return a&&a.__esModule?a:{default:a}}var f={regions:{root:"[data-region=\"core/userfeedback\"]"},actions:{}};f.actions.give="".concat(f.regions.root," [data-action=\"give\"]");f.actions.remind="".concat(f.regions.root," [data-action=\"remind\"]");a.registerEventListeners=function registerEventListeners(){document.addEventListener("click",function(a){var b=a.target.closest(f.actions.give);if(b){a.preventDefault();g().then(function(){return i(b)}).then(h).catch(c.default.exception)}var d=a.target.closest(f.actions.remind);if(d){a.preventDefault();Promise.resolve(d).then(i).then(h).catch(c.default.exception)}})};var g=function(){return b.default.call([{methodname:"core_get_userfeedback_url",args:{contextid:M.cfg.contextid}}])[0].then(function(a){if(!window.open(a)){throw new Error("Unable to open popup")}})},h=function(a){if(a.dataset.record){return b.default.call([{methodname:"core_create_userfeedback_action_record",args:{action:a.dataset.action}}])[0]}return Promise.resolve()},i=function(a){if(a.dataset.hide){a.closest(f.regions.root).remove()}return a}});
|
||||
define ("core/userfeedback",["exports","core/ajax","core/notification"],function(a,b,c){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.registerEventListeners=void 0;b=d(b);c=d(c);function d(a){return a&&a.__esModule?a:{default:a}}var f={regions:{root:"[data-region=\"core/userfeedback\"]"},actions:{}};f.actions.give="".concat(f.regions.root," [data-action=\"give\"]");f.actions.remind="".concat(f.regions.root," [data-action=\"remind\"]");a.registerEventListeners=function registerEventListeners(){document.addEventListener("click",function(a){var b=a.target.closest(f.actions.give);if(b){a.preventDefault();g().then(function(){return i(b)}).then(h).catch(c.default.exception)}var d=a.target.closest(f.actions.remind);if(d){a.preventDefault();Promise.resolve(d).then(i).then(h).catch(c.default.exception)}})};var g=function(){return b.default.call([{methodname:"core_get_userfeedback_url",args:{contextid:M.cfg.contextid}}])[0].then(function(a){if(!window.open(a)){throw new Error("Unable to open popup")}})},h=function(a){if(a.dataset.record){return b.default.call([{methodname:"core_create_userfeedback_action_record",args:{action:a.dataset.action,contextid:M.cfg.contextid}}])[0]}return Promise.resolve()},i=function(a){if(a.dataset.hide){a.closest(f.regions.root).remove()}return a}});
|
||||
//# sourceMappingURL=userfeedback.min.js.map
|
||||
|
File diff suppressed because one or more lines are too long
@ -92,6 +92,7 @@ const recordAction = clickedItem => {
|
||||
methodname: 'core_create_userfeedback_action_record',
|
||||
args: {
|
||||
action: clickedItem.dataset.action,
|
||||
contextid: M.cfg.contextid,
|
||||
}
|
||||
}])[0];
|
||||
}
|
||||
|
63
lib/classes/event/userfeedback_give.php
Normal file
63
lib/classes/event/userfeedback_give.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Feedback given.
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2020 Shamim Rezaie <shamim@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core\event;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Class userfeedback_give
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2020 Shamim Rezaie <shamim@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class userfeedback_give extends base {
|
||||
|
||||
/**
|
||||
* Initialise required event data properties.
|
||||
*/
|
||||
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 with id '$this->userid' clicked on the give feedback link";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('eventuserfeedbackgiven');
|
||||
}
|
||||
|
||||
}
|
63
lib/classes/event/userfeedback_remind.php
Normal file
63
lib/classes/event/userfeedback_remind.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Feedback remind.
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2020 Shamim Rezaie <shamim@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core\event;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Class userfeedback_remind
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2020 Shamim Rezaie <shamim@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class userfeedback_remind extends base {
|
||||
|
||||
/**
|
||||
* Initialise required event data properties.
|
||||
*/
|
||||
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 with id '$this->userid' clicked on the remind later to feedback link";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('eventuserfeedbackremind');
|
||||
}
|
||||
|
||||
}
|
@ -47,6 +47,7 @@ class record_action extends external_api {
|
||||
public static function execute_parameters() {
|
||||
return new external_function_parameters([
|
||||
'action' => new external_value(PARAM_ALPHA, 'The action taken by user'),
|
||||
'contextid' => new external_value(PARAM_INT, 'The context id of the page the user is in'),
|
||||
]);
|
||||
}
|
||||
|
||||
@ -54,17 +55,28 @@ class record_action extends external_api {
|
||||
* Record users action to the feedback CTA
|
||||
*
|
||||
* @param string $action The action the user took
|
||||
* @param int $contextid The context id
|
||||
* @throws \invalid_parameter_exception
|
||||
*/
|
||||
public static function execute(string $action) {
|
||||
external_api::validate_parameters(self::execute_parameters(), ['action' => $action]);
|
||||
public static function execute(string $action, int $contextid) {
|
||||
external_api::validate_parameters(self::execute_parameters(), [
|
||||
'action' => $action,
|
||||
'contextid' => $contextid,
|
||||
]);
|
||||
|
||||
$context = \context::instance_by_id($contextid);
|
||||
self::validate_context($context);
|
||||
|
||||
switch ($action) {
|
||||
case 'give':
|
||||
set_user_preference('core_userfeedback_give', time());
|
||||
$event = \core\event\userfeedback_give::create(['context' => $context]);
|
||||
$event->trigger();
|
||||
break;
|
||||
case 'remind':
|
||||
set_user_preference('core_userfeedback_remind', time());
|
||||
$event = \core\event\userfeedback_remind::create(['context' => $context]);
|
||||
$event->trigger();
|
||||
break;
|
||||
default:
|
||||
throw new \invalid_parameter_exception('Invalid value for action parameter (value: ' . $action . '),' .
|
||||
|
@ -69,6 +69,7 @@ class record_action_testcase extends externallib_advanced_testcase {
|
||||
$context = context_system::instance();
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$this->setUser($user);
|
||||
$eventsink = $this->redirectEvents();
|
||||
|
||||
$now = time();
|
||||
|
||||
@ -78,5 +79,10 @@ class record_action_testcase extends externallib_advanced_testcase {
|
||||
|
||||
$preference = get_user_preferences('core_userfeedback_' . $action);
|
||||
$this->assertGreaterThanOrEqual($now, $preference);
|
||||
|
||||
$events = $eventsink->get_events();
|
||||
$this->assertCount(1, $events);
|
||||
$this->assertInstanceOf('\core\event\userfeedback_' . $action, $events[0]);
|
||||
$eventsink->clear();
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$version = 2020052900.02; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
$version = 2020052900.03; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
// RR = release increments - 00 in DEV branches.
|
||||
// .XX = incremental changes.
|
||||
$release = '3.9dev+ (Build: 20200529)'; // Human-friendly version name
|
||||
|
Loading…
x
Reference in New Issue
Block a user