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