Rev 3 | Go to most recent revision | Blame | Last modification | View Log | RSS feed
<?php
// declare(encoding='UTF-8');
/**
* Classe de gestion des images.
*
* @package ODS_saisie
* @category Php 5.2
* @author Aurélien Peronnet <aurelien@tela-botanica.org>
* @copyright 2010 Tela-Botanica
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
* @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
* @version SVN: $Id: Fiche.php 152 2010-09-06 16:19:12Z jpm $
*/
class Image extends aControleur {
private $start = 0;
private $limit = 100;
private $total_resultats = 0;
private $intervalle_pages = 5;
public function __construct() {
parent::__construct();
$this->initialiser();
}
public function initialiser() {
}
public function executerActionParDefaut() {
return $this->rechercherImage();
}
public function afficherFormulaireRechercheImage() {
$donnees = array('criteres' => '');
$formulaire = $this->getVue('formulaires/image_recherche',$donnees);
$this->setSortie(self::RENDU_CORPS, $formulaire);
}
public function rechercherImage() {
if (!isset($_GET['image_recherche']) || trim($_GET['image_recherche']) == '') {
$_GET['image_recherche'] = '';
}
if (isset($_GET['start'])) {
$this->start = $_GET['start'];
}
if (isset($_GET['limit'])) {
$this->limit = $_GET['limit'];
}
$critere_pour_dao = $_GET['image_recherche'];
if (aControleur::estUneRechercheGenerale($critere_pour_dao)) {
$critere_pour_dao = aControleur::convertirChaineRequeteGeneralePourDao($critere_pour_dao);
} else {
$critere_pour_dao = aControleur::convertirChaineRequetePourDao($critere_pour_dao);
}
$image_dao = new ImageDao();
$resultat_recherche = $image_dao->getListeImage($critere_pour_dao, $this->start, $this->limit);
$critere_a_reafficher = aControleur::convertirChaineRequetePourMoteur($_GET['image_recherche']);
$this->afficherResultatRechercheImage($resultat_recherche, $critere_a_reafficher);
}
public function afficherResultatRechercheImage($donnees_images, $criteres = '') {
$images = array();
if (isset($donnees_images['images'])) {
$images = $donnees_images['images'];
$this->total_resultats = $donnees_images['total'];
}
foreach ($images as &$image) {
$taille_image = array($image['ci_meta_height'],$image['ci_meta_width']);
$image['taille'] = $this->calculerDimensionPourVignette($taille_image);
$id = $image['coi_ce_image'];
$format_galerie = Config::get('format_image_galerie');
$format_zoom = Config::get('format_image_zoom');
$image['url_image_format_galerie'] = $this->getUrlImageBase($id, $format_galerie);
$image['url_image_format_zoom'] = $this->getUrlImageBase($id, $format_zoom);
}
$donnees['pagination'] = $this->afficherBarrePagination($criteres);
$donnees['images'] = $images;
$donnees['criteres'] = $criteres;
$this->setSortie(self::RENDU_CORPS, $this->getVue('formulaires/image_recherche',$donnees).$this->getVue('listes/image_liste', $donnees));
}
// +---------------------------------------------------------------------------------------------------------------+
// METHODES D'AFFICHAGE DE PAGE
public function afficherBarrePagination($criteres) {
if (isset($_GET['start'])) {
$this->start = $_GET['start'];
}
if (isset($_GET['limit'])) {
$this->limit = $_GET['limit'];
}
if ($this->start == 0) {
$page_en_cours = 1;
} else if ($this->total_resultats != 0) {
$page_en_cours = floor(($this->start + 1)/$this->limit + 1);
}
$pages_avant_apres = (ceil($this->intervalle_pages /2) + 1);
$pages_debut_intervalle = 0;
$nb_pages = 0;
if ($page_en_cours < $pages_avant_apres) {
$pages_debut_intervalle = 1;
} else {
$pages_debut_intervalle = $page_en_cours - $pages_avant_apres + 2;
}
$pages_a_afficher = $this->intervalle_pages;
$intervalle_max = (($page_en_cours) * $this->limit);
$donnees['url_base_pagination'] = '?module=Image&action=rechercherImage&image_recherche='.$criteres.'&limit='.$this->limit.'&start=';
$nb_pages = ceil($this->total_resultats/$this->limit);
if ($page_en_cours == $nb_pages) {
$intervalle_max = $this->total_resultats;
}
$donnees['pages_taille_intervalle'] = $this->intervalle_pages;
$donnees['pages_debut_intervalle'] = $pages_debut_intervalle;
$donnees['page_en_cours'] = $page_en_cours;
$donnees['intervalle_min'] = (($page_en_cours-1) * $this->limit);
$donnees['intervalle_max'] = $intervalle_max;
$donnees['nb_resultats'] = $this->total_resultats;
$donnees['nb_pages'] = $nb_pages;
$donnees['taille_page'] = $this->limit;
return $this->getVue('navigation/pagination',$donnees);
}
// +---------------------------------------------------------------------------------------------------------------+
// METHODES POUR L'AFFICHAGE DE DONNEES
private function getUrlImageBase($id, $format = 'L') {
$id = sprintf('%09s', $id) ;
$id = wordwrap($id, 3 , '_', true) ;
$chemin_sur_serveur = Config::get('url_base_images');
$id_fichier = $id.".jpg" ;
$niveauDossier = split("_", $id) ;
$dossierNiveau1 = $niveauDossier[0] ;
$dossierNiveau2 = $niveauDossier[1] ;
$fichier = $chemin_sur_serveur.'/'.$dossierNiveau1.'/'.$dossierNiveau2.'/'.$format.'/'.$id.'_'.$format.'.jpg' ;
return $fichier;
}
// commentaire
private function getTypeMime($format) {
$mime = '';
switch ($format) {
case 'atom' :
$mime = 'application/atom+xml';
break;
case 'rss1' :
case 'rss2' :
$mime = 'application/rss+xml';
break;
default:
$mime = 'text/html';
}
return $mime;
}
private function calculerDimensionPourVignette($tab_dimension_originale) {
$taille_max = Config::get('taille_max_vignettes');
$res = array('hauteur' => $taille_max,'largeur' => $taille_max) ;
return $res;
}
}
?>