From b457221277abc4c4afd44cce5c3ff7b694d3dcb3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 22 Jun 2011 11:05:06 +0000 Subject: [PATCH] Uniformize code and increase speed for extrafields --- htdocs/includes/modules/modAdherent.class.php | 8 +++--- htdocs/includes/modules/modSociete.class.php | 28 +++++++++++++++++-- .../install/mysql/migration/3.0.0-3.1.0.sql | 15 +++++----- .../tables/llx_adherent_extrafields.key.sql | 3 +- .../tables/llx_product_extrafields.key.sql | 22 +++++++++++++++ .../tables/llx_societe_extrafields.key.sql | 22 +++++++++++++++ 6 files changed, 83 insertions(+), 15 deletions(-) create mode 100755 htdocs/install/mysql/tables/llx_product_extrafields.key.sql create mode 100755 htdocs/install/mysql/tables/llx_societe_extrafields.key.sql diff --git a/htdocs/includes/modules/modAdherent.class.php b/htdocs/includes/modules/modAdherent.class.php index 4650e493f15..1f8f9e5d263 100644 --- a/htdocs/includes/modules/modAdherent.class.php +++ b/htdocs/includes/modules/modAdherent.class.php @@ -189,20 +189,20 @@ class modAdherent extends DolibarrModules $this->export_permission[$r]=array(array("adherent","export")); $this->export_fields_array[$r]=array('a.rowid'=>'Id','a.civilite'=>"UserTitle",'a.nom'=>"Lastname",'a.prenom'=>"Firstname",'a.login'=>"Login",'a.morphy'=>'MorPhy','a.societe'=>'Company','a.adresse'=>"Address",'a.cp'=>"Zip",'a.ville'=>"Town",'a.pays'=>"Country",'a.phone'=>"PhonePro",'a.phone_perso'=>"PhonePerso",'a.phone_mobile'=>"PhoneMobile",'a.email'=>"Email",'a.naiss'=>"Birthday",'a.statut'=>"Status",'a.photo'=>"Photo",'a.note'=>"Note",'a.datec'=>'DateCreation','a.datevalid'=>'DateValidation','a.tms'=>'DateLastModification','a.datefin'=>'DateEndSubscription','ta.rowid'=>'MemberTypeId','ta.libelle'=>'MemberTypeLabel','c.rowid'=>'SubscriptionId','c.dateadh'=>'DateSubscription','c.cotisation'=>'Amount'); $this->export_entities_array[$r]=array('a.rowid'=>'member','a.civilite'=>"member",'a.nom'=>"member",'a.prenom'=>"member",'a.login'=>"member",'a.morphy'=>'member','a.societe'=>'member','a.adresse'=>"member",'a.cp'=>"member",'a.ville'=>"member",'a.pays'=>"member",'a.phone'=>"member",'a.phone_perso'=>"member",'a.phone_mobile'=>"member",'a.email'=>"member",'a.naiss'=>"member",'a.statut'=>"member",'a.photo'=>"member",'a.note'=>"member",'a.datec'=>'member','a.datevalid'=>'member','a.tms'=>'member','a.datefin'=>'member','ta.rowid'=>'member_type','ta.libelle'=>'member_type','c.rowid'=>'subscription','c.dateadh'=>'subscription','c.cotisation'=>'subscription'); - // TODO Use generic method + // Add extra fields $sql="SELECT name, label FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'member'"; $resql=$this->db->query($sql); while ($obj=$this->db->fetch_object($resql)) { - $fieldname='ao.'.$obj->name; + $fieldname='extra.'.$obj->name; $fieldlabel=ucfirst($obj->label); $this->export_fields_array[$r][$fieldname]=$fieldlabel; $this->export_entities_array[$r][$fieldname]='member'; } - // Fin complement + // End add axtra fields $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM ('.MAIN_DB_PREFIX.'adherent_type as ta, '.MAIN_DB_PREFIX.'adherent as a)'; - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'adherent_extrafields as ao ON a.rowid = ao.fk_object'; + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'adherent_extrafields as extra ON a.rowid = extra.fk_object'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'cotisation as c ON c.fk_adherent = a.rowid'; $this->export_sql_end[$r] .=' WHERE a.fk_adherent_type = ta.rowid'; diff --git a/htdocs/includes/modules/modSociete.class.php b/htdocs/includes/modules/modSociete.class.php index 76937af74ae..3cca6b58316 100644 --- a/htdocs/includes/modules/modSociete.class.php +++ b/htdocs/includes/modules/modSociete.class.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2010 Laurent Destailleur + * Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2004 Sebastien Di Cintio * Copyright (C) 2004 Benoit Mortier * Copyright (C) 2005-2010 Regis Houssin @@ -204,9 +204,20 @@ class modSociete extends DolibarrModules $this->export_permission[$r]=array(array("societe","export")); $this->export_fields_array[$r]=array('s.rowid'=>"Id",'s.nom'=>"Name",'s.status'=>"Status",'s.client'=>"Customer",'s.fournisseur'=>"Supplier",'s.datec'=>"DateCreation",'s.tms'=>"DateLastModification",'s.code_client'=>"CustomerCode",'s.code_fournisseur'=>"SupplierCode",'s.address'=>"Address",'s.cp'=>"Zip",'s.ville'=>"Town",'p.libelle'=>"Country",'p.code'=>"CountryCode",'s.tel'=>"Phone",'s.fax'=>"Fax",'s.url'=>"Url",'s.email'=>"Email",'s.default_lang'=>"DefaultLang",'s.siret'=>"IdProf1",'s.siren'=>"IdProf2",'s.ape'=>"IdProf3",'s.idprof4'=>"IdProf4",'s.tva_intra'=>"VATIntraShort",'s.capital'=>"Capital",'s.note'=>"Note",'t.libelle'=>"ThirdPartyType",'ce.code'=>"Effectif","cfj.libelle"=>"JuridicalStatus",'s.fk_prospectlevel'=>'ProspectLevel','s.fk_stcomm'=>'ProspectStatus','d.nom'=>'State'); $this->export_entities_array[$r]=array(); // We define here only fields that use another picto - + // Add extra fields + $sql="SELECT name, label FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'company'"; + $resql=$this->db->query($sql); + while ($obj=$this->db->fetch_object($resql)) + { + $fieldname='extra.'.$obj->name; + $fieldlabel=ucfirst($obj->label); + $this->export_fields_array[$r][$fieldname]=$fieldlabel; + $this->export_entities_array[$r][$fieldname]='company'; + } + // End add axtra fields $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s'; + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extra ON s.rowid = extra.fk_object'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as t ON s.fk_typent = t.id'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_pays as p ON s.fk_pays = p.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_effectif as ce ON s.fk_effectif = ce.id'; @@ -227,7 +238,18 @@ class modSociete extends DolibarrModules unset($this->export_fields_array[$r]['s.code_fournisseur']); unset($this->export_entities_array[$r]['s.code_fournisseur']); } - $this->export_sql_start[$r]='SELECT DISTINCT '; + // Add extra fields + $sql="SELECT name, label FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'contact'"; + $resql=$this->db->query($sql); + while ($obj=$this->db->fetch_object($resql)) + { + $fieldname='extra.'.$obj->name; + $fieldlabel=ucfirst($obj->label); + $this->export_fields_array[$r][$fieldname]=$fieldlabel; + $this->export_entities_array[$r][$fieldname]='contact'; + } + // End add axtra fields + $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'socpeople as c'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON c.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_pays as p ON c.fk_pays = p.rowid'; diff --git a/htdocs/install/mysql/migration/3.0.0-3.1.0.sql b/htdocs/install/mysql/migration/3.0.0-3.1.0.sql index a7aee5d7deb..e20749805d2 100755 --- a/htdocs/install/mysql/migration/3.0.0-3.1.0.sql +++ b/htdocs/install/mysql/migration/3.0.0-3.1.0.sql @@ -381,6 +381,12 @@ update llx_actioncomm set elementtype='contract' where elementtype='contrat'; alter table llx_propal add column tms timestamp after fk_projet; +create table llx_product_extrafields +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + tms timestamp, + fk_object integer NOT NULL +) ENGINE=innodb; create table llx_societe_extrafields ( rowid integer AUTO_INCREMENT PRIMARY KEY, @@ -388,13 +394,8 @@ create table llx_societe_extrafields fk_object integer NOT NULL ) ENGINE=innodb; -create table llx_product_extrafields -( - rowid integer AUTO_INCREMENT PRIMARY KEY, - tms timestamp, - fk_object integer NOT NULL -) ENGINE=innodb; - +ALTER TABLE llx_product_extrafields ADD INDEX idx_product_extrafields (fk_object); +ALTER TABLE llx_societe_extrafields ADD INDEX idx_societe_extrafields (fk_object); alter table llx_adherent_options_label drop index uk_adherent_options_label_name; alter table llx_adherent_options_label rename to llx_extrafields; diff --git a/htdocs/install/mysql/tables/llx_adherent_extrafields.key.sql b/htdocs/install/mysql/tables/llx_adherent_extrafields.key.sql index ab416392c0f..9156b439833 100755 --- a/htdocs/install/mysql/tables/llx_adherent_extrafields.key.sql +++ b/htdocs/install/mysql/tables/llx_adherent_extrafields.key.sql @@ -2,6 +2,7 @@ -- Copyright (C) 2002-2003 Rodolphe Quiedeville -- Copyright (C) 2002-2003 Jean-Louis Bergamo -- Copyright (C) 2009 Regis Houssin +-- Copyright (C) 2011 Laurent Destailleur -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by @@ -21,4 +22,4 @@ -- =================================================================== -ALTER TABLE llx_adherent_extrafields ADD INDEX idx_adherent_extrafields (fk_member); +ALTER TABLE llx_adherent_extrafields ADD INDEX idx_adherent_extrafields (fk_object); diff --git a/htdocs/install/mysql/tables/llx_product_extrafields.key.sql b/htdocs/install/mysql/tables/llx_product_extrafields.key.sql new file mode 100755 index 00000000000..3bec7551161 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_product_extrafields.key.sql @@ -0,0 +1,22 @@ +-- =================================================================== +-- Copyright (C) 2011 Laurent Destailleur +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +-- +-- $Id$ +-- =================================================================== + + +ALTER TABLE llx_product_extrafields ADD INDEX idx_product_extrafields (fk_object); diff --git a/htdocs/install/mysql/tables/llx_societe_extrafields.key.sql b/htdocs/install/mysql/tables/llx_societe_extrafields.key.sql new file mode 100755 index 00000000000..6bf45f749f5 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_societe_extrafields.key.sql @@ -0,0 +1,22 @@ +-- =================================================================== +-- Copyright (C) 2011 Laurent Destailleur +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +-- +-- $Id$ +-- =================================================================== + + +ALTER TABLE llx_societe_extrafields ADD INDEX idx_societe_extrafields (fk_object);