Fix: uniformize code

This commit is contained in:
Regis Houssin 2010-02-20 12:02:48 +00:00
parent ba32176b35
commit ca6fd04aea

View File

@ -545,6 +545,7 @@ class Product extends CommonObject
function setMultiLangs() function setMultiLangs()
{ {
global $langs; global $langs;
$langs_available = $langs->get_available_languages(); $langs_available = $langs->get_available_languages();
$current_lang = $langs->getDefaultLang(); $current_lang = $langs->getDefaultLang();
@ -609,6 +610,7 @@ class Product extends CommonObject
function getMultiLangs($langue='') function getMultiLangs($langue='')
{ {
global $langs; global $langs;
$langs_available = $langs->get_available_languages(); $langs_available = $langs->get_available_languages();
if ( $langue != '') if ( $langue != '')
@ -1533,55 +1535,60 @@ class Product extends CommonObject
} }
/** /**
* \brief retire le lien entre un sousproduit et un produit/service * \brief Retire le lien entre un sousproduit et un produit/service
* \param id_pere Id du produit auquel ne sera plus li<EFBFBD> le produit li * \param fk_parent Id du produit auquel ne sera plus lie le produit lie
* \param id_fils Id du produit <EFBFBD> ne plus li * \param fk_child Id du produit a ne plus lie
* \return int < 0 si erreur, > 0 si ok * \return int < 0 si erreur, > 0 si ok
*/ */
function del_sousproduit($id_pere, $id_fils) function del_sousproduit($fk_parent, $fk_child)
{ {
$sql = 'delete from '.MAIN_DB_PREFIX.'product_association'; $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_association";
$sql .= ' WHERE fk_product_pere = "'.$id_pere.'" and fk_product_fils = "'.$id_fils.'"'; $sql.= " WHERE fk_product_pere = '".$fk_parent."'";
$sql.= " AND fk_product_fils = '".$fk_child."'";
if (! $this->db->query($sql)) if (! $this->db->query($sql))
{ {
dol_print_error($this->db); dol_print_error($this->db);
return -1; return -1;
} }
else
return 1; return 1;
} }
/** /**
* \brief retire le lien entre un sousproduit et un produit/service * \brief Verifie si c'est un sous-produit
* \param id_pere Id du produit auquel ne sera plus li<EFBFBD> le produit li * \param fk_parent Id du produit auquel le produit est lie
* \param id_fils Id du produit <EFBFBD> ne plus li * \param fk_child Id du produit lie
* \return int < 0 si erreur, > 0 si ok * \return int < 0 si erreur, > 0 si ok
*/ */
function is_sousproduit($id_pere, $id_fils) function is_sousproduit($fk_parent, $fk_child)
{ {
$sql = 'select fk_product_pere,qty from '.MAIN_DB_PREFIX.'product_association'; $sql = "SELECT fk_product_pere, qty";
$sql .= ' WHERE fk_product_pere = "'.$id_pere.'" and fk_product_fils = "'.$id_fils.'"'; $sql.= " FROM ".MAIN_DB_PREFIX."product_association";
if (! $this->db->query($sql)) $sql.= " WHERE fk_product_pere = '".$fk_parent."'";
$sql.= " AND fk_product_fils = '".$fk_child."'";
$result = $this->db->query($sql);
if ($result)
{ {
dol_print_error($this->db); $num = $this->db->num_rows($result);
return -1;
if($num > 0)
{
$obj = $this->db->fetch_object($result);
$this->is_sousproduit_qty = $obj->qty;
return true;
}
else
{
return false;
}
} }
else else
{ {
$result = $this->db->query($sql) ; dol_print_error($this->db);
if ($result) return -1;
{
$num = $this->db->num_rows($result);
if($num > 0)
{
$obj = $this->db->fetch_object($result);
$this->is_sousproduit_qty = $obj->qty;
return true;
}
else
return false;
}
} }
} }
@ -1594,8 +1601,9 @@ class Product extends CommonObject
$this->subproducts_id = array(); $this->subproducts_id = array();
$i = 0; $i = 0;
$sql = "SELECT fk_product_subproduct FROM ".MAIN_DB_PREFIX."product_subproduct"; $sql = "SELECT fk_product_subproduct";
$sql .= " WHERE fk_product=$this->id;"; $sql.= " FROM ".MAIN_DB_PREFIX."product_subproduct";
$sql.= " WHERE fk_product = ".$this->id;
if ($result = $this->db->query($sql)) if ($result = $this->db->query($sql))
{ {
@ -1616,7 +1624,7 @@ class Product extends CommonObject
/** /**
* \brief Lie un sous produit au produit/service * \brief Lie un sous produit au produit/service
* \param id_sub Id du produit <EFBFBD> lier * \param id_sub Id du produit a lier
* \return int < 0 si erreur, > 0 si ok * \return int < 0 si erreur, > 0 si ok
*/ */
function add_subproduct($id_sub) function add_subproduct($id_sub)
@ -1626,14 +1634,14 @@ class Product extends CommonObject
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'product_subproduct(fk_product,fk_product_subproduct)'; $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'product_subproduct(fk_product,fk_product_subproduct)';
$sql .= ' VALUES ("'.$this->id.'","'.$id_sub.'")'; $sql .= ' VALUES ("'.$this->id.'","'.$id_sub.'")';
if (! $this->db->query($sql)) if (! $this->db->query($sql))
{ {
dol_print_error($this->db); dol_print_error($this->db);
return -1; return -1;
} }
else else
{ {
return 0; return 0;
} }
} }
else else
{ {