| 314 | delphine | 1 | <?php
 | 
        
           |  |  | 2 | class CelFormateur implements Formateur {
 | 
        
           |  |  | 3 | 	public $dest_map = array();
 | 
        
           |  |  | 4 | 	public $img = array();
 | 
        
           | 315 | delphine | 5 | 	public function __construct($info) {
 | 
        
           | 314 | delphine | 6 | 		$this->info = $info;
 | 
        
           |  |  | 7 | 	}
 | 
        
           |  |  | 8 | 	public function img() {
 | 
        
           |  |  | 9 | 		$qualite = 90;
 | 
        
           |  |  | 10 | 		imagejpeg($this->img['cel'], Config::get('cache.stockageChemin').$this->dest_map['cel'], $qualite);
 | 
        
           |  |  | 11 | 	}
 | 
        
           |  |  | 12 | 	//+----------------------------------------------------------------------------------------------------------------+
 | 
        
           |  |  | 13 | 	// Méthodes d'accès aux objets du Framework
 | 
        
           |  |  | 14 | 	/**
 | 
        
           |  |  | 15 | 	* Méthode de connection à la base de données sur demande.
 | 
        
           |  |  | 16 | 	* Tous les services web n'ont pas besoin de s'y connecter.
 | 
        
           |  |  | 17 | 	*/
 | 
        
           |  |  | 18 | 	protected function getBdd() {
 | 
        
           |  |  | 19 | 		if (! isset($this->Bdd)) {
 | 
        
           |  |  | 20 | 			$this->Bdd = new Bdd();
 | 
        
           |  |  | 21 | 		}
 | 
        
           |  |  | 22 | 		return $this->Bdd;
 | 
        
           |  |  | 23 | 	}
 | 
        
           |  |  | 24 |   | 
        
           |  |  | 25 | 	public function definirCouleurs() {
 | 
        
           |  |  | 26 | 		// green
 | 
        
           |  |  | 27 | 		$couleurs['green'] = imagecolorallocate($this->img['cel'], 0, 255, 0);
 | 
        
           |  |  | 28 | 		return $couleurs;
 | 
        
           |  |  | 29 | 	}
 | 
        
           |  |  | 30 | 	public function initialiserImage() {
 | 
        
           |  |  | 31 | 		// Nom du fichier image en sortie
 | 
        
           |  |  | 32 | 		$this->cheminCartesBase = Config::get('Cartes.chemin');
 | 
        
           |  |  | 33 | 		$this->dest_map['cel'] = 'cel_nt'.$this->info['nt'].'_'.$this->info['src_map'];
 | 
        
           |  |  | 34 | 		$this->img['cel'] = imagecreatefromjpeg($this->cheminCartesBase.$this->info['src_map']);
 | 
        
           |  |  | 35 | 	}
 | 
        
           |  |  | 36 |   | 
        
           |  |  | 37 | 	public function chargerDonnees() {
 | 
        
           |  |  | 38 | 		// Recherche nom correspondant au numero nomenclatural en cours (pour etablir le lien avec les donnees moissonnes).
 | 
        
           |  |  | 39 |   | 
        
           |  |  | 40 | 		// R�cuperation donn�e inventaire
 | 
        
           |  |  | 41 | 		/*
 | 
        
           |  |  | 42 | 		* Les donnees issues du carnet en ligne sont recuperes directement, sans passer par le mecanisme de moissonage car :
 | 
        
           |  |  | 43 | 		*   - pour l'instant le service de moissonage n'est pas automatise et donc il y a un decalage dans l'affichage des donnees transmises
 | 
        
           |  |  | 44 | 		*   - la table contenant les donnees moissonees ne reprend pas tous les champs necessaires a l'exploitation par eflore (notamment pas de code localite, pas d'identifiant libre)
 | 
        
           |  |  | 45 | 		*
 | 
        
           |  |  | 46 | 		* A terme, utilser vraiment le moissonage, y compris pour les donnees issues du CEL, en utilisant ABCD et en modifiant le programme d'harvesting.
 | 
        
           |  |  | 47 | 		*/
 | 
        
           |  |  | 48 | 		$queryCel = "SELECT 'cel' as collection_code,  location, id_location, date_observation,  ".
 | 
        
           |  |  | 49 | 		"	coord_y as y_utm, coord_x as x_utm, ref_geo as sector, identifiant FROM tb_cel.cel_inventory ".
 | 
        
           |  |  | 50 | 							"WHERE num_taxon = '".$this->info['nt']."' ".
 | 
        
           |  |  | 51 | 							"	AND transmission = 1";
 | 
        
           |  |  | 52 | 		$inventoriesCel = $this->getBdd()->recupererTous($queryCel);
 | 
        
           |  |  | 53 | 		return $inventoriesCel;
 | 
        
           |  |  | 54 | 	}
 | 
        
           |  |  | 55 |   | 
        
           |  |  | 56 |   | 
        
           |  |  | 57 | 	public function dessinerPoint($text, $merge, $couleurs) {
 | 
        
           |  |  | 58 | 		$usemap['cel'] = '';
 | 
        
           |  |  | 59 |   | 
        
           |  |  | 60 | 		foreach ($text as $coord => $origines ) {
 | 
        
           |  |  | 61 | 			foreach ($origines as $origine => $maptext ) {
 | 
        
           |  |  | 62 | 				$maptext = preg_replace("/\"/", "\'", $maptext);
 | 
        
           |  |  | 63 |   | 
        
           |  |  | 64 | 				list($x,$y) = explode('|', $coord);
 | 
        
           |  |  | 65 |   | 
        
           |  |  | 66 | 				$tpl_area = '<area shape="%s" alt="" class="tooltip" coords="%s" title="%s"/>';
 | 
        
           |  |  | 67 | 				$rayon = 2;
 | 
        
           |  |  | 68 | 				$type = 'circle';
 | 
        
           |  |  | 69 | 				$coords = "$x,$y,5";
 | 
        
           |  |  | 70 | 				$on_mouseover = "this.ttBgColor='#99C242';this.ttFontColor='#000000';this.T_OFFSETX=-200;this.T_OFFSETY=-50;this.T_STICKY=1;return escape('$maptext')";
 | 
        
           |  |  | 71 |   | 
        
           |  |  | 72 | 				imagefilledrectangle($this->img['cel'], ($x - $rayon), ($y - $rayon), ($x + $rayon), ($y + $rayon), $couleurs['green']);
 | 
        
           |  |  | 73 | 				$coords = ($x - $rayon).','.($y - $rayon).','.($x + $rayon).','.($y + $rayon);
 | 
        
           |  |  | 74 | 				$usemap['cel'] = $usemap['cel'].sprintf($tpl_area, 'rect', $coords, $maptext);
 | 
        
           |  |  | 75 | 			}
 | 
        
           |  |  | 76 | 		}
 | 
        
           |  |  | 77 | 		return $usemap;
 | 
        
           |  |  | 78 | 	}
 | 
        
           |  |  | 79 |   | 
        
           | 315 | delphine | 80 | 	public function formaterCartes($usemap) {
 | 
        
           |  |  | 81 | 		$retour = Config::get('Cartes.cel_dst').$this->dest_map['cel'];
 | 
        
           |  |  | 82 | 		if ($this->info['retour'] == self::MIME_MAP) {
 | 
        
           |  |  | 83 | 			$retour =  "<img src=\"".$retour."\" style=\"border:none; ".
 | 
        
           |  |  | 84 | 					"cursor:crosshair\" alt=\"\" usemap=\"#themap\" /><br />\n".
 | 
        
           |  |  | 85 | 					"<map name=\"themap\" id=\"themap\">".utf8_encode($usemap['cel'])."</map>";
 | 
        
           |  |  | 86 | 		}
 | 
        
           | 314 | delphine | 87 | 		return $retour;
 | 
        
           |  |  | 88 | 	}
 | 
        
           |  |  | 89 |   | 
        
           |  |  | 90 |   | 
        
           |  |  | 91 |   | 
        
           |  |  | 92 |   | 
        
           |  |  | 93 | 	//+----------------------------------------------------------------------------------------------------------------+
 | 
        
           |  |  | 94 | 	// sous fonction de calculer répartition
 | 
        
           |  |  | 95 | 	public function chercherVille($inventory, $tab_code_insee = array()) {
 | 
        
           |  |  | 96 | 		$location_protege = $this->getBdd()->proteger($inventory['location']);
 | 
        
           |  |  | 97 | 		$id_location_protege = $this->getBdd()->proteger($inventory['id_location']);
 | 
        
           |  |  | 98 | 		$utm = array();
 | 
        
           |  |  | 99 | 			if ($inventory['id_location'] != 'null') {
 | 
        
           |  |  | 100 | 				if (isset($tab_code_insee) & in_array($inventory['id_location'], $tab_code_insee)) {
 | 
        
           |  |  | 101 | 					$utm = array(0 => $this->tab_code_insee[$id_location_protege]);
 | 
        
           |  |  | 102 | 				} else {
 | 
        
           |  |  | 103 | 					$requete = "SELECT * ".
 | 
        
           |  |  | 104 | 										"FROM tb_cel.locations ".
 | 
        
           |  |  | 105 | 										"WHERE name LIKE $location_protege ".
 | 
        
           |  |  | 106 | 										"	AND code = $id_location_protege ";
 | 
        
           |  |  | 107 | 					$resultat = $this->getBdd()->recupererTous($requete);
 | 
        
           |  |  | 108 | 					$utm = $resultat;
 | 
        
           |  |  | 109 | 				}
 | 
        
           |  |  | 110 | 			} else {
 | 
        
           |  |  | 111 | 				$requete = "SELECT * FROM tb_cel.locations WHERE name LIKE $location_protege ";
 | 
        
           |  |  | 112 | 				$utm = $this->getBdd()->recupererTous($requete);
 | 
        
           |  |  | 113 | 			}
 | 
        
           |  |  | 114 | 		return $utm;
 | 
        
           |  |  | 115 | 	}
 | 
        
           |  |  | 116 |   | 
        
           |  |  | 117 | 	public function formerCommentaire($utm, $inventory) {
 | 
        
           |  |  | 118 | 		$comment = '';
 | 
        
           |  |  | 119 |   | 
        
           |  |  | 120 | 		if ($inventory['date_observation'] != '0000-00-00 00:00:00') {
 | 
        
           |  |  | 121 | 			$comment .= $this->formerDate($inventory);
 | 
        
           |  |  | 122 | 		}
 | 
        
           |  |  | 123 |   | 
        
           |  |  | 124 | 		list($identifiant) = explode("@", $inventory['identifiant']);
 | 
        
           |  |  | 125 | 		$comment .= " par ".$identifiant."@...";
 | 
        
           |  |  | 126 |   | 
        
           |  |  | 127 | 		return $comment;
 | 
        
           |  |  | 128 | 	}
 | 
        
           |  |  | 129 |   | 
        
           |  |  | 130 | 	public function formerDate($inventory) {
 | 
        
           |  |  | 131 | 			list($year, $month, $day) = explode ('-',$inventory['date_observation']);
 | 
        
           |  |  | 132 | 			list($day) = explode (' ',$day);
 | 
        
           |  |  | 133 | 			if ($month == '00') {
 | 
        
           |  |  | 134 | 				$date = ', en '.$year;
 | 
        
           |  |  | 135 | 			} else {
 | 
        
           |  |  | 136 | 				$date = ', le '.$day.'/'.$month.'/'.$year;
 | 
        
           |  |  | 137 | 			}
 | 
        
           |  |  | 138 | 		return $date;
 | 
        
           |  |  | 139 | 	}
 | 
        
           |  |  | 140 | 	/*
 | 
        
           |  |  | 141 | 	 * Stockage commentaire associe a un point :
 | 
        
           |  |  | 142 | 	 *
 | 
        
           |  |  | 143 | 	 * Param :
 | 
        
           |  |  | 144 | 	 * @text : texte cumule
 | 
        
           |  |  | 145 | 	 * @merge : indicateur de commentaire fusionne
 | 
        
           |  |  | 146 | 	 * @name : commune associee
 | 
        
           |  |  | 147 | 	 * @comment : commentaire
 | 
        
           |  |  | 148 | 	 * @origine : origine de la donnee
 | 
        
           |  |  | 149 | 	 *
 | 
        
           |  |  | 150 | 	 *
 | 
        
           |  |  | 151 | 	 * TODO : rendre cette fonction independante des valeurs d'origine passee en parametre
 | 
        
           |  |  | 152 | 	 */
 | 
        
           |  |  | 153 | 	public function stockerCommentaire($text, $merge, $name, $comment, $origine, $x, $y) {
 | 
        
           |  |  | 154 | 		$prefix = 'CEL : ';
 | 
        
           |  |  | 155 |   | 
        
           |  |  | 156 | 		// Cumul toute origine :
 | 
        
           |  |  | 157 | 		if (isset($text[$x.'|'.$y]['tout']) && ($text[$x.'|'.$y])) {
 | 
        
           |  |  | 158 | 			$text[$x.'|'.$y]['tout'] = $text[$x.'|'.$y]['tout'].'<br>'.$prefix.$name.$comment;
 | 
        
           |  |  | 159 | 		} else {
 | 
        
           |  |  | 160 | 			// Nouveau commentaire
 | 
        
           |  |  | 161 | 			$text[$x.'|'.$y]['tout']=$prefix.$name.$comment;
 | 
        
           |  |  | 162 | 		}
 | 
        
           |  |  | 163 |   | 
        
           |  |  | 164 | 		// Deja present  pour cette origine ? on ajoute
 | 
        
           |  |  | 165 | 		if (isset ($text[$x.'|'.$y][$origine]) && ($text[$x.'|'.$y][$origine])) {
 | 
        
           |  |  | 166 | 			$text[$x.'|'.$y][$origine] = $text[$x.'|'.$y][$origine].'<br>'.$name.$comment;
 | 
        
           |  |  | 167 | 		} else { // Nouveau commentaire
 | 
        
           |  |  | 168 | 			$text[$x.'|'.$y][$origine] = $name.$comment;
 | 
        
           |  |  | 169 | 		}
 | 
        
           |  |  | 170 |   | 
        
           |  |  | 171 |   | 
        
           |  |  | 172 | 		// Detection superposition de donnee
 | 
        
           |  |  | 173 | 		if ((isset ($text[$x.'|'.$y]['sophy']) && ($text[$x.'|'.$y]['sophy'])) || (isset ($text[$x.'|'.$y]['flore']) && ($text[$x.'|'.$y]['flore']))
 | 
        
           |  |  | 174 | 			|| (isset ($text[$x.'|'.$y]['FLORE - VAR']) && ($text[$x.'|'.$y]['FLORE - VAR']))) {
 | 
        
           |  |  | 175 | 				$merge[$x.'|'.$y]=true;
 | 
        
           |  |  | 176 | 		}
 | 
        
           |  |  | 177 | 		return array($text, $merge);
 | 
        
           |  |  | 178 | 	}
 | 
        
           |  |  | 179 |   | 
        
           |  |  | 180 |   | 
        
           |  |  | 181 |   | 
        
           |  |  | 182 | }
 | 
        
           |  |  | 183 | ?>
 |