Skip to content

Commit

Permalink
MDL-68076 core: log user's click on feedback links
Browse files Browse the repository at this point in the history
  • Loading branch information
rezaies committed Jun 4, 2020
1 parent a3a9539 commit 363aaf6
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 5 deletions.
2 changes: 2 additions & 0 deletions lang/en/moodle.php
Expand Up @@ -805,6 +805,8 @@
$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';
Expand Down
2 changes: 1 addition & 1 deletion lib/amd/build/userfeedback.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/amd/build/userfeedback.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/amd/src/userfeedback.js
Expand Up @@ -92,6 +92,7 @@ const recordAction = clickedItem => {
methodname: 'core_create_userfeedback_action_record',
args: {
action: clickedItem.dataset.action,
contextid: M.cfg.contextid,
}
}])[0];
}
Expand Down
63 changes: 63 additions & 0 deletions lib/classes/event/userfeedback_give.php
@@ -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 changes: 63 additions & 0 deletions lib/classes/event/userfeedback_remind.php
@@ -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');
}

}
16 changes: 14 additions & 2 deletions lib/classes/external/userfeedback/record_action.php
Expand Up @@ -47,24 +47,36 @@ 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'),
]);
}

/**
* 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 . '),' .
Expand Down

0 comments on commit 363aaf6

Please sign in to comment.