예제 #1
0
 /**
  * Lists all Info models.
  * @return mixed
  */
 public function actionIndex()
 {
     $searchModel = new InfoSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     $dataProvider->sort = ['defaultOrder' => ['published_at' => SORT_DESC]];
     $dataProvider->query->andFilterWhere(['{{info}}.locale' => Yii::$app->language]);
     if (Yii::$app->request->get('mid')) {
         $parentModel = Model::findOne(['id' => Yii::$app->request->get('mid')]);
         $models = Info::find()->andFilterWhere(['{{info}}.domain_id' => Yii::getAlias('@defaultDomainId'), '{{info}}.locale' => 'uk-UA'])->andWhere(['like', 'slug', $parentModel->slug])->all();
     } else {
         $models = Info::find()->andFilterWhere(['{{info}}.domain_id' => Yii::getAlias('@defaultDomainId'), '{{info}}.locale' => 'uk-UA'])->all();
     }
     $list = \yii\helpers\ArrayHelper::map($models, 'locale_group_id', 'title');
     $cars = Model::find()->andFilterWhere(['{{model}}.domain_id' => Yii::getAlias('@defaultDomainId'), '{{model}}.locale' => 'uk-UA'])->all();
     $carList = \yii\helpers\ArrayHelper::map($cars, 'id', 'title');
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'list' => $list, 'carList' => $carList]);
 }
예제 #2
0
 /**
  * Creates data provider instance with search query applied
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Model::find();
     if (!\Yii::$app->user->can('administrator')) {
         $query->forDomain();
     }
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'author_id' => $this->author_id, 'category_id' => $this->category_id, 'updater_id' => $this->updater_id, 'status' => $this->status, 'published_at' => $this->published_at, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'domain_id' => $this->domain_id]);
     $query->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'price', $this->price])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'weight', $this->weight])->andFilterWhere(['like', 'body', $this->body])->andFilterWhere(['like', 'before_body', $this->before_body])->andFilterWhere(['like', 'after_body', $this->after_body])->andFilterWhere(['like', 'on_scenario', $this->on_scenario]);
     if (!empty($params['ModelSearch']['cid'])) {
         $query->onlyCategory($params['ModelSearch']['cid']);
     }
     return $dataProvider;
 }
예제 #3
0
 /**
  * Creates a new Model model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     foreach (Yii::$app->params['availableLocales'] as $key => $value) {
         $currentModel = Model::getLocaleInstance($key);
         $currentModel->locale = $key;
         if (Yii::$app->request->get('scenario')) {
             $currentModel->on_scenario = Yii::$app->request->get('scenario');
         }
         $models[$key] = $currentModel;
     }
     //set data from default model
     if (Yii::$app->request->get('locale_group_id')) {
         $defaultDomainModels = Model::find()->andFilterWhere(['domain_id' => Yii::getAlias('@defaultDomainId'), 'locale_group_id' => Yii::$app->request->get('locale_group_id')])->all();
         foreach ($defaultDomainModels as $key => $value) {
             if (!in_array($value->locale, array_keys(Yii::$app->params['availableLocales']))) {
                 continue;
             }
             $models[$value->locale]->slug = $value->slug;
             $models[$value->locale]->title = $value->title;
             $models[$value->locale]->head = $value->head;
             $models[$value->locale]->body = $value->body;
             $models[$value->locale]->price = $value->price;
             $models[$value->locale]->description = $value->description;
             $models[$value->locale]->thumbnail = $value->thumbnail;
             $models[$value->locale]->before_body = $value->before_body;
             $models[$value->locale]->after_body = $value->after_body;
         }
     }
     $model = new MultiModel(['models' => $models]);
     if ($model->load(Yii::$app->request->post()) && Model::multiSave($model)) {
         return $this->redirect(['index']);
     } else {
         switch (Yii::$app->request->get('scenario')) {
             case 'extend':
                 $viewName = 'extend';
                 break;
             default:
                 $viewName = 'create';
         }
         return $this->render($viewName, ['model' => $model, 'categories' => ModelCategory::find()->active()->all(), 'domains' => array_combine(explode(',', Yii::getAlias('@frontendUrls')), explode(',', Yii::getAlias('@frontendUrls')))]);
     }
 }
예제 #4
0
 /**
  * Lists all Info models.
  * @return mixed
  */
 public function actionIndex()
 {
     $searchModel = new InfoSearch();
     $searchModel->detachBehaviors();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     // $dataProvider->sort = [
     //     'defaultOrder' => ['published_at' => SORT_DESC]
     // ];
     $dataProvider->sort->attributes['search_date_published'] = ['asc' => ['published_at' => SORT_ASC], 'desc' => ['published_at' => SORT_DESC]];
     $dataProvider->query->andFilterWhere(['info.locale' => Yii::$app->language]);
     //        $dataProvider->query->andFilterWhere(['!=', 'info.locale', 'en-US']);
     if (Yii::$app->request->get('mid')) {
         $parentModel = Model::findOne(['id' => Yii::$app->request->get('mid')]);
         $models = Info::find()->andFilterWhere(['domain_id' => Yii::getAlias('@defaultDomainId'), 'locale' => 'uk-UA'])->andWhere(['like', 'slug', $parentModel->slug])->all();
     } else {
         $models = Info::find()->andFilterWhere(['domain_id' => Yii::getAlias('@defaultDomainId'), 'locale' => 'uk-UA'])->all();
     }
     $list = \yii\helpers\ArrayHelper::map($models, 'locale_group_id', 'title');
     $cars = Model::find()->andFilterWhere(['domain_id' => Yii::$app->user->identity->domain_id, 'locale' => 'uk-UA'])->all();
     $carList = \yii\helpers\ArrayHelper::map($cars, 'id', 'title');
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'list' => $list, 'carList' => $carList]);
 }
예제 #5
0
파일: Model.php 프로젝트: efabrikov/renault
 public function afterDelete()
 {
     $model = Model::find()->andWhere(['locale_group_id' => $this->locale_group_id, 'domain_id' => Yii::$app->user->identity->domain_id])->one();
     if ($model) {
         $model->delete();
     }
     return parent::afterDelete();
 }
예제 #6
0
 /**
  * Deletes an existing ModelCategory model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $modelModel = Model::find()->andWhere(['category_id' => $id])->one();
     if (null === $modelModel) {
         $this->findModel($id)->delete();
     } else {
         Yii::$app->session->setFlash('alert', ['body' => \Yii::t('backend', 'Can not delete category #' . $id . '. It used in other table. Change category for model #' . $modelModel->id . ' before delete.'), 'options' => ['class' => 'alert-error']]);
     }
     return $this->redirect(['index']);
 }
예제 #7
0
파일: index.php 프로젝트: efabrikov/renault
            <span class="caret"></span>
        </button>
        <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
            <?php 
    foreach ($list as $key => $value) {
        echo '<li><a href="/info/create?locale_group_id=' . $key . '&' . $additionalGetParam . '&scenario=extend">' . $value . '</a></li>';
    }
    ?>

        </ul>
    </span>
<?php 
}
?>
    <?php 
$campuses = Model::find()->orderBy('title')->where(['locale' => Yii::$app->language])->asArray()->all();
foreach ($campuses as $key => $value) {
    $id = $value['id'];
    $title = $value['title'];
    $user = User::findIdentity($value['author_id']);
    $user = $user->username;
    $data[] = ['id' => $id, 'title' => $title . "(" . $user . ")"];
}
$columns = ['id', ['attribute' => 'model_id', 'filter' => Arrayhelper::map($data, 'id', 'title')], 'title', 'slug', ['class' => \common\grid\EnumColumn::className(), 'attribute' => 'status', 'enum' => [Yii::t('backend', 'Not Published'), Yii::t('backend', 'Published')]], ['attribute' => 'search_date_published', 'label' => 'Дата публикации', 'value' => 'published_at', 'format' => ['date', 'php:d-m-Y']], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update} {log} {delete}', 'buttons' => ['log' => function ($url, $model) {
    $customurl = Yii::$app->getUrlManager()->createUrl(['timeline-event/index', 'TimelineEventSearch[category]' => 'common\\models\\locale\\Info', 'TimelineEventSearch[row_id]' => $model->id]);
    return Html::a('<span class="glyphicon glyphicon-time"></span>', $customurl, ['title' => Yii::t('yii', 'Log'), 'data-pjax' => '0']);
}]]];
if (\Yii::$app->user->can('administrator')) {
    // adding after url
    array_splice($columns, 4, 0, [['attribute' => 'domain_id', 'content' => function ($model) {
        $domain = Domain::findOne($model->domain_id);