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) \brief Fonction qui met a jour l'adherent (sauf mot de passe)
\param user Utilisateur qui realise la mise a jour \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(); $db->begin();
$res=$propal->update_note_public($_POST["note_public"]); $res=$propal->update_note_public($_POST["note_public"],$user);
if ($res < 0) if ($res < 0)
{ {
$mesg='<div class="error">'.$propal->error.'</div>'; $mesg='<div class="error">'.$propal->error.'</div>';
@ -71,7 +71,7 @@ if ($_POST['action'] == 'update' && $user->rights->propale->creer)
$db->begin(); $db->begin();
$res=$propal->update_note($_POST["note"]); $res=$propal->update_note($_POST["note"],$user);
if ($res < 0) if ($res < 0)
{ {
$mesg='<div class="error">'.$propal->error.'</div>'; $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 * \brief Définit une date de livraison

View File

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

View File

@ -762,6 +762,67 @@ class CommonObject
} }
} }
} }
/**
* \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(); $db->begin();
$res=$fac->update_note_public($_POST["note_public"]); $res=$fac->update_note_public($_POST["note_public"],$user);
if ($res < 0) if ($res < 0)
{ {
$mesg='<div class="error">'.$fac->error.'</div>'; $mesg='<div class="error">'.$fac->error.'</div>';
@ -73,7 +73,7 @@ if ($_POST["action"] == 'update' && $user->rights->facture->creer)
{ {
$db->begin(); $db->begin();
$res=$fac->update_note($_POST["note"]); $res=$fac->update_note($_POST["note"],$user);
if ($res < 0) if ($res < 0)
{ {
$mesg='<div class="error">'.$fac->error.'</div>'; $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 * \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 * \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(); $db->begin();
$res=$contrat->update_note_public($_POST["note_public"]); $res=$contrat->update_note_public($_POST["note_public"],$user);
if ($res < 0) if ($res < 0)
{ {
$mesg='<div class="error">'.$contrat->error.'</div>'; $mesg='<div class="error">'.$contrat->error.'</div>';
@ -93,7 +93,7 @@ if ($_POST["action"] == 'update' && $user->rights->contrat->creer)
{ {
$db->begin(); $db->begin();
$res=$contrat->update_note($_POST["note"]); $res=$contrat->update_note($_POST["note"],$user);
if ($res < 0) if ($res < 0)
{ {
$mesg='<div class="error">'.$contrat->error.'</div>'; $mesg='<div class="error">'.$contrat->error.'</div>';

View File

@ -108,8 +108,6 @@ class Facture extends CommonObject
function Facture($DB, $socid='', $facid='') function Facture($DB, $socid='', $facid='')
{ {
$this->db = $DB; $this->db = $DB;
$this->table = 'facture';
$this->tabledetail = 'facturedet';
$this->id = $facid; $this->id = $facid;
$this->socid = $socid; $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 * \brief Charge les informations de l'onglet info dans l'objet facture
* \param id Id de la facture a charger * \param id Id de la facture a charger

View File

@ -353,32 +353,6 @@ 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 * \brief Information sur l'objet fiche intervention
* \param id id de la fiche d'intervention * \param id id de la fiche d'intervention

View File

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

View File

@ -58,7 +58,7 @@ if ($_POST["action"] == 'update_public' && $user->rights->facture->creer)
{ {
$db->begin(); $db->begin();
$res=$fac->update_note_public($_POST["note_public"]); $res=$fac->update_note_public($_POST["note_public"],$user);
if ($res < 0) if ($res < 0)
{ {
$mesg='<div class="error">'.$fac->error.'</div>'; $mesg='<div class="error">'.$fac->error.'</div>';
@ -74,7 +74,7 @@ if ($_POST["action"] == 'update' && $user->rights->fournisseur->facture->creer)
{ {
$db->begin(); $db->begin();
$res=$fac->update_note($_POST["note"]); $res=$fac->update_note($_POST["note"],$user);
if ($res < 0) if ($res < 0)
{ {
$mesg='<div class="error">'.$fac->error.'</div>'; $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 * \brief Change les conditions de r<EFBFBD>glement de la facture

View File

@ -1076,35 +1076,6 @@ class User extends CommonObject
} }
/**
\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 * \brief Mise e jour en base de la date de deniere connexion d'un utilisateur
* Fonction appelee lors d'une nouvelle connexion * Fonction appelee lors d'une nouvelle connexion