/**
  * Finds the ModificatorCategory model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return ModificatorCategory the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = ModificatorCategory::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Ejemplo n.º 2
0
 public function import()
 {
     $f = fopen($this->file->tempName, 'rb');
     $result = true;
     $i = 0;
     while ($row = fgetcsv($f, 2048, ';', '"')) {
         array_map('trim', $row);
         list($category, $key, $value) = $row;
         if ($i == 0 && empty($category)) {
             $result = false;
             $this->addError('file', 'Неверный формат файла');
             break;
         }
         $i++;
         if (!empty($category)) {
             $modelCategory = ModificatorCategory::find()->where(['title' => $category, 'productId' => $this->productId])->one();
             if (!$modelCategory) {
                 $modelCategory = new ModificatorCategory();
             }
             $modelCategory->title = $category;
             $modelCategory->productId = $this->productId;
             $modelCategory->categoryId = $this->categoryId;
             $modelCategory->memo = $key;
             $modelCategory->save();
             continue;
         }
         $modelItem = ModificatorItem::find()->where(['title' => $key, 'categoryId' => $modelCategory->id])->one();
         if (!$modelItem) {
             $modelItem = new ModificatorItem();
         }
         $modelItem->categoryId = $modelCategory->id;
         $modelItem->title = $key;
         $modelItem->content = $value;
         $modelItem->save();
     }
     fclose($f);
     return $result;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ModificatorCategory::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'productId' => $this->productId, 'categoryId' => $this->categoryId]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'titleLink', $this->titleLink])->andFilterWhere(['like', 'alias', $this->alias])->andFilterWhere(['like', 'memo', $this->memo]);
     return $dataProvider;
 }
Ejemplo n.º 4
0
 public function getModificators()
 {
     return $this->hasMany(ModificatorCategory::className(), ['productId' => 'id']);
 }