Qual: Factorize duplicate code

This commit is contained in:
Laurent Destailleur 2008-02-24 17:01:48 +00:00
parent fe62f493e0
commit 6edf6c8100
14 changed files with 110 additions and 324 deletions

View File

@ -433,35 +433,6 @@ class Adherent extends CommonObject
}
/**
\brief Fonction qui met e jour le commentaire d'un adherent
\param note Note
\param user Utilisateur qui realise la mise a jour
\return int <0 si KO, >0 si OK
*/
function update_note($note,$user)
{
$this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
$sql.= " note='".addslashes($note)."'";
$sql.= " WHERE rowid = ".$this->id;
dolibarr_syslog("Adherent::update_note sql=$sql");
$result = $this->db->query($sql);
if (! $result)
{
$this->error=$this->db->error();
$this->db->rollback();
return -1;
}
$this->commentaire = $note;
$this->db->commit();
return 1;
}
/**
\brief Fonction qui met a jour l'adherent (sauf mot de passe)
\param user Utilisateur qui realise la mise a jour

View File

@ -52,7 +52,7 @@ if ($_POST["action"] == 'update_public' && $user->rights->propale->creer)
$db->begin();
$res=$propal->update_note_public($_POST["note_public"]);
$res=$propal->update_note_public($_POST["note_public"],$user);
if ($res < 0)
{
$mesg='<div class="error">'.$propal->error.'</div>';
@ -71,7 +71,7 @@ if ($_POST['action'] == 'update' && $user->rights->propale->creer)
$db->begin();
$res=$propal->update_note($_POST["note"]);
$res=$propal->update_note($_POST["note"],$user);
if ($res < 0)
{
$mesg='<div class="error">'.$propal->error.'</div>';

View File

@ -1391,51 +1391,6 @@ class Commande extends CommonObject
}
}
/**
* \brief Mets à jour les commentaires privés
* \param note Commentaire
* \return int <0 si ko, >0 si ok
*/
function update_note($note)
{
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande';
$sql.= " SET note = '".addslashes($note)."'";
$sql.= " WHERE rowid =". $this->id;
if ($this->db->query($sql))
{
$this->note = $note;
return 1;
}
else
{
$this->error=$this->db->error();
return -1;
}
}
/**
* \brief Mets à jour les commentaires publiques
* \param note_public Commentaire
* \return int <0 si ko, >0 si ok
*/
function update_note_public($note_public)
{
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande';
$sql.= " SET note_public = '".addslashes($note_public)."'";
$sql.= " WHERE rowid =". $this->id;
if ($this->db->query($sql))
{
$this->note_public = $note_public;
return 1;
}
else
{
$this->error=$this->db->error();
return -1;
}
}
/**
* \brief Définit une date de livraison

View File

@ -58,7 +58,7 @@ if ($_POST["action"] == 'update_public' && $user->rights->commande->creer)
{
$db->begin();
$res=$commande->update_note_public($_POST["note_public"]);
$res=$commande->update_note_public($_POST["note_public"],$user);
if ($res < 0)
{
$mesg='<div class="error">'.$commande->error.'</div>';
@ -74,7 +74,7 @@ if ($_POST["action"] == 'update' && $user->rights->commande->creer)
{
$db->begin();
$res=$commande->update_note($_POST["note"]);
$res=$commande->update_note($_POST["note"],$user);
if ($res < 0)
{
$mesg='<div class="error">'.$commande->error.'</div>';

View File

@ -326,17 +326,17 @@ class CommonObject
return $result;
}
/**
/**
* \brief Charge le contact d'id $id dans this->contact
* \param contactid Id du contact
* \return int <0 if KO, >0 if OK
*/
function fetch_contact($contactid)
{
function fetch_contact($contactid)
{
require_once(DOL_DOCUMENT_ROOT."/contact.class.php");
$contact = new Contact($this->db);
$result=$contact->fetch($contactid);
$this->contact = $contact;
$contact = new Contact($this->db);
$result=$contact->fetch($contactid);
$this->contact = $contact;
return $result;
}
@ -364,19 +364,19 @@ class CommonObject
return $result;
}
/**
/**
* \brief Charge le user d'id userid dans this->user
* \param userid Id du contact
* \return int <0 if KO, >0 if OK
*/
function fetch_user($userid)
{
$user = new User($this->db, $userid);
function fetch_user($userid)
{
$user = new User($this->db, $userid);
$result=$user->fetch();
$this->user = $user;
$this->user = $user;
return $result;
}
/**
* \brief Charge l'adresse de livraison d'id $this->adresse_livraison_id dans this->deliveryaddress
* \param userid Id du contact
@ -389,7 +389,7 @@ class CommonObject
$this->deliveryaddress = $address;
return $result;
}
/**
* \brief Retourne la liste déroulante des sociétés
* \param object Fetch du document
@ -400,7 +400,7 @@ class CommonObject
function selectCompaniesForNewContact($object, $var_id, $selected = '', $htmlname = 'newcompany')
{
global $conf, $langs;
// On recherche les societes
$sql = "SELECT s.rowid, s.nom FROM";
$sql .= " ".MAIN_DB_PREFIX."societe as s";
@ -476,9 +476,9 @@ class CommonObject
}
}
/**
*
*
*/
function selectTypeContact($object, $defValue, $htmlname = 'type', $source)
{
@ -521,7 +521,7 @@ class CommonObject
$row = $this->db->fetch_row($result);
$this->ref_previous = $row[0];
$sql = "SELECT MIN(".$fieldid.")";
$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element;
$sql.= " WHERE ".$fieldid." > '".addslashes($this->ref)."'";
@ -537,11 +537,11 @@ class CommonObject
}
$row = $this->db->fetch_row($result);
$this->ref_next = $row[0];
return 1;
}
/**
* \brief On récupère les id de liste_contact
* \param source Source du contact external (llx_socpeople) ou internal (llx_user)
@ -561,7 +561,7 @@ class CommonObject
return $contactAlreadySelected;
}
/**
* \brief Link ekement with a project
* \param projid Project id to link element to
@ -579,7 +579,7 @@ class CommonObject
if ($projid) $sql.= ' SET fk_projet = '.$projid;
else $sql.= ' SET fk_projet = NULL';
$sql.= ' WHERE rowid = '.$this->id;
dolibarr_syslog("CommonObject::set_project sql=".$sql);
if ($this->db->query($sql))
{
@ -592,7 +592,7 @@ class CommonObject
}
}
/**
* \brief Set last model used by doc generator
* \param user User object that make change
@ -626,8 +626,8 @@ class CommonObject
return 0;
}
}
/**
* \brief Stocke un numéro de rang pour toutes les lignes de
* detail d'une facture qui n'en ont pas.
@ -761,7 +761,68 @@ class CommonObject
dolibarr_print_error($this->db);
}
}
}
}
/**
* \brief Update private note of element
* \param note New value for note
* \return int <0 if KO, >0 if OK
*/
function update_note($note)
{
if (! $this->table_element)
{
dolibarr_syslog("CommonObject::update_note was called on objet with property table_element not defined",LOG_ERR);
return -1;
}
$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
$sql.= " SET note = '".addslashes($note)."'";
$sql.= " WHERE rowid =". $this->id;
dolibarr_syslog("CommonObject::update_note sql=".$sql);
if ($this->db->query($sql))
{
$this->note = $note;
return 1;
}
else
{
$this->error=$this->db->error();
return -1;
}
}
/**
* \brief Update public note of element
* \param note_public New value for note
* \return int <0 if KO, >0 if OK
*/
function update_note_public($note_public)
{
if (! $this->table_element)
{
dolibarr_syslog("CommonObject::update_note_public was called on objet with property table_element not defined",LOG_ERR);
return -1;
}
$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
$sql.= " SET note_public = '".addslashes($note_public)."'";
$sql.= " WHERE rowid =". $this->id;
dolibarr_syslog("CommonObject::update_note_public sql=".$sql);
if ($this->db->query($sql))
{
$this->note_public = $note_public;
return 1;
}
else
{
$this->error=$this->db->error();
return -1;
}
}
}
?>

View File

@ -57,7 +57,7 @@ if ($_POST["action"] == 'update_public' && $user->rights->facture->creer)
{
$db->begin();
$res=$fac->update_note_public($_POST["note_public"]);
$res=$fac->update_note_public($_POST["note_public"],$user);
if ($res < 0)
{
$mesg='<div class="error">'.$fac->error.'</div>';
@ -73,7 +73,7 @@ if ($_POST["action"] == 'update' && $user->rights->facture->creer)
{
$db->begin();
$res=$fac->update_note($_POST["note"]);
$res=$fac->update_note($_POST["note"],$user);
if ($res < 0)
{
$mesg='<div class="error">'.$fac->error.'</div>';

View File

@ -909,53 +909,6 @@ class Contrat extends CommonObject
}
/**
* \brief Mets à jour les commentaires privés
* \param note Commentaire
* \return int <0 si ko, >0 si ok
*/
function update_note($note)
{
$sql = 'UPDATE '.MAIN_DB_PREFIX.'contrat';
$sql.= " SET note = '".addslashes($note)."'";
$sql.= " WHERE rowid =". $this->id;
if ($this->db->query($sql))
{
$this->note = $note;
return 1;
}
else
{
$this->error=$this->db->error();
return -1;
}
}
/**
* \brief Mets à jour les commentaires publiques
* \param note_public Commentaire
* \return int <0 si ko, >0 si ok
*/
function update_note_public($note_public)
{
$sql = 'UPDATE '.MAIN_DB_PREFIX.'contrat';
$sql.= " SET note_public = '".addslashes($note_public)."'";
$sql.= " WHERE rowid =". $this->id;
if ($this->db->query($sql))
{
$this->note_public = $note_public;
return 1;
}
else
{
$this->error=$this->db->error();
return -1;
}
}
/**
* \brief Retourne le libellé du statut du contrat
* \param mode 0=libellé long, 1=libellé court, 2=Picto + Libellé court, 3=Picto, 4=Picto + Libellé long, 5=Libellé court + Picto

View File

@ -77,7 +77,7 @@ if ($_POST["action"] == 'update_public' && $user->rights->contrat->creer)
{
$db->begin();
$res=$contrat->update_note_public($_POST["note_public"]);
$res=$contrat->update_note_public($_POST["note_public"],$user);
if ($res < 0)
{
$mesg='<div class="error">'.$contrat->error.'</div>';
@ -93,7 +93,7 @@ if ($_POST["action"] == 'update' && $user->rights->contrat->creer)
{
$db->begin();
$res=$contrat->update_note($_POST["note"]);
$res=$contrat->update_note($_POST["note"],$user);
if ($res < 0)
{
$mesg='<div class="error">'.$contrat->error.'</div>';

View File

@ -108,8 +108,6 @@ class Facture extends CommonObject
function Facture($DB, $socid='', $facid='')
{
$this->db = $DB;
$this->table = 'facture';
$this->tabledetail = 'facturedet';
$this->id = $facid;
$this->socid = $socid;
@ -2021,54 +2019,6 @@ class Facture extends CommonObject
}
}
/**
* \brief Mets à jour les commentaires privés
* \param note Commentaire
* \return int <0 si ko, >0 si ok
*/
function update_note($note)
{
$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table;
$sql.= " SET note = '".addslashes($note)."'";
$sql.= " WHERE rowid =". $this->id;
dolibarr_syslog("Facture.class::update_note sql=$sql");
if ($this->db->query($sql))
{
$this->note = $note;
return 1;
}
else
{
$this->error=$this->db->error();
return -1;
}
}
/**
* \brief Mets à jour les commentaires publiques
* \param note_public Commentaire
* \return int <0 si ko, >0 si ok
*/
function update_note_public($note_public)
{
$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table;
$sql.= " SET note_public = '".addslashes($note_public)."'";
$sql.= " WHERE rowid =". $this->id;
dolibarr_syslog("Facture.class::update_note_public sql=$sql");
if ($this->db->query($sql))
{
$this->note_public = $note_public;
return 1;
}
else
{
$this->error=$this->db->error();
return -1;
}
}
/**
* \brief Charge les informations de l'onglet info dans l'objet facture
* \param id Id de la facture a charger

View File

@ -353,38 +353,12 @@ class Fichinter extends CommonObject
}
}
/**
* \brief Mets a jour les commentaires publiques et prives
* \param note Commentaire
* \param type Type de note
* \return int <0 si ko, >0 si ok
*/
function update_note($note,$type)
{
$sql = 'UPDATE '.MAIN_DB_PREFIX.'fichinter';
$sql.= " SET ".$type." = '".addslashes($note)."'";
$sql.= " WHERE rowid =". $this->id;
dolibarr_syslog("Fichinter::update_note type=".$type." sql=".$sql);
if ($this->db->query($sql))
{
$this->$type = $type;
return 1;
}
else
{
$this->error=$this->db->error();
return -1;
}
}
/**
* \brief Information sur l'objet fiche intervention
* \param id id de la fiche d'intervention
*/
function info($id)
{
* \brief Information sur l'objet fiche intervention
* \param id id de la fiche d'intervention
*/
function info($id)
{
$sql = "SELECT f.rowid, ";
$sql.= $this->db->pdate("f.datec")." as datec, ".$this->db->pdate("f.date_valid")." as datev";
$sql.= ", f.fk_user_author, f.fk_user_valid";

View File

@ -46,7 +46,7 @@ if ($_POST["action"] == 'update_public' && $user->rights->ficheinter->creer)
$db->begin();
$res=$fichinter->update_note($_POST["note_public"],'note_public');
$res=$fichinter->update_note_public($_POST["note_public"],$user);
if ($res < 0)
{
$mesg='<div class="error">'.$fichinter->error.'</div>';
@ -65,7 +65,7 @@ if ($_POST['action'] == 'update' && $user->rights->ficheinter->creer)
$db->begin();
$res=$fichinter->update_note($_POST["note_private"],'note_private');
$res=$fichinter->update_note($_POST["note_private"],$user);
if ($res < 0)
{
$mesg='<div class="error">'.$fichinter->error.'</div>';

View File

@ -58,7 +58,7 @@ if ($_POST["action"] == 'update_public' && $user->rights->facture->creer)
{
$db->begin();
$res=$fac->update_note_public($_POST["note_public"]);
$res=$fac->update_note_public($_POST["note_public"],$user);
if ($res < 0)
{
$mesg='<div class="error">'.$fac->error.'</div>';
@ -74,7 +74,7 @@ if ($_POST["action"] == 'update' && $user->rights->fournisseur->facture->creer)
{
$db->begin();
$res=$fac->update_note($_POST["note"]);
$res=$fac->update_note($_POST["note"],$user);
if ($res < 0)
{
$mesg='<div class="error">'.$fac->error.'</div>';

View File

@ -1462,55 +1462,6 @@ class Propal extends CommonObject
}
}
/**
* \brief Mets <EFBFBD> jour les commentaires priv<EFBFBD>s
* \param note Commentaire
* \return int <0 si ko, >0 si ok
*/
function update_note($note)
{
$sql = 'UPDATE '.MAIN_DB_PREFIX.'propal';
$sql.= " SET note = '".addslashes($note)."'";
$sql.= " WHERE rowid =". $this->id;
dolibarr_syslog("Propal::update_note $sql");
if ($this->db->query($sql))
{
$this->note = $note;
return 1;
}
else
{
$this->error=$this->db->error();
return -1;
}
}
/**
* \brief Mets <EFBFBD> jour les commentaires publiques
* \param note_public Commentaire
* \return int <0 si ko, >0 si ok
*/
function update_note_public($note_public)
{
$sql = 'UPDATE '.MAIN_DB_PREFIX.'propal';
$sql.= " SET note_public = '".addslashes($note_public)."'";
$sql.= " WHERE rowid =". $this->id;
dolibarr_syslog("Propal::update_note_public $sql");
if ($this->db->query($sql))
{
$this->note_public = $note_public;
return 1;
}
else
{
$this->error=$this->db->error();
return -1;
}
}
/**
* \brief Change les conditions de r<EFBFBD>glement de la facture

View File

@ -1074,43 +1074,14 @@ class User extends CommonObject
return -1;
}
}
/**
\brief Fonction qui met a jour le commentaire d'un utilisateur
\param note Note
\param user Utilisateur qui realise la mise a jour
\return int <0 si KO, >0 si OK
*/
function update_note($note,$user)
{
$this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."user SET";
$sql.= " note='".addslashes($note)."'";
$sql.= " WHERE rowid = ".$this->id;
dolibarr_syslog("User::update_note sql=$sql");
$result = $this->db->query($sql);
if (! $result)
{
$this->error=$this->db->error();
$this->db->rollback();
return -1;
}
$this->note = $note;
$this->db->commit();
return 1;
}
/**
* \brief Mise e jour en base de la date de deniere connexion d'un utilisateur
* Fonction appelee lors d'une nouvelle connexion
* \return <0 si echec, >=0 si ok
*/
function update_last_login_date()
/**
* \brief Mise e jour en base de la date de deniere connexion d'un utilisateur
* Fonction appelee lors d'une nouvelle connexion
* \return <0 si echec, >=0 si ok
*/
function update_last_login_date()
{
dolibarr_syslog ("Mise a jour date derniere connexion pour user->id=".$this->id);