Subversion Repositories eFlore/Applications.cel

Rev

Rev 1617 | Rev 1631 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1617 Rev 1625
Line 69... Line 69...
69
		'dept' => 'departement',
69
		'dept' => 'departement',
70
		'projet' => 'mots_cles',
70
		'projet' => 'mots_cles',
71
		'num_taxon' => 'nt',
71
		'num_taxon' => 'nt',
72
		'date_debut' => 'date_debut',
72
		'date_debut' => 'date_debut',
73
		'date_fin' => 'date_fin',
73
		'date_fin' => 'date_fin',
74
		'taxon' => 'taxon'
74
		'taxon' => 'taxon',
-
 
75
		'debut' => 'debut',
-
 
76
		'limite' => 'limite',
-
 
77
		'format' => 'format'
75
	);
78
	);
Line -... Line 79...
-
 
79
	
-
 
80
	private $limite_decoupage_defaut = 9000; 
76
	
81
	
Line 77... Line 82...
77
	private $format = 'csv';
82
	private $format = 'csv';
78
	
83
	
79
	public function getRessource() {
84
	public function getRessource() {
Line 80... Line 85...
80
		return $this->getElement(array());
85
		return $this->getElement(array());
81
	}
86
	}
82
		
87
		
83
	/**
88
	/**
-
 
89
	 * Méthode appelée avec une requête de type GET.
-
 
90
	 */
-
 
91
	public function getElement($params = array()) {		
-
 
92
		if(count($params) > 0) {
-
 
93
			switch(strtolower($params[0])) {
-
 
94
				case 'calcul':
-
 
95
					$this->getCalcul();
-
 
96
				break;
-
 
97
				
-
 
98
				case 'export':
-
 
99
					$this->getExport();
-
 
100
				break;
-
 
101
				
-
 
102
				default:
-
 
103
					$this->getExport();
-
 
104
			}
-
 
105
		} else {
84
	 * Méthode appelée avec une requête de type GET.
106
			$this->getExport();
-
 
107
		}
85
	 */
108
	}
86
	public function getElement($params = array()) {
-
 
87
		
109
	
88
		$criteres = $this->traiterParametresAutorises($_GET);
110
	private function getCalcul() {
89
		
111
		$criteres = $this->traiterParametresAutorises($_GET);
Line 90... Line 112...
90
		// Seulement les observation publiques
112
		// Seulement les observation publiques
91
		$criteres['transmission'] = 1;
113
		$criteres['transmission'] = 1;
Line 92... Line 114...
92
		$chercheur_observations = new RechercheObservation($this->config);
114
		$chercheur_observations = new RechercheObservation($this->config);
93
		
115
		
-
 
116
		$numero_page = isset($criteres['debut']) ? $criteres['debut'] : 0;
-
 
117
		$limite = isset($criteres['limite']) ? $criteres['limite'] : 0;
-
 
118
		
-
 
119
		unset($criteres['limite']);
-
 
120
		unset($criteres['debut']);
-
 
121
		unset($criteres['format']);
-
 
122
		
-
 
123
		$nb_observations = $chercheur_observations->compterObservations(null, $criteres);
-
 
124
		$limite_decoupage = $this->calculerNbLignesMaxParFichier();
-
 
125
		
-
 
126
		$url_telechargements = array();
-
 
127
		$intervalle = 0;
-
 
128
		
-
 
129
		$params_url = $criteres;
-
 
130
		unset($params_url['transmission']);
-
 
131
		do {
-
 
132
			$base_url = $this->config['settings']['baseURLAbsolu'].'CelWidgetExport/export';
-
 
133
			$params_url['debut'] = $intervalle;
-
 
134
			$params_url['limite'] = $limite_decoupage;
-
 
135
			$url_telechargement_fichier = $base_url;
-
 
136
			$url_telechargements[] = $base_url.'?'.http_build_query($params_url).'&format='.$this->format;
-
 
137
			$intervalle += $limite_decoupage;
Line -... Line 138...
-
 
138
			$nb_observations -= $limite_decoupage;
-
 
139
		} while($nb_observations >= $limite_decoupage);
-
 
140
		
-
 
141
		$this->envoyerJson($url_telechargements);
-
 
142
	}
-
 
143
	
-
 
144
	private function calculerNbLignesMaxParFichier() {
-
 
145
		$limite = $this->limite_decoupage_defaut;
-
 
146
		switch($this->format) {
-
 
147
			case 'csv':
-
 
148
				$limite = 20000;
-
 
149
				break;
-
 
150
			case 'xls':
-
 
151
				$limite = 8000;
-
 
152
				break;
-
 
153
		}
-
 
154
		return $limite;
-
 
155
	}
-
 
156
	
-
 
157
	private function getExport() {
-
 
158
		$criteres = $this->traiterParametresAutorises($_GET);
-
 
159
 
-
 
160
		// Seulement les observation publiques
-
 
161
		$criteres['transmission'] = 1;
-
 
162
		$chercheur_observations = new RechercheObservation($this->config);
-
 
163
		
-
 
164
		$debut = isset($criteres['debut']) ? $criteres['debut'] : 0;
94
		$numero_page = isset($criteres['debut']) ? $criteres['debut'] : 0;
165
		$limite = isset($criteres['limite']) ? $criteres['limite'] : 0;
95
		$limite = isset($criteres['limite']) ? $criteres['limite'] : 0;
166
		
96
		
167
		unset($criteres['limite']);
97
		unset($criteres['limite']);
168
		unset($criteres['debut']);
98
		unset($criteres['debut']);
169
		unset($criteres['format']);
99
	
170
		
100
		$observations = $chercheur_observations->rechercherObservations(null, $criteres, $numero_page, $limite);
171
		$observations = $chercheur_observations->rechercherObservations(null, $criteres, $debut, $limite);
101
		switch($this->format) {
172
		switch($this->format) {
102
			case 'csv':
173
			case 'csv':
103
				$csv = $this->convertirEnCsv($observations);
174
				$csv = $this->convertirEnCsv($observations);
104
				$this->envoyerCsv($csv);
175
				$this->envoyerCsv($csv);
105
			break;
176
				break;
106
			case 'xls':
177
			case 'xls':
Line 107... Line 178...
107
				$xls = $this->convertirEnXls($observations);
178
				$xls = $this->convertirEnXls($observations);
Line 157... Line 228...
157
	private function convertirEnXls($data) {		
228
	private function convertirEnXls($data) {		
158
		$this->extendSpreadsheetProductor = new SpreadsheetProductor();
229
		$this->extendSpreadsheetProductor = new SpreadsheetProductor();
159
		$this->extendSpreadsheetProductor->initSpreadsheet();
230
		$this->extendSpreadsheetProductor->initSpreadsheet();
Line 160... Line 231...
160
		
231
		
-
 
232
		$workbook = new Spreadsheet_Excel_Writer();
-
 
233
		$worksheet = $workbook->addWorksheet('Liste');
161
		$workbook = new Spreadsheet_Excel_Writer();
234
		$workbook->setTempDir($this->config['cel']['chemin_stockage_temp']);
Line 162... Line -...
162
		$workbook->setVersion(8);
-
 
163
 
235
		$workbook->setVersion(8);
164
		$worksheet = $workbook->addWorksheet('Liste');
236
 
Line 165... Line 237...
165
		$worksheet->setInputEncoding('utf-8');
237
		$worksheet->setInputEncoding('utf-8');