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 const EXCEPTION_USERNAME_NOT_FOUND = 0xd00;
38 protected function __construct ($class = "") {
39 // Is the class name empty? Then this is not a specialized user class
40 if (empty($class)) $class = __CLASS__;
42 // Call parent constructor
43 parent::__construct($class);
45 // Set part description
46 $this->setObjectDescription("Generic user class");
48 // Create unique ID number
49 $this->createUniqueID();
52 $this->removeNumberFormaters();
53 $this->removeSystemArray();
57 * Creates an instance of this user class by a provided username. This
58 * factory method will check if the username is already taken and if not
59 * so it will throw an exception.
61 * @param $username Username we need a class instance for
62 * @return $userInstance An instance of this user class
63 * @throws UsernameMissingException If the username does not exist
65 public final static function createUserByUsername ($userName) {
67 $userInstance = new User();
70 $userInstance->setUsername($userName);
72 // Check if the username exists
73 if (!$userInstance->ifUsernameExists()) {
74 // Throw an exception here
75 throw new UsernameMissingException(array($userInstance, $userName), self::EXCEPTION_USERNAME_NOT_FOUND);
78 // Return the instance
85 * @param $userName The username to set
88 protected final function setUsername ($userName) {
89 $this->userNane = $userName;
95 * @return $userName The username to get
97 public final function getUsername () {
98 return $this->userNane;
102 * Determines wether the username exists or not
104 * @return $exists Wether the username exists
106 protected function ifUsernameExists () {
107 // By default the username does exist
110 // Try to get a UserDatabaseClient object back
112 // Get the instance by providing this class
113 $this->userClient = UserDatabaseClient::createUserDatabaseClient($this);
114 } catch (ClientUserNameNotFoundException $e) {