Ejemplo n.º 1
0
 function addAction()
 {
     $this->view->title = "Ajout d'une image à une galerie";
     //if ($this->view->aclIsAllowed('gallery','manage',true)){
     $this->view->assign('isXmlHttpRequest', $this->_isXmlHttpRequest);
     $this->view->assign('success', false);
     $pageID = $this->_getParam('pageID');
     $blockID = $this->_getParam('blockID');
     $galleryID = $this->_getParam('galleryID');
     $baseDir = $this->view->baseUrl();
     $galleryObject = new GalleryObject();
     $galleryData = $galleryObject->populate($galleryID, Zend_Registry::get("languageID"));
     if ($this->_request->isPost()) {
         $formData = $this->_request->getPost();
         if ($formData['ImageSrc'] != '') {
             $imageSrc = Zend_Registry::get("www_root") . "/data/images/gallery/{$galleryID}/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";
     }
     if (!$galleryData) {
         if ($this->_request->isPost()) {
             $this->view->assign('success', true);
         }
         $this->view->assign('deleted', true);
         $this->view->assign('galleryID', $galleryID);
     } else {
         $this->view->assign('deleted', false);
         $cancelUrl = "/gallery/index/list/blockID/{$blockID}/pageID/{$pageID}";
         $form = new FormImage(array('baseDir' => $baseDir, 'cancelUrl' => "", 'galleryID' => $galleryID, 'imageID' => 0, 'addAction' => true));
         $this->view->form = $form;
         if ($this->_request->isPost()) {
             $formData = $this->_request->getPost();
             if ($form->isValid($formData)) {
                 if ($form->getValue('ImageSrc') == "") {
                     $form->getElement('ImageSrc')->addError('Vous devez choisir une image');
                 } else {
                     $imageObject = new ImageObject();
                     //$this->view->dump($formData); die();
                     $imageID = $imageObject->insert($formData, $this->_config->defaultEditLanguage);
                     $galleryImage = new GalleriesImages();
                     $galleryImageData = $galleryImage->createRow();
                     $galleryImageData->GI_GalleryID = $galleryID;
                     $galleryImageData->GI_ImageID = $imageID;
                     $galleryImageData->GI_Online = $form->getValue('GI_Online');
                     $galleryImageData->GI_Position = $form->getValue('GI_Position');
                     //$galleryImageData->GI_LinkOriginal  = $form->getValue('ImageSrc');
                     $galleryImageData->save();
                     $config = Zend_Registry::get('config')->toArray();
                     $srcOriginal = "../../{$this->_config->document_root}/data/images/gallery/" . $galleryID . "/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/" . $galleryID . "/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/" . $galleryID . "/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/" . $galleryID . "/tmp/mcith/mcith_" . $form->getValue('ImageSrc'), "../../{$this->_config->document_root}/data/images/gallery/" . $galleryID . "/" . $imageID . "/" . $thumbName);
                     if ($formData['GI_Online'] == 1 && $galleryData['G_Online'] == 1 && $blockID > 0) {
                         $blockParameters = Cible_FunctionsBlocks::getBlockParameters($blockID);
                         $categoryID = $blockParameters[0]['P_Value'];
                         $indexData['pageID'] = $categoryID;
                         $indexData['moduleID'] = $this->_moduleID;
                         $indexData['contentID'] = $galleryID;
                         $indexData['languageID'] = Zend_Registry::get("currentEditLanguage");
                         $indexData['title'] = $formData['II_Title'];
                         $indexData['text'] = '';
                         $indexData['link'] = 'image';
                         $indexData['contents'] = $formData['II_Title'] . " " . $formData['II_Description'];
                         $indexData['action'] = 'add';
                         Cible_FunctionsIndexation::indexation($indexData);
                     }
                     if (!$this->_isXmlHttpRequest) {
                         //$this->_redirect('/');
                         $this->_redirect("/gallery/index/list/blockID/{$blockID}/pageID/{$pageID}");
                     } else {
                         $buttonAction = $formData['buttonAction'];
                         $this->view->assign('buttonAction', $buttonAction);
                         $this->view->assign('success', true);
                         $this->view->assign('galleryID', $galleryID);
                         $this->view->assign('imageID', $imageID);
                         $this->view->assign('orginalName', $originalName);
                         $this->view->assign('thumbName', $thumbName);
                         $this->view->assign('imageTitle', $form->getValue('II_Title'));
                     }
                 }
             } else {
                 $form->populate($formData);
                 $form->getElement('ImageSrc_preview')->setAttrib('src', $imageSrc);
             }
         } else {
             $form->getElement('ImageSrc_preview')->setAttrib('src', $imageSrc);
         }
     }
     //}
 }