Perf: Little optimization

This commit is contained in:
Laurent Destailleur 2011-11-02 22:41:34 +01:00
parent ee92964ef7
commit 253a21eb33

View File

@ -1,4 +1,5 @@
<?php <?php
/* Copyright (C) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005-2008 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2005-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
@ -30,9 +31,9 @@ require_once(DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php");
*/ */
class Project extends CommonObject class Project extends CommonObject
{ {
public $element = 'project'; //!< Id that identify managed objects public $element = 'project'; //!< Id that identify managed objects
public $table_element = 'projet'; //!< Name of table without prefix where object is stored public $table_element = 'projet'; //!< Name of table without prefix where object is stored
var $id; var $id;
var $ref; var $ref;
var $description; var $description;
@ -47,7 +48,6 @@ class Project extends CommonObject
var $public; //!< Tell if this is a public or private project var $public; //!< Tell if this is a public or private project
var $note_private; var $note_private;
var $note_public; var $note_public;
var $statuts_short; var $statuts_short;
var $statuts; var $statuts;
@ -126,7 +126,11 @@ class Project extends CommonObject
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
$interface = new Interfaces($this->db); $interface = new Interfaces($this->db);
$result = $interface->run_triggers('PROJECT_CREATE', $this, $user, $langs, $conf); $result = $interface->run_triggers('PROJECT_CREATE', $this, $user, $langs, $conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; } if ($result < 0)
{
$error++;
$this->errors = $interface->errors;
}
// End call triggers // End call triggers
} }
} }
@ -156,7 +160,6 @@ class Project extends CommonObject
} }
} }
/** /**
* Update a project * Update a project
* *
@ -195,7 +198,11 @@ class Project extends CommonObject
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
$interface = new Interfaces($this->db); $interface = new Interfaces($this->db);
$result = $interface->run_triggers('PROJECT_MODIFY', $this, $user, $langs, $conf); $result = $interface->run_triggers('PROJECT_MODIFY', $this, $user, $langs, $conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; } if ($result < 0)
{
$error++;
$this->errors = $interface->errors;
}
// End call triggers // End call triggers
} }
@ -217,7 +224,6 @@ class Project extends CommonObject
return $result; return $result;
} }
/** /**
* Get object and lines from database * Get object and lines from database
* *
@ -318,7 +324,6 @@ class Project extends CommonObject
{ {
print $this->db->lasterror(); print $this->db->lasterror();
} }
} }
/** /**
@ -332,16 +337,26 @@ class Project extends CommonObject
$elements = array(); $elements = array();
$sql = ''; $sql = '';
if ($type == 'propal') $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."propal WHERE fk_projet=".$this->id; if ($type == 'propal')
if ($type == 'order') $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande WHERE fk_projet=".$this->id; $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "propal WHERE fk_projet=" . $this->id;
if ($type == 'invoice') $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture WHERE fk_projet=".$this->id; if ($type == 'order')
if ($type == 'invoice_predefined') $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture_rec WHERE fk_projet=".$this->id; $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "commande WHERE fk_projet=" . $this->id;
if ($type == 'order_supplier') $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande_fournisseur WHERE fk_projet=".$this->id; if ($type == 'invoice')
if ($type == 'invoice_supplier') $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture_fourn WHERE fk_projet=".$this->id; $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "facture WHERE fk_projet=" . $this->id;
if ($type == 'contract') $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."contrat WHERE fk_projet=".$this->id; if ($type == 'invoice_predefined')
if ($type == 'intervention') $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."fichinter WHERE fk_projet=".$this->id; $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "facture_rec WHERE fk_projet=" . $this->id;
if ($type == 'trip') $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."deplacement WHERE fk_projet=".$this->id; if ($type == 'order_supplier')
if ($type == 'agenda') $sql = "SELECT id as rowid FROM ".MAIN_DB_PREFIX."actioncomm WHERE fk_project=".$this->id; $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "commande_fournisseur WHERE fk_projet=" . $this->id;
if ($type == 'invoice_supplier')
$sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "facture_fourn WHERE fk_projet=" . $this->id;
if ($type == 'contract')
$sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "contrat WHERE fk_projet=" . $this->id;
if ($type == 'intervention')
$sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "fichinter WHERE fk_projet=" . $this->id;
if ($type == 'trip')
$sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "deplacement WHERE fk_projet=" . $this->id;
if ($type == 'agenda')
$sql = "SELECT id as rowid FROM " . MAIN_DB_PREFIX . "actioncomm WHERE fk_project=" . $this->id;
if (! $sql) return -1; if (! $sql) return -1;
//print $sql; //print $sql;
@ -450,7 +465,11 @@ class Project extends CommonObject
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
$interface = new Interfaces($this->db); $interface = new Interfaces($this->db);
$result = $interface->run_triggers('PROJECT_DELETE', $this, $user, $langs, $conf); $result = $interface->run_triggers('PROJECT_DELETE', $this, $user, $langs, $conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; } if ($result < 0)
{
$error++;
$this->errors = $interface->errors;
}
// End call triggers // End call triggers
} }
@ -494,7 +513,11 @@ class Project extends CommonObject
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
$interface = new Interfaces($this->db); $interface = new Interfaces($this->db);
$result = $interface->run_triggers('PROJECT_VALIDATE', $this, $user, $langs, $conf); $result = $interface->run_triggers('PROJECT_VALIDATE', $this, $user, $langs, $conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; } if ($result < 0)
{
$error++;
$this->errors = $interface->errors;
}
// Fin appel triggers // Fin appel triggers
if (!$error) if (!$error)
@ -548,7 +571,11 @@ class Project extends CommonObject
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
$interface = new Interfaces($this->db); $interface = new Interfaces($this->db);
$result = $interface->run_triggers('PROJECT_CLOSE', $this, $user, $langs, $conf); $result = $interface->run_triggers('PROJECT_CLOSE', $this, $user, $langs, $conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; } if ($result < 0)
{
$error++;
$this->errors = $interface->errors;
}
// Fin appel triggers // Fin appel triggers
if (!$error) if (!$error)
@ -606,27 +633,39 @@ class Project extends CommonObject
} }
if ($mode == 2) if ($mode == 2)
{ {
if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]),'statut0').' '.$langs->trans($this->statuts_short[$statut]); if ($statut == 0)
if ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4').' '.$langs->trans($this->statuts_short[$statut]); return img_picto($langs->trans($this->statuts_short[$statut]), 'statut0') . ' ' . $langs->trans($this->statuts_short[$statut]);
if ($statut==2) return img_picto($langs->trans($this->statuts_short[$statut]),'statut6').' '.$langs->trans($this->statuts_short[$statut]); if ($statut == 1)
return img_picto($langs->trans($this->statuts_short[$statut]), 'statut4') . ' ' . $langs->trans($this->statuts_short[$statut]);
if ($statut == 2)
return img_picto($langs->trans($this->statuts_short[$statut]), 'statut6') . ' ' . $langs->trans($this->statuts_short[$statut]);
} }
if ($mode == 3) if ($mode == 3)
{ {
if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]),'statut0'); if ($statut == 0)
if ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4'); return img_picto($langs->trans($this->statuts_short[$statut]), 'statut0');
if ($statut==2) return img_picto($langs->trans($this->statuts_short[$statut]),'statut6'); if ($statut == 1)
return img_picto($langs->trans($this->statuts_short[$statut]), 'statut4');
if ($statut == 2)
return img_picto($langs->trans($this->statuts_short[$statut]), 'statut6');
} }
if ($mode == 4) if ($mode == 4)
{ {
if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]),'statut0').' '.$langs->trans($this->statuts_short[$statut]); if ($statut == 0)
if ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4').' '.$langs->trans($this->statuts_short[$statut]); return img_picto($langs->trans($this->statuts_short[$statut]), 'statut0') . ' ' . $langs->trans($this->statuts_short[$statut]);
if ($statut==2) return img_picto($langs->trans($this->statuts_short[$statut]),'statut6').' '.$langs->trans($this->statuts_short[$statut]); if ($statut == 1)
return img_picto($langs->trans($this->statuts_short[$statut]), 'statut4') . ' ' . $langs->trans($this->statuts_short[$statut]);
if ($statut == 2)
return img_picto($langs->trans($this->statuts_short[$statut]), 'statut6') . ' ' . $langs->trans($this->statuts_short[$statut]);
} }
if ($mode == 5) if ($mode == 5)
{ {
if ($statut==0) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut0'); if ($statut == 0)
if ($statut==1) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut1'); return $langs->trans($this->statuts_short[$statut]) . ' ' . img_picto($langs->trans($this->statuts_short[$statut]), 'statut0');
if ($statut==2) return img_picto($langs->trans($this->statuts_short[$statut]),'statut6').' '.$langs->trans($this->statuts_short[$statut]); if ($statut == 1)
return $langs->trans($this->statuts_short[$statut]) . ' ' . img_picto($langs->trans($this->statuts_short[$statut]), 'statut1');
if ($statut == 2)
return img_picto($langs->trans($this->statuts_short[$statut]), 'statut6') . ' ' . $langs->trans($this->statuts_short[$statut]);
} }
} }
@ -798,7 +837,6 @@ class Project extends CommonObject
{ {
return -1; return -1;
} }
} }
return $userAccess; return $userAccess;
@ -828,16 +866,17 @@ class Project extends CommonObject
$sql.= ", " . MAIN_DB_PREFIX . "c_type_contact as ctc"; $sql.= ", " . MAIN_DB_PREFIX . "c_type_contact as ctc";
} }
$sql.= " WHERE p.entity = " . $conf->entity; $sql.= " WHERE p.entity = " . $conf->entity;
// Internal users must see project he is contact to even if project linked to a third party he can't see. // Internal users must see project he is contact to even if project linked to a third party he can't see.
//if ($socid || ! $user->rights->societe->client->voir) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")"; //if ($socid || ! $user->rights->societe->client->voir) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
if ($socid) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")"; if ($socid)
$sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = " . $socid . ")";
if ($mode == 0) if ($mode == 0)
{ {
$sql.= " AND ( p.public = 1"; $sql.= " AND ec.element_id = p.rowid AND ( p.public = 1";
//$sql.= " OR p.fk_user_creat = ".$user->id; //$sql.= " OR p.fk_user_creat = ".$user->id;
$sql.= " OR ( ec.element_id = p.rowid"; $sql.= " OR ( ctc.rowid = ec.fk_c_type_contact";
$sql.= " AND ctc.rowid = ec.fk_c_type_contact";
$sql.= " AND ctc.element = '" . $this->element . "'"; $sql.= " AND ctc.element = '" . $this->element . "'";
$sql.= " AND ec.fk_socpeople = " . $user->id . " ) )"; $sql.= " AND ec.fk_socpeople = " . $user->id . " ) )";
} }
@ -885,4 +924,5 @@ class Project extends CommonObject
} }
} }
?> ?>