3 namespace Org\Mxchange\CoreFramework\User\Guest;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Manager\Guest\ManageableGuest;
7 use Org\Mxchange\CoreFramework\Registry\Registerable;
8 use Org\Mxchange\CoreFramework\Request\Requestable;
9 use Org\Mxchange\CoreFramework\User\BaseUser;
12 * A generic class for handling guests
14 * @author Roland Haeder <webmaster@shipsimu.org>
16 <<<<<<< HEAD:framework/main/classes/user/guest/class_Guest.php
17 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
19 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2016 Core Developer Team
20 >>>>>>> Some updates::inc/main/classes/user/guest/class_Guest.php
21 * @license GNU GPL 3.0 or any newer version
22 * @link http://www.shipsimu.org
24 * This program is free software: you can redistribute it and/or modify
25 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation, either version 3 of the License, or
27 * (at your option) any later version.
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
34 * You should have received a copy of the GNU General Public License
35 * along with this program. If not, see <http://www.gnu.org/licenses/>.
37 class Guest extends BaseUser implements ManageableGuest, Registerable {
39 const EXCEPTION_USERNAME_NOT_FOUND = 0x170;
40 const EXCEPTION_USER_EMAIL_NOT_FOUND = 0x171;
41 const EXCEPTION_USER_PASS_MISMATCH = 0x172;
42 const EXCEPTION_USER_NOT_GUEST = 0x173;
45 * Protected constructor
49 protected function __construct () {
50 // Call parent constructor
51 parent::__construct(__CLASS__);
55 * Creates a user by a given request instance
57 * @param $requestInstance An instance of a Requestable class
58 * @return $userInstance An instance of this user class
59 * @todo Add more ways over creating user classes
61 public static final function createGuestByRequest (Requestable $requestInstance) {
62 // Determine if by email or username
63 if (!is_null($requestInstance->getRequestElement('username'))) {
65 $userInstance = self::createGuestByUserName($requestInstance->getRequestElement('username'));
66 } elseif (!is_null($requestInstance->getRequestElement('email'))) {
68 $userInstance = self::createGuestByEmail($requestInstance->getRequestElement('email'));
71 $userInstance = new Guest();
72 $userInstance->debugBackTrace('More ways of creating user classes are needed here.');
76 // Return the prepared instance
81 * Creates an instance of this user class by a provided username. This
82 * factory method will check if username is already taken and if not so it
83 * will throw an exception.
85 * @param $userName Username we need a class instance for
86 * @return $userInstance An instance of this user class
87 * @throws UsernameMissingException If the username does not exist
88 * @throws UserNoGuestException If the user is no guest account
90 public static final function createGuestByUsername ($userName) {
92 $userInstance = new Guest();
95 $userInstance->setUserName($userName);
97 // Check if username exists
98 if ($userInstance->ifUsernameExists() === false) {
99 // Throw an exception here
100 throw new UsernameMissingException(array($userInstance, $userName), self::EXCEPTION_USERNAME_NOT_FOUND);
101 } elseif ($userInstance->isGuest() === false) {
102 // Sanity check on 'guest' status failed
103 throw new UserNoGuestException(array($userInstance, $userName), self::EXCEPTION_USER_NOT_GUEST_STATUS);
106 // Return the instance
107 return $userInstance;
111 * Creates an instance of this user class by a provided email address. This
112 * factory method will not check if email address is there.
114 * @param $email Email address of the user
115 * @return $userInstance An instance of this user class
117 public static final function createGuestByEmail ($email) {
118 // Get a new instance
119 $userInstance = new Guest();
122 $userInstance->setEmail($email);
124 // Return the instance
125 return $userInstance;
129 * Updates the last activity timestamp and last performed action in the
130 * database result. You should call flushPendingUpdates() to flush these updates
131 * to the database layer.
133 * @param $requestInstance A requestable class instance
136 public function updateLastActivity (Requestable $requestInstance) {
137 // No activity will be logged for guest accounts
141 * Flushs all pending updates to the database layer
145 public function flushPendingUpdates () {
146 // No updates will be flushed to database!