示例#1
0
 /**
  * Creates data provider instance with search query applied
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = AboutCategory::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;
 }
示例#2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCategory()
 {
     return $this->hasOne(AboutCategory::className(), ['id' => 'category_id']);
 }
示例#3
0
 /**
  * Updates an existing About model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $firstAbout = $this->findAbout($id);
     foreach (Yii::$app->params['availableLocales'] as $key => $value) {
         $currentAbout = About::getLocaleInstance($key);
         $dataAbout = $currentAbout::find()->andWhere(['locale_group_id' => $firstAbout->locale_group_id, 'locale' => $key])->one();
         $dataAbout->categoriesList = $this->getCategoriesListIds($dataAbout->id);
         if (!empty($dataAbout->domain)) {
             $dataAbout->domain = explode(',', $dataAbout->domain);
         }
         $abouts[$key] = $dataAbout;
         if (!$abouts[$key]) {
             $currentAbout->attributes = $firstAbout->attributes;
             $currentAbout->attachments = $firstAbout->attachments;
             $currentAbout->thumbnail = $firstAbout->thumbnail;
             //TODO: thumbnail copy fix
             $currentAbout->categoriesList = $firstAbout->categoriesList;
             //$currentAbout->video = $firstAbout->video;
             $currentAbout->locale_group_id = $firstAbout->locale_group_id;
             $currentAbout->locale = $key;
             $currentAbout->title = 'title ' . $key . ' ' . time();
             $currentAbout->descripton = $firstAbout->description;
             $currentAbout->price = $firstAbout->price;
             $currentAbout->slug = '';
             $abouts[$key] = $currentAbout;
         }
     }
     $about = new MultiModel(['models' => $abouts]);
     if ($about->load(Yii::$app->request->post()) && About::multiSave($about)) {
         return $this->redirect(['index']);
     } else {
         switch ($firstAbout->on_scenario) {
             case 'extend':
                 $viewName = 'extend';
                 break;
             default:
                 $viewName = 'update';
         }
         return $this->render($viewName, ['model' => $about, 'categories' => AboutCategory::find()->active()->all(), 'domains' => array_combine(explode(',', Yii::getAlias('@frontendUrls')), explode(',', Yii::getAlias('@frontendUrls')))]);
     }
 }
 /**
  * Finds the AboutCategory model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return AboutCategory the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findAbout($id)
 {
     if (($about = AboutCategory::findOne($id)) !== null) {
         return $about;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }