Optimisation code (reduction nb requetes sql)

This commit is contained in:
Laurent Destailleur 2007-10-09 21:27:49 +00:00
parent 18e3fa6200
commit 1b14ab95fb
4 changed files with 53 additions and 72 deletions

View File

@ -158,51 +158,18 @@ class CActionComm {
/* /*
* \brief Renvoie le nom sous forme d'un libellé traduit d'un type d'action * \brief Renvoie le nom sous forme d'un libellé traduit d'un type d'action
* \param id id ou code du type d'action * \param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul
* \return string libelle du type d'action * \param option Sur quoi pointe le lien
* \return string Libelle du type d'action
*/ */
function getNom() function getNomUrl($withpicto=0)
{ {
global $langs; global $langs;
// Check if translation available // Check if translation available
$transcode=$langs->trans("Action".$this->code); $transcode=$langs->trans("Action".$this->code);
if ($transcode != "Action".$this->code) return $transcode; if ($transcode != "Action".$this->code) return $transcode;
// Check if available in cach
if (isset($this->type_actions[$this->code]))
{
// Si valeur disponible en cache
return $this->type_actions[$this->code];
}
// If no translation and no cache available
$sql = 'SELECT id, code, libelle';
$sql.= ' FROM '.MAIN_DB_PREFIX.'c_actioncomm';
if (is_numeric($id)) $sql.= " WHERE id=".$this->code;
else $sql.= " WHERE code='".$this->code."'";
dolibarr_syslog("CActionComm::getNom sql=".$sql);
$result = $this->db->query($sql);
if ($result)
{
if ($this->db->num_rows($result))
{
$obj = $this->db->fetch_object($result);
$transcode=$langs->trans("Action".$obj->code);
$libelle=($transcode!="Action".$obj->code?$transcode:$obj->libelle);
$this->type_actions[$obj->code]=$libelle; // Put in cache
return $libelle;
}
$this->db->free($result);
}
else
{
dolibarr_print_error($db);
}
} }
} }

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com> * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr> * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2005-2007 Regis Houssin <regis.houssin@cap-networks.com> * Copyright (C) 2005-2007 Regis Houssin <regis.houssin@cap-networks.com>
@ -273,7 +273,7 @@ if ($socid > 0)
print '</tr>'; print '</tr>';
// multiprix // multiprix
if($conf->global->PRODUIT_MULTIPRICES == 1) if ($conf->global->PRODUIT_MULTIPRICES)
{ {
print '<tr><td nowrap>'; print '<tr><td nowrap>';
print '<table width="100%" class="nobordernopadding"><tr><td nowrap>'; print '<table width="100%" class="nobordernopadding"><tr><td nowrap>';
@ -653,18 +653,16 @@ if ($socid > 0)
{ {
$obj = $db->fetch_object($result); $obj = $db->fetch_object($result);
$var = !$var; $var = !$var;
print "<tr $bc[$var]>"; print "<tr $bc[$var]>";
print '<td>';
$contactstatic->id = $obj->rowid; $contactstatic->id = $obj->rowid;
$contactstatic->name = $obj->name; $contactstatic->name = $obj->name;
$contactstatic->firstname = $obj->firstname; $contactstatic->firstname = $obj->firstname;
print '<td>';
print $contactstatic->getNomUrl(1); print $contactstatic->getNomUrl(1);
if (trim($obj->note))
{
print '<br>'.nl2br(trim($obj->note));
}
print '</td>'; print '</td>';
print '<td>'.$obj->poste.'&nbsp;</td>'; print '<td>'.$obj->poste.'&nbsp;</td>';
// Lien click to dial // Lien click to dial
@ -716,13 +714,17 @@ if ($socid > 0)
$sql.= " ".$db->pdate("a.datep")." as dp,"; $sql.= " ".$db->pdate("a.datep")." as dp,";
$sql.= " ".$db->pdate("a.datea")." as da,"; $sql.= " ".$db->pdate("a.datea")." as da,";
$sql.= " a.percent,"; $sql.= " a.percent,";
$sql.= " c.code as acode, c.libelle, a.propalrowid, a.fk_user_author, fk_contact, u.login, u.rowid "; $sql.= " c.code as acode, c.libelle, a.propalrowid, a.fk_user_author, a.fk_contact,";
$sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as a, ".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."user as u "; $sql.= " u.login, u.rowid,";
$sql.= " sp.name, sp.firstname";
$sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."actioncomm as a";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON a.fk_contact = sp.rowid";
$sql.= " WHERE a.fk_soc = ".$objsoc->id; $sql.= " WHERE a.fk_soc = ".$objsoc->id;
$sql.= " AND u.rowid = a.fk_user_author"; $sql.= " AND u.rowid = a.fk_user_author";
$sql.= " AND c.id=a.fk_action AND a.percent < 100"; $sql.= " AND c.id=a.fk_action AND a.percent < 100";
$sql.= " ORDER BY a.datep DESC, a.id DESC"; $sql.= " ORDER BY a.datep DESC, a.id DESC";
dolibarr_syslog("comm/fiche.php sql=".$sql);
$result=$db->query($sql); $result=$db->query($sql);
if ($result) if ($result)
{ {
@ -774,9 +776,9 @@ if ($socid > 0)
if ($obj->propalrowid) if ($obj->propalrowid)
{ {
print '<td><a href="propal.php?propalid='.$obj->propalrowid.'">'.img_object($langs->trans("ShowAction"),"task"); print '<td><a href="propal.php?propalid='.$obj->propalrowid.'">'.img_object($langs->trans("ShowAction"),"task");
$transcode=$langs->trans("Action".$obj->acode); $transcode=$langs->trans("Action".$obj->acode);
$libelle=($transcode!="Action".$obj->acode?$transcode:$obj->libelle); $libelle=($transcode!="Action".$obj->acode?$transcode:$obj->libelle);
print $libelle; print $libelle;
print '</a></td>'; print '</a></td>';
} }
else else
@ -791,9 +793,10 @@ if ($socid > 0)
// Contact pour cette action // Contact pour cette action
if ($obj->fk_contact > 0) if ($obj->fk_contact > 0)
{ {
$contact = new Contact($db); $contactstatic->name=$obj->name;
$contact->fetch($obj->fk_contact); $contactstatic->firstname=$obj->firstname;
print '<td>'.$contact->getNomUrl(1).'</td>'; $contactstatic->id=$obj->fk_contact;
print '<td>'.$contactstatic->getNomUrl(1).'</td>';
} }
else else
{ {
@ -843,13 +846,16 @@ if ($socid > 0)
$sql.= " a.percent,"; $sql.= " a.percent,";
$sql.= " a.propalrowid, a.fk_facture, a.fk_user_author, a.fk_contact,"; $sql.= " a.propalrowid, a.fk_facture, a.fk_user_author, a.fk_contact,";
$sql.= " c.code as acode, c.libelle,"; $sql.= " c.code as acode, c.libelle,";
$sql.= " u.login, u.rowid"; $sql.= " u.login, u.rowid,";
$sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as a, ".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."user as u "; $sql.= " sp.name, sp.firstname";
$sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."actioncomm as a";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON a.fk_contact = sp.rowid";
$sql.= " WHERE a.fk_soc = ".$objsoc->id; $sql.= " WHERE a.fk_soc = ".$objsoc->id;
$sql.= " AND u.rowid = a.fk_user_author"; $sql.= " AND u.rowid = a.fk_user_author";
$sql.= " AND c.id=a.fk_action AND a.percent = 100"; $sql.= " AND c.id=a.fk_action AND a.percent = 100";
$sql.= " ORDER BY a.datea DESC, a.id DESC"; $sql.= " ORDER BY a.datea DESC, a.id DESC";
dolibarr_syslog("comm/fiche.php sql=".$sql);
$result=$db->query($sql); $result=$db->query($sql);
if ($result) if ($result)
{ {
@ -927,9 +933,10 @@ if ($socid > 0)
// Contact pour cette action // Contact pour cette action
if ($obj->fk_contact > 0) if ($obj->fk_contact > 0)
{ {
$contact = new Contact($db); $contactstatic->name=$obj->name;
$contact->fetch($obj->fk_contact); $contactstatic->firstname=$obj->firstname;
print '<td>'.$contact->getNomUrl(1).'</td>'; $contactstatic->id=$obj->fk_contact;
print '<td>'.$contactstatic->getNomUrl(1).'</td>';
} }
else else
{ {

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -17,7 +17,6 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* *
* $Id$ * $Id$
* $Source$
*/ */
/** /**
@ -456,13 +455,17 @@ if ($socid > 0)
print '</tr>'; print '</tr>';
$sql = "SELECT a.id, a.label, ".$db->pdate("a.datea")." as da, a.percent,"; $sql = "SELECT a.id, a.label, ".$db->pdate("a.datea")." as da, a.percent,";
$sql.= " c.code as acode, c.libelle, u.login, a.propalrowid, a.fk_user_author, fk_contact, u.rowid "; $sql.= " c.code as acode, c.libelle, u.login, a.propalrowid, a.fk_user_author, a.fk_contact,";
$sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as a, ".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."user as u "; $sql.= " u.login, u.rowid,";
$sql.= " sp.name, sp.firstname";
$sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."actioncomm as a";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON a.fk_contact = sp.rowid";
$sql.= " WHERE a.fk_soc = ".$societe->id; $sql.= " WHERE a.fk_soc = ".$societe->id;
$sql.= " AND u.rowid = a.fk_user_author"; $sql.= " AND u.rowid = a.fk_user_author";
$sql.= " AND c.id=a.fk_action AND a.percent < 100"; $sql.= " AND c.id=a.fk_action AND a.percent < 100";
$sql.= " ORDER BY a.datea DESC, a.id DESC"; $sql.= " ORDER BY a.datea DESC, a.id DESC";
dolibarr_syslog("compta/fiche.php sql=".$sql);
$result=$db->query($sql); $result=$db->query($sql);
if ($result) if ($result)
{ {
@ -530,9 +533,10 @@ if ($socid > 0)
// Contact pour cette action // Contact pour cette action
if ($obj->fk_contact > 0) if ($obj->fk_contact > 0)
{ {
$contact = new Contact($db); $contactstatic->name=$obj->name;
$contact->fetch($obj->fk_contact); $contactstatic->firstname=$obj->firstname;
print '<td>'.$contact->getNomUrl(1).'</td>'; $contactstatic->id=$obj->fk_contact;
print '<td>'.$contactstatic->getNomUrl(1).'</td>';
} }
else else
{ {
@ -568,13 +572,16 @@ if ($socid > 0)
$sql = "SELECT a.id, a.label, ".$db->pdate("a.datea")." as da, a.percent,"; $sql = "SELECT a.id, a.label, ".$db->pdate("a.datea")." as da, a.percent,";
$sql.= " a.propalrowid, a.fk_facture, a.fk_user_author, a.fk_contact,"; $sql.= " a.propalrowid, a.fk_facture, a.fk_user_author, a.fk_contact,";
$sql.= " c.code as acode, c.libelle,"; $sql.= " c.code as acode, c.libelle,";
$sql.= " u.login, u.rowid"; $sql.= " u.login, u.rowid,";
$sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as a, ".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."user as u "; $sql.= " sp.name, sp.firstname";
$sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."actioncomm as a";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON a.fk_contact = sp.rowid";
$sql.= " WHERE a.fk_soc = ".$societe->id; $sql.= " WHERE a.fk_soc = ".$societe->id;
$sql.= " AND u.rowid = a.fk_user_author"; $sql.= " AND u.rowid = a.fk_user_author";
$sql.= " AND c.id=a.fk_action AND a.percent = 100"; $sql.= " AND c.id=a.fk_action AND a.percent = 100";
$sql.= " ORDER BY a.datea DESC, a.id DESC"; $sql.= " ORDER BY a.datea DESC, a.id DESC";
dolibarr_syslog("compta/fiche.php sql=".$sql);
$result=$db->query($sql); $result=$db->query($sql);
if ($result) if ($result)
{ {
@ -644,9 +651,10 @@ if ($socid > 0)
// Contact pour cette action // Contact pour cette action
if ($obj->fk_contact > 0) if ($obj->fk_contact > 0)
{ {
$contact = new Contact($db); $contactstatic->name=$obj->name;
$contact->fetch($obj->fk_contact); $contactstatic->firstname=$obj->firstname;
print '<td>'.$contact->getNomUrl(1).'</td>'; $contactstatic->id=$obj->fk_contact;
print '<td>'.$contactstatic->getNomUrl(1).'</td>';
} }
else else
{ {
@ -679,5 +687,4 @@ $db->close();
llxFooter('$Date$ - $Revision$'); llxFooter('$Date$ - $Revision$');
?> ?>

View File

@ -2153,7 +2153,7 @@ class Propal extends CommonObject
} }
/** /**
\brief Renvoie nom clicable (avec eventuellement le picto) \brief Renvoie nom clicable (avec eventuellement le picto)
\param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul \param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul
\param option Sur quoi pointe le lien \param option Sur quoi pointe le lien
\param get_param Parametres ajouté à l'url \param get_param Parametres ajouté à l'url