Add a way to quick-set API fields via an array
[isso.git] / Api.php
diff --git a/Api.php b/Api.php
index 3f5d8603c348e5f7c1a00a0373360ea1d87034c0..89d8dd90b318640fef09c625a641551b5dd8ac34 100644 (file)
--- a/Api.php
+++ b/Api.php
@@ -174,6 +174,25 @@ abstract class BSApi
                }
        }
        
+       /**
+        * Sets an array of data into the API, ignoring things in $exclude. Keys
+        * in the array that don't exist in the API will be ignored.
+        * 
+        * @param       array   A dictionary of field names and values to set
+        * @param       array   Array of keys to exclude
+        */
+       public function setArray(Array $data, $exclude = array())
+       {
+               foreach ($data as $key => $value)
+               {
+                       if (in_array($key, $exclude) || !isset($this->fields[$key]))
+                       {
+                               continue;
+                       }
+                       $this->set($key, $value);
+               }
+       }
+       
        /**
         * Sets a value, sanitizes it, and validates it
         *