Ejemplo n.º 1
0
 /**
  * Updates an existing ServiceCategory model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $service = $this->findService($id);
     if ($service->load(Yii::$app->request->post()) && $service->save()) {
         return $this->redirect(['view', 'id' => $service->id]);
     } else {
         return $this->render('update', ['model' => $service, 'categories' => ServiceCategory::find()->noParents()->all()]);
     }
 }
Ejemplo n.º 2
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;
 }
Ejemplo 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')))]);
     }
 }