/**
  * Creates data provider instance with search query applied
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ModelCategory::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, 'status' => $this->status, 'domain_id' => $this->domain_id]);
     $query->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'weight', $this->weight])->andFilterWhere(['like', 'title', $this->title]);
     return $dataProvider;
 }
Exemple #2
0
 public static function getLeftMenuListItems()
 {
     $items = [];
     $items[] = ['label' => Yii::t('backend', 'All'), 'url' => ['/model/index'], 'icon' => '<i class="fa fa-angle-double-right"></i>'];
     foreach (ModelCategory::find()->active()->all() as $category) {
         $items[] = ['label' => Yii::t('backend', $category->slug), 'url' => ['/model/index', 'ModelSearch' => ['cid' => $category->id]], 'icon' => '<i class="fa fa-angle-double-right"></i>', 'active' => self::isActiveListItem($category->id)];
     }
     return $items;
 }
 /**
  * Finds the ModelCategory model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return ModelCategory the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = ModelCategory::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemple #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCategory()
 {
     return $this->hasOne(ModelCategory::className(), ['id' => 'category_id']);
 }
Exemple #5
0
 /**
  * Updates an existing Model model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $firstModel = $this->findModel($id);
     foreach (Yii::$app->params['availableLocales'] as $key => $value) {
         $currentModel = Model::getLocaleInstance($key);
         $dataModel = $currentModel::find()->andWhere(['locale_group_id' => $firstModel->locale_group_id, 'locale' => $key])->one();
         $dataModel->categoriesList = $this->getCategoriesListIds($dataModel->id);
         if (!empty($dataModel->domain)) {
             $dataModel->domain = explode(',', $dataModel->domain);
         }
         $models[$key] = $dataModel;
         if (!$models[$key]) {
             $currentModel->attributes = $firstModel->attributes;
             $currentModel->attachments = $firstModel->attachments;
             $currentModel->thumbnail = $firstModel->thumbnail;
             //TODO: thumbnail copy fix
             $currentModel->categoriesList = $firstModel->categoriesList;
             //$currentModel->video = $firstModel->video;
             $currentModel->locale_group_id = $firstModel->locale_group_id;
             $currentModel->locale = $key;
             $currentModel->title = 'title ' . $key . ' ' . time();
             $currentModel->descripton = $firstModel->description;
             $currentModel->price = $firstModel->price;
             $currentModel->slug = '';
             $models[$key] = $currentModel;
         }
     }
     $model = new MultiModel(['models' => $models]);
     if ($model->load(Yii::$app->request->post()) && Model::multiSave($model)) {
         return $this->redirect(['index']);
     } else {
         switch ($firstModel->on_scenario) {
             case 'extend':
                 $viewName = 'extend';
                 break;
             default:
                 $viewName = 'update';
         }
         return $this->render($viewName, ['model' => $model, 'categories' => ModelCategory::find()->active()->all(), 'domains' => array_combine(explode(',', Yii::getAlias('@frontendUrls')), explode(',', Yii::getAlias('@frontendUrls')))]);
     }
 }