69d7763552f0d72e506cd8bad8d2ad22b4ca6190
[shipsimu.git] / application / ship-simu / main / user / extended / class_ShipSimuGuest.php
1 <?php
2 /**
3  * A special guest class for Ship-Simu
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             0.0.0
7  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, this is free software
8  * @license             GNU GPL 3.0 or any newer version
9  * @link                http://www.ship-simu.org
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <http://www.gnu.org/licenses/>.
23  */
24 class ShipSimuGuest extends ShipSimuBaseUser implements ManageableGuest {
25         // Exceptions
26         const EXCEPTION_USERNAME_NOT_FOUND   = 0x170;
27         const EXCEPTION_USER_EMAIL_NOT_FOUND = 0x171;
28         const EXCEPTION_USER_PASS_MISMATCH   = 0x172;
29
30         /**
31          * Protected constructor
32          *
33          * @param       $className      Name of the class
34          * @return      void
35          */
36         protected function __construct ($className = __CLASS__) {
37                 // Call parent constructor
38                 parent::__construct($className);
39         }
40
41         /**
42          * Creates an instance of this user class by a provided username. This
43          * factory method will check if the username is already taken and if not
44          * so it will throw an exception.
45          *
46          * @param       $userName               Username we need a class instance for
47          * @return      $userInstance   An instance of this user class
48          * @throws      UsernameMissingException        If the username does not exist
49          */
50         public final static function createGuestByUsername ($userName) {
51                 // Get a new instance
52                 $userInstance = new ShipSimuGuest();
53
54                 // Set the username
55                 $userInstance->setUserName($userName);
56
57                 // Check if the username exists
58                 if (!$userInstance->ifUsernameExists()) {
59                         // Throw an exception here
60                         throw new UsernameMissingException(array($userInstance, $userName), self::EXCEPTION_USERNAME_NOT_FOUND);
61                 }
62
63                 // Return the instance
64                 return $userInstance;
65         }
66
67         /**
68          * Creates an instance of this user class by a provided email address. This
69          * factory method will not check if the email address is there.
70          *
71          * @param       $email                  Email address of the user
72          * @return      $userInstance   An instance of this user class
73          */
74         public final static function createGuestByEmail ($email) {
75                 // Get a new instance
76                 $userInstance = new ShipSimuGuest();
77
78                 // Set the username
79                 $userInstance->setEmail($email);
80
81                 // Return the instance
82                 return $userInstance;
83         }
84
85         /**
86          * Updates the last activity timestamp and last performed action in the
87          * database result. You should call flushPendingUpdates() to flush these updates
88          * to the database layer.
89          *
90          * @param       $requestInstance        A requestable class instance
91          * @return      void
92          */
93         public function updateLastActivity (Requestable $requestInstance) {
94                 // No activity will be logged for guest accounts
95         }
96
97         /**
98          * Flushs all pending updates to the database layer
99          *
100          * @return      void
101          */
102         public function flushPendingUpdates () {
103                 // No updates will be flushed to database!
104         }
105 }
106
107 // [EOF]
108 ?>