/[openfoncier]/trunk/services/metier/consultationmanager.php
ViewVC logotype

Diff of /trunk/services/metier/consultationmanager.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 577 by mlimic, Fri Nov 2 10:10:56 2012 UTC revision 744 by fmichon, Mon Nov 19 11:52:29 2012 UTC
# Line 1  Line 1 
1  <?php  <?php
2    /**
3  /*   * Ce fichier permet de déclarer la classe ConsultationManager, qui effectue les
4   * Processes requests received via services which concern consultations (by   * traitements pour la ressource 'consultations'.
  * ERP or other services).  
  *  
  * @author Mirna Limic <[email protected]>  
  * Date: 18/10/2012  
5   *   *
6   * Follow-up:   * @package openfoncier
7   * Bugs:   * @version SVN : $Id$
8   */   */
9    
10    // Inclusion de la classe de base MetierManager
11    require_once("./metier/metiermanager.php");
12    
13  require_once ("./metier/metiermanager.php");  // Inclusion de la classe métier consultation
14  require_once("../obj/consultation.class.php");  require_once("../obj/consultation.class.php");
15    
16    /**
17     * Cette classe hérite de la classe MetierManager. Elle permet d'effectuer des
18     * traitements pour la ressource 'consultations'. Le traitement permet de
19     * rendre un retour d'avis sur une consultation existante par un service
20     * interne à la mairie directement depuis son application.
21     *
22     * @todo XXX Traduire et commenter toutes les méthodes
23     */
24  class ConsultationManager extends MetierManager {  class ConsultationManager extends MetierManager {
       
25    
26      /*      /**
27       * Constructor.       * Constructeur
28       *       *
29       * Calls it's parent constructor to establish a DB connection       * @todo XXX Ajouter la description des attributs
30       * and initializes the instance variables       */
      */      
31      public function __construct() {      public function __construct() {
32    
33            // Appel du constructeur parent
34          parent::__construct();          parent::__construct();
35          /*$this->date_limite = null;  
36          $this->date_retour = null;          //
         $this->date_envoi = null;  
         $this->dossier_id = null;*/  
37          $this->decisions = null;          $this->decisions = null;
38          $this->metier_instance = null;          $this->metier_instance = null;
39          $this->filename_prefix = null;          $this->filename_prefix = null;
40          $this->filename = null;          $this->filename = null;
41    
42      }      }
43        
44            /**
45      /*       * Destructeur
46       * Destructor       */
      *  
      * Call's its parent's destructor.  
      */      
47      public function __destruct() {      public function __destruct() {
48    
49            // Appel du destructeur parent
50          parent::__destruct();          parent::__destruct();
51    
52      }      }
       
53    
54      /*      /**
55       * Verifies that the date_retour received in the incomming data       * Verifies that the date_retour received in the incomming data
56       * is in the (date_envoi, date_limite) interval. Also, check that       * is in the (date_envoi, date_limite) interval. Also, check that
57       * there is no date_retour set for the consultation, as well as the       * there is no date_retour set for the consultation, as well as the
# Line 90  class ConsultationManager extends Metier Line 94  class ConsultationManager extends Metier
94          return $this->OK;          return $this->OK;
95      }      }
96    
97        /**
     /*  
98       * Verifies that the avis received in the incomming data corresponds       * Verifies that the avis received in the incomming data corresponds
99       * to one of the avis found in DB.       * to one of the avis found in DB.
100       * @param string $avis The avis recived in the request       * @param string $avis The avis recived in the request
# Line 100  class ConsultationManager extends Metier Line 103  class ConsultationManager extends Metier
103       */       */
104      private function avisValid($avis, $id) {      private function avisValid($avis, $id) {
105          // get all of the decisions possible from table avis_decision          // get all of the decisions possible from table avis_decision
106          $sql = "SELECT libelle, avis_consultation FROM avis_consultation";          $sql = "SELECT libelle, avis_consultation FROM ".DB_PREFIXE."avis_consultation";
107          $res = $this->db->query($sql);          $res = $this->db->query($sql);
108          if ($this->checkDBError($res, 'Erreur lors de recuperation des avis '.          if ($this->checkDBError($res, 'Erreur lors de recuperation des avis '.
109                  'possibles pendant traitement de la consultation '.$id)) {                  'possibles pendant traitement de la consultation '.$id)) {
# Line 122  class ConsultationManager extends Metier Line 125  class ConsultationManager extends Metier
125          return $this->OK;          return $this->OK;
126      }      }
127    
128            /**
     /*  
129       * Verifies that all the data concerning file to be stored (if any)       * Verifies that all the data concerning file to be stored (if any)
130       * are present in full or not present at all       * are present in full or not present at all
131       * @param mixed $data The data recived in the request       * @param mixed $data The data recived in the request
# Line 142  class ConsultationManager extends Metier Line 144  class ConsultationManager extends Metier
144          return $this->OK;          return $this->OK;
145      }      }
146    
147        /**
     /*  
      * Store the data recived in the request into a file on the  
      * local filesystem.  
      * @todo This function will need to be changed for the save to  
      * be on GED  
      * @param mixed $data The data received with the request  
      * @param string $id The consultation ID  
      * @return string OK on success, KO otherwise  
      */  
     private function storeDecisionFile(&$data, $id) {  
         if (isset($data['fichier_base64'])) {  
             $dir = dirname(__FILE__).'/../../trs/'.$this->dossier_id;  
               
             // if a file already exists by that name and it  
             // is not a directory, back out  
             if (file_exists($dir) && !is_dir($dir)) {  
                 $this->setMessage("Fichier d'avis ne peut pas être ".  
                 "enregistré pour la consultation ".$id);  
                 return $this->KO;        
             }  
             // if a dirextory by that name exists, make sure it does  
             // not already contain an avis de consultation  
             if (file_exists($dir) && is_dir($dir)) {  
                 $dir_contents = trim(shell_exec('ls '.$dir));  
                 if (strpos($dir_contents, ' ') != false) {  
                     $dir_contents = explode(' ', $dir_contents);  
                 } else {  
                     $dir_contents = array($dir_contents);  
                 }  
                 foreach ($dir_contents as $filename) {  
                     if (strspn($filename, $this->filename_prefix, 0) > 0) {  
                         $this->setMessage("Un fichier d'avis existe déjà ".  
                         "pour la consultation ".$id);  
                         return $this->KO;  
                     }  
                 }  
             }  
             // if no file by that name exists, create the directory  
             if (!file_exists($dir)) {  
                 if (!mkdir($dir, 0775)) {  
                     $this->setMessage("Erreur dans la création de répertoire ".  
                     "pour la sauvegarde de l'avis de la consultation ".$id);  
                     return $this->KO;  
                 }  
             }  
   
               
             // store the file contents into the file named:  
             //      consultation_<ID>_<file_name_received>  
             $file_len = strlen($data['fichier_base64']);  
             $filename = $dir.$this->metier_instance->valF['dossier'].'/'.  
                     $this->filename_prefix.$data['nom_fichier'];  
             $this->filename = $filename;  
             $file = fopen($filename, 'w');  
             if (!$file) {  
                 $this->setMessage("Echec en création de pointeur de fichier ".  
                     "pour la sauvegarde de l'avis de la consultation ".$id);  
                 return $this->KO;  
             }  
             // check that the number of bytes written is equal to the length  
             // of the data received  
             $num_written = fwrite($file, $data['fichier_base64'], $file_len);  
             if (!$num_written || $num_written != $file_len) {  
                 $this->setMessage("Sauvegarde de fichier d'avis pour la ".  
                 "consultation ".$id." a échouée");  
                 // remove the file  
                 // the return value from shell can't be used for checking since  
                 // one can not know if the NULL returned is because there was no  
                 // output or because there was an error  
                 $ret = shell_exec("rm -f $filename 2>&1");  
                 //if ($ret == NULL) { // an error occured while deleting the file  
                 //    $msg = $this->getMessage();  
                 //    $this->setMessage($msg . ' Problème pendent la suppression '.  
                 //            'des données corrompues');  
                 //}  
                 return $this->KO;  
             }  
             fclose($file);  
         }  
         return $this->OK;  
     }  
       
     /*  
148       * Called when one of the external services sends its recommendation       * Called when one of the external services sends its recommendation
149       * as a responde to a demand issued by openfoncier.       * as a responde to a demand issued by openfoncier.
150       * @param mixed $data The array containing building number.       * @param mixed $data The array containing building number.
# Line 268  class ConsultationManager extends Metier Line 187  class ConsultationManager extends Metier
187          $res = $this->avisValid($data['avis'], $id);          $res = $this->avisValid($data['avis'], $id);
188          if ($res != $this->OK) {          if ($res != $this->OK) {
189              return $res;              return $res;
         }          
         // first store the file if needed  
         $res = $this->storeDecisionFile($data, $id);  
         if ($res != $this->OK) {  
             return $res;  
190          }          }
191            if(isset($data['fichier_base64'])) {
192                if($file_content = base64_decode ($data['fichier_base64'] , TRUE )) {
193                    // first store the file if needed
194                    $res = $this->f->storeDecisionFile($file_content,
195                                               $data['nom_fichier'],
196                                               $this->metier_instance->valF['dossier'],
197                                               $this->filename_prefix);
198                    if ($res !== true) {
199                        return $res;
200                    }
201                } else {
202                    $this->setMessage(_("Le contenu du fichier n'est pas valide."));
203                    return $this->BAD_DATA;
204                }
205            }
206    
207          $this->metier_instance->valF['date_retour'] = $data['date_retour'];          $this->metier_instance->valF['date_retour'] = $data['date_retour'];
208          $this->metier_instance->valF['avis_consultation'] = $this->decisions[$data['avis']];          $this->metier_instance->valF['avis_consultation'] = $this->decisions[$data['avis']];
209          $this->metier_instance->valF['lu'] = FALSE;          $this->metier_instance->valF['lu'] = FALSE;
# Line 295  class ConsultationManager extends Metier Line 225  class ConsultationManager extends Metier
225          }          }
226          return $ret;          return $ret;
227      }      }
228        
       
229  }  }
230    
231  ?>  ?>

Legend:
Removed from v.577  
changed lines
  Added in v.744

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26