protected function _update(Default_Model_Comment $comment) { $db = $this->getWriteAdapter(); $oldComment = $this->getCommentById($comment->getCommentId()); $data = array(); if ($oldComment->getText() != $comment->getText()) { $data['text'] = $comment->getText(false); $oldData['text'] = $oldComment->getText(); } if ($oldComment->getPrivate() != $comment->getPrivate()) { $data['private'] = $comment->getPrivate() ? 1 : 0; $oldData['private'] = $oldComment->getPrivate() ? 1 : 0; } if ($oldComment->isDeleted() != $comment->isDeleted()) { $data['deleted'] = $comment->getDeleted() ? 1 : 0; $oldData['deleted'] = $oldComment->getDeleted() ? 1 : 0; } if (!count($data)) { return true; } // save audit trail foreach ($data as $field => $newValue) { $this->auditTrail($comment, 'update', $field, $oldData[$field], $newValue); } return $db->update('comment', $data, array('comment_id = ?' => $comment->getCommentId())); }
public function setDefaultValues(Default_Model_Comment $comment) { $this->getElement('text')->setValue($comment->getText(false)); $this->getSubform('permissions')->getElement('private')->setChecked($comment->isPrivate()); $roles = Zend_Registry::get('Default_DiContainer')->getAclService()->getRolesForResource('comment', $comment->getCommentId()); $roleIds = array(); foreach ($roles as $role) { $roleIds[] = $role->getRoleId(); } $this->getSubform('permissions')->getElement('roles')->setValue($roleIds); }
public function createFromForm($form, $issueId, $userId = null) { $acl = Zend_Registry::get('Default_DiContainer')->getAclService(); if (!$acl->isAllowed('issue', 'comment')) { return false; } $identity = Zend_Registry::get('Default_DiContainer')->getUserService()->getIdentity(); if ($userId === null) { $userId = $identity->getUserId(); } $permissions = $form->getValue('permissions'); $comment = new Default_Model_Comment(); $comment->setCreatedBy($identity)->setIssue($issueId)->setText($form->getValue('text'))->setPrivate($permissions['private'] ? true : false); $return = $this->_mapper->save($comment); if ($permissions['private']) { Zend_Registry::get('Default_DiContainer')->getAclService()->addResourceRecord($permissions['roles'], 'comment', $return); } return $return; }
public function auditTrail($issue, array $changes) { $user = Zend_Registry::get('Default_DiContainer')->getUserService()->getIdentity(); $comment = new Default_Model_Comment(); $comment->setCreatedBy($user)->setIssue($issue)->setPrivate(false)->setSystem(true)->setText(json_encode($changes)); Zend_Registry::get('Default_DiContainer')->getCommentService()->save($comment); }
public function commentAction() { $this->_helper->layout->disableLayout(); $this->_helper->ViewRenderer->setNoRender(); $commentDb = new Default_Model_Comment(); /* $removeId = $this->getRequest()->getQuery('remove'); //if a comment is to be removed if(isset($removeId)){ //get handle of profile page $profile_id = $commentDb->find($removeId)->current()->profile_id; $user = new Default_Model_User(); $handle = $user->find($profile_id)->current()->handle; //delete the comment $where = $commentDb->getAdapter()->quoteInto('id = ?', $removeId); $commentDb->delete($where); }*/ $session = new Zend_Session_Namespace('captcha'); if (isset($session->phrase)) { $phrase = $session->phrase; } if ($this->getRequest()->isPost()) { $handle = $this->getRequest()->getPost('handle'); $profile_id = $this->getRequest()->getPost('profile_id'); $user_id = $this->getRequest()->getPost('user_id'); $comment = $this->getRequest()->getPost('comment'); $captchatext = $this->getRequest()->getPost('captchatext'); // Valid captcha? $isValidCaptcha = $captchatext == $phrase ? true : false; //process incoming data (if comment not empty and valid captcha) if (Zend_Validate::is($comment, 'NotEmpty') && $isValidCaptcha) { $data['user_id'] = $user_id; $data['profile_id'] = $profile_id; $data['comment'] = $comment; $data['posted_at'] = date('Y-m-d H:i:s'); $commentDb->insert($data); } } //redirect back to profile $handle = strtolower($handle); if ($isValidCaptcha) { $this->_redirector->gotoUrl("/gamers/profile/{$handle}"); } else { $this->_redirector->gotoUrl("/gamers/profile/{$handle}/?captchaerr=1"); } }