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