/**
  * Get the latest user's favorite information to display
  *
  * @param unknown $nbElts to display
  * @return multitype:
  */
 public function getLatestFav($nbElts)
 {
     /*
      * Initialisation des variables :
      * Tableau avec les champs pour remplir la requete
      */
     $requestField = array(array('table' => '_interetRue', 'id' => 'idRue'), array('table' => '_interetSousQuartier', 'id' => 'idSousQuartier'), array('table' => '_interetVille', 'id' => 'idVille'), array('table' => '_interetAdresse', 'id' => 'idHistoriqueAdresse'), array('table' => '_interetPays', 'id' => 'idPays'), array('table' => '_interetQuartier', 'id' => 'idQuartier'));
     $auth = new ArchiAuthentification();
     $userId = $auth->getIdUtilisateur();
     /*
      * Boucle pour faire les sous requetes
      */
     $subRequest = array();
     $request = "";
     $i = 0;
     foreach ($requestField as $fields) {
         $request .= "\n\t\t\t\t\t(\n\t\t\t\t\tSELECT\n\n\t\t\t\t\tevt.idEvenement AS idEvenement,\n\t\t\t\t\tevt.idEvenementRecuperationTitre,\n\t\t\t\t\tevt.idImagePrincipale AS idHistoriqueImage,\n\t\t\t\t\tee.idEvenement AS idEvenementGroupeAdresse,\n\t\t\t\t\tae.idAdresse AS idAdresse,\n\t\t\t\t\tha.nom ,\n\t\t\t\t\tdate_format(evt.dateCreationEvenement," . _('"%e/%m/%Y"') . ") as dateCreationEvenement,\n\t\t\t\t\t\t\ti.created as created,\n\t\t\t\t\t\t\tevt.description,\n\t\t\t\t\t\t\tevt.titre AS titre\n\t\t\t\t\t\t\t\t\n\n\t\t\t\t\t\t\tFROM evenements evt\n\t\t\t\t\t\t\tINNER JOIN _evenementEvenement ee ON ee.idEvenementAssocie = evt.idEvenement\n\t\t\t\t\t\t\tINNER JOIN _adresseEvenement ae ON ae.idEvenement = ee.idEvenement\n\t\t\t\t\t\t\tINNER JOIN historiqueAdresse ha ON ha.idAdresse = ae.idAdresse\n\t\t\t\t\t\t\tINNER JOIN " . $fields['table'] . " i ON i." . $fields['id'] . " = ha." . $fields['id'] . "\n\t\t\t\t\t\t\t\t\tWHERE i.idUtilisateur =" . $userId . "\n\t\t\t\t\t\t\t\t\tGROUP BY idEvenement DESC\n\t\t\t\t\t\t\t\t\tORDER BY i.created\n\t\t\t\t\t\t\t\t\tLIMIT {$nbElts}\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t";
         if ($i++ < count($requestField) - 1) {
             $request .= " UNION ";
         }
     }
     /*
      * Data processing
      */
     //Strange request wrapping to avoid redundancy, might not be accepted by MySQL
     $request = "SELECT * FROM\n\t\t\t\t(" . $request . ")\n\t\t\t\tAS tmp\n\t\t\t\tGROUP BY idEvenementGroupeAdresse\n\t\t\t\tORDER BY created\n\t\t\t\tLIMIT {$nbElts} ";
     $result = $this->connexionBdd->requete($request);
     while ($fetch = mysql_fetch_assoc($result)) {
         $item['CSSClassWrapper'] = 'interest';
         $item['titreItem'] = $fetch['nom'];
         $item['imgUrl'] = $this->getUrlImage() . 'resizeImage.php?id=' . $fetch['idHistoriqueImage'];
         $item['urlItem'] = $this->creerUrl('', '', array('archiAffichage' => 'adresseDetail', "archiIdAdresse" => $fetch['idAdresse'], "archiIdEvenementGroupeAdresse" => $fetch['idEvenementGroupeAdresse']));
         $item['textItem'] = $fetch['nom'];
         $itemContent[] = $fetch;
     }
     return $itemContent;
 }
 public function getPrivateProfil()
 {
     $auth = new ArchiAuthentification();
     if ($auth->estConnecte()) {
         $userId = $auth->getIdUtilisateur();
     } else {
         $this->messages->addError("Identifiant d'utilisateur incorrect");
         $this->messages->display();
         return false;
     }
     //Utilisateur banni
     if (!$this->isUtilisateurBanni(array('idUtilisateur' => $idUtilisateur))) {
         $t = new Template('modules/archi/templates/utilisateur');
         $t->set_filenames(array('general' => 'profile.tpl', 'userStats' => 'statistics.tpl'));
         //Presentation
         $presentation = $this->getUserPresentation($userId);
         //Statistics
         $statistics = $this->getProfileStatistics($userId);
         foreach ($statistics as $stat) {
             $t->assign_block_vars('statistic', $stat);
         }
         //Informations
         $info = $this->getUserInfos($userId);
         //Formulaire
         $form = $this->getUserForm();
         //Get contributions
         $contributions = $this->getAllContribution($userId);
         $t->assign_vars(array('userPresentation' => $presentation, 'userFormInfo' => $form, 'userInformations' => $info, 'userContributions' => $contributions));
         $t->assign_var_from_handle('userStatistics', 'userStats');
         $t->pparse('general');
     } else {
         $this->messages->addWarning("Cet utilisateur est banni");
         $this->messages->display();
         return false;
     }
 }
 /**
  * Get the form for comment
  *
  *
  * @param unknown $idEvenement
  * @param unknown $fields
  * @param string $ty : type of comment
  * @return string
  */
 public function getFormComment($idEvenement, $fields, $ty = '')
 {
     $t = new Template('modules/archi/templates/');
     $labelButton = "Ajouter un commentaire";
     $type = $ty == '' ? 0 : $ty;
     $classButton = 'addCommentButtonWrapper';
     $auth = new ArchiAuthentification();
     if ($auth->estConnecte()) {
         $t->set_filenames(array('formComment' => 'comment/comment.tpl'));
         $url = "";
         $userId = $auth->getIdUtilisateur();
         $utilisateur = new archiUtilisateur();
         $utilisateur->setUserId($userId);
         $nom = $utilisateur->getNom();
         $prenom = $utilisateur->getPrenom();
         $email = $utilisateur->getEmail();
         $urlProfilePic = $utilisateur->getImageAvatar(array('idUtilisateur' => $userId));
         $profileAlt = $prenom . " " . $nom;
         if ($ty == '') {
             $array_type = array();
             $url = $this->creerUrl('enregistreCommentaire', '', array());
             $labelButton .= " sur l'adresse";
             $classButton .= " addCommentAdresseButtonWrapper";
         } else {
             $array_type = array('type' => array('id' => 'type', 'type' => 'hidden', 'value' => $type));
             $url = $this->creerUrl('enregistreCommentaireEvenement', '', array());
         }
         $inputs = array('nom' => array('id' => 'nom', 'type' => 'hidden', 'value' => $nom), 'prenom' => array('id' => 'prenom', 'type' => 'hidden', 'value' => $prenom), 'email' => array('id' => 'email', 'type' => 'hidden', 'value' => $email), 'idEvenementGroupeAdresse' => array('id' => 'idEvenementGroupeAdresse', 'type' => 'hidden', 'value' => $idEvenement));
         $inputs = array_merge($inputs, $array_type);
         foreach ($inputs as $input) {
             $t->assign_block_vars('input', $input);
         }
         $t->assign_vars(array('urlRedirect' => $url, 'name' => 'formAjoutCommentaire', 'urlProfilePic' => $urlProfilePic, 'profileAlt' => $profileAlt, 'labelButton' => $labelButton, 'classButton' => $classButton, 'idEvenement' => $idEvenement));
     } else {
         $t->set_filenames(array('formComment' => 'comment/notconnected.tpl'));
         $urlConnexion = $this->creerUrl('', 'authentification');
         $urlInscription = $this->creerUrl('', 'inscription');
         if ($ty == '') {
             $labelButton .= " sur l'adresse";
             $classButton .= " addCommentAdresseButtonWrapper";
         }
         $t->assign_vars(array('urlInscription' => $urlInscription, 'urlConnexion' => $urlConnexion, 'labelButton' => $labelButton, 'classButton' => $classButton, 'idEvenement' => $idEvenement));
     }
     //Setting CSS class for opening the form
     if (isset($this->variablesGet['commentFormActive']) && $this->variablesGet['commentFormActive']) {
         if ($this->variablesGet['commentFormActive'] == $idEvenement) {
             $t->assign_var('classWrappingDiv', 'active');
         }
     }
     ob_start();
     $t->pparse('formComment');
     $html .= ob_get_contents();
     ob_end_clean();
     return $html;
 }
 public function getFavorisByCategories()
 {
     $returnArray = array();
     $auth = new ArchiAuthentification();
     if (!$auth->estConnecte()) {
         $this->messages->addError('Impossible de récupérer vos favoris, vous n\'êtes pas connecté.');
         $this->messages->display();
         return false;
     }
     $userId = $auth->getIdUtilisateur();
     //Rues
     $requete = "\n\t\tSELECT idRue\n\t\tFROM _interetRue\n\t\tWHERE idUtilisateur = {$userId}\n\t\t";
     $result = $this->connexionBdd->requete($requete);
     $array = array();
     while ($row = mysql_fetch_assoc($result)) {
         $array[] = $row['idRue'];
     }
     if (!empty($array)) {
         $returnArray['rue'] = $array;
     }
     //Sous-quartier
     $requete = "\n\t\tSELECT idSousQuartier\n\t\tFROM _interetSousQuartier\n\t\tWHERE idUtilisateur = {$userId}\n\t\t";
     $result = $this->connexionBdd->requete($requete);
     $array = array();
     while ($row = mysql_fetch_assoc($result)) {
         $array[] = $row['idSousQuartier'];
     }
     if (!empty($array)) {
         $returnArray['sousQuartier'] = $array;
     }
     //Quartier
     $requete = "\n\t\tSELECT idQuartier\n\t\tFROM _interetQuartier\n\t\tWHERE idUtilisateur = {$userId}\n\t\t";
     $result = $this->connexionBdd->requete($requete);
     $array = array();
     while ($row = mysql_fetch_assoc($result)) {
         $array[] = $row['idQuartier'];
     }
     if (!empty($array)) {
         $returnArray['quartier'] = $array;
     }
     //Villes
     $requete = "\n\t\tSELECT idVille\n\t\tFROM _interetVille\n\t\tWHERE idUtilisateur = {$userId}\n\t\t";
     $result = $this->connexionBdd->requete($requete);
     $array = array();
     while ($row = mysql_fetch_assoc($result)) {
         $array[] = $row['idVille'];
     }
     if (!empty($array)) {
         $returnArray['ville'] = $array;
     }
     //Pays
     $requete = "\n\t\tSELECT idPays\n\t\tFROM _interetPays\n\t\tWHERE idUtilisateur = {$userId}\n\t\t";
     $result = $this->connexionBdd->requete($requete);
     $array = array();
     while ($row = mysql_fetch_assoc($result)) {
         $array[] = $row['idPays'];
     }
     if (!empty($array)) {
         $returnArray['pays'] = $array;
     }
     return $returnArray;
 }