From d1ecefde4d38cfa9edd268332d19c7515c86a7a5 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Fri, 7 Nov 2008 12:16:59 -0500 Subject: [PATCH] Add BSApi::fetchValue() and BSApi::reset() methods * 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 | 47 +++++++++++++++++++++++++++++++++++++++++++++++ CHANGES | 2 ++ 2 files changed, 49 insertions(+) diff --git a/Api.php b/Api.php index 0e5ecd3..2636d40 100644 --- 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 c11ae01..516ead2 100644 --- 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 =================== -- 2.22.5