Rev 2 | Blame | Last modification | View Log | RSS feed
<?php// +------------------------------------------------------------------------------------------------------+// | PHP version 4.1 |// +------------------------------------------------------------------------------------------------------+// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org) |// +------------------------------------------------------------------------------------------------------+// | This library is free software; you can redistribute it and/or |// | modify it under the terms of the GNU Lesser General Public |// | License as published by the Free Software Foundation; either |// | version 2.1 of the License, or (at your option) any later version. |// | |// | This library is distributed in the hope that it will be useful, |// | but WITHOUT ANY WARRANTY; without even the implied warranty of |// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |// | Lesser General Public License for more details. |// | |// | You should have received a copy of the GNU Lesser General Public |// | License along with this library; if not, write to the Free Software |// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |// +------------------------------------------------------------------------------------------------------+// |@author ABDOOL RAHEEM shaheen shaheenar50@hotmail.com |// |@version 3 |class Preference{private $table = 'gestion_preferences';private $id_utilisateur = null;private $id_projet = null;/*** Constructeur */function Preference($u, $p){$this->_utilisateur = $u;$this->_projet = $p;}/*** Ajouter une préférence dans la base de données.*@return true si ok, false si aucun enregistrement effectué*/function ajouter(){$requete = 'INSERT INTO gestion_preferences (gp_id_utilisateur, gp_id_projet) '.'VALUES ('.$this->id_utilisateur.', '.$this->id_projet.')';$resultat = $GLOBALS['db']->query($requete);if (DB::isError($resultat)) {die($resultat->getMessage());}$nbre_enregistrement_ajoute = $GLOBALS['db']->affectedRows();if ($nbre_enregistrement_ajoute == 1) {return true;} elseif ($nbre_enregistrement_ajoute == 0) {return false;}}/*** Récupérer la liste de préférences d'un utilisateur.*@param identifiant utilisateur.*/function recupererTableauPreferences(){$table = array();$requete = "SELECT P.".GEST_CHAMPS_ID_PROJET.", P.".GEST_CHAMPS_NOM_PROJET." ,C.".GEST_CHAMPS_ID_CATEGORIE.",C.".GEST_CHAMPS_LIBELLE_CATEGORIE." FROM ".GEST_PREFERENCES." F, ".GEST_PROJET." P,".GEST_CATEGORIE." C"." WHERE ".GEST_CHAMPS_ID_UTILISATEUR. " = $this->_utilisateur"." AND F.".GEST_CHAMPS_ID_PROJET." = P.".GEST_CHAMPS_ID_PROJET." AND P.".GEST_CHAMPS_ID_CATEGORIE." = C.".GEST_CHAMPS_ID_CATEGORIE." ORDER BY ".GEST_CHAMPS_LIBELLE_CATEGORIE;$resultat = $GLOBALS['db']->query($requete);(DB::isError($resultat)) ? die (BOG_afficherErreurSql(__FILE__, __LINE__, $resultat->getMessage(), $requete)) : '' ;while ( $ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {$case = array('id_proj' => $ligne[GEST_CHAMPS_ID_PROJET], 'nom_proj' => $ligne[GEST_CHAMPS_NOM_PROJET],'id_cat' => $ligne[GEST_CHAMPS_ID_CATEGORIE], 'libelle_cat' => $ligne[GEST_CHAMPS_LIBELLE_CATEGORIE]);array_push($table, $case);}return $table;}/***supprimer liste de preferences*pour un utilisateur donne*@param identifiant d'un utilisateur*/function supprimerPreferences($id){$requete = 'DELETE FROM '.GEST_PREFERENCES.' '.'WHERE '.GEST_CHAMPS_ID_UTILISATEUR.' = '.$id;$resultat = $GLOBALS['db']->query($requete);return $GLOBALS['db']->affectedRows();}/*** Méthode renvoyant vrai si un projet est dans la liste de préférence d'un utilisateur.*$id : identifiant du projet a chercher*@return true : si existe*@return false si n'existe pas*/function isInPreferences($id){$tab = $this->recupererTableauPreferences();$res = false;for ($r = 0; $r < count($tab); $r++) {$t = $tab[$r];if ($t['id_proj'] == $id) {$res = true;}}return $res;}/*** Afficher préférences*/function afficherPreference(){echo "<br /> preferences <br />";$u= array($this->_utilisateur,$this->_projet);foreach ($u as $p) {echo "$p , ";}echo "<br /> ";}}?>