public function editAction() { if ($datas = $this->getRequest()->getPost()) { try { $application = $this->getApplication(); // Test s'il y a un value_id if (empty($datas['agenda_id'])) { throw new Exception($this->_('An error occurred while saving. Please try again later.')); } $event = new Event_Model_Event_Custom(); $option_value = $this->getCurrentOptionValue(); $data = array(); if (!empty($datas['id'])) { $event->find($datas['id']); if ($event->getAgendaId() != $datas['agenda_id']) { throw new Exception($this->_('An error occurred while saving. Please try again later.')); } } if (!empty($datas['picture'])) { if (substr($datas['picture'], 0, 1) == '/') { unset($datas['picture']); } else { $application = $this->getApplication(); $illus_relative_path = '/feature/' . $option_value->getId() . '/'; $folder = Application_Model_Application::getBaseImagePath() . $illus_relative_path; $file = Core_Model_Directory::getTmpDirectory(true) . '/' . $datas['picture']; if (!is_dir($folder)) { mkdir($folder, 0777, true); } if (!copy($file, $folder . $datas['picture'])) { throw new exception($this->_("An error occurred while saving your picture. Please try againg later.")); } else { $datas['picture'] = $illus_relative_path . $datas['picture']; } } } else { $datas['picture'] = null; } if (!empty($datas['rsvp']) and stripos($datas['rsvp'], 'http') === false) { $datas['rsvp'] = 'http://' . $datas['rsvp']; } $event->addData($datas)->save(); $cache = Zend_Registry::get('cache'); $cache->remove($option_value->getObject()->getCacheId()); $html = array('success' => '1', 'success_message' => $this->_("Event successfully saved"), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0); } catch (Exception $e) { $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1); } $this->getLayout()->setHtml(Zend_Json::encode($html)); } }
public function createDummyContents($option_value, $design, $category) { $dummy_content_xml = $this->_getDummyXml($design, $category); foreach ($dummy_content_xml->events->event as $event) { $this->unsData(); $this->setValueId($option_value->getId())->addData((array) $event->content)->save(); if ($event->custom_contents) { foreach ($event->custom_contents->custom_content as $custom_content) { $custom = new Event_Model_Event_Custom(); $custom->addData((array) $custom_content)->setAgendaId($this->getId())->save(); } } } }
public function editAction() { if ($datas = $this->getRequest()->getPost()) { try { $application = $this->getApplication(); // Test s'il y a un value_id if (empty($datas['agenda_id'])) { throw new Exception($this->_('An error occurred while saving. Please try again later.')); } $event = new Event_Model_Event_Custom(); $option_value = $this->getCurrentOptionValue(); $data = array(); if (!empty($datas['id'])) { $event->find($datas['id']); if ($event->getAgendaId() != $datas['agenda_id']) { throw new Exception($this->_('An error occurred while saving. Please try again later.')); } } if (!empty($datas['picture'])) { $filename = $datas['picture']; $img_src = Core_Model_Directory::getTmpDirectory(true) . '/' . $filename; if (file_exists($img_src)) { $relative_path = $option_value->getImagePathTo(); $folder = Application_Model_Application::getBaseImagePath() . $relative_path; $img_dst = $folder . '/' . $filename; if (!is_dir($folder)) { mkdir($folder, 0777, true); } if (!@copy($img_src, $img_dst)) { throw new exception($this->_("An error occurred while saving your picture. Please try againg later.")); } else { $datas['picture'] = $relative_path . '/' . $filename; } } else { unset($data['picture']); } } else { $datas['picture'] = null; } foreach (array("rsvp", "ticket_shop_url", "location_url") as $url_type) { if (!empty($datas[$url_type]) and stripos($datas[$url_type], 'http') === false) { $datas[$url_type] = 'http://' . $datas[$url_type]; } } if (!empty($datas["websites"]) and is_array($datas["websites"])) { $websites = array(); $cpt = 0; foreach ($datas["websites"] as $website) { if (empty($website["label"]) or empty($website["url"])) { continue; } if (stripos($website["url"], 'http') === false) { $website["url"] = 'http://' . $website["url"]; } $websites[++$cpt] = $website; } $datas["websites"] = Zend_Json::encode($websites); } else { $datas["websites"] = null; } $event->addData($datas)->save(); $cache = Zend_Registry::get('cache'); $cache->remove($option_value->getObject()->getCacheId()); $html = array('success' => '1', 'success_message' => $this->_("Event successfully saved"), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0); } catch (Exception $e) { $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1); } $this->getLayout()->setHtml(Zend_Json::encode($html)); } }