public function saveAction() { if ($datas = $this->getRequest()->getPost()) { try { // S'il y a embrouille if (empty($datas['block_id'])) { throw new Exception($this->_('An error occurred while saving your colors.')); } // Récupère l'application en cours $application = $this->getApplication(); // Récupère le block $block = new Template_Model_Block(); $block->find($datas['block_id']); // S'il y a re-embrouille if (!$block->getId()) { throw new Exception($this->_('An error occurred while saving your colors.')); } if (!empty($datas['color'])) { $block->setData('color', $datas['color']); } if (!empty($datas['background_color'])) { $block->setData('background_color', $datas['background_color']); } if (!empty($datas['tabbar_color'])) { $block->setData('image_color', $datas['tabbar_color']); } $block->save(); $html = array('success' => '1'); } catch (Exception $e) { $html = array('message' => $e->getMessage()); } $this->getLayout()->setHtml(Zend_Json::encode($html)); } }
public function duplicate() { // Retrieve all the accounts $admins = $this->getAdmins(); $admin_ids = array(); foreach ($admins as $admin) { $admin_ids[] = $admin; } // Retrieve the design $blocks = array(); foreach ($this->getBlocks() as $block) { $blocks[] = $block->getData(); } $layout_id = $this->getLayoutId(); // Load the options $option_values = $this->getOptions(); $value_ids = array(); // Save the new application $old_app_id = $this->getId(); $this->setId(null)->setName($this->getName() . " (Copy)")->setLayoutId($layout_id)->unsCreatedAt()->unsUpdatedAt()->setBundleId(null)->setDomain(null)->setSubdomain(null)->setSubdomainIsValidated(null)->save(); // Save the design if (!empty($blocks)) { foreach ($blocks as $template_block) { $block = new Template_Model_Block(); $block->setData($template_block); $block->setAppId($this->getId()); $block->save(); } } $this->setLayoutId($layout_id)->save(); // Copy all the features but folders foreach ($option_values as $option_value) { if ($option_value->getCode() != 'folder') { $option_value->copyTo($this); $value_ids[$option_value->getOldValueId()] = $option_value->getId(); } } // Copy the folders foreach ($option_values as $option_value) { if ($option_value->getCode() == 'folder') { $option_value->copyTo($this); $value_ids[$option_value->getOldValueId()] = $option_value->getId(); } } // Lock the features $locker = new Padlock_Model_Padlock(); $old_locked_value_ids = $locker->getValueIds($old_app_id); $locked_value_ids = array(); foreach ($old_locked_value_ids as $old_locked_value_id) { if (!empty($value_ids[$old_locked_value_id])) { $locked_value_ids[] = $value_ids[$old_locked_value_id]; } } if (!empty($locked_value_ids)) { $locker->setValueIds($locked_value_ids)->saveValueIds($this->getId()); } // Set the accounts to the application $this->setAdminIds($admin_ids); $this->save(); return $this; }