public function _saveFeed($datas) { $html = ''; try { // Test s'il y a une erreur dans la saisie if (empty($datas['title'])) { throw new Exception($this->_('Please enter a title')); } if (empty($datas['link']) or !Zend_Uri::check($datas['link'])) { throw new Exception($this->_('Please enter a valid url')); } // Test s'il y a un value_id if (empty($datas['value_id'])) { throw new Exception($this->_('An error occurred while saving your RSS feed')); } if (!isset($datas['picture'])) { $datas['picture'] = 0; } // Récupère l'option_value en cours $option_value = new Application_Model_Option_Value(); $option_value->find($datas['value_id']); $isNew = true; $html = ''; $feed = new Rss_Model_Feed(); $feeds = new Rss_Model_Feed(); $feeds = $feeds->findAll(array(), 'position DESC'); if ($feeds->count() > 0) { $last_position = $feeds->seek($feeds->count() - 1)->current()->getPosition(); } else { $last_position = 0; } // Si un id est passé en paramètre if (!empty($datas['feed_id'])) { // Charge le flux $feed->find($datas['feed_id']); // Si le flux existe mais qu'il n'appartient pas à cette option_value if ($feed->getId() and $feed->getValueId() != $option_value->getId()) { // Envoi l'erreur throw new Exception($this->_('An error occurred while saving your RSS feed')); } $isNew = !$feed->getId(); $last_position = $feed->getPosition(); } if (!empty($last_position)) { $datas["position"] = $last_position + 1; } else { $datas["position"] = 0; } $feed->setData($datas)->save(); $html = array('success' => 1, 'success_message' => $this->_('RSS feed successfully saved'), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0); if ($isNew) { $html['row_html'] = $this->getLayout()->addPartial('row_' . $feed->getId(), 'admin_view_default', 'rss/application/feed/edit/row.phtml')->setCurrentFeed($feed)->setCurrentOptionValue($option_value)->toHtml(); } } catch (Exception $e) { $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1); } return $html; }