Changeset 3167 for branches/2.2/workflow/inc/engine/src/common/Base.php
- Timestamp:
- 08/17/10 16:17:12 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2/workflow/inc/engine/src/common/Base.php
r795 r3167 1 1 <?php 2 require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'common'.SEP.'Observable.php');3 2 /** 4 3 * This class is derived by all the API classes so they get the 5 * database connection , database methods and the Observable interface6 * 4 * database connection and the database methods. 5 * 7 6 * @package Galaxia 8 * @license http://www.gnu.org/copyleft/gpl.html GPL 7 * @license http://www.gnu.org/copyleft/gpl.html GPL 9 8 */ 10 class Base extends Observable{9 class Base { 11 10 /** 12 11 * @var object $db Database abstraction object used to access the database … … 17 16 * @var int $num_queries Debugging var 18 17 * @access private 19 */ 18 */ 20 19 var $num_queries = 0; 21 20 /** 22 21 * @var int $num_queries_total Debugging var 23 22 * @access private 24 */ 23 */ 25 24 var $num_queries_total = 0; 26 25 /** 27 26 * @var array $error Error messages 28 27 * @access public 29 */ 28 */ 30 29 var $error= Array(); 31 30 /** … … 39 38 */ 40 39 var $child_name = 'Base'; 41 40 41 /** 42 * @var object $db_shared_obj The database abstraction object shared between 43 * all instances of this class. 44 * @acess private 45 * @static 46 */ 47 private static $db_shared_obj = null; 48 42 49 /** 43 50 * Constructor receiving a database abstraction object … … 47 54 * @access public 48 55 */ 49 function Base( &$db)56 function Base() 50 57 { 51 if(!$db) { 58 /** 59 * New Stuff! 60 * We decided to get here the database object. In a recent past, 61 * all the classes that specialize this one passed a db object. 62 * Now, to simplify and save memory, we store the database object 63 * into a single and static atribute shared among each instance 64 * of this class. 65 * 66 * To prevent to modify all sub-classes to use "self::$db" instead 67 * of "this->db", we made a very tiny workaround here. In the first 68 * instantiation of this class, we instantiate the database object 69 * and store it into 'self::$db_shared_obj'. Any subsequent 70 * instantiations will just point to the static one. 71 */ 72 if (!self::$db_shared_obj) 73 self::$db_shared_obj = &Factory::getInstance('WorkflowObjects')->getDBGalaxia()->Link_ID; 74 75 $this->db = &self::$db_shared_obj; 76 77 78 if(!$this->db) { 52 79 die('Invalid db object passed to '.$this->child_name.' constructor'); 53 80 } 54 81 //Force transactionnal mysql (Innodb) -> mysqlt 55 if ($ db->databaseType=='mysql')82 if ($this->db->databaseType=='mysql') 56 83 { 57 84 $GLOBALS['phpgw']->db->disconnect(); 58 $ db = $GLOBALS['phpgw']->db->connect(85 $this->db = $GLOBALS['phpgw']->db->connect( 59 86 $GLOBALS['phpgw_info']['server']['db_name'], 60 87 $GLOBALS['phpgw_info']['server']['db_host'], … … 65 92 ); 66 93 } 67 $this->db = &$db;68 94 } 69 95 … … 72 98 * Always call this function after failed operations on a workflow object to obtain messages 73 99 * 74 * @param bool $as_array if true the result will be send as an array of errors or an empty array. Else, if you do not give any parameter 100 * @param bool $as_array if true the result will be send as an array of errors or an empty array. Else, if you do not give any parameter 75 101 * or give a false parameter you will obtain a single string which can be empty or will contain error messages with <br /> html tags 76 102 * @param bool $debug is false by default, if true you wil obtain more messages 77 103 * @param string $prefix string appended to the debug message 78 104 * @return mixed Error and debug messages or an array of theses messages and empty the error messages 79 * @access public 105 * @access public 80 106 */ 81 function get_error($as_array=false, $debug=false, $prefix='') 107 function get_error($as_array=false, $debug=false, $prefix='') 82 108 { 83 109 //collect errors from used objects … … 96 122 /** 97 123 * Gets warnings recorded by this object 98 * 99 * @param bool $as_array if true the result will be send as an array of warnings or an empty array. Else, if you do not give any parameter 124 * 125 * @param bool $as_array if true the result will be send as an array of warnings or an empty array. Else, if you do not give any parameter 100 126 * or give a false parameter you will obtain a single string which can be empty or will contain warning messages with <br /> html tags 101 127 * @return mixed Warning messages or an array of theses messages and empty the warning messages 102 * @access public 128 * @access public 103 129 */ 104 function get_warning($as_array=false) 130 function get_warning($as_array=false) 105 131 { 106 132 if ($as_array) … … 118 144 * Collect errors from all linked objects which could have been used by this object 119 145 * Each child class should instantiate this function with her linked objetcs, calling get_error(true) 120 * 146 * 121 147 * @param bool $debug is false by default, if true debug messages can be added to 'normal' messages 122 148 * @param string $prefix is a string appended to the debug message 123 149 * @abstract 124 150 * @access public 125 * @return void 151 * @return void 126 152 */ 127 153 function collect_errors($debug=false, $prefix = '') … … 134 160 } 135 161 } 136 162 137 163 /** 138 164 * Performs a query on the AdoDB database object 139 * 165 * 140 166 * @param string $query sql query, parameters should be replaced with ? 141 167 * @param array $values array containing the parameters (going in the ?), use it to avoid security problems. If … … 196 222 197 223 /** 198 * @see Base::query 224 * @see Base::query 199 225 * @param string $query sql query, parameters should be replaced with ? 200 226 * @param array $values array containing the parameters (going in the ?), use it to avoid security problems … … 224 250 if (!$result && $reporterrors ) 225 251 $this->sql_error($query, $clean_values, $result); 226 if (!!$result) 252 if (!!$result) 227 253 { 228 254 $res = $result->fetchRow(); … … 241 267 /** 242 268 * Throws error warnings 243 * 269 * 244 270 * @param string $query 245 271 * @param array $values 246 272 * @param mixed $result 247 273 * @access public 248 * @return void 274 * @return void 249 275 */ 250 276 function sql_error($query, $values, $result) { … … 252 278 // DO NOT DIE, if transactions are there, they will do things in a better way 253 279 } 254 280 255 281 /** 256 282 * Clean the data before it is recorded on the database 257 * 283 * 258 284 * @param $value is a data we want to be stored in the database. 259 * If it is an array we'll make a serialize and then an base64_encode 285 * If it is an array we'll make a serialize and then an base64_encode 260 286 * (you'll have to make an unserialize(base64_decode()) 261 287 * If it is not an array we make an htmlspecialchars() on it … … 292 318 /** 293 319 * Supports DB abstraction 294 * 320 * 295 321 * @param string &$query 296 * @return void 322 * @return void 297 323 * @access public 298 324 */ … … 302 328 case "oci8": 303 329 $query = preg_replace("/`/", "\"", $query); 304 // convert bind variables - adodb does not do that 330 // convert bind variables - adodb does not do that 305 331 $qe = explode("?", $query); 306 332 $query = ''; … … 318 344 /** 319 345 * Supports DB abstraction 320 * 346 * 321 347 * @param string $sort_mode 322 * @return string 348 * @return string 323 349 * @access public 324 350 */ … … 330 356 /** 331 357 * Supports DB abstraction 332 * 333 * @return mixed 358 * 359 * @return mixed 334 360 * @access public 335 361 */
Note: See TracChangeset
for help on using the changeset viewer.