Exposez-nous votre projet !
English version  | Version française

Notice: Undefined index: HTTP_REFERER in /home/_or/olivier/pub/www.samalyse.com/prepend.php on line 202

<< Retour

<?php
/**
 * Mercure - API for Accountancy Documents Generation
 *
 * @package Mercure
 * @copyright  2004 Samalyse SARL corporation
 * @author     Olivier Guilyardi <olivier@samalyse.com>
 */

require_once 'Mercure/DataObject.php';

/**
 * Product DataObject
 * 
 * @copyright  2004 Samalyse SARL corporation
 * @author     Olivier Guilyardi <olivier@samalyse.com>
 * @package Mercure
 */
class Mercure_Product extends Mercure_DataObject 
{
    var 
$_handleAllLanguages false;    
    var 
$_formbuilderEventHandlers = array(
        
'onPregenerateForm' => null,
    );
    
###START_AUTOCODE
    /* the code below is auto generated do not remove the above tag */

    
var $__table 'product';                         // table name
    
var $id;                              // string(16)  not_null primary_key
    
var $price;                           // real(22)  
    
var $tax;                             // real(22)  
    
var $facture;                         // int(1)  
    
var $bon_livraison;                   // int(1)  
    
var $bon_achat;                       // int(1)  
    
var $avis_virement;                   // int(1)  
    
var $avoir;                           // int(1)  
    
var $unit_type;                       // string(6)  not_null enum

    /* ZE2 compatibility trick*/
    
function __clone() { return $this;}

    
/* Static get */
    
function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Mercure_Product',$k,$v); }

    
/* the code above is auto generated do not remove the tag below */
    ###END_AUTOCODE

    
function table() 
    {
        
$fields = array();
        if (
$this->_handleAllLanguages) {
            
$langs $this->_i18n->getLangs();
//                var_dump($langs);
            
foreach ($langs as $id => $name) {
                
$fields["name_$id"] = DB_DATAOBJECT_STR
            }
        } else {
            
$fields["name"] = DB_DATAOBJECT_STR;
        }
        return 
array_merge(parent::table(),$fields);
    } 
    
    function 
fetch ()
    {
        
$ret parent::fetch();
        if (
$ret === false) {
            return 
false;
        }
        if (
$this->_handleAllLanguages) {
            
$langs $this->_i18n->getLangs();
            foreach (
$langs as $id => $name) {
                
$var "name_$id";
                
$this->$var $this->_i18n->get($this->id'products'$id);
            }
        } else {
            
$this->name $this->_i18n->get($this->id'products');
        }
                
        return 
true;
    }

    function 
orderBy ($order)
    {
        if (
strstr ($order'name')) {
           
            
$products_i18n $this->_i18n->getPage('products');
            if (!empty(
$products_i18n)) {
                
$name_sort '(CASE id ';
                foreach (
$products_i18n as $id => $name) {
                    
$name_sort .= "WHEN \"$id\" THEN \"$name\" ";
                }
                
$name_sort .= ' END)';
            } else {
                
$name_sort 'id';
            }
            
$order str_replace ('name',$name_sort,$order);
        }
        
parent::orderBy($order);
    }

    function 
deleteSingle ($productId)
    {
        
$product = clone ($this);
        
$product->get($productId);
        if (
$product->delete() != 1) {
            
$ret false;
        } else {
            
$this->_i18n->remove($productId'products');
            
$ret true;
        }
        return 
$ret;
    }

    function 
handleAllLanguages()
    {
        
$this->_handleAllLanguages true;
    }

    function 
_updateTranslations($dataobject false)
    {
        if (
$this->_handleAllLanguages) {
            
$translations = array();
            
$vars get_object_vars($this);
            foreach (
$vars as $key => $val) {
                if (
substr ($key,0,5) == 'name_') {
                    
$lang_id substr ($key5);
                    
$translations[$lang_id] = $val;
                    unset (
$this->$key);
                    if (
$dataobject) {
                        if (isset(
$dataobject->$key)) {
                            unset (
$dataobject->$key);
                        }
                    }
                }
            }
            
$this->_i18n->add ($this->id'products'$translations);
        } else {
            
$translations[$this->_i18n->defaultLang] = $this->name;
            unset(
$this->name);
            if (
$dataobject) {
                if (isset(
$dataobject->name)) {
                    unset (
$dataobject->name);
                }
            }
            
$this->_i18n->add ($this->id'products'$translations);
            
        }
    }
    
    function 
insert()
    {
        if (!
$this->_perm->canWriteProduct()) {
            return 
false;
        }
        
$this->_updateTranslations();
        return 
parent::insert();
    }

    function 
update($dataobject false)
    {
        if (!
$this->_perm->canWriteProduct()) {
            return 
false;
        }
        
$this->_updateTranslations ($dataobject);
        return 
parent::update($dataobject);
    }

    function 
pregenerateForm(&$formBuilder)
    {
        
$func $this->_formbuilderEventHandlers['onPregenerateForm'];
        if (!
is_null($func)) {
            if (
is_array($func)) {
                
$object =& $func[0];
                
$method $func[1];
                
$object->$method($formBuilder);
            } else {
                
$func($formBuilder);
            }
        }
    }
    
    function 
setFormbuilderEventHandler ($eventName$func)
    {    
        
$this->_formbuilderEventHandlers[$eventName] = $func;
    }

    function 
delete()
    {
        if (!
$this->_perm->canWriteProduct()) {
            return 
false;
        }
        return 
parent::delete();
    }
}

Notice: Undefined index: HTTP_REFERER in /home/_or/olivier/pub/www.samalyse.com/prepend.php on line 208

<< Retour

Icon
Faites-nous part de votre projet
Progress bar