* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-class User extends BaseFrameworkSystem implements ManageableUser {
+class User extends BaseFrameworkSystem implements ManageableUser, Registerable {
/**
- * Username
+ * Username of current user
*/
- private $username = "";
+ private $userName = "";
+
+ /**
+ * Email of current user
+ */
+ private $email = "";
// Exceptions
- const EXCEPTION_USERNAME_NOT_FOUND = 0xd00;
+ const EXCEPTION_USERNAME_NOT_FOUND = 0xd00;
+ const EXCEPTION_USER_EMAIL_NOT_FOUND = 0xd01;
/**
- * Private constructor
+ * Protected constructor
*
* @return void
*/
$this->setObjectDescription("Generic user class");
// Create unique ID number
- $this->createUniqueID();
+ $this->generateUniqueId();
// Clean up a little
$this->removeNumberFormaters();
* factory method will check if the username is already taken and if not
* so it will throw an exception.
*
- * @param $username Username we need a class instance for
+ * @param $userName Username we need a class instance for
* @return $userInstance An instance of this user class
* @throws UsernameMissingException If the username does not exist
*/
$userInstance = new User();
// Set the username
- $userInstance->setUsername($userName);
+ $userInstance->setUserName($userName);
// Check if the username exists
if (!$userInstance->ifUsernameExists()) {
return $userInstance;
}
+ /**
+ * Creates an instance of this user class by a provided email address. This
+ * factory method will not check if the email address is there.
+ *
+ * @param $email Email address of the user
+ * @return $userInstance An instance of this user class
+ */
+ public final static function createUserByEmail ($email) {
+ // Get a new instance
+ $userInstance = new User();
+
+ // Set the username
+ $userInstance->setEmail($email);
+
+ // Return the instance
+ return $userInstance;
+ }
+
/**
* Setter for username
*
* @param $userName The username to set
* @return void
*/
- protected final function setUsername ($userName) {
- $this->userNane = $userName;
+ public final function setUserName ($userName) {
+ $this->userName = $userName;
+ }
+
+ /**
+ * Setter for email
+ *
+ * @param $email The email to set
+ * @return void
+ */
+ protected final function setEmail ($email) {
+ $this->email = $email;
}
/**
* @return $userName The username to get
*/
public final function getUsername () {
- return $this->userNane;
+ return $this->userName;
+ }
+
+ /**
+ * Getter for email
+ *
+ * @return $email The email to get
+ */
+ public final function getEmail () {
+ return $this->email;
}
/**
*
* @return $exists Wether the username exists
*/
- protected function ifUsernameExists () {
+ public function ifUsernameExists () {
// By default the username does exist
$exists = true;
// Get a UserDatabaseWrapper instance
- $wrapperInstance = UserDatabaseWrapper::createUserDatabaseWrapper();
+ $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper');
// Create a search criteria
$criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria');
$result = $wrapperInstance->doSelectByCriteria($criteriaInstance);
// Search for it
- if ($result->next()) {
- // Entry found, so all is fine
- $exists = true;
- }
+ if (!$result->next()) {
+ // Entry not found
+ $exists = false;
+ } // END - if
+
+ // Return the status
+ return $exists;
+ }
+
+ /**
+ * Determines wether the email exists or not
+ *
+ * @return $exists Wether the email exists
+ */
+ public function ifEmailAddressExists () {
+ // By default the username does exist
+ $exists = true;
+
+ // Get a UserDatabaseWrapper instance
+ $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper');
+
+ // Create a search criteria
+ $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria');
+
+ // Add the username as a criteria and set limit to one entry
+ $criteriaInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_EMAIL, $this->getEmail());
+ $criteriaInstance->setLimit(1);
+
+ // Get a search result
+ $result = $wrapperInstance->doSelectByCriteria($criteriaInstance);
+
+ // Search for it
+ if (!$result->next()) {
+ // Entry not found
+ $exists = false;
+ } // END - if
// Return the status
return $exists;