コード例 #1
0
ファイル: CommentWidget.php プロジェクト: psych88/fifa
 public function run()
 {
     $model = new Comments();
     if (!is_string($this->model)) {
         $model->post_id = $this->model->getPrimaryKey();
         $model->module = get_class($this->model);
         $order = '';
     } else {
         $model->post_id = 0;
         $model->module = $this->model;
         $order = 'DESC';
     }
     //  Получаем комментарии этого модуля и пост айди
     $models = Comments::getComments($model->module, $model->post_id, $order);
     //  Получаем кол-во страниц комментариев для редиректа
     $page = $models['pages']->totalCount / $models['pages']->pageSize + 1;
     if ($model->load(Yii::$app->request->post())) {
         if ($model->save()) {
             Url::remember(Url::current());
             Yii::$app->getSession()->setFlash('success', '<i class="fa fa-check fa-1x"></i> Good! ');
             if (!is_string($this->model)) {
                 return Yii::$app->getResponse()->redirect('/post/' . $this->model->slug . '/' . $model->post_id . '?page=' . round($page) . '#' . $model->id);
             } else {
                 return Yii::$app->getResponse()->refresh();
             }
         }
     }
     return $this->render('widgetComment', ['model' => $model, 'models' => $models['models'], 'pages' => $models['pages'], 'options' => $this->options]);
 }
コード例 #2
0
ファイル: DefaultController.php プロジェクト: akula22/fifa
 protected function findModel($id)
 {
     if (is_array($id)) {
         $model = Comments::findAll($id);
     } else {
         $model = Comments::findOne($id);
     }
     if ($model !== null) {
         return $model;
     } else {
         throw new HttpException(404);
     }
 }
コード例 #3
0
ファイル: CommentsSearch.php プロジェクト: akula22/fifa
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Comments::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['created_at' => '']]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'username' => $this->username, 'module' => $this->module, 'FROM_UNIXTIME(created_at, "%d.%m.%Y")' => $this->created_at]);
     $query->andFilterWhere(['like', 'post', $this->post])->andFilterWhere(['like', 'post', $this->post])->andFilterWhere(['like', 'username', $this->username]);
     return $dataProvider;
 }
コード例 #4
0
ファイル: index.php プロジェクト: psych88/fifa
<div class="header">
        <h1><?php 
echo Html::encode($this->title);
?>
</h1>
</div>

<div class="comments-index">

    <div class="well">

        <?php 
Pjax::begin();
?>
        <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'id' => 'comments_tbl', 'columns' => [['class' => CheckboxColumn::classname()], 'id', 'post:ntext', ['attribute' => 'created_at', 'format' => ['date', 'dd.MM.yyyy'], 'options' => array('width' => '225px'), 'filter' => \yii\jui\DatePicker::widget(['dateFormat' => 'dd.MM.yyyy', 'model' => $searchModel, 'attribute' => 'created_at', 'options' => ['class' => 'form-control'], 'clientOptions' => ['dateFormat' => 'dd.mm.yy']])], ['attribute' => 'post_id', 'options' => array('width' => '80')], ['attribute' => 'module', 'options' => array('width' => '80'), 'filter' => Html::activeDropDownList($searchModel, 'module', \yii\helpers\Arrayhelper::map(Comments::find()->groupBy('module')->all(), 'module', 'module'), ['class' => 'form-control', 'prompt' => 'Все'])], ['attribute' => 'username', 'format' => 'raw', 'value' => function ($model) {
    return Html::a($model['username'], ['/user/' . $model['username']], ['target' => '_blank']);
}], ['class' => 'yii\\grid\\ActionColumn', 'header' => 'Действия', 'headerOptions' => ['width' => '80']]]]);
?>
 



<p> 
  <?php 
echo Html::a('Удалить выбранные', ['massdelete'], ['class' => 'btn btn-danger', 'data' => ['confirm' => 'Вы уверены?', 'data-method' => 'post']]);
?>
  
</p>

<?php