/** * Displays homepage. * * @return mixed */ public function actionIndex() { //$mainCategory = new MainCategory(); // $category = new Category(); //Search $mainCategory = MainCategory::find()->all(); $searchModel = new \common\models\search\GSearch(); $dataProvider = $searchModel->search(\Yii::$app->request->queryParams); return $this->render('index', ['maincategory' => $mainCategory, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]); }
public static function getHierarchy() { $options = []; $parents = MainCategory::find()->where(['is_status' => 1])->all(); foreach ($parents as $id => $p) { $children = self::find()->where(['main_category_id' => $p->id, 'is_status' => 1])->all(); $child_options = []; foreach ($children as $child) { $child_options[$child->id] = $child->category; } $options[$p->main_category] = $child_options; } return $options; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = MainCategory::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $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; } $query->andFilterWhere(['id' => $this->id, 'create_at' => $this->create_at, 'update_at' => $this->update_at, 'is_status' => $this->is_status]); $query->andFilterWhere(['like', 'main_category', $this->main_category])->andFilterWhere(['like', 'icon', $this->icon]); return $dataProvider; }
public function actionClassified($id) { $modelCover = new Profile(); $modelCover = $this->findModel($id); //Sort data $sort = new \yii\data\Sort(['attributes' => ['create_at' => ['asc' => ['create_at' => SORT_ASC], 'desc' => ['create_at' => SORT_DESC], 'default' => SORT_DESC]]]); //pagination $queryPage = Classified::find()->where(['user_id' => $id]); $countQueryPage = clone $queryPage; $pagination = new \yii\data\Pagination(['totalCount' => $countQueryPage->count(), 'pageSize' => 2]); //Search $mainCategory = \common\models\MainCategory::find()->all(); $searchModel = new \common\models\search\GSearch(); $dataProvider = $searchModel->search(\Yii::$app->request->queryParams); //query model $query = new \yii\db\Query(); $query->select(['classified.id', 'classified.title', 'classified.description', 'classified.price', 'classified.create_at', 'classified.type', 'classified.user_id', 'classified.is_status', 'main_category.main_category', 'category.category', 'country.country', 'region.region', 'city.city', 'user.username'])->from('classified')->join('JOIN', 'category', 'category.id = classified.category_id')->join('JOIN', 'main_category', 'main_category.id = classified.main_category_id')->join('JOIN', 'country', 'country.id = classified.country_id')->join('JOIN', 'region', 'region.id = classified.region_id')->join('JOIN', 'city', 'city.id = classified.city_id')->join('JOIN', 'user', 'user.id = classified.user_id')->where(['user_id' => $id])->offset($pagination->offset)->limit($pagination->limit)->orderBy($sort->orders)->all(); $command = $query->createCommand(); $data = $command->queryAll(); return $this->render('classified', ['data' => $data, 'sort' => $sort, 'pagination' => $pagination, 'maincategory' => $mainCategory, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'modelCover' => $modelCover]); }
</div> <div class="row"> <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"> <h3 class="box-title" style="padding-bottom: 20px"> <i class="fa fa-th-list"></i> <?php echo Yii::t('app', 'List Category'); ?> <span class="pull-right"><a href="<?php echo \yii\helpers\Url::to(['/main-category/']); ?> " class="btn btn-info"> Main Category <i class="fa fa-arrow-right"></i></a></span> </h3> <div class="box view-item"> <div class="box-body"> <div class="category-index"> <?php yii\widgets\Pjax::begin(); ?> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'category', ['attribute' => 'main_category_id', 'value' => 'mainCategory.main_category', 'filter' => yii\helpers\ArrayHelper::map(\common\models\MainCategory::find()->where(['is_status' => 1])->all(), 'id', 'main_category')], ['attribute' => 'is_status', 'class' => '\\pheme\\grid\\ToggleColumn', 'enableAjax' => false, 'filter' => ['1' => 'Active', '0' => 'Not Active']], ['class' => 'common\\components\\CustomActionColumn']]]); ?> <?php yii\widgets\Pjax::end(); ?> </div> </div> </div> </div> </div>
<div class="container"> <div class="row"> <div class="col-lg-9"> <div class="panel"> <div class="panel-heading"> <h2 class="heading2"> List Category</h2> </div> <div class="panel-body"> <div class="mt40"> <ul class="row clearfix"> <?php // if($maincategory){ $maincategory2 = \common\models\MainCategory::find()->where(['is_status' => 1])->all(); foreach ($maincategory2 as $row) { $category = \common\models\Category::find()->where(['main_category_id' => $row['id'], 'is_status' => 1])->all(); ?> <li class="col-lg-4 col-md-4 col-sm-6 col-xs-12"> <section class="directorylist" style="min-height: 250px"> <div><i class="fa <?php echo $row['icon']; ?> "></i><span class="directorytitle"><?php echo $row['main_category']; ?> </span></div> <ul class="list"> <?php foreach ($category as $cat) {
<?php if ($this->context->action->id == 'update') { $action = ['update', 'id' => $_REQUEST['id']]; } else { $action = ['create']; } ?> <?php $form = ActiveForm::begin(['id' => 'category-form', 'action' => $action, 'enableAjaxValidation' => true]); ?> <?php $listMainCategory = yii\helpers\ArrayHelper::map(\common\models\MainCategory::find()->where(['is_status' => 1])->all(), 'id', 'main_category'); ?> <?php echo $form->field($model, 'main_category_id')->dropDownList($listMainCategory, ['prompt' => '-- Select Main Category --'])->label(false); ?> <?php echo $form->field($model, 'category', ['inputOptions' => ['placeholder' => 'Category Name', 'class' => 'form-control']])->textInput(['maxlength' => true])->label(false); ?> <?php echo $form->field($model, 'is_status')->dropDownList(['1' => 'Active', '0' => 'Not Active'], ['prompt' => '-- Status --'])->label(false); ?> <div class="form-group">