Ejemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params, $addParams = [])
 {
     $pagination = ['pageSize' => 10];
     if ($addParams['limit']) {
         $pagination = false;
     }
     $query = Comments::find();
     $query->orderBy($this->orderBy);
     if (isset($addParams['limit'])) {
         $query->limit($addParams['limit']);
     }
     if (isset($addParams['pagination'])) {
         $pagination = $addParams['pagination'];
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => $pagination]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'user_id' => $this->user_id, 'object' => $this->object, 'object_id' => $this->object_id, 'parent_id' => $this->parent_id, 'date_create' => $this->date_create, 'date_update' => $this->date_update]);
     $query->andFilterWhere(['like', 'text', $this->text])->andFilterWhere(['like', 'note', $this->note]);
     return $dataProvider;
 }
Ejemplo n.º 2
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     $model = new Comments(['scenario' => 'create']);
     Yii::$app->response->format = Response::FORMAT_JSON;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $level = Yii::$app->request->get('level');
         if ($level !== null) {
             $level = $level < CommentsWidget::MAX_LEVEL ? $level + 1 : CommentsWidget::MAX_LEVEL;
         } else {
             $level = 0;
         }
         if ($this->callback != null) {
             $this->callback($model);
         }
         return ['status' => true];
     } else {
         return ['status' => false, 'errors' => ActiveForm::validate($model)];
     }
 }
 /**
  * Finds the Comments model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return User the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Comments::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Ejemplo n.º 4
0
            <?php 
echo $form->field($model, 'user_id')->dropDownList(\common\modules\users\models\User::getUsersRoleUser(), ['prompt' => 'Выберите пользователя']);
?>
            <?php 
echo $form->field($model, 'date_create')->textInput(['class' => 'datepicker form-control']);
?>
            <?php 
echo $form->field($model, 'text')->textarea(['rows' => 5]);
?>
            <?php 
echo $form->field($model, 'show_main')->checkbox();
?>
            <?php 
echo $form->field($model, 'note')->textarea(['rows' => 3]);
?>
            <?php 
echo $form->field($model, 'status')->dropDownList(Comments::getStatusList(), array('prompt' => ''));
?>
        </div>
    </div>

    <div class="form-group">
        <?php 
echo Html::submitButton('Сохранить', ['class' => 'btn btn-primary']);
?>
    </div>
    <?php 
ActiveForm::end();
?>
</div>
Ejemplo n.º 5
0
Modal::end();
?>

    <p>
        <?php 
echo Html::a('Добавить отзыв', ['create'], ['data-original-title' => 'Новый отзыв', 'data-header' => 'Новый отзыв', 'class' => 'btn btn-success btn-xs btn-open-modal']);
?>
    </p>

    <?php 
Pjax::begin(['id' => 'comments-list', 'timeout' => 10000]);
?>
    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'user_id', 'format' => 'html', 'value' => function ($model) {
    $author = $model->author;
    return Html::a($author->firstname . ' ' . $author->lastname, ['/users/default/update', 'id' => $author->id]);
}], ['attribute' => 'object', 'format' => 'html', 'filter' => Html::activeDropDownList($searchModel, 'object', Comments::getObjects(1), ['class' => 'form-control', 'prompt' => 'Все']), 'value' => function ($model) {
    return Html::a(Comments::getObjectTitle($model->object) . ' #' . $model->object_id, ['/' . $model->object . '/default/update', 'id' => $author->id]);
}], 'date_create', 'text', 'note', ['attribute' => 'status', 'filter' => Html::activeDropDownList($searchModel, 'status', Comments::getStatusList(), ['class' => 'form-control', 'prompt' => 'Все']), 'value' => function ($model) {
    return $model->getStatusTitle();
}], 'show_main', ['class' => 'yii\\grid\\ActionColumn', 'headerOptions' => ['style' => 'width:70px'], 'template' => '{update} {delete}', 'buttons' => ['update' => function ($url, $model) {
    return Html::a('<i class="fa fa-edit"></i>', $url, ['data-original-title' => 'Редактировать', 'class' => 'btn btn-info btn-minier tooltip-info  btn-open-modal', 'data-header' => 'Редактирование', 'data-rel' => 'tooltip']);
}, 'delete' => function ($url, $model) {
    return Html::a('<i class="fa fa-trash"></i>', $url, ['data-original-title' => 'Удалить', 'class' => 'btn btn-danger btn-minier tooltip-error', 'data-rel' => 'tooltip', 'data-confirm' => "Вы уверены, что хотите удалить этого пользователя?", 'data-method' => 'post', 'data-pjax' => 0]);
}]]]]);
?>
    <?php 
Pjax::end();
?>
</div>