3 * A generic class for handling users
5 * @author Roland Haeder <webmaster@ship-simu.org>
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
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 User extends BaseFrameworkSystem implements ManageableUser {
28 private $username = "";
31 * An instance of a database wrapper
33 private $userWrapper = null;
36 const EXCEPTION_USERNAME_NOT_FOUND = 0xd00;
43 protected function __construct ($class = "") {
44 // Is the class name empty? Then this is not a specialized user class
45 if (empty($class)) $class = __CLASS__;
47 // Call parent constructor
48 parent::__construct($class);
50 // Set part description
51 $this->setObjectDescription("Generic user class");
53 // Create unique ID number
54 $this->createUniqueID();
57 $this->removeNumberFormaters();
58 $this->removeSystemArray();
62 * Creates an instance of this user class by a provided username. This
63 * factory method will check if the username is already taken and if not
64 * so it will throw an exception.
66 * @param $username Username we need a class instance for
67 * @return $userInstance An instance of this user class
68 * @throws UsernameMissingException If the username does not exist
70 public final static function createUserByUsername ($userName) {
72 $userInstance = new User();
75 $userInstance->setUsername($userName);
77 // Check if the username exists
78 if (!$userInstance->ifUsernameExists()) {
79 // Throw an exception here
80 throw new UsernameMissingException(array($userInstance, $userName), self::EXCEPTION_USERNAME_NOT_FOUND);
83 // Return the instance
90 * @param $userName The username to set
93 protected final function setUsername ($userName) {
94 $this->userNane = $userName;
100 * @return $userName The username to get
102 public final function getUsername () {
103 return $this->userNane;
107 * Determines wether the username exists or not
109 * @return $exists Wether the username exists
111 protected function ifUsernameExists () {
112 // By default the username does exist
115 // Try to get a UserDatabaseWrapper object back
117 // Get the instance by providing this class
118 $this->userWrapper = UserDatabaseWrapper::createUserDatabaseWrapper($this);
119 } catch (WrapperUserNameNotFoundException $e) {