Exemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Comment::find();
     $query->joinWith(['person']);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->sort->attributes['nick'] = ['asc' => ['person.nick' => SORT_ASC], 'desc' => ['person.nick' => SORT_DESC]];
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'datetime' => $this->datetime, 'joke_id' => $this->joke_id, 'aprooved' => $this->aprooved, 'active' => $this->active]);
     $query->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'user_id', $this->user_id]);
     $query->andFilterWhere(['like', 'person.nick', $this->nick]);
     return $dataProvider;
 }
Exemplo n.º 2
0
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'content:ntext', ['attribute' => 'nick', 'value' => function ($data) {
    /*if($data->person != NULL){
      return $data->person->nick;
      }else
      {return '';}}*/
    if (!empty($data->person->nick)) {
        return $data->person->nick;
    } else {
        return '';
    }
}], ['attribute' => 'datetime', 'value' => 'datetime', 'filter' => \yii\jui\DatePicker::widget(['model' => $searchModel, 'attribute' => 'datetime', 'language' => 'eng', 'dateFormat' => 'yyyy-M-d']), 'format' => 'html'], ['attribute' => 'joke_id', 'value' => function ($data) {
    $joke = Comment::getJoke($data->joke_id);
    return $joke->name;
}], ['attribute' => 'aprooved', 'value' => function ($data) {
    if ($data->aprooved == 1) {
        return "Yes";
    } else {
        return "No";
    }
}], ['class' => 'yii\\grid\\ActionColumn', 'header' => 'Action', 'headerOptions' => ['width' => '80'], 'template' => '{update}{delete}{active}', 'buttons' => ['active' => function ($url, $model, $key) {
    $url = 'index.php?r=admin/comment/active&id=' . $model->id;
    if ($model->aprooved == 0) {
        $options = ['class' => 'glyphicon glyphicon-ok'];
    } else {
        $options = ['class' => 'glyphicon glyphicon-remove'];
    }
    return Html::a('', $url, $options);
Exemplo n.º 3
0
 /**
  * Finds the Comment model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Comment the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Comment::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 4
0
 public function findComment($id)
 {
     if ($model = Comment::find()->where(['joke_id' => $id])->all()) {
         return $model;
     } else {
         $model = [];
         return $model;
     }
 }