/** * Save a new testimonial, or changes to an existing testimonial. If it's a new entry the function will return the ID for the record * * @return int */ protected function _saveQuote() { $requiredText = new Zend_Validate(); $requiredText->addValidator(new Zend_Validate_NotEmpty()); $tagFilter = new Zend_Filter(); $tagFilter->addFilter(new Zend_Filter_StringTrim()); $tagFilter->addFilter(new Zend_Filter_StringTrim(',')); $filters = array('id' => 'Digits', 'title' => 'StringTrim', 'subtitle' => 'StringTrim', 'tags' => $tagFilter); $validators = array('id' => array('allowEmpty' => true), 'title' => $requiredText, 'subtitle' => array('allowEmpty' => true), 'tags' => $requiredText); $input = new Zend_Filter_Input($filters, $validators, $_POST); if ($input->isValid()) { $quote = new Datasource_Cms_HeaderQuotes(); // Data is all valid, formatted and sanitized so we can save it in the database if (!$input->id) { // This is a new quote so we need to create a new ID $quoteID = $quote->addNew($input->getUnescaped('title'), $input->subtitle, $input->tags); } else { // This is an existing article so we can just update the data $quote->saveChanges($input->id, $input->getUnescaped('title'), $input->subtitle, $input->tags); $quoteID = $input->id; } // Changes saved - so send them back with a nice success message $this->_helper->getHelper('FlashMessenger')->addMessage(array('saved' => true)); $this->_helper->getHelper('Redirector')->goToUrl('/cms-admin/header-quotes/edit?id=' . $quoteID); } else { // Invalid data in form /* print_r($_POST); print_r($input->getErrors()); print_r($input->getInvalid()); */ } }