Ejemplo n.º 1
0
 /**
  * @return static
  */
 public function withoutDeleted()
 {
     /** @var Comments\models\Comment $CommentModel */
     $CommentModel = \Yii::createObject(Comments\Module::instance()->model('comment'));
     $this->andWhere(['deleted' => $CommentModel::NOT_DELETED]);
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * @return bool
  * @throws \yii\web\NotFoundHttpException
  */
 public function save()
 {
     $Comment = $this->Comment;
     $CommentModelClassName = Comments\Module::instance()->model('comment');
     if (empty($this->id)) {
         $Comment = \Yii::createObject($CommentModelClassName);
     } elseif ($this->id > 0 && $Comment->id !== $this->id) {
         /** @var Comments\models\Comment $CommentModel */
         $CommentModel = \Yii::createObject($CommentModelClassName);
         $Comment = $CommentModel::find()->byId($this->id)->one();
         if (!$Comment instanceof Comments\models\Comment) {
             throw new \yii\web\NotFoundHttpException();
         }
     }
     $Comment->entity = $this->entity;
     $Comment->from = $this->from;
     $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;
 }
Ejemplo n.º 3
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     CommentFormAsset::register($this->getView());
     /** @var Comments\forms\CommentCreateForm $CommentCreateForm */
     $CommentCreateFormClassData = Comments\Module::instance()->model('commentCreateForm', ['Comment' => $this->Comment, 'entity' => $this->entity]);
     $CommentCreateForm = \Yii::createObject($CommentCreateFormClassData);
     if ($CommentCreateForm->load(\Yii::$app->getRequest()->post())) {
         if ($CommentCreateForm->validate()) {
             if ($CommentCreateForm->save()) {
                 \Yii::$app->getResponse()->refresh(sprintf($this->anchor, $CommentCreateForm->Comment->id))->send();
                 exit;
             }
         }
     }
     return $this->render('comment-form', ['CommentCreateForm' => $CommentCreateForm]);
 }
Ejemplo n.º 4
0
 private function processDelete()
 {
     $delete = (int) \Yii::$app->getRequest()->get('delete-comment');
     if ($delete > 0) {
         /** @var Comments\models\Comment $CommentModel */
         $CommentModel = \Yii::createObject(Comments\Module::instance()->model('comment'));
         /** @var Comments\models\Comment $Comment */
         $Comment = $CommentModel::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 = $CommentModel::DELETED;
         $Comment->update();
     }
 }
Ejemplo n.º 5
0
                        </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();
}]);
/** @var Comments\models\Comment $CommentModel */
$CommentModel = \Yii::createObject(Comments\Module::instance()->model('comment'));
if ($CommentListWidget->showCreateForm && $CommentModel::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' => $CommentModel, 'anchor' => $CommentListWidget->anchorAfterUpdate]);
}
$CommentListWidget->getView()->registerJs('jQuery("#' . $CommentListWidget->options['id'] . '").yiiCommentsList(' . Json::encode($comments) . ');');
Ejemplo n.º 6
0
 /**
  * @return queries\CommentQuery
  */
 public static function find()
 {
     return \Yii::createObject(Comments\Module::instance()->model('commentQuery'), [get_called_class()]);
 }