Ejemplo n.º 1
0
 public function editAction()
 {
     // web page title
     $this->view->title = "Édition d'une sous-catégorie";
     // variables
     $recordID = $this->_getParam($this->_paramId);
     $returnAction = $this->_getParam('return');
     $baseDir = $this->view->baseUrl();
     $lang = $this->_getParam('lang');
     if (!$lang) {
         $this->_registry->currentEditLanguage = $this->_defaultEditLanguage;
     }
     $langId = $this->_registry->currentEditLanguage;
     if ($this->view->aclIsAllowed($this->_moduleTitle, 'edit', true)) {
         $cancelUrl = $baseDir . "/" . $this->_moduleTitle . "/" . $this->_name . "/" . $this->_defaultAction . "/";
         if ($returnAction) {
             $returnUrl = $this->_moduleTitle . "/" . $this->_name . "/" . $returnAction;
         } else {
             $returnUrl = $this->_moduleTitle . "/" . $this->_name . "/" . $this->_defaultAction . "/";
         }
         // get event details
         $oSubCategories = new SubCategoriesObject();
         $data = $oSubCategories->populate($recordID, $langId);
         // image src.
         $config = Zend_Registry::get('config')->toArray();
         $imageSrc = "";
         // generate the form
         $form = new FormSubCategories(array('moduleName' => $this->_moduleTitle . '/' . $this->_name, 'baseDir' => $baseDir, 'cancelUrl' => $cancelUrl, 'imageSrc' => $imageSrc, 'imgField' => $this->_imageSrc, 'dataId' => $recordID, 'isNewImage' => true));
         $this->view->form = $form;
         // action
         if (!$this->_request->isPost()) {
             $form->populate($data);
         } else {
             $formData = $this->_request->getPost();
             if ($form->isValid($formData)) {
                 $formattedName = Cible_FunctionsGeneral::formatValueForUrl($formData['SCI_Name']);
                 $formData['SCI_ValUrl'] = $formattedName;
                 if ($formData['isNewImage'] == 'true' && $form->getValue($this->_imageSrc) != '') {
                     $config = Zend_Registry::get('config')->toArray();
                     $srcOriginal = $this->_imageFolder . $recordID . "/tmp/" . $form->getValue($this->_imageSrc);
                     $originalMaxHeight = $config[$this->_moduleTitle]['image']['original']['maxHeight'];
                     $originalMaxWidth = $config[$this->_moduleTitle]['image']['original']['maxWidth'];
                     $originalName = str_replace($form->getValue($this->_imageSrc), $originalMaxWidth . 'x' . $originalMaxHeight . '_' . $form->getValue($this->_imageSrc), $form->getValue($this->_imageSrc));
                     $srcMedium = $this->_imageFolder . $recordID . "/tmp/medium_" . $form->getValue($this->_imageSrc);
                     $mediumMaxHeight = $config[$this->_moduleTitle]['image']['medium']['maxHeight'];
                     $mediumMaxWidth = $config[$this->_moduleTitle]['image']['medium']['maxWidth'];
                     if ($mediumMaxHeight > 0 && $mediumMaxWidth > 0) {
                         $mediumName = str_replace($form->getValue($this->_imageSrc), $mediumMaxWidth . 'x' . $mediumMaxHeight . '_' . $form->getValue($this->_imageSrc), $form->getValue($this->_imageSrc));
                         copy($srcOriginal, $srcMedium);
                     }
                     $srcThumb = $this->_imageFolder . $recordID . "/tmp/thumb_" . $form->getValue($this->_imageSrc);
                     $thumbMaxHeight = $config[$this->_moduleTitle]['image']['thumb']['maxHeight'];
                     $thumbMaxWidth = $config[$this->_moduleTitle]['image']['thumb']['maxWidth'];
                     $thumbName = str_replace($form->getValue($this->_imageSrc), $thumbMaxWidth . 'x' . $thumbMaxHeight . '_' . $form->getValue($this->_imageSrc), $form->getValue($this->_imageSrc));
                     copy($srcOriginal, $srcThumb);
                     Cible_FunctionsImageResampler::resampled(array('src' => $srcOriginal, 'maxWidth' => $originalMaxWidth, 'maxHeight' => $originalMaxHeight));
                     Cible_FunctionsImageResampler::resampled(array('src' => $srcThumb, 'maxWidth' => $thumbMaxWidth, 'maxHeight' => $thumbMaxHeight));
                     if ($mediumMaxHeight > 0 && $mediumMaxWidth > 0) {
                         Cible_FunctionsImageResampler::resampled(array('src' => $srcMedium, 'maxWidth' => $mediumMaxWidth, 'maxHeight' => $mediumMaxHeight));
                         rename($srcMedium, $this->_imageFolder . $recordID . "/" . $mediumName);
                     }
                     rename($srcOriginal, $this->_imageFolder . $recordID . "/" . $originalName);
                     rename($srcThumb, $this->_imageFolder . $recordID . "/" . $thumbName);
                 }
                 $oSubCategories->save($recordID, $formData, $langId);
                 // redirect
                 if (!empty($pageID)) {
                     $this->_redirect($this->_moduleTitle . "/" . $this->_name . "/" . $this->_defaultAction . "/blockID/{$blockID}/pageID/{$pageID}");
                 } else {
                     $this->_redirect($returnUrl);
                 }
             }
         }
     }
 }