/**
  * Creates a new AnItems model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new AnItems();
     $NeccFunc = new NeccFunctions();
     // вибираємо головних батьків
     $parentCats = AnCats::find()->roots()->all();
     $list = $NeccFunc->getCorrectList($parentCats);
     // вибираємо регіони
     $regionsQuery = AnRegions::find()->asArray()->all();
     $regions = array();
     // формую правильний масив для select форми
     // хоча потрібно було б використати ArrayHelper::map($array, 'key', 'key')
     foreach ($regionsQuery as $region) {
         $regions[$region['id']] = $region['name'];
     }
     if ($model->load(Yii::$app->request->post())) {
         $model->created_at = DATE('Y-m-d H:i:s');
         $model->status = 0;
         $model->local = Yii::$app->language;
         $model->save();
         return $this->redirect('/announcement/anitems');
     } else {
         return $this->render('create', ['model' => $model, 'regions' => $regions, 'list' => $list]);
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params, $perPage)
 {
     $query = AnItems::find()->where(['status' => 1])->orderBy('created_at DESC');
     $query->joinwith(['cat', 'region']);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $perPage]]);
     $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;
     }
     // якщо вибрана категорія є головним батьком (root) - вибираємо всіх його дітей
     if ($this->category != null) {
         $cats = AnCats::find()->where(['id' => $this->category])->all();
         foreach ($cats as $cat) {
             $children[] = $cat->children()->all();
         }
         foreach ($children as $childs) {
             foreach ($childs as $child) {
                 $this->category[] = $child->id;
             }
         }
     }
     $query->andFilterWhere(['id' => $this->id, 'an_cats.id' => $this->category, 'an_regions.id' => $this->region, 'an_cats.local' => Yii::$app->language, 'an_items.local' => Yii::$app->language]);
     $query->andFilterWhere(['like', 'created_at', $this->created_at])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'text', $this->text])->andFilterWhere(['like', 'person', $this->person])->andFilterWhere(['like', 'phone', $this->phone])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'site', $this->site]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $perPage]]);
     return $dataProvider;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = AnCats::find()->orderBy('tree');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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, 'tree' => $this->parentCat, 'lft' => $this->lft, 'rgt' => $this->rgt, 'depth' => $this->depth]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'local', $this->local]);
     return $dataProvider;
 }
 public function init()
 {
     parent::init();
     $NeccFunc = new NeccFunctions();
     $perPage = $this->perPage ? $this->perPage : 10;
     // вибираємо головних батьків
     $parentCats = AnCats::find()->where(['local' => Yii::$app->language])->roots()->all();
     $this->categories = $NeccFunc->getCorrectList($parentCats);
     foreach ($parentCats as $cats) {
         $this->categories[$cats->id] = $cats->name;
     }
     // виборка категорій та регіонів
     //$this->categories = AnCats::find()->addOrderBy('tree')->addOrderBy('lft')->all();
     $parentRegs = AnRegions::find()->roots()->all();
     $this->regions = $NeccFunc->getCorrectList($parentRegs);
     //$this->regions = AnRegions::find()->addOrderBy('tree')->addOrderBy('lft')->all();
     // пошукові запроси, якщо такі є
     $this->searchModel = new AnItemsSearch();
     $this->dataProvider = $this->searchModel->search(Yii::$app->request->queryParams, $perPage);
     $this->registerTranslations();
 }
 /**
  * Creates a new AnItems model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new AnItems();
     $catsQuery = AnCats::find()->asArray()->all();
     $cats = array();
     foreach ($catsQuery as $cat) {
         $cats[$cat['id']] = $cat['name'];
     }
     $regionsQuery = AnRegions::find()->asArray()->all();
     $regions = array();
     foreach ($regionsQuery as $region) {
         $regions[$region['id']] = $region['name'];
     }
     if ($model->load(Yii::$app->request->post())) {
         $model->created_at = DATE('Y-m-d H:i:s');
         $model->status = 0;
         $model->local = Yii::$app->language;
         $model->save();
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'cats' => $cats, 'regions' => $regions]);
     }
 }
Exemple #6
0
/* @var $searchModel vov\announcement\backend\models\AnCatsSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'An Cats';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="an-cats-index">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <p>
        <?php 
echo Html::a('Create An Cats', ['create'], ['class' => 'btn btn-success']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'name', ['label' => 'parentCat', 'attribute' => 'parentCat', 'value' => function ($searchModel) {
    $cat = \vov\announcement\backend\models\AnCats::findOne(['id' => $searchModel->id]);
    $parentCat = $cat->parents(1)->one();
    return $parentCat->name;
}, 'filter' => yii\Helpers\ArrayHelper::map($searchModel->getParents(), 'id', 'name')], ['label' => 'local', 'attribute' => 'local', 'value' => 'local', 'filter' => \vov\announcement\common\helpers\NeccFunctions::getLanguages()], ['class' => 'yii\\grid\\ActionColumn']]]);
?>

</div>
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCat()
 {
     return $this->hasOne(AnCats::className(), ['id' => 'cat_id']);
 }
Exemple #8
0
 public function getParents()
 {
     return AnCats::find()->roots()->all();
 }
 /**
  * Finds the AnCats model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return AnCats the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = AnCats::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }