示例#1
0
 private function processDelete()
 {
     $delete = (int) \Yii::$app->getRequest()->get('delete-comment');
     if ($delete > 0) {
         /** @var Comments\models\Comment $Comment */
         $Comment = Comments\models\Comment::find()->byId($delete)->one();
         if ($Comment->isDeleted()) {
             return;
         }
         if (!$Comment instanceof Comments\models\Comment) {
             throw new \yii\web\NotFoundHttpException(\Yii::t('app', 'Comment not found.'));
         }
         if (!$Comment->canDelete()) {
             throw new \yii\web\ForbiddenHttpException(\Yii::t('app', 'Access Denied.'));
         }
         $Comment->deleted = Comments\models\Comment::DELETED;
         $Comment->update();
     }
 }
 /**
  * @return bool
  * @throws \yii\web\NotFoundHttpException
  */
 public function save()
 {
     $Comment = $this->Comment;
     if (empty($this->id)) {
         $Comment = new Comments\models\Comment();
     } elseif ($this->id > 0 && $Comment->id !== $this->id) {
         $Comment = Comments\models\Comment::find()->byId($this->id)->one();
         if (!$Comment instanceof Comments\models\Comment) {
             throw new \yii\web\NotFoundHttpException();
         }
     }
     $Comment->entity = $this->entity;
     $Comment->text = $this->text;
     $result = $Comment->save();
     if ($Comment->hasErrors()) {
         foreach ($Comment->getErrors() as $attribute => $messages) {
             foreach ($messages as $mes) {
                 $this->addError($attribute, $mes);
             }
         }
     }
     $this->Comment = $Comment;
     return $result;
 }
示例#3
0
 /**
  * Displays a single Post model.
  * @param string $id
  * @return mixed
  */
 public function actionView($id)
 {
     return $this->render('view', ['model' => $this->findModel($id), 'category' => Category::find()->all(), 'comment_list' => Comment::find()->all()]);
 }
示例#4
0
 /**
  * Get default model classes
  */
 protected function getDefaultModels()
 {
     return ['Comment' => Comments\models\Comment::className(), 'CommentQuery' => Comments\models\queries\CommentQuery::className(), 'CommentCreateForm' => Comments\forms\CommentCreateForm::className()];
 }
示例#5
0
        echo Comments\widgets\CommentFormWidget::widget(['entity' => $CommentListWidget->entity, 'Comment' => $Comment, 'anchor' => $CommentListWidget->anchorAfterUpdate]);
        ?>
                        </div>
                    <?php 
    }
    ?>
                    <div class="actions">
                        <?php 
    if (!$Comment->isDeleted()) {
        if ($Comment->canCreate()) {
            echo Html::a(FA::icon('reply') . ' ' . Yii::t('app', 'Reply'), '#', ['class' => 'btn btn-info btn-xs', 'data-role' => 'reply']);
        }
        if ($Comment->canUpdate()) {
            echo Html::a(FA::icon('pencil') . ' ' . Yii::t('app', 'Edit'), '#', ['data-role' => 'edit', 'class' => 'btn btn-primary btn-xs']);
        }
        if ($Comment->canDelete()) {
            echo Html::a(FA::icon('times') . ' ' . Yii::t('app', 'Delete'), ['', 'delete-comment' => $Comment->id], ['class' => 'btn btn-danger btn-xs']);
        }
    }
    ?>
                    </div>
                </div>
            </div>
            <?php 
    return ob_get_clean();
}]);
if ($CommentListWidget->showCreateForm && Comments\models\Comment::canCreate()) {
    echo Html::tag('h3', Yii::t('app', 'Add comment'), ['class' => 'comment-title']);
    echo Comments\widgets\CommentFormWidget::widget(['theme' => $CommentListWidget->theme, 'entity' => $CommentListWidget->entity, 'Comment' => new Comments\models\Comment(), 'anchor' => $CommentListWidget->anchorAfterUpdate]);
}
$CommentListWidget->view->registerJs('jQuery("#' . $CommentListWidget->options['id'] . '").yiiCommentsList(' . Json::encode($comments) . ');');