/**
  * 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)
 {
     $query = AnRegions::find();
     $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->parentReg, '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]);
     }
 }
Example #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRegion()
 {
     return $this->hasOne(AnRegions::className(), ['id' => 'region_id']);
 }
Example #6
0
/* @var $searchModel vov\announcement\backend\models\AnRegionsSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'An Regions';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="an-regions-index">

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

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

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'name', ['label' => 'parentReg', 'attribute' => 'parentReg', 'value' => function ($searchModel) {
    $cat = \vov\announcement\backend\models\AnRegions::findOne(['id' => $searchModel->id]);
    $parentReg = $cat->parents(1)->one();
    return $parentReg->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>
 /**
  * Finds the AnRegions model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return AnRegions the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = AnRegions::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #8
0
 public function getParents()
 {
     return AnRegions::find()->roots()->all();
 }