Esempio n. 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params, $parent)
 {
     $query = CatalogProducts::find();
     $query->andWhere(['parent' => $parent]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 25]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'parent' => $this->parent, 'isparent' => $this->isparent, 'views' => $this->views, 'createdby' => $this->createdby, 'createdon' => $this->createdon, 'status' => $this->status, 'publishedon' => $this->publishedon, 'price' => $this->price, 'sellout' => $this->sellout]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'introtext', $this->introtext])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'image', $this->image]);
     return $dataProvider;
 }
Esempio n. 2
0
/* @var $searchModel common\modules\catalog\models\CatalogSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
if (empty($parentModel->name)) {
    $this->title = Yii::t('catalog/main', 'Index');
} else {
    $this->title = $parentModel->name;
}
$this->params['breadcrumbs'][] = $this->title;
?>

<?php 
echo GridView::widget(['options' => ['boxTitle' => Yii::t('catalog/main', 'Catalog'), 'buttonUp' => Url::to(['index', 'parent' => $parentModel->parent]), 'buttonCreate' => Url::to(['create', 'class' => $class]), 'buttonUndo' => Url::home(), 'buttonDelete' => Url::to(['batch-delete']), 'ajax' => $ajax], 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => CheckboxColumn::classname(), 'contentOptions' => ['style' => 'width: 1px;']], 'id', ['format' => 'image', 'attribute' => 'image', 'filter' => '', 'contentOptions' => ['class' => 'text-center', 'style' => 'width: 1px;'], 'value' => function ($model) {
    return Image::thumb($model->image, 50, 50);
}], ['attribute' => 'name', 'format' => 'html', 'value' => function ($model) {
    return $model['isparent'] ? Html::a($model['name'], ['index', 'parent' => $model['id']]) : $model['name'];
}], 'price', ['attribute' => 'status', 'label' => \Yii::t('catalog/main', 'Status'), 'filter' => Html::activeDropDownList($searchModel, 'status', CatalogProducts::getStatusArray(), ['class' => 'form-control', 'prompt' => Yii::t('catalog/main', 'All')]), 'format' => 'html', 'value' => function ($model) {
    if ($model->status === CatalogProducts::STATUS_PUBLISHED) {
        $class = 'label-success';
        $lable = CatalogProducts::getStatusArray()[CatalogProducts::STATUS_PUBLISHED];
    } elseif ($model->status === CatalogProducts::STATUS_NOT_PUBLISHED) {
        $class = 'label-danger';
        $lable = CatalogProducts::getStatusArray()[CatalogProducts::STATUS_NOT_PUBLISHED];
    } elseif ($model->status === CatalogProducts::STATUS_DELETED) {
        $class = 'label-warning';
        $lable = CatalogProducts::getStatusArray()[CatalogProducts::STATUS_DELETED];
    }
    return '<span class="label ' . $class . '">' . $lable . '</span>';
}], ['class' => ActionColumn::className()]]]);
?>

Esempio n. 3
0
 /**
  * Finds the CatalogCategorys model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return CatalogCategorys the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = CatalogProducts::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }