Optimisation code (reduction nb requetes sql)

This commit is contained in:
Laurent Destailleur 2007-10-09 21:03:49 +00:00
parent a9187d82d6
commit 18e3fa6200
6 changed files with 74 additions and 70 deletions

View File

@ -162,18 +162,28 @@ class CActionComm {
* \param id id ou code du type d'action * \param id id ou code du type d'action
* \return string libelle du type d'action * \return string libelle du type d'action
*/ */
function get_nom($id) function getNom()
{ {
global $langs; global $langs;
if (! isset($this->type_actions[$id])) // Check if translation available
$transcode=$langs->trans("Action".$this->code);
if ($transcode != "Action".$this->code) return $transcode;
// Check if available in cach
if (isset($this->type_actions[$this->code]))
{ {
// Si valeur non disponible en cache // Si valeur disponible en cache
return $this->type_actions[$this->code];
}
// If no translation and no cache available
$sql = 'SELECT id, code, libelle'; $sql = 'SELECT id, code, libelle';
$sql.= ' FROM '.MAIN_DB_PREFIX.'c_actioncomm'; $sql.= ' FROM '.MAIN_DB_PREFIX.'c_actioncomm';
if (is_numeric($id)) $sql.= " WHERE id=".$id; if (is_numeric($id)) $sql.= " WHERE id=".$this->code;
else $sql.= " WHERE code='".$id."'"; else $sql.= " WHERE code='".$this->code."'";
dolibarr_syslog("CActionComm::getNom sql=".$sql);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result)
{ {
@ -184,34 +194,15 @@ class CActionComm {
$transcode=$langs->trans("Action".$obj->code); $transcode=$langs->trans("Action".$obj->code);
$libelle=($transcode!="Action".$obj->code?$transcode:$obj->libelle); $libelle=($transcode!="Action".$obj->code?$transcode:$obj->libelle);
$this->type_actions[$obj->id]=$libelle; // Met en cache $this->type_actions[$obj->code]=$libelle; // Put in cache
return $libelle; return $libelle;
} }
$this->db->free($result); $this->db->free($result);
} }
else { else
{
dolibarr_print_error($db); dolibarr_print_error($db);
} }
}
else {
// Si valeur disponible en cache
return $this->type_actions[$id];
}
}
/*
* \brief Renvoie le nom sous forme d'un libellé traduit d'un type d'action
* \return string Libelle du type d'action
*/
function getNom()
{
global $langs;
$transcode=$langs->trans("Action".$this->code);
$libelle=($transcode!="Action".$this->code ? $transcode : $this->get_nom($this->code));
return $libelle;
} }
} }

View File

@ -443,7 +443,8 @@ if ($_GET["action"] == 'create')
if ($_GET["actioncode"]) if ($_GET["actioncode"])
{ {
print '<input type="hidden" name="actioncode" value="'.$_GET["actioncode"].'">'."\n"; print '<input type="hidden" name="actioncode" value="'.$_GET["actioncode"].'">'."\n";
print $caction->get_nom($_GET["actioncode"]); $caction->fetch($_GET["actioncode"]);
print $caction->getNom();
} }
else else
{ {
@ -471,6 +472,14 @@ if ($_GET["action"] == 'create')
} }
print '</td></tr>'; print '</td></tr>';
// Si la societe est imposée, on propose ces contacts
if ($_REQUEST["socid"])
{
print '<tr><td nowrap>'.$langs->trans("ActionOnContact").'</td><td>';
$html->select_contacts($_REQUEST["socid"],'','contactid',1,1);
print '</td></tr>';
}
// Affecte a // Affecte a
print '<tr><td nowrap>'.$langs->trans("ActionAffectedTo").'</td><td>'; print '<tr><td nowrap>'.$langs->trans("ActionAffectedTo").'</td><td>';
print $langs->trans("FeatureNotYetSupported"); print $langs->trans("FeatureNotYetSupported");
@ -481,14 +490,6 @@ if ($_GET["action"] == 'create')
print $langs->trans("FeatureNotYetSupported"); print $langs->trans("FeatureNotYetSupported");
print '</td></tr>'; print '</td></tr>';
// Si la societe est imposée, on propose ces contacts
if ($_REQUEST["socid"])
{
print '<tr><td nowrap>'.$langs->trans("ActionOnContact").'</td><td>';
$html->select_contacts($_REQUEST["socid"],'','contactid',1,1);
print '</td></tr>';
}
// Avancement // Avancement
if ($_GET["afaire"] == 1) if ($_GET["afaire"] == 1)
{ {

View File

@ -1,7 +1,7 @@
<?php <?php
/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2003 Éric Seigne <erics@rycks.com> * Copyright (C) 2003 Éric Seigne <erics@rycks.com>
* Copyright (C) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2007 Regis Houssin <regis.houssin@cap-networks.com> * Copyright (C) 2005-2007 Regis Houssin <regis.houssin@cap-networks.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -66,10 +66,13 @@ llxHeader();
$sql = "SELECT s.nom as societe, s.rowid as socid, s.client,"; $sql = "SELECT s.nom as societe, s.rowid as socid, s.client,";
$sql.= " a.id,".$db->pdate("a.datep")." as dp, a.fk_contact, a.note, a.label, a.percent as percent,"; $sql.= " a.id,".$db->pdate("a.datep")." as dp, a.fk_contact, a.note, a.label, a.percent as percent,";
$sql.= " c.code as acode, c.libelle,"; $sql.= " c.code as acode, c.libelle,";
$sql.= " u.login, u.rowid as userid"; $sql.= " u.login, u.rowid as userid,";
$sql.= " sp.name, sp.firstname";
if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user"; if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
$sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as a, ".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."user as u"; $sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."user as u,";
if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc,";
$sql.= " ".MAIN_DB_PREFIX."actioncomm as a";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople sp ON a.fk_contact = sp.rowid";
$sql.= " WHERE a.fk_soc = s.rowid AND c.id = a.fk_action AND a.fk_user_author = u.rowid"; $sql.= " WHERE a.fk_soc = s.rowid AND c.id = a.fk_action AND a.fk_user_author = u.rowid";
if ($_GET["type"]) if ($_GET["type"])
{ {
@ -92,6 +95,7 @@ if ($status == 'todo') { $sql.= " AND a.percent < 100"; }
$sql .= " ORDER BY $sortfield $sortorder"; $sql .= " ORDER BY $sortfield $sortorder";
$sql .= $db->plimit( $limit + 1, $offset); $sql .= $db->plimit( $limit + 1, $offset);
dolibarr_syslog("comm/action/index.php sql=".$sql);
$resql=$db->query($sql); $resql=$db->query($sql);
if ($resql) if ($resql)
{ {
@ -126,6 +130,9 @@ if ($resql)
print_liste_field_titre($langs->trans("Author"),$_SERVER["PHP_SELF"],"u.login",$param,"","",$sortfield); print_liste_field_titre($langs->trans("Author"),$_SERVER["PHP_SELF"],"u.login",$param,"","",$sortfield);
print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"a.percent",$param,"",'align="right"',$sortfield); print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"a.percent",$param,"",'align="right"',$sortfield);
print "</tr>\n"; print "</tr>\n";
$contactstatic = new Contact($db);
$var=true; $var=true;
while ($i < min($num,$limit)) while ($i < min($num,$limit))
{ {
@ -192,9 +199,10 @@ if ($resql)
print '<td>'; print '<td>';
if ($obj->fk_contact > 0) if ($obj->fk_contact > 0)
{ {
$cont = new Contact($db); $contactstatic->name=$obj->name;
$cont->fetch($obj->fk_contact); $contactstatic->firstname=$obj->firstname;
print $cont->getNomUrl(1); $contactstatic->id=$obj->fk_contact;
print $contactstatic->getNomUrl(1);
} }
else else
{ {

View File

@ -1,7 +1,7 @@
<?php <?php
/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2003 Éric Seigne <erics@rycks.com> * Copyright (C) 2003 Éric Seigne <erics@rycks.com>
* 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
@ -18,7 +18,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$
*/ */
/** /**
@ -29,6 +28,7 @@
*/ */
require("./pre.inc.php"); require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/contact.class.php");
$langs->load("companies"); $langs->load("companies");
$langs->load("suppliers"); $langs->load("suppliers");
@ -167,10 +167,13 @@ else
$sql .= " ORDER BY $sortfield $sortorder " . $db->plimit( $limit + 1, $offset); $sql .= " ORDER BY $sortfield $sortorder " . $db->plimit( $limit + 1, $offset);
} }
dolibarr_syslog("contact/index.php sql=".$sql);
$result = $db->query($sql); $result = $db->query($sql);
if ($result) if ($result)
{ {
$contactstatic=new Contact($db);
$begin=$_GET["begin"]; $begin=$_GET["begin"];
$num = $db->num_rows($result); $num = $db->num_rows($result);
@ -257,9 +260,10 @@ if ($result)
// Name // Name
print '<td valign="center">'; print '<td valign="center">';
print '<a href="'.DOL_URL_ROOT.'/contact/fiche.php?id='.$obj->cidp.'">'; $contactstatic->name=$obj->name;
print img_object($langs->trans("ShowContact"),"contact"); $contactstatic->firstname='';
print ' '.$obj->name.'</a>'; $contactstatic->id=$obj->cidp;
print $contactstatic->getNomUrl(1);
print '</td>'; print '</td>';
// Firstname // Firstname

View File

@ -16,7 +16,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$
*/ */
/** /**

View File

@ -2034,6 +2034,7 @@ function dol_delete_dir($dir)
/** /**
\brief Effacement d'un répertoire $dir et de son arborescence \brief Effacement d'un répertoire $dir et de son arborescence
\param file Répertoire a effacer \param file Répertoire a effacer
\param count Compteur pour comptage nb elements supprimés
\return int Nombre de fichier+repértoires supprimés \return int Nombre de fichier+repértoires supprimés
*/ */
function dol_delete_dir_recursive($dir,$count=0) function dol_delete_dir_recursive($dir,$count=0)