public function editAction() { // web page title $this->view->title = "Modification d'un produit"; // variables $recordID = (int) $this->_getParam($this->_paramId); $returnAction = $this->_getParam('return'); $baseDir = $this->view->baseUrl(); $lang = $this->_getParam('lang'); if (!$lang) { $this->_registry->currentEditLanguage = $this->_defaultEditLanguage; } $langId = (int) $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 . "/"; } $oCollections = new ProductsObject(); $collectionData = $oCollections->getAll($langId, true); $this->view->assign('collectionData', $collectionData); // get products details $oData = new ProductsObject(); $record = $oData->populate($recordID, $langId); // image src. $config = Zend_Registry::get('config')->toArray(); $thumbMaxHeight = $config[$this->_moduleTitle]['image']['thumb']['maxHeight']; $thumbMaxWidth = $config[$this->_moduleTitle]['image']['thumb']['maxWidth']; if (!empty($record[$this->_imageSrc])) { $this->view->assign('imageUrl', $this->_rootImgPath . $recordID . "/" . str_replace($record[$this->_imageSrc], $thumbMaxWidth . 'x' . $thumbMaxHeight . '_' . $record[$this->_imageSrc], $record[$this->_imageSrc])); $isNewImage = 'false'; } if ($this->_request->isPost()) { $formData = $this->_request->getPost(); if ($formData[$this->_imageSrc] != $record[$this->_imageSrc]) { if ($formData[$this->_imageSrc] == "") { $imageSrc = $this->view->baseUrl() . "/icons/image_non_ disponible.jpg"; } else { $imageSrc = $this->_rootImgPath . $recordID . "/tmp/mcith/mcith_" . $formData[$this->_imageSrc]; } $isNewImage = 'true'; } else { if ($record[$this->_imageSrc] == "") { $imageSrc = $this->view->baseUrl() . "/icons/image_non_ disponible.jpg"; } else { $imageSrc = $this->_rootImgPath . $recordID . "/" . str_replace($record[$this->_imageSrc], $thumbMaxWidth . 'x' . $thumbMaxHeight . '_' . $record[$this->_imageSrc], $record[$this->_imageSrc]); } } } else { if (empty($record[$this->_imageSrc])) { $imageSrc = $this->view->baseUrl() . "/icons/image_non_ disponible.jpg"; } else { $imageSrc = $this->_rootImgPath . $recordID . "/" . str_replace($record[$this->_imageSrc], $thumbMaxWidth . 'x' . $thumbMaxHeight . '_' . $record[$this->_imageSrc], $record[$this->_imageSrc]); } } // generate the form $form = new FormProducts(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()) { $association = new ProductsAssociationData(); $selectAssociation = $association->select(); $selectAssociation->where("AP_MainProductID = ?", $recordID); $associationFind = $association->fetchAll($selectAssociation)->toArray(); $collectionChoice = array(); foreach ($associationFind as $association) { $collectionChoice[] = $association['AP_RelatedProductID']; } $this->view->assign('collectionChoice', $collectionChoice); $oItem = new ItemsObject(); $itemList = $oItem->getAssociatedItems($recordID, $langId); $this->view->assign('renderItemsList', $itemList); $form->populate($record); } else { $formData = $this->_request->getPost(); if ($form->isValid($formData)) { $oData = new ProductsObject(); $newData = array_merge($formData['productFormLeft'], $formData['productFormRight'], $formData['productFormBotPub'], $formData['productFormBotPro']); $formattedName = Cible_FunctionsGeneral::formatValueForUrl($newData['PI_Name']); $newData['PI_ValUrl'] = $formattedName; $oData->save($recordID, $newData, $langId); // DELETE ASSOCIATION $association = new ProductsAssociationData(); $where = "AP_MainProductID = " . $recordID; $association->delete($where); // ADD Association if (array_key_exists("collectionSet", $formData)) { foreach ($formData['collectionSet'] as $collectionID) { $oAssociation = new ProductsAssociationData(); $associateData = $oAssociation->createRow(); $associateData->AP_MainProductID = $recordID; $associateData->AP_RelatedProductID = $collectionID; $associateData->save(); } } $newImage = $form->getSubForm('productFormRight')->getValue('isNewImage'); if ($newImage && $newData[$this->_imageSrc] != '') { $config = Zend_Registry::get('config')->toArray(); $srcOriginal = $this->_imageFolder . $recordID . "/tmp/" . $newData[$this->_imageSrc]; $originalMaxHeight = $config[$this->_moduleTitle]['image']['original']['maxHeight']; $originalMaxWidth = $config[$this->_moduleTitle]['image']['original']['maxWidth']; $originalName = str_replace($newData[$this->_imageSrc], $originalMaxWidth . 'x' . $originalMaxHeight . '_' . $newData[$this->_imageSrc], $newData[$this->_imageSrc]); $srcMedium = $this->_imageFolder . $recordID . "/tmp/medium_" . $newData[$this->_imageSrc]; $mediumMaxHeight = $config[$this->_moduleTitle]['image']['medium']['maxHeight']; $mediumMaxWidth = $config[$this->_moduleTitle]['image']['medium']['maxWidth']; $mediumName = str_replace($newData[$this->_imageSrc], $mediumMaxWidth . 'x' . $mediumMaxHeight . '_' . $newData[$this->_imageSrc], $newData[$this->_imageSrc]); $srcThumb = $this->_imageFolder . $recordID . "/tmp/thumb_" . $newData[$this->_imageSrc]; $thumbMaxHeight = $config[$this->_moduleTitle]['image']['thumb']['maxHeight']; $thumbMaxWidth = $config[$this->_moduleTitle]['image']['thumb']['maxWidth']; $thumbName = str_replace($newData[$this->_imageSrc], $thumbMaxWidth . 'x' . $thumbMaxHeight . '_' . $newData[$this->_imageSrc], $newData[$this->_imageSrc]); copy($srcOriginal, $srcMedium); copy($srcOriginal, $srcThumb); Cible_FunctionsImageResampler::resampled(array('src' => $srcOriginal, 'maxWidth' => $originalMaxWidth, 'maxHeight' => $originalMaxHeight)); Cible_FunctionsImageResampler::resampled(array('src' => $srcMedium, 'maxWidth' => $mediumMaxWidth, 'maxHeight' => $mediumMaxHeight)); Cible_FunctionsImageResampler::resampled(array('src' => $srcThumb, 'maxWidth' => $thumbMaxWidth, 'maxHeight' => $thumbMaxHeight)); rename($srcOriginal, $this->_imageFolder . $recordID . "/" . $originalName); rename($srcMedium, $this->_imageFolder . $recordID . "/" . $mediumName); rename($srcThumb, $this->_imageFolder . $recordID . "/" . $thumbName); } if ($formData['Status'] == 0) { $formData['Status'] = 2; } // redirect if (isset($formData['submitSaveClose'])) { $this->_redirect($returnUrl); } else { $this->_redirect($this->_moduleTitle . "/" . $this->_name . "/edit/productID/" . $recordID); } } else { if (array_key_exists("collectionSet", $formData)) { $this->view->assign('collectionChoice', $formData['collectionSet']); } else { $this->view->assign('collectionChoice', array()); } $form->populate($record); } } } }