/**
* Performs the action; returns true on success, false on error.
*
* @param $p_context - the current context object
* @return bool
*/
public function takeAction(CampContext &$p_context)
{
$p_context->default_url->reset_parameter('f_' . $this->m_name);
$p_context->url->reset_parameter('f_' . $this->m_name);
if (!is_null($this->m_error)) {
return false;
}
// Check that the article exists.
$articleMetaObj = $p_context->default_article;
if (!$articleMetaObj->defined) {
$this->m_error = new PEAR_Error('The article was not selected. You must view an article in order to post comments.', ACTION_PREVIEW_COMMENT_ERR_NO_ARTICLE);
return false;
}
if (!$articleMetaObj->comments_enabled || $articleMetaObj->comments_locked) {
$this->m_error = new PEAR_Error('Comments are not enabled for this publication/article.', ACTION_PREVIEW_COMMENT_ERR_NOT_ENABLED);
return false;
}
// Get the publication.
$publicationObj = new Publication($articleMetaObj->publication->identifier);
$user = $p_context->user;
if ($user->defined) {
$this->m_properties['reader_email'] = $user->email;
} else {
if (!isset($this->m_properties['reader_email'])) {
$this->m_error = new PEAR_Error('You must be a registered user in order to submit a comment. Please subscribe or log in if you already have a subscription.', ACTION_SUBMIT_COMMENT_ERR_NO_PUBLIC);
return false;
}
if (!$publicationObj->getPublicComments()) {
$this->m_error = new PEAR_Error('EMail field is empty. You must fill in your EMail address.', ACTION_SUBMIT_COMMENT_ERR_NO_EMAIL);
return false;
}
}
// Check if the reader was banned from posting comments.
global $controller;
$repositoryAcceptance = $controller->getHelper('entity')->getRepository('Newscoop\\Entity\\Comment\\Acceptance');
$repository = $controller->getHelper('entity')->getRepository('Newscoop\\Entity\\Comment');
if ($repositoryAcceptance->checkParamsBanned($userRealName, $userEmail, $userIp, $publication_id)) {
$this->m_error = new PEAR_Error('You are banned from submitting comments.', ACTION_SUBMIT_COMMENT_ERR_BANNED);
return false;
}
$this->m_error = ACTION_OK;
return true;
}