| 1 | efrain | 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 |  * User login event.
 | 
        
           |  |  | 19 |  *
 | 
        
           |  |  | 20 |  * @package    core
 | 
        
           |  |  | 21 |  * @copyright  2013 Frédéric Massart
 | 
        
           |  |  | 22 |  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 | 
        
           |  |  | 23 |  */
 | 
        
           |  |  | 24 |   | 
        
           |  |  | 25 | namespace core\event;
 | 
        
           |  |  | 26 |   | 
        
           |  |  | 27 | defined('MOODLE_INTERNAL') || die();
 | 
        
           |  |  | 28 |   | 
        
           |  |  | 29 | /**
 | 
        
           |  |  | 30 |  * User login event class.
 | 
        
           |  |  | 31 |  *
 | 
        
           |  |  | 32 |  * @property-read array $other {
 | 
        
           |  |  | 33 |  *      Extra information about event.
 | 
        
           |  |  | 34 |  *
 | 
        
           |  |  | 35 |  *      - string username: name of user.
 | 
        
           |  |  | 36 |  * }
 | 
        
           |  |  | 37 |  *
 | 
        
           |  |  | 38 |  * @package    core
 | 
        
           |  |  | 39 |  * @since      Moodle 2.6
 | 
        
           |  |  | 40 |  * @copyright  2013 Frédéric Massart
 | 
        
           |  |  | 41 |  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 | 
        
           |  |  | 42 |  */
 | 
        
           |  |  | 43 | class user_loggedin extends base {
 | 
        
           |  |  | 44 |   | 
        
           |  |  | 45 |     /**
 | 
        
           |  |  | 46 |      * Returns non-localised event description with id's for admin use only.
 | 
        
           |  |  | 47 |      *
 | 
        
           |  |  | 48 |      * @return string
 | 
        
           |  |  | 49 |      */
 | 
        
           |  |  | 50 |     public function get_description() {
 | 
        
           |  |  | 51 |         return "The user with id '$this->userid' has logged in.";
 | 
        
           |  |  | 52 |     }
 | 
        
           |  |  | 53 |   | 
        
           |  |  | 54 |     /**
 | 
        
           |  |  | 55 |      * Return localised event name.
 | 
        
           |  |  | 56 |      *
 | 
        
           |  |  | 57 |      * @return string
 | 
        
           |  |  | 58 |      */
 | 
        
           |  |  | 59 |     public static function get_name() {
 | 
        
           |  |  | 60 |         return get_string('eventuserloggedin', 'auth');
 | 
        
           |  |  | 61 |     }
 | 
        
           |  |  | 62 |   | 
        
           |  |  | 63 |     /**
 | 
        
           |  |  | 64 |      * Get URL related to the action.
 | 
        
           |  |  | 65 |      *
 | 
        
           |  |  | 66 |      * @return \moodle_url
 | 
        
           |  |  | 67 |      */
 | 
        
           |  |  | 68 |     public function get_url() {
 | 
        
           |  |  | 69 |         return new \moodle_url('/user/profile.php', array('id' => $this->data['objectid']));
 | 
        
           |  |  | 70 |     }
 | 
        
           |  |  | 71 |   | 
        
           |  |  | 72 |     /**
 | 
        
           |  |  | 73 |      * Return the username of the logged in user.
 | 
        
           |  |  | 74 |      *
 | 
        
           |  |  | 75 |      * @return string
 | 
        
           |  |  | 76 |      */
 | 
        
           |  |  | 77 |     public function get_username() {
 | 
        
           |  |  | 78 |         return $this->other['username'];
 | 
        
           |  |  | 79 |     }
 | 
        
           |  |  | 80 |   | 
        
           |  |  | 81 |     /**
 | 
        
           |  |  | 82 |      * Init method.
 | 
        
           |  |  | 83 |      *
 | 
        
           |  |  | 84 |      * @return void
 | 
        
           |  |  | 85 |      */
 | 
        
           |  |  | 86 |     protected function init() {
 | 
        
           |  |  | 87 |         $this->context = \context_system::instance();
 | 
        
           |  |  | 88 |         $this->data['crud'] = 'r';
 | 
        
           |  |  | 89 |         $this->data['edulevel'] = self::LEVEL_OTHER;
 | 
        
           |  |  | 90 |         $this->data['objecttable'] = 'user';
 | 
        
           |  |  | 91 |     }
 | 
        
           |  |  | 92 |   | 
        
           |  |  | 93 |     /**
 | 
        
           |  |  | 94 |      * Custom validation.
 | 
        
           |  |  | 95 |      *
 | 
        
           |  |  | 96 |      * @throws \coding_exception when validation does not pass.
 | 
        
           |  |  | 97 |      * @return void
 | 
        
           |  |  | 98 |      */
 | 
        
           |  |  | 99 |     protected function validate_data() {
 | 
        
           |  |  | 100 |         parent::validate_data();
 | 
        
           |  |  | 101 |   | 
        
           |  |  | 102 |         if (!isset($this->other['username'])) {
 | 
        
           |  |  | 103 |             throw new \coding_exception('The \'username\' value must be set in other.');
 | 
        
           |  |  | 104 |         }
 | 
        
           |  |  | 105 |     }
 | 
        
           |  |  | 106 |   | 
        
           |  |  | 107 |     public static function get_objectid_mapping() {
 | 
        
           |  |  | 108 |         return array('db' => 'user', 'restore' => 'user');
 | 
        
           |  |  | 109 |     }
 | 
        
           |  |  | 110 |   | 
        
           |  |  | 111 |     public static function get_other_mapping() {
 | 
        
           |  |  | 112 |         return false;
 | 
        
           |  |  | 113 |     }
 | 
        
           |  |  | 114 | }
 |