3 * A generic class for handling guests
5 * @author Roland Haeder <webmaster@shipsimu.org>
7 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Core Developer Team
8 * @license GNU GPL 3.0 or any newer version
9 * @link http://www.shipsimu.org
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.
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.
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/>.
24 class Guest extends BaseUser implements ManageableGuest, Registerable {
26 const EXCEPTION_USERNAME_NOT_FOUND = 0x170;
27 const EXCEPTION_USER_EMAIL_NOT_FOUND = 0x171;
28 const EXCEPTION_USER_PASS_MISMATCH = 0x172;
29 const EXCEPTION_USER_NOT_GUEST = 0x173;
32 * Protected constructor
36 protected function __construct () {
37 // Call parent constructor
38 parent::__construct(__CLASS__);
42 * Creates an instance of this user class by a provided username. This
43 * factory method will check if username is already taken and if not so it
44 * will throw an exception.
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 * @throws UserNoGuestException If the user is no guest account
51 public static final function createGuestByUsername ($userName) {
53 $userInstance = new Guest();
56 $userInstance->setUserName($userName);
58 // Check if username exists
59 if ($userInstance->ifUsernameExists() === FALSE) {
60 // Throw an exception here
61 throw new UsernameMissingException(array($userInstance, $userName), self::EXCEPTION_USERNAME_NOT_FOUND);
62 } elseif ($userInstance->isGuest() === FALSE) {
63 // Sanity check on 'guest' status failed
64 throw new UserNoGuestException(array($userInstance, $userName), self::EXCEPTION_USER_NOT_GUEST_STATUS);
67 // Return the instance
72 * Creates an instance of this user class by a provided email address. This
73 * factory method will not check if email address is there.
75 * @param $email Email address of the user
76 * @return $userInstance An instance of this user class
78 public static final function createGuestByEmail ($email) {
80 $userInstance = new Guest();
83 $userInstance->setEmail($email);
85 // Return the instance
90 * Updates the last activity timestamp and last performed action in the
91 * database result. You should call flushPendingUpdates() to flush these updates
92 * to the database layer.
94 * @param $requestInstance A requestable class instance
97 public function updateLastActivity (Requestable $requestInstance) {
98 // No activity will be logged for guest accounts
102 * Flushs all pending updates to the database layer
106 public function flushPendingUpdates () {
107 // No updates will be flushed to database!