See Release Notes
Long Term Support Release
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Mock events for xAPI testing. 19 * 20 * @package core_xapi 21 * @copyright 2020 Ferran Recio 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 namespace core_xapi\event; 26 27 use context_system; 28 use core_xapi\local\statement; 29 30 defined('MOODLE_INTERNAL') || die(); 31 32 /** 33 * xAPI statement webservice testing event. 34 * 35 * @package core_xapi 36 * @since Moodle 3.9 37 * @copyright 2020 Ferran Recio 38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 39 */ 40 class xapi_test_statement_post extends \core\event\base { 41 42 /** 43 * Initialise the event data. 44 */ 45 protected function init() { 46 $this->data['crud'] = 'c'; 47 $this->data['edulevel'] = self::LEVEL_PARTICIPATING; 48 } 49 50 /** 51 * Returns localised general event name. 52 * 53 * @return string 54 */ 55 public static function get_name() { 56 return "xAPI test statement"; 57 } 58 59 /** 60 * Returns non-localised description of what happened. 61 * 62 * @return string 63 */ 64 public function get_description() { 65 return "User '$this->userid' send a statement to component '$this->component'"; 66 } 67 68 /** 69 * Compare if a given statement is similar to the one on the record. 70 * 71 * The information stored in the logstore is not exactly a xAPI standard. 72 * Similar checks for actor, verb, object (+ definition) and result for now. 73 * 74 * @param statement $statement An xAPI compatible statement. 75 * @return bool True if the $statement represents this event. 76 */ 77 public function compare_statement(statement $statement): bool { 78 // Check minified version. 79 $calculatedfields = ['actor', 'id', 'timestamp', 'stored', 'version']; 80 foreach ($calculatedfields as $field) { 81 if (isset($this->data['other'][$field])) { 82 return false; 83 } 84 } 85 // Check verb structure. 86 $data = $statement->get_verb()->get_data(); 87 if ($this->data['other']['verb']['id'] != $data->id) { 88 return false; 89 } 90 // Check user. 91 $users = $statement->get_all_users(); 92 if (empty($users) || !isset($users[$this->data['userid']])) { 93 return false; 94 } 95 // Check object. 96 $data = $statement->get_object()->get_data(); 97 if ($this->data['other']['object']['id'] != $data->id) { 98 return false; 99 } 100 return true; 101 } 102 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body