2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
17 namespace core_payment\event;
20 use core_payment\account;
23 * Class account_created
25 * @package core_payment
26 * @copyright 2020 Marina Glancy
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32 * Class account_created
34 * @package core_payment
35 * @copyright 2020 Marina Glancy
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38 class account_created extends base {
41 * Initialise event parameters.
43 protected function init() {
44 $this->data['objecttable'] = 'payment_accounts';
45 $this->data['crud'] = 'c';
46 $this->data['edulevel'] = self::LEVEL_OTHER;
50 * Create an instance of the event and add a record snapshot
52 * @param account $account
54 * @throws \coding_exception
56 public static function create_from_account(account $account) {
58 'objectid' => $account->get('id'),
59 'context' => $account->get_context(),
60 'other' => ['name' => $account->get('name')]
62 $event = self::create($eventparams);
63 $event->add_record_snapshot($event->objecttable, $account->to_record());
68 * Returns localised event name.
72 public static function get_name() {
73 return get_string('eventaccountcreated', 'payment');
77 * Returns non-localised event description with id's for admin use only.
81 public function get_description() {
82 $name = s($this->other['name']);
83 return "The user with id '$this->userid' created payment account with id '$this->objectid' and the name '{$name}'.";
87 * Returns relevant URL.
91 public function get_url() {
92 return new \moodle_url('/payment/accounts.php');