Add BSApi::fetchValue() and BSApi::reset() methods
authorRobert Sesek <rsesek@bluestatic.org>
Fri, 7 Nov 2008 17:16:59 +0000 (12:16 -0500)
committerRobert Sesek <rsesek@bluestatic.org>
Fri, 7 Nov 2008 17:16:59 +0000 (12:16 -0500)
* Api.php:
(BSApi::fetchValue): New method to return the value of a field from either the record[] or values[] array
(BSApi::reset): New method to reset the API object to only have the REQ_AUTO field set

Api.php
CHANGES

diff --git a/Api.php b/Api.php
index 0e5ecd30a29b3b85d23b80f064b0396bbd11d170..2636d405413fbb551a4b94cbfcee3bb921cdd6a6 100644 (file)
--- a/Api.php
+++ b/Api.php
@@ -193,6 +193,32 @@ abstract class BSApi
                }
        }
        
+       /**
+        * Resets the API object to an initial state. This will NOT clear the primary (REQ_AUTO)
+        * field.
+        */
+       public function reset()
+       {
+               foreach ($this->fields as $field => $settings)
+               {
+                       if ($settings[F_REQ] == REQ_AUTO)
+                       {
+                               $savename       = $field;
+                               $savevalue      = $this->fetchValue($field);
+                               $savevalue      = ($savevalue ? $savevalue : $this->insertid);
+                               break;
+                       }
+               }
+               
+               $this->setfields        = array();
+               $this->values           = array();
+               $this->condition        = '';
+               $this->insertid         = 0;
+               $this->exception        = null;
+               
+               $this->set($savename, $savevalue);
+       }
+       
        /**
         * Sets a value, sanitizes it, and validates it
         *
@@ -460,6 +486,27 @@ abstract class BSApi
                }
        }
        
+       /**
+        * Determines the value of a field from Api->record[], Api->values[] (in that order)
+        *
+        * @param       string  The field ID to determine for
+        *
+        * @return      mixed
+        */
+       public function fetchValue($field)
+       {
+               if ($this->record[$field])
+               {
+                       return $this->record[$field];
+               }
+               else if ($this->values[$field])
+               {
+                       return $this->values[$field];
+               }
+               
+               return null;
+       }
+       
        /**
         * Verify field: not a zero value
         */
diff --git a/CHANGES b/CHANGES
index c11ae019f025987f042776efc699c15783e3a045..516ead217478750d728183abcf8a1f5ea13a7cbe 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,8 @@
 3.1.3
 ===================
 - Fixed: BSPrinterRootForm's marked as ::setUpload() would not have the right enctype set
+- New: BSApi::reset() will reset the object back to an initial state with only the key field still set
+- New: BSApi::fetchValue() will return the value of a given field from either ->record[] or ->values[]
 
 3.1.2
 ===================