Subversion Repositories eFlore/Applications.cel

Rev

Rev 2414 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
class Generationimages extends Script {

        protected $bdd;
        protected $parametres_autorises = array(
                                '-id' => array(false, '1', 'Identifiants des images à traiter (séparés par des virgules')
                        );
        
        public function __construct($script_nom, $parametres_cli) {
                parent::__construct($script_nom, $parametres_cli);
                $this->bdd = new Bdd();
        }
        
        public function executer() {
                $cmd = $this->getParametre('a');
                switch($cmd) {
                        case 'genererMinaturesEnAttente';
                                $this->genererMiniaturesEnAttente();
                        break;
                        case 'genererMinaturesPourId';
                        $this->genererMinaturesPourId();
                        break;
                        default :
                                $msg = "Erreur : la commande '$cmd' n'existe pas!\n";
                        throw new Exception($msg);
                }
        }
        
        private function genererMinaturesPourId() {
                $id = $this->getParametre('id');
                $ids = explode(',',$id);
                if($id == null) {
                        echo "le paramètre id doit être un ensemble de nombres séparés par des virgules";
                } else {
                        include('ImageRecreation.php');
                        $createur_images = new ImageRecreation();
                        foreach($ids as $id_image) {
                                $createur_images->regenererMiniaturesPourId(array($id_image));
                        }
                }
        }
                
        private function genererMiniaturesEnAttente() {
                $req = "SELECT id_image FROM cel_images WHERE ".
                        "date_creation >= DATE_SUB(NOW(), INTERVAL 15 MINUTE)";
                $images_attente = $this->bdd->recupererTous($req);
                
                if(!empty($images_attente)) {                                   
                        // iterer sur config pour formats
                        include('ImageRecreation.php');
                        $createur_images = new ImageRecreation();
                        foreach($images_attente as $image) {
                                $createur_images->regenererMiniaturesPourId(array($image['id_image']));
                        }
                }
        }
}       
?>