From d96765f1528ca5f20c8ba116614f30bda605d942 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 17 Dec 2006 04:24:00 +0000 Subject: [PATCH] API is now done and much cleaner so it makes more sense --- api.php | 64 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/api.php b/api.php index 2fb6d37..1c02741 100644 --- a/api.php +++ b/api.php @@ -115,12 +115,6 @@ abstract class BSApi */ public $insertid = 0; - /** - * Pre- and post-action method stoppers - * @var array - */ - public $norunners = array(); - /** * Error list that has been generated * @var array @@ -142,7 +136,7 @@ abstract class BSApi * * @param string Error message */ - protected function error($message) + protected function _error($message) { $this->errors[] = $message; @@ -191,7 +185,7 @@ abstract class BSApi { if (!isset($this->fields["$field"])) { - trigger_error('Field `' . $field . '` is not valid'); + trigger_error('Field "' . $field . '" is not valid'); return; } @@ -305,16 +299,17 @@ abstract class BSApi /** * Fetches a record based on the condition * - * @param bool Populate $this->values[] with data, along with $this->objdata[] ? + * @param bool Run pre_fetch()? + * @param bool Run post_fetch()? */ - public function fetch($populate = false) + public function fetch($doPre = true, $doPost = true) { if ($this->condition == '') { - trigger_error('Condition is empty: cannot fetch'); + $this->setCondition(); } - $this->_runActionMethod('pre_fetch'); + $this->_runActionMethod('pre_fetch', $doPre); $result = BSRegister::GetType('Db')->queryFirst("SELECT * FROM {$this->prefix}{$this->table} WHERE {$this->condition}"); if (!$result) @@ -323,7 +318,7 @@ abstract class BSApi return; } - $this->_runActionMethod('post_fetch'); + $this->_runActionMethod('post_fetch', $doPost); $this->objdata = $result; @@ -337,19 +332,20 @@ abstract class BSApi } } } - - $this->callRelations('fetch'); } // ################################################################### /** * Inserts a record in the database + * + * @param bool Run pre_insert()? + * @param bool Run post_insert()? */ - public function insert() + public function insert($doPre = true, $doPost = true) { $this->verify(); - $this->_runActionMethod('pre_insert'); + $this->_runActionMethod('pre_insert', $doPre); foreach ($this->setfields AS $field) { @@ -377,21 +373,24 @@ abstract class BSApi $this->insertid = BSRegister::GetType('Db')->insertId(); } - $this->_runActionMethod('post_insert'); + $this->_runActionMethod('post_insert', $doPost); } // ################################################################### /** * Updates a record in the database using the data in $vaues + * + * @param bool Run pre_update()? + * @param bool Run post_update()? */ - public function update() + public function update($doPre = true, $doPost = true) { if ($this->condition == '') { - trigger_error('Condition is empty: cannot update'); + $this->setCondition(); } - $this->_runActionMethod('pre_update'); + $this->_runActionMethod('pre_update', $doPre); foreach ($this->setfields AS $field) { @@ -401,32 +400,30 @@ abstract class BSApi BSRegister::GetType('Db')->query("UPDATE {$this->prefix}{$this->table} SET $updates WHERE {$this->condition}"); - $this->_runActionMethod('post_update'); + $this->_runActionMethod('post_update', $doPost); } // ################################################################### /** * Deletes a record * - * @param bool Run API->setExisting()? + * @param bool Run pre_remove()? + * @param bool Run post_remove()? */ - public function remove($runset = true) + public function remove($doPre = true, $doPost = true) { if ($this->condition == '') { - trigger_error('Condition is empty: cannot remove'); + $this->setCondition(); } - if ($runset) - { - $this->setExisting(); - } + $this->fetch(); - $this->_runActionMethod('pre_remove'); + $this->_runActionMethod('pre_remove', $doPre); BSRegister::GetType('Db')->query("DELETE FROM {$this->prefix}{$this->table} WHERE {$this->condition}"); - $this->_runActionMethod('post_remove'); + $this->_runActionMethod('post_remove', $doPost); } // ################################################################### @@ -456,10 +453,11 @@ abstract class BSApi * Runs a pre- or post-action method for database commands * * @param string Action to run + * @param bool Actually run it? */ - private function _runActionMethod($method) + private function _runActionMethod($method, $doRun) { - if (in_array($method, $this->norunners)) + if (!$doRun) { return; } -- 2.43.5