Uniformize code and increase speed for extrafields

This commit is contained in:
Laurent Destailleur 2011-06-22 11:05:06 +00:00
parent 041b7d2955
commit b457221277
6 changed files with 83 additions and 15 deletions

View File

@ -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';

View File

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
@ -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';

View File

@ -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;

View File

@ -2,6 +2,7 @@
-- Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
-- Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
-- Copyright (C) 2009 Regis Houssin <regis@dolibarr.fr>
-- Copyright (C) 2011 Laurent Destailleur <eldy@users.sourceforge.net>
--
-- 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);

View File

@ -0,0 +1,22 @@
-- ===================================================================
-- Copyright (C) 2011 Laurent Destailleur <eldy@users.sourceforge.net>
--
-- 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);

View File

@ -0,0 +1,22 @@
-- ===================================================================
-- Copyright (C) 2011 Laurent Destailleur <eldy@users.sourceforge.net>
--
-- 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);