Misc fixes:
authorRoland Häder <roland@mxchange.org>
Sat, 22 Aug 2009 00:37:33 +0000 (00:37 +0000)
committerRoland Häder <roland@mxchange.org>
Sat, 22 Aug 2009 00:37:33 +0000 (00:37 +0000)
- UserPoints does now load points on every object initialization
- It does also now advance to first entry by default and rewind in many methods
- Fixed getField() (?)

inc/classes/main/class_BaseFrameworkSystem.php
inc/classes/main/helper/class_BaseHelper.php
inc/classes/main/points/class_UserPoints.php

index 5237b802b1faedba51b31d9a45f985d39f5aead9..c085e8e4d4d9667d736f453ad14ed793f8224746 100644 (file)
@@ -966,6 +966,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
 
                // Get current array
                $fieldArray = $resultInstance->current();
+               //* DEBUG: */ $this->debugOutput($fieldName.':<pre>'.print_r($fieldArray, true).'</pre>');
 
                // Does the field exist?
                if (isset($fieldArray[$fieldName])) {
index 5cd4ea88b0247d3f567f4185d6408e093f064b0c..81e4197c378f73d1aa14d24d44f93f37003c1ee7 100644 (file)
@@ -27,6 +27,11 @@ class BaseHelper extends BaseFrameworkSystem {
         */
        private $valueInstance = null;
 
+       /**
+        * Extra instance to the class which provides field values
+        */
+       private $extraInstance = null;
+
        /**
         * Rendered content created by the helper class
         */
@@ -173,6 +178,7 @@ class BaseHelper extends BaseFrameworkSystem {
        public function assignFieldWithFilter ($fieldName, $filterMethod) {
                // Get the value
                $fieldValue = $this->getValueField($fieldName);
+               //* DEBUG: */ $this->debugOutput($fieldName.'='.$fieldValue);
 
                // Now filter it through the value through the filter method
                $filteredValue = call_user_func_array(array($this, 'doFilter' . $this->convertToClassName($filterMethod)), array($fieldValue));
@@ -190,28 +196,33 @@ class BaseHelper extends BaseFrameworkSystem {
         * @throws      NullPointerException    If recovery of requested value instance failed
         */
        public function prefetchValueInstance ($registryKey, $extraKey = null) {
+               //* DEBUG: */ $this->debugOutput('O:'.$registryKey.'/'.$extraKey);
                try {
                        // Get the required instance
                        $this->valueInstance = Registry::getRegistry()->getInstance($registryKey);
                } catch (NullPointerException $e) {
                        // Not set in registry
                        // @TODO Try to log it here
+                       //* DEBUG: */ $this->debugOutput($registryKey.'=NULL!');
                }
 
-               // Is the value instance valid?
-               if (is_null($this->valueInstance)) {
-                       // Try to create it "from scratch", by first init extra instance
-                       $extraInstance = null;
-
-                       // Shall we get an extra instance?
-                       if (!is_null($extraKey)) {
+               // Shall we get an extra instance?
+               if (!is_null($extraKey)) {
+                       try {
                                // Get the extra instance.
-                               $extraInstance = Registry::getRegistry()->getInstance($extraKey);
-                       } // END - if
+                               $this->extraInstance = Registry::getRegistry()->getInstance($extraKey);
+                       } catch (NullPointerException $e) {
+                               // Try to create it
+                               $this->extraInstance = ObjectFactory::createObjectByConfiguredName($extraKey . '_class', array($this->valueInstance));
+                       }
+                       //* DEBUG: */ $this->debugOutput($extraKey.'='.$this->extraInstance.' - EXTRA!');
+               } // END - if
 
+               // Is the value instance valid?
+               if (is_null($this->valueInstance)) {
                        try {
                                // Get the requested instance
-                               $this->valueInstance = ObjectFactory::createObjectByConfiguredName($registryKey . '_class', array($extraInstance));
+                               $this->valueInstance = ObjectFactory::createObjectByConfiguredName($registryKey . '_class', array($this->extraInstance));
                        } catch (FrameworkException $e) {
                                // Okay, nothing found so throw a null pointer exception here
                                throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
@@ -449,6 +460,13 @@ class BaseHelper extends BaseFrameworkSystem {
 
                // Get the field value
                $fieldValue = $this->getValueInstance()->getField($fieldName);
+               //* DEBUG: */ $this->debugOutput($fieldName.'[]='.gettype($fieldValue).'('.strlen($fieldValue).')');
+
+               // Is it null?
+               if ((is_null($fieldValue)) && (!is_null($this->extraInstance))) {
+                       // So try the extra instance
+                       $fieldValue = $this->extraInstance->getField($fieldName);
+               } // END - if
 
                // Return it
                return $fieldValue;
index f4dbad4d5cb57280a2d94ae915b47b4f17d56096..2673f05515180d04f52ceb070728eeb00051fb91 100644 (file)
@@ -63,6 +63,9 @@ class UserPoints extends BaseFrameworkSystem implements Registerable, BookablePo
                // Get result back
                $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance);
 
+               // Advance to first entry by default
+               $resultInstance->next();
+
                // Set it in this instance
                $pointsInstance->setResultInstance($resultInstance);
 
@@ -103,6 +106,9 @@ class UserPoints extends BaseFrameworkSystem implements Registerable, BookablePo
                // Get the required points entry
                $requiredPoints = $this->getConfigInstance()->getConfigEntry($action . '_action_points');
 
+               // Rewind always
+               $this->getResultInstance()->rewind();
+
                // Do we have an entry?
                if ($this->getResultInstance()->next()) {
                        // Get the entry
@@ -123,6 +129,9 @@ class UserPoints extends BaseFrameworkSystem implements Registerable, BookablePo
         * @return      void
         */
        function bookPointsDirectly ($amount) {
+               // Rewind always
+               $this->getResultInstance()->rewind();
+
                // Do we have an entry?
                if ($this->getResultInstance()->next()) {
                        // Get the entry