Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
Public Member Functions | Public Attributes | List of all members
CommentsFormWidget Class Reference
Inheritance diagram for CommentsFormWidget:
CommentsBaseWidget BaseJuiWidget

Public Member Functions

 init ()
 run ()

Public Attributes

 $moderatorEmail
 $notifyModeratorOnNew = true
 $allowAnonymous = true
 $requiredForAnonymous = null
 $dontNeedApprove = false
 $hash
- Public Attributes inherited from CommentsBaseWidget
 $contentId
 $isPreview = false

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.

Widget for view comments form for current model

Definition at line 12 of file CommentsFormWidget.php.

Member Function Documentation

CommentsFormWidget::init ( )

Make widgets options hash key and store options in session

Returns
void

Reimplemented from CommentsBaseWidget.

Definition at line 48 of file CommentsFormWidget.php.

{
$options = array(
'contentId' => $this->contentId,
'moderatorEmail' => $this->moderatorEmail,
'notifyModeratorOnNew' => $this->notifyModeratorOnNew,
'allowAnonymous' => $this->allowAnonymous,
'requiredForAnonymous' => $this->requiredForAnonymous,
'dontNeedApprove' => $this->dontNeedApprove
);
$this->hash = md5(serialize($options) . Yii::app()->getModule('comments')->hashSalt);
if (Yii::app()->cache->get($this->hash) != $options) {
Yii::app()->cache->set($this->hash, $options);
}
}
CommentsFormWidget::run ( )

Show comment form or login invitation based on widget options

Returns
void

Definition at line 70 of file CommentsFormWidget.php.

References Profile\model().

{
if (!$this->allowAnonymous && Yii::app()->user->isGuest) {
$this->render('CommentsFormWidget_Login');
} else {
$model = new Comment(Yii::app()->user->isGuest ? 'createAnonymous' : 'create');
if(isset($this->requiredForAnonymous)){
$model->setRequiredForAnonymous($this->requiredForAnonymous);
}
if (!Yii::app()->user->isGuest) {
$model->email = Yii::app()->user->email;
$profile = Profile::model()->findByPk(Yii::app()->user->id);
$model->firstname = $profile->firstname;
$model->lastname = $profile->lastname;
}
if (($modelData = Yii::app()->user->getState('Comment' . $this->contentId)) !== null) {
$model->attributes = $modelData['attributes'];
foreach ($modelData['errors'] as $attribute => $errors) {
foreach ($errors as $e) {
$model->addError($attribute, $e);
}
}
Yii::app()->user->setState('Comment' . $this->contentId, null);
}
$this->render('CommentsFormWidget', array('model' => $model));
}
}

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