Ejemplo n.º 1
0
 public function addAction()
 {
     $dir = "../../{$this->_config->document_root}/data/images/gallery/tmp";
     //echo $dir;
     if (!file_exists($dir)) {
         mkdir($dir);
     }
     $this->view->title = "Ajout d'une galerie";
     //if ($this->view->aclIsAllowed('gallery','manage',true)){
     // variables
     $this->view->assign('isXmlHttpRequest', $this->_isXmlHttpRequest);
     $this->view->assign('success', false);
     $pageID = $this->_getParam('pageID');
     $blockID = $this->_getParam('blockID');
     $baseDir = $this->view->baseUrl();
     if ($this->_request->isPost()) {
         $formData = $this->_request->getPost();
         if ($formData['ImageSrc'] != '') {
             $imageSrc = Zend_Registry::get("www_root") . "/data/images/gallery/tmp/mcith/mcith_" . $formData['ImageSrc'];
         } else {
             $imageSrc = $this->view->baseUrl() . "/icons/image_non_ disponible.jpg";
         }
     } else {
         $imageSrc = $this->view->baseUrl() . "/icons/image_non_ disponible.jpg";
     }
     // generate the form
     if ($blockID != '') {
         $cancelUrl = "{$baseDir}/gallery/index/list/blockID/{$blockID}/pageID/{$pageID}";
     } elseif ($this->_categoryID != '') {
         $cancelUrl = "{$baseDir}/gallery/index/list/catID/{$this->_categoryID}";
     } else {
         $cancelUrl = "{$baseDir}/gallery/index/list/";
     }
     $form = new FormGallery(array('baseDir' => $baseDir, 'cancelUrl' => '', 'galleryID' => '', 'imageSrc' => $imageSrc, 'isNewImage' => 'true', 'addAction' => true, 'requiredTitle' => true, 'requiredPosition' => false, 'requiredDescription' => false));
     $this->view->form = $form;
     if ($this->_request->isPost()) {
         $formData = $this->_request->getPost();
         if ($form->isValid($formData)) {
             $formData['G_CreationDate'] = date("Y-m-d");
             $formData['G_ImageID'] = '0';
             if ($blockID != '') {
                 $blockParameters = Cible_FunctionsBlocks::getBlockParameters($blockID);
                 $formData['G_CategoryID'] = $blockParameters[0]['P_Value'];
             } else {
                 if ($this->_categoryID > 0) {
                     $formData['G_CategoryID'] = $this->_categoryID;
                 }
             }
             $galleryObject = new GalleryObject();
             $formattedName = Cible_FunctionsGeneral::formatValueForUrl($formData['GI_Title']);
             $formData['GI_ValUrl'] = $formattedName;
             $galleryID = $galleryObject->insert($formData, $this->_config->defaultEditLanguage);
             mkdir("../../{$this->_config->document_root}/data/images/gallery/" . $galleryID) or die("Could not make directory");
             mkdir("../../{$this->_config->document_root}/data/images/gallery/" . $galleryID . "/tmp") or die("Could not make directory");
             // create the image
             $imageObject = new ImageObject();
             $formData['II_Title'] = $formData['GI_Title'];
             $formData['II_Description'] = $formData['GI_Description'];
             $imageID = $imageObject->insert($formData, $this->_config->defaultEditLanguage);
             // update the galery
             $galleryData = $galleryObject->populate($galleryID, Zend_Registry::get("currentEditLanguage"));
             $formData['G_CreationDate'] = $galleryData['G_CreationDate'];
             $formData['G_ImageID'] = $imageID;
             $galleryObject->save($galleryID, $formData, Zend_Registry::get("currentEditLanguage"));
             $config = Zend_Registry::get('config')->toArray();
             if ($form->getValue('ImageSrc') != "") {
                 $srcOriginal = "../../{$this->_config->document_root}/data/images/gallery/tmp/" . $form->getValue('ImageSrc');
                 $originalMaxHeight = $config['gallery']['image']['original']['maxHeight'];
                 $originalMaxWidth = $config['gallery']['image']['original']['maxWidth'];
                 $originalName = str_replace($form->getValue('ImageSrc'), $originalMaxWidth . 'x' . $originalMaxHeight . '_' . $form->getValue('ImageSrc'), $form->getValue('ImageSrc'));
                 $srcThumb = "../../{$this->_config->document_root}/data/images/gallery/tmp/mcith/mcith_" . $form->getValue('ImageSrc');
                 $thumbMaxHeight = $config['gallery']['image']['thumb']['maxHeight'];
                 $thumbMaxWidth = $config['gallery']['image']['thumb']['maxWidth'];
                 $thumbName = str_replace($form->getValue('ImageSrc'), $thumbMaxWidth . 'x' . $thumbMaxHeight . '_' . $form->getValue('ImageSrc'), $form->getValue('ImageSrc'));
                 Cible_FunctionsImageResampler::resampled(array('src' => $srcOriginal, 'maxWidth' => $originalMaxWidth, 'maxHeight' => $originalMaxHeight));
                 Cible_FunctionsImageResampler::resampled(array('src' => $srcThumb, 'maxWidth' => $thumbMaxWidth, 'maxHeight' => $thumbMaxHeight));
                 // Attempts to create the directory specified by pathname.
                 mkdir("../../{$this->_config->document_root}/data/images/gallery/" . $galleryID . "/" . $imageID) or die("Could not make directory");
                 // Rename and move the original image to the specific place
                 rename("../../{$this->_config->document_root}/data/images/gallery/tmp/" . $form->getValue('ImageSrc'), "../../{$this->_config->document_root}/data/images/gallery/" . $galleryID . "/" . $imageID . "/" . $originalName);
                 // Rename and move the thumbnail image to the specific place
                 rename("../../{$this->_config->document_root}/data/images/gallery/tmp/mcith/mcith_" . $form->getValue('ImageSrc'), "../../{$this->_config->document_root}/data/images/gallery/" . $galleryID . "/" . $imageID . "/" . $thumbName);
             }
             if ($formData['G_Online'] == 1 && $blockID != '') {
                 $indexData['pageID'] = $blockParameters[0]['P_Value'];
                 $indexData['moduleID'] = $this->_moduleID;
                 $indexData['contentID'] = $galleryID;
                 $indexData['languageID'] = Zend_Registry::get("currentEditLanguage");
                 $indexData['title'] = $formData['GI_Title'];
                 $indexData['text'] = '';
                 $indexData['link'] = 'gallery';
                 $indexData['contents'] = $formData['GI_Title'] . " " . $formData['GI_Description'];
                 $indexData['action'] = 'add';
                 Cible_FunctionsIndexation::indexation($indexData);
             }
             if (!$this->_isXmlHttpRequest) {
                 //$this->_redirect('/');
                 if ($blockID != '') {
                     $this->_redirect("/gallery/index/list/blockID/{$blockID}/pageID/{$pageID}");
                 } elseif ($this->_categoryID != '') {
                     $this->_redirect("/gallery/index/list/catID/{$this->_categoryID}");
                 } else {
                     $this->_redirect("/gallery/index/list/");
                 }
             } else {
                 $buttonAction = $formData['buttonAction'];
                 $this->view->assign('buttonAction', $buttonAction);
                 $this->view->assign('success', true);
                 $this->view->assign('galleryID', $galleryID);
                 $this->view->assign('galleryTitle', $form->getValue('GI_Title'));
                 $this->view->assign('galleryDescription', $form->getValue('GI_Description'));
                 $this->view->assign('galleryDate', $formData['G_CreationDate']);
             }
             //exit;
         } else {
             $form->populate($formData);
         }
     }
     //}
 }