Subversion Repositories eFlore/Applications.cel

Rev

Rev 2414 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2119 aurelien 1
<?php
2414 jpm 2
// declare(encoding='UTF-8');
3
/**
4
 * Génère des miniatures.
5
 *
6
 * Utilisation :
7
 * - Pour ? : <code>/opt/lamp/bin/php cli.php generation_images -a genererMinaturesEnAttente</code>
8
 * - Pour ? : <code>/opt/lamp/bin/php cli.php generation_images -a genererMinaturesEnAttente</code>
9
 *
10
 * @category   CEL
11
 * @package    Scripts
12
 * @subpackage Génération Images
13
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
14
 * @author     Jean-Pascal MILCENT <jpm@tela-botanica.org>
15
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
16
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
17
 * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
18
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
19
 */
20
class GenerationImages extends Script {
2119 aurelien 21
 
22
	protected $bdd;
23
	protected $parametres_autorises = array(
2414 jpm 24
			'-id' => array(false, '1', 'Identifiants des images à traiter (séparés par des virgules')
25
		);
26
 
2119 aurelien 27
	public function __construct($script_nom, $parametres_cli) {
28
		parent::__construct($script_nom, $parametres_cli);
29
		$this->bdd = new Bdd();
30
	}
2414 jpm 31
 
2119 aurelien 32
	public function executer() {
33
		$cmd = $this->getParametre('a');
34
		switch($cmd) {
35
			case 'genererMinaturesEnAttente';
36
				$this->genererMiniaturesEnAttente();
2414 jpm 37
				break;
2119 aurelien 38
			case 'genererMinaturesPourId';
2414 jpm 39
				$this->genererMinaturesPourId();
40
				break;
2119 aurelien 41
			default :
42
				$msg = "Erreur : la commande '$cmd' n'existe pas!\n";
2414 jpm 43
				throw new Exception($msg);
2119 aurelien 44
		}
45
	}
2414 jpm 46
 
2119 aurelien 47
	private function genererMinaturesPourId() {
48
		$id = $this->getParametre('id');
49
		$ids = explode(',',$id);
2414 jpm 50
		if ($id == null) {
2119 aurelien 51
			echo "le paramètre id doit être un ensemble de nombres séparés par des virgules";
52
		} else {
2414 jpm 53
			include_once dirname(__FILE__).'/bibliotheque/ImageRecreation.php';
2119 aurelien 54
			$createur_images = new ImageRecreation();
2414 jpm 55
			foreach ($ids as $id_image) {
2119 aurelien 56
				$createur_images->regenererMiniaturesPourId(array($id_image));
57
			}
58
		}
59
	}
2414 jpm 60
 
2119 aurelien 61
	private function genererMiniaturesEnAttente() {
2436 jpm 62
		$requete = 'SELECT id_image '.
63
			'FROM cel_images '.
64
			'WHERE date_creation >= DATE_SUB(NOW(), INTERVAL 15 MINUTE)';
65
		$images_attente = $this->bdd->recupererTous($requete);
2414 jpm 66
 
67
		if (!empty($images_attente)) {
2119 aurelien 68
			// iterer sur config pour formats
2414 jpm 69
			include_once dirname(__FILE__).'/bibliotheque/ImageRecreation.php';
2119 aurelien 70
			$createur_images = new ImageRecreation();
2414 jpm 71
			foreach ($images_attente as $image) {
2119 aurelien 72
				$createur_images->regenererMiniaturesPourId(array($image['id_image']));
73
			}
74
		}
75
	}
2414 jpm 76
}