public function postAction() { if (!$this->view->authenticated && !$request->isXmlHttpRequest()) { $this->_redirector->gotoRoute(array(), 'login'); } $request = $this->getRequest(); $form = new Form_Comment(); if ($request->isPost() && $form->isValid($request->getPost())) { $model = 'Model_DbTable_' . ucfirst($form->getValue('model')); $table = new Model_DbTable_Comments(); $comment = $table->addComment($model, $form->getValue('oid'), $this->view->identity->id, $form->getValue('comment'), $form->getValue('parent')); } if ($request->isXmlHttpRequest()) { $this->_helper->layout()->disableLayout(); if (!isset($comment)) { $this->getResponse()->sendResponse(); exit; } $this->view->comment = $comment; $this->render('/partials/comment', null, true); } else { $this->_redirector->gotoRoute(array('controller' => substr($form->getValue('model'), 0, -1), 'id' => $form->getValue('oid')), 'view'); } }
function addComment($identityId) { $res = false; $form = new Form_Comment(); $formData = Zend_Controller_Front::getInstance()->getRequest()->getPost(); if ($form->isValid($formData)) { $uid = $form->getValue('user_id', 0); if ($identityId != $uid) { l($uid, __METHOD__ . ': $uid invalid!', Zend_Log::DEBUG); return false; } $data = $form->getValues(); $data['dt'] = $data['tm'] = dateMySQL(); l($data, __METHOD__ . ': $data', Zend_Log::DEBUG); $res = $this->createComment($data); } else { l($formData, __METHOD__ . ': INVALID_COMMENT::formData', Zend_Log::DEBUG); Zend_Registry::set('comment_error', FrontEnd::getMsg(array('comments', 'fail'))); } return $res; }