Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.
   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  namespace core_payment\event;
  18  
  19  use core\event\base;
  20  use core_payment\account;
  21  
  22  /**
  23   * Class account_updated
  24   *
  25   * @package     core_payment
  26   * @copyright   2020 Marina Glancy
  27   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  28   */
  29  
  30  
  31  /**
  32   * Class account_updated
  33   *
  34   * @package     core_payment
  35   * @copyright   2020 Marina Glancy
  36   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class account_updated extends base {
  39  
  40      /**
  41       * Initialise event parameters.
  42       */
  43      protected function init() {
  44          $this->data['objecttable'] = 'payment_accounts';
  45          $this->data['crud'] = 'u';
  46          $this->data['edulevel'] = self::LEVEL_OTHER;
  47      }
  48  
  49      /**
  50       * Create an instance of the event and add a record snapshot
  51       *
  52       * @param account $account
  53       * @param array $other
  54       * @return base
  55       */
  56      public static function create_from_account(account $account, array $other = []) {
  57          $eventparams = [
  58              'objectid' => $account->get('id'),
  59              'context'  => $account->get_context(),
  60              'other'    => ['name' => $account->get('name')] + $other
  61          ];
  62          $event = self::create($eventparams);
  63          $event->add_record_snapshot($event->objecttable, $account->to_record());
  64          return $event;
  65      }
  66  
  67      /**
  68       * Returns localised event name.
  69       *
  70       * @return string
  71       */
  72      public static function get_name() {
  73          return get_string('eventaccountupdated', 'payment');
  74      }
  75  
  76      /**
  77       * Returns non-localised event description with id's for admin use only.
  78       *
  79       * @return string
  80       */
  81      public function get_description() {
  82          $name = s($this->other['name']);
  83          if (!empty($this->other['archived'])) {
  84              $verb = 'archived';
  85          } else if (!empty($this->other['restored'])) {
  86              $verb = 'restored';
  87          } else {
  88              $verb = 'updated';
  89          }
  90          return "The user with id '$this->userid' $verb payment account with id '$this->objectid' and the name '{$name}'.";
  91      }
  92  
  93      /**
  94       * Returns relevant URL.
  95       *
  96       * @return \moodle_url
  97       */
  98      public function get_url() {
  99          return new \moodle_url('/payment/accounts.php');
 100      }
 101  }