artbox_comment_list.php 2.17 KB
<?php
    use artbox\webcomment\models\CommentModel;
    use yii\base\Model;
    use yii\data\ActiveDataProvider;
    use yii\helpers\Html;
    use yii\web\View;
    use yii\widgets\ListView;
    use yii\widgets\Pjax;
    
    /**
     * @var CommentModel       $comment_model
     * @var array              $list_params
     * @var array              $item_options
     * @var string             $item_view
     * @var Model              $model
     * @var ActiveDataProvider $comments
     * @var View               $this
     * @var string             $display_name
     * @var boolean            $reply ,
     * @var boolean            $delete
     */
    Pjax::begin();
    if(( $success = \Yii::$app->session->getFlash('artbox_comment_success') ) != NULL) {
        echo Html::tag('p', $success);
    }
echo '<div class="comments-border"></div>';
echo '<h4 class="text-uppercase">'.Yii::t('artbox-comment', 'Комментарии').'</h4>';
    echo ListView::widget([
        'dataProvider' => $comments,
        'itemOptions'  => $item_options,
        'itemView'     => $item_view,
        'emptyText'    => false,
        'summary'      => '',
        'viewParams'   => [
            'display_name'  => $display_name,
            'reply'         => $reply,
            'delete'        => $delete,
            'more'          => $more,
            'last'          => $comments->count,
        ],
        'beforeItem' => function ($model, $key, $index, $widget) use ($more, $comments) {
                if ($more['key'] == $index and $more['show_'] ){
                    
                    return "<a id='show_more_link' style='cursor:pointer'>".Yii::t('app', 'Показать еще')."</a>
                                <div id='show_more' style='display: none'>";
                }
        },
        'afterItem' => function ($model, $key, $index, $widget) use ($more, $comments) {
            if ($index == ($comments->count-1) and $more['show_'] and $more['key'] < $comments->count){
                
                return "<a id='hide_more_link' style='cursor:pointer'>".Yii::t('app', 'Скрыть комментарии')."</a></div>";
            }
        }
    
        
    ]);
    Pjax::end();