]> git.mxchange.org Git - shipsimu.git/blobdiff - inc/classes/main/user/user/class_User.php
User class / resending of confirm link updated:
[shipsimu.git] / inc / classes / main / user / user / class_User.php
index e362faf92e9342b5c027211948a79cc0e0c083bb..8343c33ebda6dc624c13d3c214a19e02cc7b3a31 100644 (file)
@@ -47,6 +47,19 @@ class User extends BaseUser implements ManageableUser, Registerable {
                $this->generateUniqueId();
        }
 
+       /**
+        * Destructor to always flush updates
+        *
+        * @return      void
+        */
+       public function __destruct () {
+               // Flush any updated entries to the database
+               $this->flushPendingUpdates();
+
+               // Call parent destructor
+               parent::__destruct();
+       }
+
        /**
         * Creates an instance of this user class by a provided username. This
         * factory method will check if the username is already taken and if not
@@ -131,7 +144,7 @@ class User extends BaseUser implements ManageableUser, Registerable {
 
        /**
         * Updates the last activity timestamp and last performed action in the
-        * database result. You should call flushUpdates() to flush these updates
+        * database result. You should call flushPendingUpdates() to flush these updates
         * to the database layer.
         *
         * @param       $requestInstance        A requestable class instance
@@ -168,16 +181,44 @@ class User extends BaseUser implements ManageableUser, Registerable {
        }
 
        /**
-        * Flushs all updated entries to the database layer
+        * Updates a given field with new value
         *
+        * @param       $fieldName              Field to update
+        * @param       $fieldValue             New value to store
         * @return      void
         */
-       public function flushUpdates () {
-               // Get a database wrapper
-               $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class');
+       public function updateDatabaseField ($fieldName, $fieldValue) {
+               // Get a critieria instance
+               $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+               // Add search criteria
+               $searchInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName());
+               $searchInstance->setLimit(1);
+
+               // Now get another criteria
+               $updateInstance = ObjectFactory::createObjectByConfiguredName('update_criteria_class');
+
+               // And add our both entries
+               $updateInstance->addCriteria($fieldName, $fieldValue);
+
+               // Add the search criteria for searching for the right entry
+               $updateInstance->setSearchInstance($searchInstance);
 
+               // Remember the update in database result
+               $this->getResultInstance()->add2UpdateQueue($updateInstance);
+       }
+
+       /**
+        * Flushs all pending updates to the database layer
+        *
+        * @return      void
+        */
+       public function flushPendingUpdates () {
                // Do we have data to update?
                if ($this->getResultInstance()->ifDataNeedsFlush()) {
+                       // Get a database wrapper
+                       $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class');
+
                        // Yes, then send the whole result to the database layer
                        $wrapperInstance->doUpdateByResult($this->getResultInstance());
                } // END - if