Update the comment formatting to not use the pound bar anymore and to put a space...
[isso.git] / Api.php
diff --git a/Api.php b/Api.php
index 27d6ad728c401f22ef2ed25ee8b256a3ab6914eb..3f5d8603c348e5f7c1a00a0373360ea1d87034c0 100644 (file)
--- a/Api.php
+++ b/Api.php
 \*=====================================================================*/
 
 /**
-* Abstract Datamanger API (api.php)
-*
-* @package     ISSO
-*/
+ * Abstract Datamanger API (api.php)
+ *
+ * @package    ISSO
+ */
 
 if (!defined('REQ_AUTO'))
 {      
        /**
-       * Yes, required
-       */
+        * Yes, required
+        */
        define('REQ_YES', 1);
        
        /**
-       * No, not required
-       */
+        * No, not required
+        */
        define('REQ_NO', 0);
 
        /**
-       * Auto-increasing value
-       */
+        * Auto-increasing value
+        */
        define('REQ_AUTO', -1);
        
        /**
-       * Set by a cusotm set_*() function
-       */
+        * Set by a cusotm set_*() function
+        */
        define('REQ_SET', 2);
        
        /**
-       * Index for cleaning type
-       */
+        * Index for cleaning type
+        */
        define('F_TYPE', 0);
        
        /**
-       * Index for requirement type
-       */
+        * Index for requirement type
+        */
        define('F_REQ', 1);
 }
 
 /**
-* Abstract API
-*
-* Abstract class that is used as an API base for most common database interaction
-* schemes. Creates a simple structure that holds data and can update, remove, and
-* insert.
-* 
-* Life-cycle of a new object:
-* 1. $o = new SubApi();
-* 2. $o->set('foo', 'abc');
-* 3. $o->set('test', 45);
-* 4. try { $o->insert(); <other actions that depend on the saved record> } catch (ApiException $e) {}
-*
-* @author              Blue Static
-* @copyright   Copyright (c)2005 - 2008, Blue Static
-* @package             ISSO
-* 
-*/
+ * Abstract API
+ *
+ * Abstract class that is used as an API base for most common database interaction
+ * schemes. Creates a simple structure that holds data and can update, remove, and
+ * insert.
+ 
+ * Life-cycle of a new object:
+ * 1. $o = new SubApi();
+ * 2. $o->set('foo', 'abc');
+ * 3. $o->set('test', 45);
+ * 4. try { $o->insert(); <other actions that depend on the saved record> } catch (ApiException $e) {}
+ *
+ * @author             Blue Static
+ * @copyright  Copyright (c)2005 - 2008, Blue Static
+ * @package            ISSO
+ 
+ */
 abstract class BSApi
 {
        /**
-       * Fields: used for verification and sanitization
-       * NAME => array(TYPE, REQUIRED)
-       * @var  array
-       */
+        * Fields: used for verification and sanitization
+        * NAME => array(TYPE, REQUIRED)
+        * @var array
+        */
        protected $fields = array();
        
        /**
@@ -98,39 +98,39 @@ abstract class BSApi
        protected $prefix = '';
        
        /**
-       * Values array: sanitized and validated field values
-       * @var  array
-       */
+        * Values array: sanitized and validated field values
+        * @var array
+        */
        public $values = array();
        
        /**
-       * Fields that were set by the client
-       * @var  array
-       */
+        * Fields that were set by the client
+        * @var array
+        */
        private $setfields = array();
        
        /**
-       * WHERE condition
-       * @var  string
-       */
+        * WHERE condition
+        * @var string
+        */
        protected $condition = '';
        
        /**
-       * The object table row; a fetched row that represents this instance
-       * @var  array
-       */
+        * The object table row; a fetched row that represents this instance
+        * @var array
+        */
        public $record = array();
        
        /**
-       * Insert ID from the insert() command
-       * @var  integer
-       */
+        * Insert ID from the insert() command
+        * @var integer
+        */
        public $insertid = 0;
        
        /**
-       * Error queue that builds up errors
-       * @var  ApiException
-       */
+        * Error queue that builds up errors
+        * @var ApiException
+        */
        private $exception = null;
        
        /**
@@ -148,12 +148,11 @@ abstract class BSApi
                }
        }
        
-       // ###################################################################
        /**
-       * Adds an error into the error queue that is then hit 
-       *
-       * @param        Exception       Error message
-       */
+        * Adds an error into the error queue that is then hit 
+        *
+        * @param       Exception       Error message
+        */
        protected function _error(Exception $e)
        {
                if ($this->exception == null)
@@ -163,11 +162,10 @@ abstract class BSApi
                $this->exception->addException($e);
        }
        
-       // ###################################################################
        /**
-       * This simply throws the ApiException if it exists, which inside holds
-       * all of the individual and specific errors
-       */
+        * This simply throws the ApiException if it exists, which inside holds
+        * all of the individual and specific errors
+        */
        private function _processErrorQueue()
        {
                if ($this->exception)
@@ -176,15 +174,14 @@ abstract class BSApi
                }
        }
        
-       // ###################################################################
        /**
-       * Sets a value, sanitizes it, and validates it
-       *
-       * @param        string  Field name
-       * @param        mixed   Value
-       * @param        bool    Do clean?
-       * @param        bool    Do validation?
-       */
+        * Sets a value, sanitizes it, and validates it
+        *
+        * @param       string  Field name
+        * @param       mixed   Value
+        * @param       bool    Do clean?
+        * @param       bool    Do validation?
+        */
        public function set($field, $value, $doclean = true, $dovalidate = true)
        {
                if (!isset($this->fields["$field"]))
@@ -202,13 +199,12 @@ abstract class BSApi
                }
        }
        
-       // ###################################################################
        /**
-       * Sets the condition to use in the WHERE clause; if not passed, then
-       * it calculates it from the REQ_AUTO field
-       *
-       * @param        mixed   String with WHERE condition; array of fields to use for WHERE builder
-       */
+        * Sets the condition to use in the WHERE clause; if not passed, then
+        * it calculates it from the REQ_AUTO field
+        *
+        * @param       mixed   String with WHERE condition; array of fields to use for WHERE builder
+        */
        public function setCondition($condition = null)
        {
                if (is_array($condition) && sizeof($condition) > 0)
@@ -252,15 +248,14 @@ abstract class BSApi
                }
        }
        
-       // ###################################################################
        /**
-       * Fetches a record based on the condition
-       *
-       * @param        bool    Run pre_fetch()?
-       * @param        bool    Run post_fetch()?
-       *
-       * @return       boolean Whether or not the row was successfully fetched
-       */
+        * Fetches a record based on the condition
+        *
+        * @param       bool    Run pre_fetch()?
+        * @param       bool    Run post_fetch()?
+        *
+        * @return      boolean Whether or not the row was successfully fetched
+        */
        public function fetch($doPre = true, $doPost = true)
        {
                if (!$this->condition)
@@ -286,13 +281,12 @@ abstract class BSApi
                return true;
        }
        
-       // ###################################################################
        /**
-       * Inserts a record in the database
-       *
-       * @param        bool    Run pre_insert()?
-       * @param        bool    Run post_insert()?
-       */
+        * Inserts a record in the database
+        *
+        * @param       bool    Run pre_insert()?
+        * @param       bool    Run post_insert()?
+        */
        public function insert($doPre = true, $doPost = true)
        {
                $this->_verifyRequired();
@@ -330,13 +324,12 @@ abstract class BSApi
                $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()?
-       */
+        * Updates a record in the database using the data in $vaues
+        *
+        * @param       bool    Run pre_update()?
+        * @param       bool    Run post_update()?
+        */
        public function update($doPre = true, $doPost = true)
        {
                if (!$this->condition)
@@ -359,13 +352,12 @@ abstract class BSApi
                $this->_runActionMethod('post_update', $doPost);
        }
        
-       // ###################################################################
        /**
-       * Deletes a record
-       *
-       * @param        bool    Run pre_remove()?
-       * @param        bool    Run post_remove()?
-       */
+        * Deletes a record
+        *
+        * @param       bool    Run pre_remove()?
+        * @param       bool    Run post_remove()?
+        */
        public function remove($doPre = true, $doPost = true)
        {
                if (!$this->condition)
@@ -382,10 +374,9 @@ abstract class BSApi
                $this->_runActionMethod('post_remove', $doPost);
        }
        
-       // ###################################################################
        /**
-       * Verifies that all required fields are set
-       */
+        * Verifies that all required fields are set
+        */
        private function _verifyRequired()
        {
                foreach ($this->fields as $name => $options)
@@ -404,13 +395,12 @@ abstract class BSApi
                }
        }
        
-       // ###################################################################
        /**
-       * Runs a pre- or post-action method for database commands
-       *
-       * @param        string  Action to run
-       * @param        bool    Actually run it?
-       */
+        * Runs a pre- or post-action method for database commands
+        *
+        * @param       string  Action to run
+        * @param       bool    Actually run it?
+        */
        private function _runActionMethod($method, $doRun)
        {
                if (!$doRun || !method_exists($this, $method))
@@ -421,15 +411,14 @@ abstract class BSApi
                $this->$method();
        }
        
-       // ###################################################################
        /**
-       * Prepares a value for use in a SQL query; it encases and escapes
-       * strings and string-like values
-       *
-       * @param        string  Field name
-       *
-       * @return       string  Prepared value entry
-       */
+        * Prepares a value for use in a SQL query; it encases and escapes
+        * strings and string-like values
+        *
+        * @param       string  Field name
+        *
+        * @return      string  Prepared value entry
+        */
        private function _prepareFieldForSql($name)
        {
                $type = $this->fields["$name"][F_TYPE];
@@ -452,10 +441,9 @@ abstract class BSApi
                }
        }
        
-       // ###################################################################
        /**
-       * Verify field: not a zero value
-       */
+        * Verify field: not a zero value
+        */
        protected function _verifyIsNotZero($field)
        {
                if ($this->values[$field] == 0)
@@ -467,10 +455,9 @@ abstract class BSApi
                return true;
        }
        
-       // ###################################################################
        /**
-       * Verify field: not empty
-       */
+        * Verify field: not empty
+        */
        protected function _verifyIsNotEmpty($field)
        {
                if (empty($this->values[$field]))
@@ -482,10 +469,9 @@ abstract class BSApi
                return true;
        }
        
-       // ###################################################################
        /**
-       * Verify field: unique
-       */
+        * Verify field: unique
+        */
        protected function _verifyIsNotUnique($field)
        {
                $res = BSApp::$db->queryFirst("SELECT $field FROM {$this->prefix}{$this->table} WHERE $field = " . $this->_prepareFieldForSql($field) . (empty($this->condition) ? "" : " AND !({$this->condition})"));
@@ -518,7 +504,6 @@ class ApiException extends Exception
         */
        private $exceptions = array();
        
-       // ###################################################################
        /**
         * Constructor
         */
@@ -527,7 +512,6 @@ class ApiException extends Exception
                parent::__construct(_('An error occurred while processing the API data.'));
        }
        
-       // ###################################################################
        /**
         * Adds an exception to the collection
         *
@@ -538,7 +522,6 @@ class ApiException extends Exception
                $this->exceptions[] = $e;
        }
        
-       // ###################################################################
        /**
         * Returns an array of all the exceptions in the collection
         *
@@ -557,7 +540,6 @@ class ApiException extends Exception
  *
  * @author             rsesek
  * @copyright  Copyright (c)2005 - 2008, Blue Static
- * @version            $Id$
  * @package            ISSO
  *
  */
@@ -569,7 +551,6 @@ class FieldException extends Exception
         */
        private $field;
        
-       // ###################################################################
        /**
         * Constructor: create a new exception
         */
@@ -579,7 +560,6 @@ class FieldException extends Exception
                parent::__construct($error);
        }
        
-       // ###################################################################
        /**
         * Returns the name of the field the exception is for
         *