Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
Public Member Functions | Protected Member Functions | List of all members
CommentController Class Reference
Inheritance diagram for CommentController:
BaseController

Public Member Functions

 actions ()
 actionLogin ($return_url)
 actionCreate ()
 actionDelete ($id, $key, $return_url)
 actionRemoteDelete ($id, $key)
 actionApprove ($id, $key, $status, $return_url)
 actionRemoteApprove ($id, $key, $status)
 onCommentCreated (Comment $comment)
 onCommentDeleted (Comment $comment)
- Public Member Functions inherited from BaseController
 getClient ()
 getAssetsPath ()
 getViewFile ($viewName)
 getJs ($path)
 renderMail ($view, $title=null, $data)
 redirect ($url, $terminate=true, $statusCode=302)

Protected Member Functions

 getWidgetPageUrl ()
- Protected Member Functions inherited from BaseController
 beforeAction ($action)

Additional Inherited Members

- Public Attributes inherited from BaseController
 $layout = '//layouts/gportal'
 $mailLayout = '//layouts/mail'

Detailed Description

Gentics Portal.Node PHP Author & Copyright (c) by Gentics Software GmbH sales.nosp@m.@gen.nosp@m.tics..nosp@m.com http://www.gentics.com Licenses can be found in the LICENSE.txt file in the root-folder of this installation You must not use this software without a valid license agreement.

Comment controller class file.

Definition at line 12 of file CommentController.php.

Member Function Documentation

CommentController::actionApprove (   $id,
  $key,
  $status,
  $return_url 
)

Approve comment

Parameters
int$idcomment id
string$keyoptions hash key
int$statusflag Comment::NOT_APPROVED|Comment::APPROVED. Specify approve comment or not
string$return_urlreturn url
Returns
void

Definition at line 172 of file CommentController.php.

References CommentsModule\canApprove(), Comment\model(), Comment\NOT_APPROVED, and CommentsModule\t().

{
$options = Yii::app()->cache->get($key);
if (!empty($options) && !Yii::app()->user->isGuest && in_array($status, array(Comment::APPROVED, Comment::NOT_APPROVED))) {
$comment = Comment::model()->findByPk($id);
if ($comment && CommentsModule::canApprove($comment)) {
$comment->status = $status;
$comment->update('status');
Yii::app()->user->setFlash(
'commentApproveSuccess' . $options['contentId'],
CommentsModule::t('Comment ' . ($status == Comment::NOT_APPROVED ? 'not' : '') . ' approved')
);
} else {
Yii::app()->user->setFlash('commentApproveError' . $options['contentId'], CommentsModule::t("You have no access"));
}
} else {
Yii::app()->user->setFlash('commentApproveError' . $options['contentId'], CommentsModule::t("You have no access or comment deleted"));
}
$this->redirect($return_url);
}
CommentController::actionCreate ( )

Create Comment action. Reads widget options from session using options hash key. Using options to make validation.

Returns
void

Definition at line 67 of file CommentController.php.

References Comment\NOT_APPROVED, onCommentCreated(), and CommentsModule\t().

{
if (isset($_POST['key'])) {
$options = Yii::app()->cache->get($_POST['key']);
}
if (!empty($options)) {
if (!$options['allowAnonymous'] && Yii::app()->user->isGuest) {
Yii::app()->user->setFlash('commentCreateError' . $options['contentId'], CommentsModule::t('Anonymous comments not allowed'));
} elseif (isset($_POST['Comment'])) {
$comment = new Comment(Yii::app()->user->isGuest ? 'createAnonymous' : 'create');
$comment->attributes = $_POST['Comment'];
$comment->content_id = $options['contentId'];
$comment->notify_moderator = $options['notifyModeratorOnNew'];
$comment->moderator_email = $options['moderatorEmail'];
$comment->status = $options['dontNeedApprove'] ? Comment::APPROVED : Comment::NOT_APPROVED;
$comment->language = Yii::app()->language;
if (!Yii::app()->user->isGuest) {
$comment->user_id = Yii::app()->user->id;
$comment->email = Yii::app()->user->email;
}
if ($comment->save()) {
Yii::app()->user->setFlash('commentCreateSuccess' . $options['contentId'], CommentsModule::t('Your comment added successfully and will be displayed'));
Yii::app()->user->setState('Comment' . $options['contentId'], null);
$this->onCommentCreated($comment);
}
if ($comment->hasErrors() && !isset($_POST['ajax'])) {
Yii::app()->user->setState('Comment' . $options['contentId'], array('attributes' => $comment->attributes, 'errors' => $comment->getErrors()));
}
}
} else {
Yii::app()->user->setFlash('commentCreateError', CommentsModule::t('Form error'));
}
$this->redirect($_GET['return_url']);
}
CommentController::actionDelete (   $id,
  $key,
  $return_url 
)

Delete comment

Parameters
int$idcomment id
string$keyoptions hash key
string$return_urlreturn url
Exceptions
CHttpException
Returns
void

Definition at line 114 of file CommentController.php.

References CommentsModule\canDelete(), Comment\model(), onCommentDeleted(), and CommentsModule\t().

{
$options = Yii::app()->cache->get($key);
if (!empty($options) && !Yii::app()->user->isGuest) {
$comment = Comment::model()->findByPk($id);
if ($comment && CommentsModule::canDelete($comment)) {
if ($comment->delete()) {
$this->onCommentDeleted($comment);
Yii::app()->user->setFlash('commentDeleteSuccess' . $options['contentId'], CommentsModule::t("Comment deleted successfully"));
}
} else {
Yii::app()->user->setFlash('commentDeleteError' . $options['contentId'], CommentsModule::t("You have no access or comment deleted"));
}
} else {
Yii::app()->user->setFlash('commentDeleteError' . $options['contentId'], CommentsModule::t("You have no access"));
}
$this->redirect($return_url);
}
CommentController::actionLogin (   $return_url)

Intermediate action. Used for saving $return_url in session to return back after log in.

Parameters
string$return_urlReturn url
Returns
void

Definition at line 55 of file CommentController.php.

{
Yii::app()->user->setReturnUrl($return_url);
$this->redirect($this->module->loginUrl);
}
CommentController::actionRemoteApprove (   $id,
  $key,
  $status 
)

Approve comment not logged in. Mainly using in admin mails.

Parameters
int$idcomment id
string$keyaccess hash key
int$statusflag Comment::NOT_APPROVED|Comment::APPROVED. Specify approve comment or not
Returns
void
Exceptions
CHttpException

Definition at line 203 of file CommentController.php.

References Comment\model(), Comment\NOT_APPROVED, and CommentsModule\t().

{
$comment = Comment::model()->resetScope()->findByPk($id);
if ($comment && $comment->hash() == $key) {
if ($comment->status == Comment::DELETED) {
Yii::app()->user->setFlash('remoteActionState', CommentsModule::t('Comment already deleted'));
} elseif (in_array($status, array(Comment::APPROVED, Comment::NOT_APPROVED))) {
$comment->status = $status;
$comment->update('status');
Yii::app()->user->setFlash('remoteActionState', CommentsModule::t('Comment ' . ($comment->status == Comment::NOT_APPROVED ? 'not' : '') . ' approved'));
}
}else{
$comment = false;
Yii::app()->user->setFlash('remoteActionState', CommentsModule::t('Comment is not available anymore'));
}
$this->render('remoteAction', array('comment' => $comment));
}
CommentController::actionRemoteDelete (   $id,
  $key 
)

Delete comment be not logged in. Mainly using in admin mails.

Parameters
int$idcomment id
string$keyaccess hash key
Returns
void
Exceptions
CHttpException

Definition at line 143 of file CommentController.php.

References Comment\model(), onCommentDeleted(), and CommentsModule\t().

{
$comment = Comment::model()->resetScope()->findByPk($id);
if ($comment && $comment->hash() == $key) {
if ($comment->status == Comment::DELETED) {
Yii::app()->user->setFlash('remoteActionState', CommentsModule::t('Comment already deleted'));
} else {
$comment->delete();
$this->onCommentDeleted($comment);
Yii::app()->user->setFlash('remoteActionState', CommentsModule::t('Comment deleted'));
}
}else{
Yii::app()->user->setFlash('remoteActionState', CommentsModule::t('You have no access'));
$comment = false;
}
$this->render('remoteAction', array('comment' => $comment));
}
CommentController::actions ( )

Returns a list of external action classes.

Returns
array

Definition at line 20 of file CommentController.php.

{
return (isset($_POST['ajax']) && $_POST['ajax'] === 'comment-form') ? array() : array(
'captcha' => array(
'class' => 'CCaptchaAction',
'backColor' => 0xFFFFFF,
'fixedVerifyCode' => YII_DEBUG ? 'polomo' : null
),
);
}
CommentController::getWidgetPageUrl ( )
protected

Get page url on which comments widget was placed

Returns
string

Definition at line 36 of file CommentController.php.

Referenced by onCommentCreated(), and onCommentDeleted().

{
if (isset($_GET['return_url'])) {
return Yii::app()->createAbsoluteUrl($_GET['return_url']);
} elseif (isset($_SERVER['HTTP_REFERER'])) {
return $_SERVER['HTTP_REFERER'];
} else {
return '';
}
}
CommentController::onCommentCreated ( Comment  $comment)

This method invoked when new comment created

Parameters
Comment$commentcomment
Returns
void

Definition at line 229 of file CommentController.php.

References getWidgetPageUrl(), and CommentsModule\t().

Referenced by actionCreate().

{
$pageUrl = $this->getWidgetPageUrl();
if ($comment->notify_moderator && !empty($comment->moderator_email)) {
$subject = CommentsModule::t('Comment created (Moderator) {subject}', array('{subject}' => $comment->subject));
$notification = new Notification(
$subject,
$this->renderMail('/mail_templates/comment_created_admin', $subject, array('comment' => $comment, 'pageUrl' => $pageUrl), true),
array(new EmailRecipient($comment->moderator_email, $this->module->notificationsEmail))
);
Yii::app()->notificationManager->notifyAbout($notification);
}
$subscribers = Yii::app()->db->createCommand()
->select('email')
->from('{{comments}}')
->where('content_id = :content_id AND notify_user = :notify_user AND status != :status', array(':content_id' => $comment->content_id, ':notify_user' => true, ':status' => Comment::DELETED))
->group('email')->queryAll();
$recipients = array();
$fromEmail = $this->module->notificationsEmail;
foreach ($subscribers as $subscriber) {
if (trim($subscriber["email"]) != ""){
$recipients[] = new EmailRecipient($subscriber['email'], $fromEmail);
}
}
if (sizeof($recipients) > 0) {
$subject = CommentsModule::t('Comment created: {subject}', array('{subject}' => $comment->subject));
$notification = new Notification(
$subject,
$this->renderMail('/mail_templates/comment_created_user', $subject, array('comment' => $comment, 'pageUrl' => $pageUrl), true),
$recipients
);
Yii::app()->notificationManager->notifyAbout($notification);
}
}
CommentController::onCommentDeleted ( Comment  $comment)

This method invoked when comment deleted

Parameters
Comment$commentcomment
Returns
void

Definition at line 274 of file CommentController.php.

References getWidgetPageUrl(), and CommentsModule\t().

Referenced by actionDelete(), and actionRemoteDelete().

{
if ($comment->notify_user) {
$pageUrl = $this->getWidgetPageUrl();
$subject = CommentsModule::t('Comment was deleted');
$notification = new Notification(
$subject,
$this->renderMail('/mail_templates/comment_deleted', $subject, array('comment' => $comment, 'pageUrl' => $pageUrl), true),
array(new EmailRecipient($comment->email))
);
Yii::app()->notificationManager->notifyAbout($notification);
}
}

The documentation for this class was generated from the following file: