Ignore:
Timestamp:
08/17/10 16:17:12 (14 years ago)
Author:
viani
Message:

Ticket #1135 - Merged r1990:3166 from /trunk/workflow into /branches/2.2/workflow

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2/workflow/inc/engine/src/common/Base.php

    r795 r3167  
    11<?php 
    2 require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'common'.SEP.'Observable.php'); 
    32/** 
    43 * This class is derived by all the API classes so they get the 
    5  * database connection, database methods and the Observable interface 
    6  *  
     4 * database connection and the database methods. 
     5 * 
    76 * @package Galaxia 
    8  * @license http://www.gnu.org/copyleft/gpl.html GPL  
     7 * @license http://www.gnu.org/copyleft/gpl.html GPL 
    98 */ 
    10 class Base extends Observable { 
     9class Base { 
    1110        /** 
    1211         * @var object $db Database abstraction object used to access the database 
     
    1716         * @var int     $num_queries Debugging var 
    1817         * @access private 
    19          */      
     18         */ 
    2019        var $num_queries = 0; 
    2120        /** 
    2221         * @var int     $num_queries_total Debugging var 
    2322         * @access private 
    24          */      
     23         */ 
    2524        var $num_queries_total = 0; 
    2625        /** 
    2726         * @var array  $error Error messages 
    2827         * @access public 
    29          */      
     28         */ 
    3029        var $error= Array(); 
    3130        /** 
     
    3938         */ 
    4039        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 
    4249  /** 
    4350   * Constructor receiving a database abstraction object 
     
    4754   * @access public 
    4855   */ 
    49   function Base(&$db) 
     56  function Base() 
    5057  { 
    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) { 
    5279      die('Invalid db object passed to '.$this->child_name.' constructor'); 
    5380    } 
    5481    //Force transactionnal mysql (Innodb) -> mysqlt 
    55     if ($db->databaseType=='mysql') 
     82    if ($this->db->databaseType=='mysql') 
    5683    { 
    5784        $GLOBALS['phpgw']->db->disconnect(); 
    58         $db = $GLOBALS['phpgw']->db->connect( 
     85        $this->db = $GLOBALS['phpgw']->db->connect( 
    5986                        $GLOBALS['phpgw_info']['server']['db_name'], 
    6087                        $GLOBALS['phpgw_info']['server']['db_host'], 
     
    6592                ); 
    6693    } 
    67     $this->db = &$db; 
    6894  } 
    6995 
     
    7298   * Always call this function after failed operations on a workflow object to obtain messages 
    7399   * 
    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 
    75101   * or give a false parameter you will obtain a single string which can be empty or will contain error messages with <br /> html tags 
    76102   * @param bool $debug is false by default, if true you wil obtain more messages 
    77103   * @param string $prefix string appended to the debug message 
    78104   * @return mixed Error and debug messages or an array of theses messages and empty the error messages 
    79    * @access public   
     105   * @access public 
    80106   */ 
    81   function get_error($as_array=false, $debug=false, $prefix='')  
     107  function get_error($as_array=false, $debug=false, $prefix='') 
    82108  { 
    83109    //collect errors from used objects 
     
    96122  /** 
    97123   * 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 
    100126   * or give a false parameter you will obtain a single string which can be empty or will contain warning messages with <br /> html tags 
    101127   * @return mixed Warning messages or an array of theses messages and empty the warning messages 
    102    * @access public   
     128   * @access public 
    103129   */ 
    104   function get_warning($as_array=false)  
     130  function get_warning($as_array=false) 
    105131  { 
    106132    if ($as_array) 
     
    118144   * Collect errors from all linked objects which could have been used by this object 
    119145   * Each child class should instantiate this function with her linked objetcs, calling get_error(true) 
    120    *  
     146   * 
    121147   * @param bool $debug is false by default, if true debug messages can be added to 'normal' messages 
    122148   * @param string $prefix is a string appended to the debug message 
    123149   * @abstract 
    124150   * @access public 
    125    * @return void  
     151   * @return void 
    126152   */ 
    127153  function collect_errors($debug=false, $prefix = '') 
     
    134160        } 
    135161  } 
    136          
     162 
    137163        /** 
    138164         * Performs a query on the AdoDB database object 
    139          *  
     165         * 
    140166         * @param string $query sql query, parameters should be replaced with ? 
    141167         * @param array $values array containing the parameters (going in the ?), use it to avoid security problems. If 
     
    196222 
    197223        /** 
    198          * @see Base::query  
     224         * @see Base::query 
    199225         * @param string $query sql query, parameters should be replaced with ? 
    200226     * @param array $values array containing the parameters (going in the ?), use it to avoid security problems 
     
    224250                if (!$result && $reporterrors ) 
    225251                        $this->sql_error($query, $clean_values, $result); 
    226                 if (!!$result)  
     252                if (!!$result) 
    227253                { 
    228254                        $res = $result->fetchRow(); 
     
    241267        /** 
    242268         * Throws error warnings 
    243          *  
     269         * 
    244270         * @param string $query 
    245271         * @param array $values 
    246272         * @param mixed $result 
    247273         * @access public 
    248          * @return void  
     274         * @return void 
    249275         */ 
    250276        function sql_error($query, $values, $result) { 
     
    252278                // DO NOT DIE, if transactions are there, they will do things in a better way 
    253279        } 
    254          
     280 
    255281        /** 
    256282         * Clean the data before it is recorded on the database 
    257          *  
     283         * 
    258284         * @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 
    260286         * (you'll have to make an unserialize(base64_decode()) 
    261287         * If it is not an array we make an htmlspecialchars() on it 
     
    292318        /** 
    293319         * Supports DB abstraction 
    294          *  
     320         * 
    295321         * @param string &$query 
    296          * @return void  
     322         * @return void 
    297323         * @access public 
    298324         */ 
     
    302328                case "oci8": 
    303329                        $query = preg_replace("/`/", "\"", $query); 
    304                         // convert bind variables - adodb does not do that  
     330                        // convert bind variables - adodb does not do that 
    305331                        $qe = explode("?", $query); 
    306332                        $query = ''; 
     
    318344        /** 
    319345         * Supports DB abstraction 
    320          *  
     346         * 
    321347         * @param string $sort_mode 
    322          * @return string  
     348         * @return string 
    323349         * @access public 
    324350         */ 
     
    330356        /** 
    331357         * Supports DB abstraction 
    332          *  
    333          * @return mixed  
     358         * 
     359         * @return mixed 
    334360         * @access public 
    335361         */ 
Note: See TracChangeset for help on using the changeset viewer.