* @copyright 2010 Tela-Botanica * @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL * @version SVN: * @link /doc/projet_bp/ */ class ProjetService extends JRestService { public function __construct($config, $demarrer_session= true) { parent::__construct($config, $demarrer_session); } protected function obtenirProjetsPourParticipant($id_utilisateur) { // on selectionne la liste des projets auxquel on est inscrit $requete_projets = 'SELECT DISTINCT *'. ' FROM projet'. ' WHERE p_id'. ' IN '. '(SELECT psu_id_projet FROM projet_statut_utilisateurs'. ' WHERE psu_id_utilisateur = '.$this->bdd->quote($id_utilisateur).')'. ' GROUP BY p_id'; try { $projets = $this->bdd->query($requete_projets)->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) { Log::getInstance()->ajouterEntree('projet','Fichier: '.$e->getFile().' Ligne: '.$e->getLine().' '.$e->getMessage()); return array(); } // pas de projets ? alors c'est fait ! if(!$projets || count($projets) <= 0) { return array(); } return $projets; } protected function obtenirInformationsProjet($id_projet) { $requete_informations_projet = 'SELECT DISTINCT *'. ' FROM projet'. ' WHERE p_id = '.$this->bdd->quote($id_projet) ; try { $projet = $this->bdd->query($requete_informations_projet)->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) { Log::getInstance()->ajouterEntree('projet','Fichier: '.$e->getFile().' Ligne: '.$e->getLine().' '.$e->getMessage()); return false; } // pas de projets ? alors c'est fait ! if(!$projet) { return false; } return $projet; } protected function obtenirListesAssocieesAuProjet($id_projet) { $requete_liste_projets = 'SELECT * FROM projet_liste '. 'WHERE pl_id_liste IN '. '(SELECT pl_id_liste from projet_lien_liste '. 'WHERE pl_id_projet='.$this->bdd->quote($id_projet).')' ; try { $listes_projets = $this->bdd->query($requete_liste_projets)->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) { Log::getInstance()->ajouterEntree('projet','Fichier: '.$e->getFile().' Ligne: '.$e->getLine().' '.$e->getMessage()); return array(); } if(!$listes_projets || count($listes_projets) <= 0) { return array(); } return $listes_projets; } protected function supprimerInscriptionAListeProjet($id_utilisateur, $id_liste) { $requete_suppression_liste = 'DELETE FROM projet_inscription_liste '. 'WHERE pil_id_utilisateur='.$this->bdd->quote($id_utilisateur).' and pil_id_liste='.$this->bdd->quote($id_liste) ; try { $requete_suppression_liste = $this->bdd->query($requete_suppression_liste); } catch (PDOException $e) { Log::getInstance()->ajouterEntree('projet','Fichier: '.$e->getFile().' Ligne: '.$e->getLine().' '.$e->getMessage().' '.$requete_suppression_liste); return false; } } protected function supprimerParticipantAProjet($id_utilisateur, $id_projet) { $requete_suppression_projets = 'DELETE FROM projet_statut_utilisateurs '. 'WHERE psu_id_utilisateur='.$this->bdd->quote($id_utilisateur).' and psu_id_projet='.$this->bdd->quote($id_projet) ; try { $requete_suppression_projets = $this->bdd->query($requete_suppression_projets); } catch (PDOException $e) { Log::getInstance()->ajouterEntree('projet','Fichier: '.$e->getFile().' Ligne: '.$e->getLine().' '.$e->getMessage().' '.$requete_suppression_projets); return false; } return true; } protected function estAbonneAListe($nom_liste, $mail) { try { $est_abonne = '0' ; $xml_abonne = new SimpleXMLElement(file_get_contents('http://vpopmail.tela-botanica.org/est_abonne.php?domaine=tela-botanica.org&liste='.$nom_liste.'&mail='.$mail)) ; $est_abonne = $xml_abonne[0] ; if($est_abonne == '1') { return true; } else { return false; } } catch(Exception $e) { trigger_error($e->getMessage()) ; return false; } } protected function modifierMailPourListe($nom_liste, $ancien_mail, $nouveau_mail) { return ($this->desinscriptionListe($nom_liste, $ancien_mail) && $this->inscriptionListe($nom_liste, $nouveau_mail)); } protected function inscriptionListe($nom_liste, $mail) { return $inscription_abonne = file_get_contents('http://vpopmail.tela-botanica.org/ajout_abonne.php?domaine=tela-botanica.org&liste='.$nom_liste.'&mail='.$mail) ; } protected function desinscriptionListe($nom_liste, $mail) { return $suppression_abonne = file_get_contents('http://vpopmail.tela-botanica.org/suppression_abonne.php?domaine=tela-botanica.org&liste='.$nom_liste.'&mail='.$mail) ; } } ?>