Пример #1
0
 /**
  * @see parent::store()
  */
 function store()
 {
     if ($this->_id && ($this->fieldModified("object_id") || $this->fieldModified("object_class"))) {
         $this->_old->updateFormFields();
         $this->moveFile($this->_old->_file_path);
     }
     // Make sure filename is unique for an object
     if (!$this->_id) {
         $this->completeField("file_name");
         $this->completeField("object_class");
         $this->completeField("object_id");
         $ds = $this->_spec->ds;
         $where["object_class"] = " = '{$this->object_class}'";
         $where["object_id"] = " = '{$this->object_id}'";
         $where["file_name"] = $ds->prepare("= %", $this->file_name);
         if ($this->countList($where)) {
             $last_point = strrpos($this->file_name, '.');
             $base_name = substr($this->file_name, 0, $last_point);
             $extension = substr($this->file_name, $last_point + 1);
             $indice = 1;
             do {
                 $indice++;
                 $suffixe = sprintf(" %02s", $indice);
                 $file_name = "{$base_name}{$suffixe}.{$extension}";
                 $where["file_name"] = $ds->prepare("= %", $file_name);
             } while ($this->countList($where));
             $this->file_name = $file_name;
         }
     }
     if (!$this->_id && $this->rotation === null) {
         $this->loadNbPages();
         $this->rotation = $this->rotation === null ? 0 : $this->rotation;
         $this->rotation %= 360;
     }
     if ($this->_rotate !== null) {
         $this->completeField("rotation");
         if ($this->_rotate == "left") {
             $this->rotation += 90;
         }
         if ($this->_rotate == "right") {
             $this->rotation -= 90;
         }
         $this->rotation %= 360;
         if ($this->rotation < 0) {
             $this->rotation += 360;
         }
         $this->rotation = $this->rotation % 360;
         if ($this->rotation < 0) {
             $this->rotation += 360;
         }
     }
     return parent::store();
 }
 /**
  * Enregistrement du document / modèle
  * 
  * @return string 
  */
 function store()
 {
     $this->completeField("content_id", "_source", "language", "version");
     if (!$this->creation_date) {
         $this->creation_date = CMbDT::dateTime();
         if ($this->_id) {
             $this->creation_date = $this->loadFirstLog()->date;
         }
     }
     // Prevent source modification when not editing the doc
     $this->loadContent($this->_send || $this->_source === null);
     $source_modified = $this->_ref_content->content != $this->_source || $this->fieldModified("margin_top") || $this->fieldModified("margin_left") || $this->fieldModified("margin_right") || $this->fieldModified("margin_bottom") || $this->fieldModified("page_height") || $this->fieldModified("page_width") || $this->fieldModified("header_id") || $this->fieldModified("preface_id") || $this->fieldModified("ending_id") || $this->fieldModified("footer_id");
     if ($source_modified || $this->fieldModified("valide")) {
         // Empty PDF File
         /** @var CFile $_file */
         foreach ($this->loadBackRefs("files") as $_file) {
             $_file->fileEmpty();
         }
     }
     if ($source_modified) {
         // Bug IE : delete id attribute
         $this->_source = CCompteRendu::restoreId($this->_source);
         $this->doc_size = strlen($this->_source);
         // Send status to obsolete
         $this->completeField("etat_envoi");
         if ($source_modified && $this->etat_envoi == "oui") {
             $this->etat_envoi = "obsolete";
         }
     }
     $this->_ref_content->content = $this->_source;
     if (!$this->_id) {
         $parent_modele = $this->loadModele();
         $parent_modele->loadContent(false);
         // Si issu d'une duplication depuis un document existant, alors on reprend la version du document d'origine
         // L'incrément de version se fait en fin de store
         if ($parent_modele->object_id) {
             $this->version = $parent_modele->version;
             $parent_modele->isAutoLock();
             // Si le document existant est verrouillé, alors on l'archive
             if ($parent_modele->valide || $parent_modele->_is_auto_locked) {
                 $parent_modele->annule = 1;
                 $parent_modele->store();
             }
         }
     }
     if ($msg = $this->_ref_content->store()) {
         CAppUI::setMsg($msg, UI_MSG_ERROR);
     }
     // Prevent modele_id = compte_rendu_id
     // But, allow to save the content
     if ($this->_id === $this->modele_id) {
         $this->modele_id = "";
     }
     // Detect the fields not completed
     $matches = array();
     preg_match_all("/(field|name)\">(\\[)+[^\\]]+(\\])+<\\/span>/ms", $this->_source, $matches);
     $this->fields_missing = count($matches[0]);
     if (!$this->content_id) {
         $this->content_id = $this->_ref_content->_id;
     }
     if (!$this->_id) {
         $this->author_id = CMediusers::get()->_id;
     }
     if ($this->factory == "none" || !$this->factory) {
         $this->factory = CAppUI::pref("dPcompteRendu choice_factory");
         if (!$this->factory) {
             $this->factory = "CWkHtmlToPDFConverter";
         }
     }
     $this->version++;
     return parent::store();
 }