public function addAction() { $form = new Admin_Form_EntryAdd(); $this->view->heading = 'Added: '; if (!$this->getRequest()->isPost()) { $this->view->heading = 'Add new blog'; $this->view->entryForm = $form; return; } elseif (!$form->isValid($_POST)) { $this->view->failedValidation = true; $this->view->heading = 'Add entry failed'; $this->view->entryForm = $form; return; } $values = $form->getValues(); $author_mapper = new Application_Model_AuthorMapper(); $author = $author_mapper->find(Zend_Auth::getInstance()->getIdentity()->username); $data = array('title' => $values['title'], 'published_date' => strtotime($values['date']), 'last_modified' => strtotime($values['date']), 'author' => $author, 'content' => $values['body'], 'extended_content' => $values['extended_body'], 'hide' => $values['hide'], 'description' => $values['description']); $entry = new Application_Model_Entry($data); $entry_mapper = new Application_Model_EntryMapper(); $eid = $entry_mapper->save($entry); $this->view->entrySaved = true; $tag_string = strtolower($values['tags']); $tag_array = explode(',', $tag_string); $tag_array = array_map('trim', $tag_array); $tag_array = array_unique($tag_array); foreach ($tag_array as $tag) { $tag_obj = new Application_Model_Tag(array('tag' => $tag, 'entry' => $eid)); $tag_mapper = new Application_Model_TagMapper(); $tag_mapper->save($tag_obj); } $this->view->entry = $entry; // email subscribers $this->_emailSubscribers($entry); }
public function init() { parent::init(); $this->setAction('/admin/entry/edit'); // What entry id are we editing?! $this->addElement('hidden', 'id', array('decorators' => $this->_noElementDecorator, 'validators' => array('Digits'), 'required' => true)); $this->addElement('hidden', 'author', array('decorators' => $this->_noElementDecorator)); $this->getDisplayGroup('entrydata')->setLegend('Edit Entry'); }