$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
/**
* 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
}
/**
- * 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