/**
  * Создаёт новый комментарий
  * @return bool
  */
 public function actionCreate()
 {
     $model = new Comment(['scenario' => 'guest']);
     if ($user = \Yii::$app->getModule('comments')->loadUser()) {
         $model->scenario = 'authorized';
         $model->user_id = $user->{$user->tableSchema->primaryKey[0]};
     }
     $this->performAjaxValidation($model);
     if (!isset($_POST['Comment']) || isset($_POST['ajax'])) {
         return false;
     }
     $model->attributes = $_POST['Comment'];
     $model->ip = CHelper::getRealIP();
     $model->setStatus();
     if (!$model->save()) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return $model->getErrors();
     }
     \Yii::$app->session->set("commentHash_{$model->id}", $model->getHash());
     $widget = new CommentsWidget();
     $widget->models = Comment::find()->page($model->url)->approved()->all();
     $widget->init();
     if (\Yii::$app->getModule('comments')->notifyAdmin) {
         $this->sendAdminNotify($model);
     }
     $this->sendUserNotifies($model);
     Yii::$app->response->format = Response::FORMAT_JSON;
     return array('id' => $model->id, 'premoderate' => \Yii::$app->getModule('comments')->getPremoderateStatus(), 'tree' => $widget->getTree(), 'count' => count($widget->models), 'modal' => $this->getModal(array('title' => '<i class="fa fa-comments"></i> Комментарий успешно отправлен!', 'content' => '<strong>Спасибо за комментарий!</strong> Он появится после проверки модератором.')));
 }
Example #2
0
    <div class="pull-right">
        <a href="#comment_like" title="Мне нравится" data-like="1" class="label label-success"><i class="fa fa-thumbs-up"></i></a>
        <span data-role="likes" class="label label-primary"><?php 
echo $comment->getLikes();
?>
</span>
        <a href="#comment_like" title="Мне не нравится" data-like="0" class="label label-danger"><i class="fa fa-thumbs-down"></i></a>

        <time<?php 
echo $enableMicrodata ? ' itemprop="datePublished"' : '';
?>
 datetime="<?php 
echo date('Y-m-d', $comment->created);
?>
" class="label label-default"><?php 
echo CHelper::date($comment->created);
?>
</time>

        <a href="#comment_<?php 
echo $comment->id;
?>
" class="label label-default" title="Ссылка на этот комментарий">#</a>
    </div>

    <div<?php 
echo $enableMicrodata ? ' itemprop="text"' : '';
?>
 class="content"><?php 
echo $comment->content;
?>
 /**
  * Запуск видежта
  */
 public function run()
 {
     return $this->render('count', array('count' => CHelper::getNewCommentsCount(), 'url' => CHelper::getNewCommentsUrl()));
 }
Example #4
0
echo Html::a("<i class='fa fa-search'></i> Просмотр комментария", ['view', 'id' => $model->id], $options = []);
?>
            |
            Лайки: <span class="label label-primary"><?php 
echo $model->getLikes();
?>
</span>
            Создан: <span class="label label-success"><?php 
echo CHelper::date($model->created);
?>
</span>
            <?php 
if (!empty($model->updated)) {
    ?>
                Обновлён: <span class="label label-warning"><?php 
    echo CHelper::date($model->updated);
    ?>
</span>
            <?php 
}
?>
            IP: <span class="label label-default"><?php 
echo $model->ip;
?>
</span>
        </p>
    </div>

</div>

    <?php