Clean code around fetch_optionals()

This commit is contained in:
Laurent Destailleur 2018-02-20 19:38:18 +01:00
parent 8b54a80593
commit c4130730cb
29 changed files with 135 additions and 198 deletions

View File

@ -1156,12 +1156,9 @@ class Adherent extends CommonObject
$this->model_pdf = $obj->model_pdf; $this->model_pdf = $obj->model_pdf;
// Retreive all extrafield for thirdparty // Retreive all extrafield
// fetch optionals attributes and labels // fetch optionals attributes and labels
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $this->fetch_optionals();
$extrafields=new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
$this->fetch_optionals($this->id,$extralabels);
// Load other properties // Load other properties
$result=$this->fetch_subscriptions(); $result=$this->fetch_subscriptions();

View File

@ -236,7 +236,9 @@ class Categorie extends CommonObject
$this->type = $res['type']; $this->type = $res['type'];
$this->entity = $res['entity']; $this->entity = $res['entity'];
$this->fetch_optionals($this->id,null); // Retreive all extrafield
// fetch optionals attributes and labels
$this->fetch_optionals();
$this->db->free($resql); $this->db->free($resql);

View File

@ -465,7 +465,10 @@ class ActionComm extends CommonObject
// Load source object // Load source object
$objFrom = clone $this; $objFrom = clone $this;
// Retreive all extrafield
// fetch optionals attributes and labels
$this->fetch_optionals(); $this->fetch_optionals();
// $this->fetch_userassigned(); // $this->fetch_userassigned();
$this->fetchResources(); $this->fetchResources();

View File

@ -1434,12 +1434,9 @@ class Propal extends CommonObject
$this->brouillon = 1; $this->brouillon = 1;
} }
// Retreive all extrafield for invoice // Retreive all extrafield
// fetch optionals attributes and labels // fetch optionals attributes and labels
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $this->fetch_optionals();
$extrafields=new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
$this->fetch_optionals($this->id,$extralabels);
$this->db->free($resql); $this->db->free($resql);

View File

@ -1668,12 +1668,9 @@ class Commande extends CommonOrder
if ($this->statut == self::STATUS_DRAFT) $this->brouillon = 1; if ($this->statut == self::STATUS_DRAFT) $this->brouillon = 1;
// Retrieve all extrafields for invoice // Retreive all extrafield
// fetch optionals attributes and labels // fetch optionals attributes and labels
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $this->fetch_optionals();
$extrafields=new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
$this->fetch_optionals($this->id,$extralabels);
$this->db->free($result); $this->db->free($result);

View File

@ -913,12 +913,9 @@ class Account extends CommonObject
$this->date_creation = $this->db->jdate($obj->date_creation); $this->date_creation = $this->db->jdate($obj->date_creation);
$this->date_update = $this->db->jdate($obj->date_update); $this->date_update = $this->db->jdate($obj->date_update);
// Retreive all extrafield for thirdparty // Retreive all extrafield
// fetch optionals attributes and labels // fetch optionals attributes and labels
require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'); $this->fetch_optionals();
$extrafields=new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
$this->fetch_optionals($this->id,$extralabels);
return 1; return 1;
} }

View File

@ -381,12 +381,9 @@ class FactureRec extends CommonInvoice
if ($this->statut == self::STATUS_DRAFT) $this->brouillon = 1; if ($this->statut == self::STATUS_DRAFT) $this->brouillon = 1;
// Retreive all extrafield for thirdparty // Retreive all extrafield
// fetch optionals attributes and labels // fetch optionals attributes and labels
require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'); $this->fetch_optionals();
$extrafields=new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
$this->fetch_optionals($this->id,$extralabels);
/* /*
* Lines * Lines

View File

@ -790,14 +790,17 @@ class Facture extends CommonInvoice
// Charge facture source // Charge facture source
$facture=new Facture($this->db); $facture=new Facture($this->db);
$this->fetch_optionals(); // Retreive all extrafield
if(!empty($this->array_options)){ // fetch optionals attributes and labels
$facture->array_options = $this->array_options; $this->fetch_optionals();
}
foreach($this->lines as &$line){ if(!empty($this->array_options)){
$facture->array_options = $this->array_options;
}
foreach($this->lines as &$line){
$line->fetch_optionals();//fetch extrafields $line->fetch_optionals();//fetch extrafields
} }
$facture->fk_facture_source = $this->fk_facture_source; $facture->fk_facture_source = $this->fk_facture_source;
$facture->type = $this->type; $facture->type = $this->type;
@ -1328,16 +1331,13 @@ class Facture extends CommonInvoice
if ($this->statut == self::STATUS_DRAFT) $this->brouillon = 1; if ($this->statut == self::STATUS_DRAFT) $this->brouillon = 1;
// Retrieve all extrafield for invoice // Retreive all extrafield
// fetch optionals attributes and labels // fetch optionals attributes and labels
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $this->fetch_optionals();
$extrafields=new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
$this->fetch_optionals($this->id,$extralabels);
/* /*
* Lines * Lines
*/ */
$this->lines = array(); $this->lines = array();

View File

@ -801,12 +801,9 @@ class Contact extends CommonObject
} }
} }
// Retreive all extrafield for contact // Retreive all extrafield
// fetch optionals attributes and labels // fetch optionals attributes and labels
require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'); $this->fetch_optionals();
$extrafields=new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
$this->fetch_optionals($this->id,$extralabels);
return 1; return 1;
} }

View File

@ -635,7 +635,9 @@ class Contrat extends CommonObject
$this->db->free($resql); $this->db->free($resql);
$this->fetch_optionals($this->id, null); // Retreive all extrafield
// fetch optionals attributes and labels
$this->fetch_optionals();
/* /*

View File

@ -48,14 +48,14 @@ class Ctyperesource
/** /**
*/ */
public $code; public $code;
public $label; public $label;
public $active; public $active;
/** /**
*/ */
/** /**
* Constructor * Constructor
@ -82,7 +82,7 @@ class Ctyperesource
$error = 0; $error = 0;
// Clean parameters // Clean parameters
if (isset($this->code)) { if (isset($this->code)) {
$this->code = trim($this->code); $this->code = trim($this->code);
} }
@ -93,26 +93,26 @@ class Ctyperesource
$this->active = trim($this->active); $this->active = trim($this->active);
} }
// Check parameters // Check parameters
// Put here code to add control on parameters values // Put here code to add control on parameters values
// Insert request // Insert request
$sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '('; $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '(';
$sql.= 'code,'; $sql.= 'code,';
$sql.= 'label'; $sql.= 'label';
$sql.= 'active'; $sql.= 'active';
$sql .= ') VALUES ('; $sql .= ') VALUES (';
$sql .= ' '.(! isset($this->code)?'NULL':"'".$this->db->escape($this->code)."'").','; $sql .= ' '.(! isset($this->code)?'NULL':"'".$this->db->escape($this->code)."'").',';
$sql .= ' '.(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").','; $sql .= ' '.(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").',';
$sql .= ' '.(! isset($this->active)?'NULL':$this->active); $sql .= ' '.(! isset($this->active)?'NULL':$this->active);
$sql .= ')'; $sql .= ')';
$this->db->begin(); $this->db->begin();
@ -165,18 +165,18 @@ class Ctyperesource
$sql = 'SELECT'; $sql = 'SELECT';
$sql .= ' t.rowid,'; $sql .= ' t.rowid,';
$sql .= " t.code,"; $sql .= " t.code,";
$sql .= " t.label,"; $sql .= " t.label,";
$sql .= " t.active"; $sql .= " t.active";
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
if ($id) $sql.= " WHERE t.id = ".$id; if ($id) $sql.= " WHERE t.id = ".$id;
elseif ($code) $sql.= " WHERE t.code = '".$this->db->escape($code)."'"; elseif ($code) $sql.= " WHERE t.code = '".$this->db->escape($code)."'";
elseif ($label) $sql.= " WHERE t.label = '".$this->db->escape($label)."'"; elseif ($label) $sql.= " WHERE t.label = '".$this->db->escape($label)."'";
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) { if ($resql) {
$numrows = $this->db->num_rows($resql); $numrows = $this->db->num_rows($resql);
@ -184,25 +184,20 @@ class Ctyperesource
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid; $this->id = $obj->rowid;
$this->code = $obj->code; $this->code = $obj->code;
$this->label = $obj->label; $this->label = $obj->label;
$this->active = $obj->active; $this->active = $obj->active;
} }
// Retrieve all extrafields for invoice // Retrieve all extrafields for invoice
// fetch optionals attributes and labels // fetch optionals attributes and labels
/* // $this->fetch_optionals();
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
$extrafields=new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
$this->fetch_optionals($this->id,$extralabels);
*/
// $this->fetch_lines(); // $this->fetch_lines();
$this->db->free($resql); $this->db->free($resql);
if ($numrows) { if ($numrows) {
@ -236,12 +231,12 @@ class Ctyperesource
$sql = 'SELECT'; $sql = 'SELECT';
$sql .= ' t.rowid,'; $sql .= ' t.rowid,';
$sql .= " t.code,"; $sql .= " t.code,";
$sql .= " t.label,"; $sql .= " t.label,";
$sql .= " t.active"; $sql .= " t.active";
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t'; $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t';
// Manage filter // Manage filter
@ -251,7 +246,7 @@ class Ctyperesource
$sqlwhere [] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\''; $sqlwhere [] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\'';
} }
} }
if (count($sqlwhere) > 0) { if (count($sqlwhere) > 0) {
$sql .= ' WHERE ' . implode(' '.$filtermode.' ', $sqlwhere); $sql .= ' WHERE ' . implode(' '.$filtermode.' ', $sqlwhere);
} }
@ -270,12 +265,12 @@ class Ctyperesource
$line = new self($this->db); $line = new self($this->db);
$line->id = $obj->rowid; $line->id = $obj->rowid;
$line->code = $obj->code; $line->code = $obj->code;
$line->label = $obj->label; $line->label = $obj->label;
$line->active = $obj->active; $line->active = $obj->active;
} }
$this->db->free($resql); $this->db->free($resql);
@ -303,7 +298,7 @@ class Ctyperesource
dol_syslog(__METHOD__, LOG_DEBUG); dol_syslog(__METHOD__, LOG_DEBUG);
// Clean parameters // Clean parameters
if (isset($this->code)) { if (isset($this->code)) {
$this->code = trim($this->code); $this->code = trim($this->code);
} }
@ -319,12 +314,12 @@ class Ctyperesource
// Update request // Update request
$sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET'; $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET';
$sql .= ' code = '.(isset($this->code)?"'".$this->db->escape($this->code)."'":"null").','; $sql .= ' code = '.(isset($this->code)?"'".$this->db->escape($this->code)."'":"null").',';
$sql .= ' label = '.(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").','; $sql .= ' label = '.(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").',';
$sql .= ' active = '.(isset($this->active)?$this->active:"null"); $sql .= ' active = '.(isset($this->active)?$this->active:"null");
$sql .= ' WHERE rowid=' . $this->id; $sql .= ' WHERE rowid=' . $this->id;
$this->db->begin(); $this->db->begin();
@ -387,7 +382,7 @@ class Ctyperesource
} }
// If you need to delete child tables to, you can insert them here // If you need to delete child tables to, you can insert them here
if (!$error) { if (!$error) {
$sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element; $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element;
$sql .= ' WHERE rowid=' . $this->id; $sql .= ' WHERE rowid=' . $this->id;
@ -468,7 +463,7 @@ class Ctyperesource
public function initAsSpecimen() public function initAsSpecimen()
{ {
$this->id = 0; $this->id = 0;
$this->code = ''; $this->code = '';
$this->label = ''; $this->label = '';
$this->active = ''; $this->active = '';
@ -488,7 +483,7 @@ class CtyperesourceLine
/** /**
* @var mixed Sample line property 1 * @var mixed Sample line property 1
*/ */
public $code; public $code;
public $label; public $label;
public $active; public $active;
@ -496,5 +491,5 @@ class CtyperesourceLine
/** /**
* @var mixed Sample line property 2 * @var mixed Sample line property 2
*/ */
} }

View File

@ -665,12 +665,9 @@ class Don extends CommonObject
$this->modelpdf = $obj->model_pdf; $this->modelpdf = $obj->model_pdf;
$this->commentaire = $obj->note; // deprecated $this->commentaire = $obj->note; // deprecated
// Retrieve all extrafield for thirdparty // Retreive all extrafield
// fetch optionals attributes and labels // fetch optionals attributes and labels
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $this->fetch_optionals();
$extrafields=new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
$this->fetch_optionals($this->id,$extralabels);
} }
return 1; return 1;
} }

View File

@ -337,12 +337,8 @@ class EcmFiles //extends CommonObject
// Retrieve all extrafields for invoice // Retrieve all extrafields for invoice
// fetch optionals attributes and labels // fetch optionals attributes and labels
/* // $this->fetch_optionals();
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
$extrafields=new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
$this->fetch_optionals($this->id,$extralabels);
*/
// $this->fetch_lines(); // $this->fetch_lines();
$this->db->free($resql); $this->db->free($resql);

View File

@ -547,12 +547,9 @@ class Expedition extends CommonObject
*/ */
$result=$this->fetch_thirdparty(); $result=$this->fetch_thirdparty();
// Retrieve all extrafields for expedition // Retreive all extrafield
// fetch optionals attributes and labels // fetch optionals attributes and labels
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $this->fetch_optionals();
$extrafields=new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
$this->fetch_optionals($this->id,$extralabels);
/* /*
* Lines * Lines

View File

@ -383,14 +383,13 @@ class Fichinter extends CommonObject
if ($this->statut == 0) $this->brouillon = 1; if ($this->statut == 0) $this->brouillon = 1;
require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'); // Retreive all extrafield
$extrafields=new ExtraFields($this->db); // fetch optionals attributes and labels
$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true); $this->fetch_optionals();
$this->fetch_optionals($this->id,$extralabels);
/* /*
* Lines * Lines
*/ */
$result=$this->fetch_lines(); $result=$this->fetch_lines();
if ($result < 0) if ($result < 0)
{ {

View File

@ -310,12 +310,9 @@ class CommandeFournisseur extends CommonOrder
$this->db->free($resql); $this->db->free($resql);
// Retrieve all extrafields // Retreive all extrafield
// fetch optionals attributes and labels // fetch optionals attributes and labels
require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'); $this->fetch_optionals();
$extrafields=new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
$this->fetch_optionals($this->id,$extralabels);
if ($this->statut == 0) $this->brouillon = 1; if ($this->statut == 0) $this->brouillon = 1;

View File

@ -643,10 +643,7 @@ class FactureFournisseur extends CommonInvoice
// Retreive all extrafield // Retreive all extrafield
// fetch optionals attributes and labels // fetch optionals attributes and labels
require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'); $this->fetch_optionals();
$extrafields=new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
$this->fetch_optionals($this->id,$extralabels);
if ($this->statut == self::STATUS_DRAFT) $this->brouillon = 1; if ($this->statut == self::STATUS_DRAFT) $this->brouillon = 1;

View File

@ -301,13 +301,9 @@ class Livraison extends CommonObject
if ($this->statut == 0) $this->brouillon = 1; if ($this->statut == 0) $this->brouillon = 1;
// Retreive all extrafield
// Retrieve all extrafields for delivery
// fetch optionals attributes and labels // fetch optionals attributes and labels
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $this->fetch_optionals();
$extrafields=new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
$this->fetch_optionals($this->id,$extralabels);
/* /*
* Lignes * Lignes

View File

@ -1951,13 +1951,9 @@ class Product extends CommonObject
$this->db->free($resql); $this->db->free($resql);
// Retreive all extrafield
// Retreive all extrafield for current object
// fetch optionals attributes and labels // fetch optionals attributes and labels
require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'); $this->fetch_optionals();
$extrafields=new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
$this->fetch_optionals($this->id,$extralabels);
// multilangs // multilangs
if (! empty($conf->global->MAIN_MULTILANGS)) $this->getMultiLangs(); if (! empty($conf->global->MAIN_MULTILANGS)) $this->getMultiLangs();

View File

@ -576,12 +576,9 @@ class MouvementStock extends CommonObject
$this->sellby = $this->db->jdate($obj->sellby); $this->sellby = $this->db->jdate($obj->sellby);
} }
// Retrieve all extrafields for invoice // Retreive all extrafield
// fetch optionals attributes and labels // fetch optionals attributes and labels
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $this->fetch_optionals();
$extrafields=new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
$this->fetch_optionals($this->id,$extralabels);
// $this->fetch_lines(); // $this->fetch_lines();

View File

@ -233,12 +233,9 @@ class Productlot extends CommonObject
$this->fk_user_modif = $obj->fk_user_modif; $this->fk_user_modif = $obj->fk_user_modif;
$this->import_key = $obj->import_key; $this->import_key = $obj->import_key;
// Retrieve all extrafields for invoice // Retreive all extrafield
// fetch optionals attributes and labels // fetch optionals attributes and labels
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $this->fetch_optionals();
$extrafields=new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
$this->fetch_optionals($this->id,$extralabels);
} }
$this->db->free($resql); $this->db->free($resql);

View File

@ -51,7 +51,7 @@ class ProductStockEntrepot extends CommonObject
/** /**
*/ */
public $tms = ''; public $tms = '';
public $fk_product; public $fk_product;
public $fk_entrepot; public $fk_entrepot;
@ -61,7 +61,7 @@ class ProductStockEntrepot extends CommonObject
/** /**
*/ */
/** /**
* Constructor * Constructor
@ -88,7 +88,7 @@ class ProductStockEntrepot extends CommonObject
$error = 0; $error = 0;
// Clean parameters // Clean parameters
if (isset($this->fk_product)) $this->fk_product = trim($this->fk_product); if (isset($this->fk_product)) $this->fk_product = trim($this->fk_product);
if (isset($this->fk_entrepot)) $this->fk_entrepot = trim($this->fk_entrepot); if (isset($this->fk_entrepot)) $this->fk_entrepot = trim($this->fk_entrepot);
if (isset($this->seuil_stock_alerte)) $this->seuil_stock_alerte = trim($this->seuil_stock_alerte); if (isset($this->seuil_stock_alerte)) $this->seuil_stock_alerte = trim($this->seuil_stock_alerte);
@ -100,23 +100,23 @@ class ProductStockEntrepot extends CommonObject
// Insert request // Insert request
$sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '('; $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '(';
$sql.= 'fk_product,'; $sql.= 'fk_product,';
$sql.= 'fk_entrepot,'; $sql.= 'fk_entrepot,';
$sql.= 'seuil_stock_alerte,'; $sql.= 'seuil_stock_alerte,';
$sql.= 'desiredstock,'; $sql.= 'desiredstock,';
$sql.= 'import_key'; $sql.= 'import_key';
$sql .= ') VALUES ('; $sql .= ') VALUES (';
$sql .= ' '.(! isset($this->fk_product)?'NULL':$this->fk_product).','; $sql .= ' '.(! isset($this->fk_product)?'NULL':$this->fk_product).',';
$sql .= ' '.(! isset($this->fk_entrepot)?'NULL':$this->fk_entrepot).','; $sql .= ' '.(! isset($this->fk_entrepot)?'NULL':$this->fk_entrepot).',';
$sql .= ' '.(! isset($this->seuil_stock_alerte)?'0':$this->seuil_stock_alerte).','; $sql .= ' '.(! isset($this->seuil_stock_alerte)?'0':$this->seuil_stock_alerte).',';
$sql .= ' '.(! isset($this->desiredstock)?'0':$this->desiredstock).','; $sql .= ' '.(! isset($this->desiredstock)?'0':$this->desiredstock).',';
$sql .= ' '.(! isset($this->import_key)?'NULL':"'".$this->db->escape($this->import_key)."'"); $sql .= ' '.(! isset($this->import_key)?'NULL':"'".$this->db->escape($this->import_key)."'");
$sql .= ')'; $sql .= ')';
$this->db->begin(); $this->db->begin();
@ -166,12 +166,12 @@ class ProductStockEntrepot extends CommonObject
public function fetch($id, $fk_product, $fk_entrepot) public function fetch($id, $fk_product, $fk_entrepot)
{ {
if(empty($id) && (empty($fk_product) || empty($fk_entrepot))) return -1; if(empty($id) && (empty($fk_product) || empty($fk_entrepot))) return -1;
dol_syslog(__METHOD__, LOG_DEBUG); dol_syslog(__METHOD__, LOG_DEBUG);
$sql = 'SELECT'; $sql = 'SELECT';
$sql .= ' t.rowid,'; $sql .= ' t.rowid,';
$sql .= " t.tms,"; $sql .= " t.tms,";
$sql .= " t.fk_product,"; $sql .= " t.fk_product,";
$sql .= " t.fk_entrepot,"; $sql .= " t.fk_entrepot,";
@ -179,11 +179,11 @@ class ProductStockEntrepot extends CommonObject
$sql .= " t.desiredstock,"; $sql .= " t.desiredstock,";
$sql .= " t.import_key"; $sql .= " t.import_key";
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
if(!empty($id)) $sql .= ' WHERE t.rowid = ' . $id; if(!empty($id)) $sql .= ' WHERE t.rowid = ' . $id;
else $sql.= ' WHERE t.fk_product = '.$fk_product.' AND t.fk_entrepot = '.$fk_entrepot; else $sql.= ' WHERE t.fk_product = '.$fk_product.' AND t.fk_entrepot = '.$fk_entrepot;
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) { if ($resql) {
$numrows = $this->db->num_rows($resql); $numrows = $this->db->num_rows($resql);
@ -191,7 +191,7 @@ class ProductStockEntrepot extends CommonObject
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid; $this->id = $obj->rowid;
$this->tms = $this->db->jdate($obj->tms); $this->tms = $this->db->jdate($obj->tms);
$this->fk_product = $obj->fk_product; $this->fk_product = $obj->fk_product;
$this->fk_entrepot = $obj->fk_entrepot; $this->fk_entrepot = $obj->fk_entrepot;
@ -199,18 +199,15 @@ class ProductStockEntrepot extends CommonObject
$this->desiredstock = $obj->desiredstock; $this->desiredstock = $obj->desiredstock;
$this->import_key = $obj->import_key; $this->import_key = $obj->import_key;
} }
// Retrieve all extrafields for invoice // Retreive all extrafield
// fetch optionals attributes and labels // fetch optionals attributes and labels
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $this->fetch_optionals();
$extrafields=new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
$this->fetch_optionals($this->id,$extralabels);
// $this->fetch_lines(); // $this->fetch_lines();
$this->db->free($resql); $this->db->free($resql);
if ($numrows) { if ($numrows) {
@ -246,7 +243,7 @@ class ProductStockEntrepot extends CommonObject
$sql = 'SELECT'; $sql = 'SELECT';
$sql .= ' t.rowid,'; $sql .= ' t.rowid,';
$sql .= " t.tms,"; $sql .= " t.tms,";
$sql .= " t.fk_product,"; $sql .= " t.fk_product,";
$sql .= " t.fk_entrepot,"; $sql .= " t.fk_entrepot,";
@ -254,11 +251,11 @@ class ProductStockEntrepot extends CommonObject
$sql .= " t.desiredstock,"; $sql .= " t.desiredstock,";
$sql .= " t.import_key"; $sql .= " t.import_key";
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t'; $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t';
$sql .= ' WHERE 1=1'; $sql .= ' WHERE 1=1';
// Manage filter // Manage filter
$sqlwhere = array(); $sqlwhere = array();
if (count($filter) > 0) { if (count($filter) > 0) {
@ -267,19 +264,19 @@ class ProductStockEntrepot extends CommonObject
} }
} }
if (count($sqlwhere) > 0) $sql .= ' AND ' . implode(' '.$filtermode.' ', $sqlwhere); if (count($sqlwhere) > 0) $sql .= ' AND ' . implode(' '.$filtermode.' ', $sqlwhere);
if(!empty($fk_product)) $sql .= ' AND fk_product = '.$fk_product; if(!empty($fk_product)) $sql .= ' AND fk_product = '.$fk_product;
elseif(!empty($fk_entrepot)) $sql .= ' AND fk_entrepot = '.$fk_entrepot; elseif(!empty($fk_entrepot)) $sql .= ' AND fk_entrepot = '.$fk_entrepot;
// "elseif" used instead of "if" because getting list with specified fk_product and specified fk_entrepot would be the same as doing a fetch // "elseif" used instead of "if" because getting list with specified fk_product and specified fk_entrepot would be the same as doing a fetch
if (!empty($sortfield)) $sql .= $this->db->order($sortfield,$sortorder); if (!empty($sortfield)) $sql .= $this->db->order($sortfield,$sortorder);
if (!empty($limit)) $sql .= ' ' . $this->db->plimit($limit, $offset); if (!empty($limit)) $sql .= ' ' . $this->db->plimit($limit, $offset);
$lines = array(); $lines = array();
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) { if ($resql) {
while ($obj = $this->db->fetch_object($resql)) { while ($obj = $this->db->fetch_object($resql)) {
$lines[$obj->rowid] = array( $lines[$obj->rowid] = array(
'id'=>$obj->rowid 'id'=>$obj->rowid
@ -315,20 +312,20 @@ class ProductStockEntrepot extends CommonObject
dol_syslog(__METHOD__, LOG_DEBUG); dol_syslog(__METHOD__, LOG_DEBUG);
// Clean parameters // Clean parameters
if (isset($this->fk_product)) $this->fk_product = trim($this->fk_product); if (isset($this->fk_product)) $this->fk_product = trim($this->fk_product);
if (isset($this->fk_entrepot)) $this->fk_entrepot = trim($this->fk_entrepot); if (isset($this->fk_entrepot)) $this->fk_entrepot = trim($this->fk_entrepot);
if (isset($this->seuil_stock_alerte)) $this->seuil_stock_alerte = trim($this->seuil_stock_alerte); if (isset($this->seuil_stock_alerte)) $this->seuil_stock_alerte = trim($this->seuil_stock_alerte);
if (isset($this->desiredstock)) $this->desiredstock = trim($this->desiredstock); if (isset($this->desiredstock)) $this->desiredstock = trim($this->desiredstock);
if (isset($this->import_key)) $this->import_key = trim($this->import_key); if (isset($this->import_key)) $this->import_key = trim($this->import_key);
// Check parameters // Check parameters
// Put here code to add a control on parameters values // Put here code to add a control on parameters values
// Update request // Update request
$sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET'; $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET';
$sql .= ' tms = '.(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : "'".$this->db->idate(dol_now())."'").','; $sql .= ' tms = '.(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : "'".$this->db->idate(dol_now())."'").',';
$sql .= ' fk_product = '.(isset($this->fk_product)?$this->fk_product:"null").','; $sql .= ' fk_product = '.(isset($this->fk_product)?$this->fk_product:"null").',';
$sql .= ' fk_entrepot = '.(isset($this->fk_entrepot)?$this->fk_entrepot:"null").','; $sql .= ' fk_entrepot = '.(isset($this->fk_entrepot)?$this->fk_entrepot:"null").',';
@ -336,7 +333,7 @@ class ProductStockEntrepot extends CommonObject
$sql .= ' desiredstock = '.(isset($this->desiredstock)?$this->desiredstock:"null").','; $sql .= ' desiredstock = '.(isset($this->desiredstock)?$this->desiredstock:"null").',';
$sql .= ' import_key = '.(isset($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null"); $sql .= ' import_key = '.(isset($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null");
$sql .= ' WHERE rowid=' . $this->id; $sql .= ' WHERE rowid=' . $this->id;
$this->db->begin(); $this->db->begin();
@ -573,7 +570,7 @@ class ProductStockEntrepot extends CommonObject
public function initAsSpecimen() public function initAsSpecimen()
{ {
$this->id = 0; $this->id = 0;
$this->tms = ''; $this->tms = '';
$this->fk_product = ''; $this->fk_product = '';
$this->fk_entrepot = ''; $this->fk_entrepot = '';
@ -581,7 +578,7 @@ class ProductStockEntrepot extends CommonObject
$this->desiredstock = ''; $this->desiredstock = '';
$this->import_key = ''; $this->import_key = '';
} }
} }

View File

@ -444,7 +444,8 @@ class Project extends CommonObject
$this->db->free($resql); $this->db->free($resql);
// Retreive all extrafield for thirdparty // Retreive all extrafield
// fetch optionals attributes and labels
$this->fetch_optionals(); $this->fetch_optionals();
if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT)) if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT))

View File

@ -266,8 +266,9 @@ class Task extends CommonObject
$this->task_parent_position = $obj->task_parent_position; $this->task_parent_position = $obj->task_parent_position;
} }
// Retreive all extrafield data // Retreive all extrafield
$this->fetch_optionals(); // fetch optionals attributes and labels
$this->fetch_optionals();
} }
$this->db->free($resql); $this->db->free($resql);

View File

@ -213,13 +213,9 @@ class Dolresource extends CommonObject
$this->note_private = $obj->note_private; $this->note_private = $obj->note_private;
$this->type_label = $obj->type_label; $this->type_label = $obj->type_label;
// Retreive all extrafield for thirdparty // Retreive all extrafield
// fetch optionals attributes and labels // fetch optionals attributes and labels
require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'); $this->fetch_optionals();
$extrafields=new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
$this->fetch_optionals($this->id,$extralabels);
} }
$this->db->free($resql); $this->db->free($resql);

View File

@ -334,7 +334,7 @@ class Societe extends CommonObject
*/ */
var $price_level; var $price_level;
var $outstanding_limit; var $outstanding_limit;
/** /**
* Min order amounts * Min order amounts
*/ */
@ -1315,8 +1315,9 @@ class Societe extends CommonObject
$result = 1; $result = 1;
// Retreive all extrafield for thirdparty // Retreive all extrafield
$this->fetch_optionals(); // fetch optionals attributes and labels
$this->fetch_optionals();
} }
else else
{ {

View File

@ -1215,12 +1215,9 @@ class SupplierProposal extends CommonObject
$this->brouillon = 1; $this->brouillon = 1;
} }
// Retreive all extrafield for invoice // Retreive all extrafield
// fetch optionals attributes and labels // fetch optionals attributes and labels
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $this->fetch_optionals();
$extrafields=new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
$this->fetch_optionals($this->id,$extralabels);
$this->db->free($resql); $this->db->free($resql);
@ -1311,12 +1308,9 @@ class SupplierProposal extends CommonObject
return -1; return -1;
} }
// Retreive all extrafield for askprice // Retreive all extrafield
// fetch optionals attributes and labels // fetch optionals attributes and labels
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $this->fetch_optionals();
$extrafields=new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
$this->fetch_optionals($this->id,$extralabels);
return 1; return 1;
} }

View File

@ -324,12 +324,9 @@ class User extends CommonObject
// in such case, this admin user must be admin for ALL entities. // in such case, this admin user must be admin for ALL entities.
if (empty($conf->multicompany->enabled) && $this->admin && $this->entity == 1) $this->entity = 0; if (empty($conf->multicompany->enabled) && $this->admin && $this->entity == 1) $this->entity = 0;
// Retreive all extrafield for thirdparty // Retreive all extrafield
// fetch optionals attributes and labels // fetch optionals attributes and labels
require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'); $this->fetch_optionals();
$extrafields=new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
$this->fetch_optionals($this->id,$extralabels);
$this->db->free($result); $this->db->free($result);
} }

View File

@ -116,12 +116,9 @@ class UserGroup extends CommonObject
$this->members=$this->listUsersForGroup(); $this->members=$this->listUsersForGroup();
// Retreive all extrafield for group // Retreive all extrafield
// fetch optionals attributes and labels // fetch optionals attributes and labels
dol_include_once('/core/class/extrafields.class.php'); $this->fetch_optionals();
$extrafields=new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
$this->fetch_optionals($this->id,$extralabels);
// Sav current LDAP Current DN // Sav current LDAP Current DN