Criteria added for abstract database programming
[shipsimu.git] / inc / classes / main / user / class_User.php
index 62c4f17e9d15b913a1a993fad06fd58fbbf6f6bd..280adec1600d86e43d65fc161b223fbe348da7eb 100644 (file)
@@ -27,11 +27,6 @@ class User extends BaseFrameworkSystem implements ManageableUser {
         */
        private $username = "";
 
-       /**
-        * An instance of a database wrapper
-        */
-       private $userWrapper = null;
-
        // Exceptions
        const EXCEPTION_USERNAME_NOT_FOUND = 0xd00;
 
@@ -112,13 +107,23 @@ class User extends BaseFrameworkSystem implements ManageableUser {
                // By default the username does exist
                $exists = true;
 
-               // Try to get a UserDatabaseWrapper object back
-               try {
-                       // Get the instance by providing this class
-                       $this->userWrapper = UserDatabaseWrapper::createUserDatabaseWrapper($this);
-               } catch (WrapperUserNameNotFoundException $e) {
-                       // Does not exist!
-                       $exists = false;
+               // Get a UserDatabaseWrapper instance
+               $wrapperInstance = UserDatabaseWrapper::createUserDatabaseWrapper();
+
+               // 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_USERNAME, $this->getUsername());
+               $criteriaInstance->setLimit(1);
+
+               // Get a search result
+               $result = $wrapperInstance->doSelectByCriteria($criteriaInstance);
+
+               // Search for it
+               if ($result->next()) {
+                       // Entry found, so all is fine
+                       $exists = true;
                }
 
                // Return the status