From ce8c60613237b0c35c137875a5820b5daf32a108 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 12 May 2021 11:04:22 +0200 Subject: [PATCH] Clean APIs --- htdocs/api/class/api.class.php | 25 +++++++-- htdocs/product/class/api_products.class.php | 60 +++++++++++++++++---- htdocs/product/class/product.class.php | 12 +---- htdocs/user/card.php | 12 +++-- 4 files changed, 80 insertions(+), 29 deletions(-) diff --git a/htdocs/api/class/api.class.php b/htdocs/api/class/api.class.php index 7a9dd908a59..0a84de7b7c1 100644 --- a/htdocs/api/class/api.class.php +++ b/htdocs/api/class/api.class.php @@ -124,6 +124,16 @@ class DolibarrApi unset($object->ref_previous); unset($object->ref_next); unset($object->ref_int); + unset($object->imgWidth); + unset($object->imgHeight); + unset($object->barcode_type_code); + unset($object->barcode_type_label); + + unset($object->mode_reglement); // We use mode_reglement_id now + unset($object->cond_reglement); // We use cond_reglement_id now + unset($object->note); // We use note_public or note_private now + unset($object->contact); // We use contact_id now + unset($object->thirdparty); // We use thirdparty_id or fk_soc or socid now unset($object->projet); // Should be fk_project unset($object->project); // Should be fk_project @@ -137,6 +147,12 @@ class DolibarrApi unset($object->timespent_fk_user); unset($object->timespent_note); unset($object->fk_delivery_address); + unset($object->modelpdf); + unset($object->sendtoid); + unset($object->name_bis); + unset($object->newref); + unset($object->alreadypaid); + unset($object->openid); unset($object->statuts); unset($object->statuts_short); @@ -169,16 +185,17 @@ class DolibarrApi unset($object->region); unset($object->region_code); + unset($object->country); + unset($object->state); + unset($object->state_code); + unset($object->departement); + unset($object->departement_code); unset($object->libelle_statut); unset($object->libelle_paiement); unset($object->prefix_comm); - unset($object->sendtoid); - unset($object->name_bis); - unset($object->newref); - if (!isset($object->table_element) || $object->table_element != 'ticket') { unset($object->comments); } diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index fc89787deda..b4e860a1069 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -73,15 +73,16 @@ class Products extends DolibarrApi * @param int $includestockdata Load also information about stock (slower) * @param bool $includesubproducts Load information about subproducts * @param bool $includeparentid Load also ID of parent product (if product is a variant of a parent product) + * @param bool $includetrans Load also the translations of product label and description * @return array|mixed Data without useless information * * @throws RestException 401 * @throws RestException 403 * @throws RestException 404 */ - public function get($id, $includestockdata = 0, $includesubproducts = false, $includeparentid = false) + public function get($id, $includestockdata = 0, $includesubproducts = false, $includeparentid = false, $includetrans = false) { - return $this->_fetch($id, '', '', '', $includestockdata, $includesubproducts, $includeparentid); + return $this->_fetch($id, '', '', '', $includestockdata, $includesubproducts, $includeparentid, false, $includetrans); } /** @@ -93,6 +94,7 @@ class Products extends DolibarrApi * @param int $includestockdata Load also information about stock (slower) * @param bool $includesubproducts Load information about subproducts * @param bool $includeparentid Load also ID of parent product (if product is a variant of a parent product) + * @param bool $includetrans Load also the translations of product label and description * * @return array|mixed Data without useless information * @@ -102,9 +104,9 @@ class Products extends DolibarrApi * @throws RestException 403 * @throws RestException 404 */ - public function getByRef($ref, $includestockdata = 0, $includesubproducts = false, $includeparentid = false) + public function getByRef($ref, $includestockdata = 0, $includesubproducts = false, $includeparentid = false, $includetrans = false) { - return $this->_fetch('', $ref, '', '', $includestockdata, $includesubproducts, $includeparentid); + return $this->_fetch('', $ref, '', '', $includestockdata, $includesubproducts, $includeparentid, false, $includetrans); } /** @@ -116,6 +118,7 @@ class Products extends DolibarrApi * @param int $includestockdata Load also information about stock (slower) * @param bool $includesubproducts Load information about subproducts * @param bool $includeparentid Load also ID of parent product (if product is a variant of a parent product) + * @param bool $includetrans Load also the translations of product label and description * * @return array|mixed Data without useless information * @@ -125,9 +128,9 @@ class Products extends DolibarrApi * @throws RestException 403 * @throws RestException 404 */ - public function getByRefExt($ref_ext, $includestockdata = 0, $includesubproducts = false, $includeparentid = false) + public function getByRefExt($ref_ext, $includestockdata = 0, $includesubproducts = false, $includeparentid = false, $includetrans = false) { - return $this->_fetch('', '', $ref_ext, '', $includestockdata, $includesubproducts, $includeparentid); + return $this->_fetch('', '', $ref_ext, '', $includestockdata, $includesubproducts, $includeparentid, false, $includetrans); } /** @@ -139,6 +142,7 @@ class Products extends DolibarrApi * @param int $includestockdata Load also information about stock (slower) * @param bool $includesubproducts Load information about subproducts * @param bool $includeparentid Load also ID of parent product (if product is a variant of a parent product) + * @param bool $includetrans Load also the translations of product label and description * * @return array|mixed Data without useless information * @@ -148,9 +152,9 @@ class Products extends DolibarrApi * @throws RestException 403 * @throws RestException 404 */ - public function getByBarcode($barcode, $includestockdata = 0, $includesubproducts = false, $includeparentid = false) + public function getByBarcode($barcode, $includestockdata = 0, $includesubproducts = false, $includeparentid = false, $includetrans = false) { - return $this->_fetch('', '', '', $barcode, $includestockdata, $includesubproducts, $includeparentid); + return $this->_fetch('', '', '', $barcode, $includestockdata, $includesubproducts, $includeparentid, false, $includetrans); } /** @@ -1895,6 +1899,8 @@ class Products extends DolibarrApi // phpcs:enable $object = parent::_cleanObjectDatas($object); + unset($object->statut); + unset($object->regeximgext); unset($object->price_by_qty); unset($object->prices_by_qty_id); @@ -1906,8 +1912,39 @@ class Products extends DolibarrApi unset($object->firstname); unset($object->lastname); unset($object->civility_id); + unset($object->contact); + unset($object->contact_id); + unset($object->thirdparty); + unset($object->user); + unset($object->origin); + unset($object->origin_id); + unset($object->fourn_pu); + unset($object->fourn_price_base_type); + unset($object->fourn_socid); + unset($object->ref_fourn); + unset($object->ref_supplier); + unset($object->product_fourn_id); + unset($object->fk_project); + unset($object->mode_reglement_id); + unset($object->cond_reglement_id); + unset($object->demand_reason_id); + unset($object->transport_mode_id); + unset($object->cond_reglement); + unset($object->shipping_method_id); + unset($object->model_pdf); + unset($object->note); + + unset($object->nbphoto); unset($object->recuperableonly); + unset($object->multiprices_recuperableonly); + unset($object->tva_npr); + unset($object->lines); + unset($object->fk_bank); + unset($object->fk_account); + + unset($object->supplierprices); // Mut use another API to get them + return $object; } @@ -1942,14 +1979,15 @@ class Products extends DolibarrApi * @param int $includestockdata Load also information about stock (slower) * @param bool $includesubproducts Load information about subproducts (if product is a virtual product) * @param bool $includeparentid Load also ID of parent product (if product is a variant of a parent product) - * @param bool $includeifobjectisused Check if product object is used and set is_object_used with result. + * @param bool $includeifobjectisused Check if product object is used and set property 'is_object_used' with result. + * @param bool $includetrans Load also the translations of product label and description * @return array|mixed Data without useless information * * @throws RestException 401 * @throws RestException 403 * @throws RestException 404 */ - private function _fetch($id, $ref = '', $ref_ext = '', $barcode = '', $includestockdata = 0, $includesubproducts = false, $includeparentid = false, $includeifobjectisused = false) + private function _fetch($id, $ref = '', $ref_ext = '', $barcode = '', $includestockdata = 0, $includesubproducts = false, $includeparentid = false, $includeifobjectisused = false, $includetrans = false) { if (empty($id) && empty($ref) && empty($ref_ext) && empty($barcode)) { throw new RestException(400, 'bad value for parameter id, ref, ref_ext or barcode'); @@ -1961,7 +1999,7 @@ class Products extends DolibarrApi throw new RestException(403); } - $result = $this->product->fetch($id, $ref, $ref_ext, $barcode); + $result = $this->product->fetch($id, $ref, $ref_ext, $barcode, 0, 0, ($includetrans ? 0 : 1)); if (!$result) { throw new RestException(404, 'Product not found'); } diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index b359d7629b7..22e28001743 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -330,13 +330,6 @@ class Product extends CommonObject */ public $barcode_type_code; - /** - * Additional barcodes (Some products have different barcodes according to the country of origin of manufacture) - * - * @var array - */ - public $barcodes_extra = array(); - public $stats_propale = array(); public $stats_commande = array(); public $stats_contrat = array(); @@ -2237,7 +2230,7 @@ class Product extends CommonObject if ($separatedStock) { $sql .= " AND sp.fk_entrepot IN ( SELECT rowid - FROM ".MAIN_DB_PREFIX."entrepot WHERE entity IN (" . $this->db->sanitize($visibleWarehousesEntities) ."))"; + FROM ".MAIN_DB_PREFIX."entrepot WHERE entity IN (".$this->db->sanitize($visibleWarehousesEntities)."))"; } @@ -2336,11 +2329,10 @@ class Product extends CommonObject $this->db->free($resql); - // Retrieve all extrafield // fetch optionals attributes and labels $this->fetch_optionals(); - // multilangs + // Multilangs if (!empty($conf->global->MAIN_MULTILANGS) && empty($ignore_lang_load)) { $this->getMultiLangs(); } diff --git a/htdocs/user/card.php b/htdocs/user/card.php index b1a9a229827..8b31f8b544b 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -240,10 +240,12 @@ if (empty($reshook)) { //$object->twitter = GETPOST("twitter", 'alphanohtml'); //$object->facebook = GETPOST("facebook", 'alphanohtml'); //$object->linkedin = GETPOST("linkedin", 'alphanohtml'); - $object->socialnetworks = array(); if (!empty($conf->socialnetworks->enabled)) { + $object->socialnetworks = array(); foreach ($socialnetworks as $key => $value) { - $object->socialnetworks[$key] = GETPOST($key, 'alphanohtml'); + if (GETPOST($key, 'alphanohtml')) { + $object->socialnetworks[$key] = GETPOST($key, 'alphanohtml'); + } } } @@ -400,10 +402,12 @@ if (empty($reshook)) { //$object->twitter = GETPOST("twitter", 'alphanohtml'); //$object->facebook = GETPOST("facebook", 'alphanohtml'); //$object->linkedin = GETPOST("linkedin", 'alphanohtml'); - $object->socialnetworks = array(); if (!empty($conf->socialnetworks->enabled)) { + $object->socialnetworks = array(); foreach ($socialnetworks as $key => $value) { - $object->socialnetworks[$key] = GETPOST($key, 'alphanohtml'); + if (GETPOST($key, 'alphanohtml')) { + $object->socialnetworks[$key] = GETPOST($key, 'alphanohtml'); + } } } $object->email = preg_replace('/\s+/', '', GETPOST("email", 'alphanohtml'));