MDL-68076 core: log user's click on feedback links

This commit is contained in:
Shamim Rezaie 2020-05-19 11:14:20 +10:00
parent a3a9539bd7
commit 363aaf6eaa
9 changed files with 152 additions and 5 deletions

View 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');
}
}

View 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');
}
}

View file

@ -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 . '),' .