Commit a61ab7a733ebd6da980a5dc25a3db5753bcb292d
1 parent
a874d14e
stock
Showing
16 changed files
with
1237 additions
and
0 deletions
Show diff stats
1 | +<?php | |
2 | + | |
3 | +namespace artbox\stock\controllers; | |
4 | + | |
5 | +use Yii; | |
6 | +use artbox\stock\models\City; | |
7 | +use yii\data\ActiveDataProvider; | |
8 | +use yii\web\Controller; | |
9 | +use yii\web\NotFoundHttpException; | |
10 | +use yii\filters\VerbFilter; | |
11 | +use yii\filters\AccessControl; | |
12 | +use yii\web\Response; | |
13 | +/** | |
14 | + * CityController implements the CRUD actions for City model. | |
15 | + */ | |
16 | +class CityController extends Controller | |
17 | +{ | |
18 | + /** | |
19 | + * @inheritdoc | |
20 | + */ | |
21 | + public function getViewPath() | |
22 | + { | |
23 | + return '@artbox/stock/views/city'; | |
24 | + } | |
25 | + | |
26 | + public function behaviors() | |
27 | + { | |
28 | + return [ | |
29 | + 'access' => [ | |
30 | + 'class' => AccessControl::className(), | |
31 | + 'rules' => [ | |
32 | + [ | |
33 | + 'actions' => [ | |
34 | + 'login', | |
35 | + 'error', | |
36 | + ], | |
37 | + 'allow' => true, | |
38 | + ], | |
39 | + [ | |
40 | + 'allow' => true, | |
41 | + 'roles' => [ '@' ], | |
42 | + ], | |
43 | + ], | |
44 | + ], | |
45 | + 'verbs' => [ | |
46 | + 'class' => VerbFilter::className(), | |
47 | + 'actions' => [ | |
48 | + 'delete' => ['POST'], | |
49 | + ], | |
50 | + ], | |
51 | + ]; | |
52 | + } | |
53 | + | |
54 | + /** | |
55 | + * Lists all City models. | |
56 | + * @return mixed | |
57 | + */ | |
58 | + public function actionIndex() | |
59 | + { | |
60 | + $dataProvider = new ActiveDataProvider([ | |
61 | + 'query' => City::find()->with(['lang']), | |
62 | + ]); | |
63 | + | |
64 | + return $this->render('index', [ | |
65 | + 'dataProvider' => $dataProvider, | |
66 | + ]); | |
67 | + } | |
68 | + | |
69 | + /** | |
70 | + * Displays a single City model. | |
71 | + * @param integer $id | |
72 | + * @return mixed | |
73 | + */ | |
74 | + public function actionView($id) | |
75 | + { | |
76 | + return $this->render('view', [ | |
77 | + 'model' => $this->findModel($id), | |
78 | + ]); | |
79 | + } | |
80 | + | |
81 | + /** | |
82 | + * Creates a new City model. | |
83 | + * If creation is successful, the browser will be redirected to the 'view' page. | |
84 | + * @return mixed | |
85 | + */ | |
86 | + public function actionCreate() | |
87 | + { | |
88 | + $model = new City(); | |
89 | + $model->generateLangs(); | |
90 | + if ($model->loadWithLangs(\Yii::$app->request) && $model->saveWithLangs()) { | |
91 | + return $this->redirect( | |
92 | + [ | |
93 | + 'view', | |
94 | + 'id' => $model->id, | |
95 | + ] | |
96 | + ); | |
97 | + } | |
98 | + return $this->render( | |
99 | + 'create', | |
100 | + [ | |
101 | + 'model' => $model, | |
102 | + 'modelLangs' => $model->modelLangs, | |
103 | + ] | |
104 | + ); | |
105 | + } | |
106 | + | |
107 | + /** | |
108 | + * Updates an existing City model. | |
109 | + * If update is successful, the browser will be redirected to the 'view' page. | |
110 | + * @param integer $id | |
111 | + * @return mixed | |
112 | + */ | |
113 | + public function actionUpdate($id) | |
114 | + { | |
115 | + $model = $this->findModel($id); | |
116 | + | |
117 | + $model->generateLangs(); | |
118 | + | |
119 | + if ($model->loadWithLangs(\Yii::$app->request) && $model->saveWithLangs()) { | |
120 | + return $this->redirect( | |
121 | + [ | |
122 | + 'view', | |
123 | + 'id' => $model->id, | |
124 | + ] | |
125 | + ); | |
126 | + } | |
127 | + return $this->render( | |
128 | + 'update', | |
129 | + [ | |
130 | + 'model' => $model, | |
131 | + 'modelLangs' => $model->modelLangs, | |
132 | + ] | |
133 | + ); | |
134 | + } | |
135 | + | |
136 | + /** | |
137 | + * Deletes an existing City model. | |
138 | + * If deletion is successful, the browser will be redirected to the 'index' page. | |
139 | + * @param integer $id | |
140 | + * @return mixed | |
141 | + */ | |
142 | + public function actionDelete($id) | |
143 | + { | |
144 | + $this->findModel($id)->delete(); | |
145 | + | |
146 | + return $this->redirect(['index']); | |
147 | + } | |
148 | + | |
149 | + /** | |
150 | + * Finds the City model based on its primary key value. | |
151 | + * If the model is not found, a 404 HTTP exception will be thrown. | |
152 | + * @param integer $id | |
153 | + * @return City the loaded model | |
154 | + * @throws NotFoundHttpException if the model cannot be found | |
155 | + */ | |
156 | + protected function findModel($id) | |
157 | + { | |
158 | + if (($model = City::findOne($id)) !== null) { | |
159 | + return $model; | |
160 | + } else { | |
161 | + throw new NotFoundHttpException('The requested page does not exist.'); | |
162 | + } | |
163 | + } | |
164 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace artbox\stock\controllers; | |
4 | + | |
5 | +use Yii; | |
6 | +use artbox\stock\models\Shop; | |
7 | +use yii\data\ActiveDataProvider; | |
8 | +use yii\helpers\VarDumper; | |
9 | +use yii\web\Controller; | |
10 | +use yii\web\NotFoundHttpException; | |
11 | +use yii\filters\VerbFilter; | |
12 | +use yii\filters\AccessControl; | |
13 | +/** | |
14 | + * ShopController implements the CRUD actions for Shop model. | |
15 | + */ | |
16 | +class ShopController extends Controller | |
17 | +{ | |
18 | + /** | |
19 | + * @inheritdoc | |
20 | + */ | |
21 | + public function getViewPath() | |
22 | + { | |
23 | + return '@artbox/stock/views/shop'; | |
24 | + } | |
25 | + public function behaviors() | |
26 | + { | |
27 | + return [ | |
28 | + 'access' => [ | |
29 | + 'class' => AccessControl::className(), | |
30 | + 'rules' => [ | |
31 | + [ | |
32 | + 'actions' => [ | |
33 | + 'login', | |
34 | + 'error', | |
35 | + ], | |
36 | + 'allow' => true, | |
37 | + ], | |
38 | + [ | |
39 | + 'allow' => true, | |
40 | + 'roles' => [ '@' ], | |
41 | + ], | |
42 | + ], | |
43 | + ], | |
44 | + 'verbs' => [ | |
45 | + 'class' => VerbFilter::className(), | |
46 | + 'actions' => [ | |
47 | + 'delete' => ['POST'], | |
48 | + ], | |
49 | + ], | |
50 | + ]; | |
51 | + } | |
52 | + | |
53 | + /** | |
54 | + * Lists all Shop models. | |
55 | + * @return mixed | |
56 | + */ | |
57 | + public function actionIndex() | |
58 | + { | |
59 | + $dataProvider = new ActiveDataProvider([ | |
60 | + 'query' => Shop::find(), | |
61 | + ]); | |
62 | + | |
63 | + return $this->render('index', [ | |
64 | + 'dataProvider' => $dataProvider, | |
65 | + ]); | |
66 | + } | |
67 | + | |
68 | + /** | |
69 | + * Displays a single Shop model. | |
70 | + * @param integer $id | |
71 | + * @return mixed | |
72 | + */ | |
73 | + public function actionView($id) | |
74 | + { | |
75 | + return $this->render('view', [ | |
76 | + 'model' => $this->findModel($id), | |
77 | + ]); | |
78 | + } | |
79 | + | |
80 | + /** | |
81 | + * Creates a new Shop model. | |
82 | + * If creation is successful, the browser will be redirected to the 'view' page. | |
83 | + * @return mixed | |
84 | + */ | |
85 | + public function actionCreate() | |
86 | + { | |
87 | + $model = new Shop(); | |
88 | + $model->generateLangs(); | |
89 | + $model->getCities(); | |
90 | + if ($model->loadWithLangs(\Yii::$app->request) && $model->saveWithLangs()) { | |
91 | + return $this->redirect( | |
92 | + [ | |
93 | + 'view', | |
94 | + 'id' => $model->id, | |
95 | + ] | |
96 | + ); | |
97 | + } | |
98 | + return $this->render( | |
99 | + 'create', | |
100 | + [ | |
101 | + 'model' => $model, | |
102 | + 'modelLangs' => $model->modelLangs, | |
103 | + ] | |
104 | + ); | |
105 | + | |
106 | + } | |
107 | + | |
108 | + /** | |
109 | + * Updates an existing Shop model. | |
110 | + * If update is successful, the browser will be redirected to the 'view' page. | |
111 | + * @param integer $id | |
112 | + * @return mixed | |
113 | + */ | |
114 | + public function actionUpdate($id) | |
115 | + { | |
116 | + $model = $this->findModel($id); | |
117 | + $model->generateLangs(); | |
118 | + $model->getCities(); | |
119 | + $model->loadWithLangs(\Yii::$app->request); | |
120 | + //print_r(\Yii::$app->request); | |
121 | + if ($model->loadWithLangs(\Yii::$app->request) && $model->saveWithLangs()) { | |
122 | + return $this->redirect( | |
123 | + [ | |
124 | + 'view', | |
125 | + 'id' => $model->id, | |
126 | + ] | |
127 | + ); | |
128 | + } | |
129 | + return $this->render( | |
130 | + 'update', | |
131 | + [ | |
132 | + 'model' => $model, | |
133 | + 'modelLangs' => $model->modelLangs, | |
134 | + ] | |
135 | + ); | |
136 | + } | |
137 | + | |
138 | + /** | |
139 | + * Deletes an existing Shop model. | |
140 | + * If deletion is successful, the browser will be redirected to the 'index' page. | |
141 | + * @param integer $id | |
142 | + * @return mixed | |
143 | + */ | |
144 | + public function actionDelete($id) | |
145 | + { | |
146 | + $this->findModel($id)->delete(); | |
147 | + | |
148 | + return $this->redirect(['index']); | |
149 | + } | |
150 | + | |
151 | + /** | |
152 | + * Finds the Shop model based on its primary key value. | |
153 | + * If the model is not found, a 404 HTTP exception will be thrown. | |
154 | + * @param integer $id | |
155 | + * @return Shop the loaded model | |
156 | + * @throws NotFoundHttpException if the model cannot be found | |
157 | + */ | |
158 | + protected function findModel($id) | |
159 | + { | |
160 | + if (($model = Shop::findOne($id)) !== null) { | |
161 | + return $model; | |
162 | + } else { | |
163 | + throw new NotFoundHttpException('The requested page does not exist.'); | |
164 | + } | |
165 | + } | |
166 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace artbox\stock\models; | |
4 | + | |
5 | +use Yii; | |
6 | +use artbox\core\models\Language; | |
7 | +use artbox\core\behaviors\LanguageBehavior; | |
8 | +use yii\db\ActiveQuery; | |
9 | +use yii\db\ActiveRecord; | |
10 | +use yii\web\Request; | |
11 | + | |
12 | +/** | |
13 | + * This is the model class for table "city". | |
14 | + * | |
15 | + * @property integer $id | |
16 | + * @property integer $sort | |
17 | + * @property boolean $status | |
18 | + * | |
19 | + * @property CityLang[] $cityLangs | |
20 | + * @property Language[] $languages | |
21 | + * @property Shop[] $shops | |
22 | + */ | |
23 | +class City extends \yii\db\ActiveRecord | |
24 | +{ | |
25 | + /** | |
26 | + * @inheritdoc | |
27 | + */ | |
28 | + public static function tableName() | |
29 | + { | |
30 | + return 'city'; | |
31 | + } | |
32 | + | |
33 | + public function behaviors() | |
34 | + { | |
35 | + return [ | |
36 | + 'language' => [ | |
37 | + 'class' => LanguageBehavior::className(), | |
38 | + ], | |
39 | + ]; | |
40 | + } | |
41 | + | |
42 | + /** | |
43 | + * @inheritdoc | |
44 | + */ | |
45 | + public function rules() | |
46 | + { | |
47 | + return [ | |
48 | + [['sort'], 'integer'], | |
49 | + [['status'], 'boolean'], | |
50 | + ]; | |
51 | + } | |
52 | + | |
53 | + /** | |
54 | + * @inheritdoc | |
55 | + */ | |
56 | + public function attributeLabels() | |
57 | + { | |
58 | + return [ | |
59 | + 'id' => 'ID', | |
60 | + 'sort' => Yii::t('stock', 'Sort'), | |
61 | + 'status' => Yii::t('stock', 'Status'), | |
62 | + ]; | |
63 | + } | |
64 | + | |
65 | + /** | |
66 | + * @return \yii\db\ActiveQuery | |
67 | + */ | |
68 | + public function getCityLangs() | |
69 | + { | |
70 | + return $this->hasMany(CityLang::className(), ['city_id' => 'id']) | |
71 | + ->inverseOf('city'); | |
72 | + } | |
73 | + | |
74 | + /** | |
75 | + * @return \yii\db\ActiveQuery | |
76 | + */ | |
77 | + public function getLanguages() | |
78 | + { | |
79 | + return $this->hasMany(Language::className(), ['id' => 'language_id'])->viaTable('city_lang', ['city_id' => 'id']); | |
80 | + } | |
81 | + | |
82 | + /** | |
83 | + * @return \yii\db\ActiveQuery | |
84 | + */ | |
85 | + public function getShops() | |
86 | + { | |
87 | + return $this->hasMany(Shop::className(), ['city_id' => 'id']); | |
88 | + } | |
89 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace artbox\stock\models; | |
4 | + | |
5 | +use Yii; | |
6 | +use artbox\core\behaviors\SlugBehavior; | |
7 | +use artbox\core\models\Alias; | |
8 | +use artbox\core\models\Language; | |
9 | + | |
10 | +/** | |
11 | + * This is the model class for table "city_lang". | |
12 | + * | |
13 | + * @property integer $city_id | |
14 | + * @property integer $language_id | |
15 | + * @property string $title | |
16 | + * @property integer $alias_id | |
17 | + * @property string $description | |
18 | + * | |
19 | + * @property Alias $alias | |
20 | + * @property City $city | |
21 | + * @property Language $language | |
22 | + */ | |
23 | +class CityLang extends \yii\db\ActiveRecord | |
24 | +{ | |
25 | + /** | |
26 | + * @inheritdoc | |
27 | + */ | |
28 | + public static function tableName() | |
29 | + { | |
30 | + return 'city_lang'; | |
31 | + } | |
32 | + | |
33 | + /** | |
34 | + * @inheritdoc | |
35 | + */ | |
36 | + public function behaviors() | |
37 | + { | |
38 | + return [ | |
39 | + 'slug' => [ | |
40 | + 'class' => SlugBehavior::className(), | |
41 | + 'action' => 'city/view', | |
42 | + 'params' => [ | |
43 | + 'id' => 'city_id', | |
44 | + ], | |
45 | + 'fields' => [ | |
46 | + 'title' => \Yii::t('stock', 'Title'), | |
47 | + 'description' => \Yii::t('stock', 'Description'), | |
48 | + ], | |
49 | + ], | |
50 | + ]; | |
51 | + } | |
52 | + public function rules() | |
53 | + { | |
54 | + return [ | |
55 | + [ | |
56 | + [ | |
57 | + 'title', | |
58 | + ], | |
59 | + 'required', | |
60 | + ], | |
61 | + [ | |
62 | + [ 'description' ], | |
63 | + 'string', | |
64 | + ], | |
65 | + [ | |
66 | + [ | |
67 | + 'title', | |
68 | + 'aliasValue', | |
69 | + ], | |
70 | + 'string', | |
71 | + 'max' => 255, | |
72 | + ], | |
73 | + ]; | |
74 | + } | |
75 | + | |
76 | + /** | |
77 | + * @inheritdoc | |
78 | + */ | |
79 | + public function attributeLabels() | |
80 | + { | |
81 | + return [ | |
82 | + 'city_id' => 'City ID', | |
83 | + 'language_id' => 'Language ID', | |
84 | + 'title' => \Yii::t('stock', 'Title'), | |
85 | + 'alias_id' => 'Alias ID', | |
86 | + 'description' => \Yii::t('stock', 'Description'), | |
87 | + ]; | |
88 | + } | |
89 | + | |
90 | + /** | |
91 | + * @return \yii\db\ActiveQuery | |
92 | + */ | |
93 | + public function getAlias() | |
94 | + { | |
95 | + return $this->hasOne(Alias::className(), ['id' => 'alias_id']); | |
96 | + } | |
97 | + | |
98 | + /** | |
99 | + * @return \yii\db\ActiveQuery | |
100 | + */ | |
101 | + public function getCity() | |
102 | + { | |
103 | + return $this->hasOne(City::className(), ['id' => 'city_id'])->inverseOf('cityLangs'); | |
104 | + } | |
105 | + | |
106 | + /** | |
107 | + * @return \yii\db\ActiveQuery | |
108 | + */ | |
109 | + public function getLanguage() | |
110 | + { | |
111 | + return $this->hasOne(Language::className(), ['id' => 'language_id']); | |
112 | + } | |
113 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace artbox\stock\models; | |
4 | + | |
5 | +use Yii; | |
6 | +use artbox\core\models\Language; | |
7 | +use artbox\core\behaviors\LanguageBehavior; | |
8 | +use yii\helpers\Json; | |
9 | + | |
10 | +/** | |
11 | + * This is the model class for table "shop". | |
12 | + * | |
13 | + * @property integer $id | |
14 | + * @property string $mode | |
15 | + * @property integer $city_id | |
16 | + * @property integer $sort | |
17 | + * @property boolean $status | |
18 | + * | |
19 | + * @property City $city | |
20 | + * @property ShopLang[] $shopLangs | |
21 | + * @property Language[] $languages | |
22 | + */ | |
23 | +class Shop extends \yii\db\ActiveRecord | |
24 | +{ | |
25 | + /** | |
26 | + * @inheritdoc | |
27 | + */ | |
28 | + public $cities = []; | |
29 | + public static function tableName() | |
30 | + { | |
31 | + return 'shop'; | |
32 | + } | |
33 | + public function behaviors() | |
34 | + { | |
35 | + return [ | |
36 | + 'language' => [ | |
37 | + 'class' => LanguageBehavior::className(), | |
38 | + ], | |
39 | + ]; | |
40 | + } | |
41 | + /** | |
42 | + * @inheritdoc | |
43 | + */ | |
44 | + public function rules() | |
45 | + { | |
46 | + return [ | |
47 | + [['city_id', 'sort'], 'integer'], | |
48 | + [['status'], 'boolean'], | |
49 | + [['mode', 'modeStr'], 'safe'], | |
50 | + [['coords', 'coordsArr'], 'safe'], | |
51 | + [['city_id'], 'exist', 'skipOnError' => true, 'targetClass' => City::className(), 'targetAttribute' => ['city_id' => 'id']], | |
52 | + ]; | |
53 | + } | |
54 | + | |
55 | + /** | |
56 | + * @inheritdoc | |
57 | + */ | |
58 | + public function attributeLabels() | |
59 | + { | |
60 | + return [ | |
61 | + 'id' => 'ID', | |
62 | + 'mode' => \Yii::t('stock', 'Mode'), | |
63 | + 'city_id' => 'City ID', | |
64 | + 'sort' => \Yii::t('stock', 'Sort'), | |
65 | + 'status' => \Yii::t('stock', 'Status'), | |
66 | + ]; | |
67 | + } | |
68 | + | |
69 | + /** | |
70 | + * @return \yii\db\ActiveQuery | |
71 | + */ | |
72 | + public function getCity() | |
73 | + { | |
74 | + return $this->hasOne(City::className(), ['id' => 'city_id']); | |
75 | + } | |
76 | + | |
77 | + public function getCities(){ | |
78 | + $cities = City::find()->with(['lang'])->all(); | |
79 | + foreach($cities as $city){ | |
80 | + $this->cities[$city->id] = $city->lang->title; | |
81 | + } | |
82 | + | |
83 | + } | |
84 | + | |
85 | + /** | |
86 | + * @return \yii\db\ActiveQuery | |
87 | + */ | |
88 | + public function getShopLangs() | |
89 | + { | |
90 | + return $this->hasMany(ShopLang::className(), ['shop_id' => 'id']); | |
91 | + } | |
92 | + | |
93 | + /** | |
94 | + * @return \yii\db\ActiveQuery | |
95 | + */ | |
96 | + public function getLanguages() | |
97 | + { | |
98 | + return $this->hasMany(Language::className(), ['id' => 'language_id'])->viaTable('shop_lang', ['shop_id' => 'id']); | |
99 | + } | |
100 | + | |
101 | + public function setModeStr($value){ | |
102 | + $this->mode = Json::encode($value); | |
103 | + } | |
104 | + | |
105 | + public function getModeStr(){ | |
106 | + return Json::decode($this->mode); | |
107 | + } | |
108 | + | |
109 | + public function setCoordsArr($value){ | |
110 | + $this->coords = Json::encode($value); | |
111 | + } | |
112 | + | |
113 | + public function getCoordsArr(){ | |
114 | + return Json::decode($this->coords); | |
115 | + } | |
116 | + | |
117 | + | |
118 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace artbox\stock\models; | |
4 | + | |
5 | +use Yii; | |
6 | +use artbox\core\models\Alias; | |
7 | +use artbox\core\models\Language; | |
8 | +use artbox\core\behaviors\SlugBehavior; | |
9 | +/** | |
10 | + * This is the model class for table "shop_lang". | |
11 | + * | |
12 | + * @property integer $shop_id | |
13 | + * @property integer $language_id | |
14 | + * @property string $title | |
15 | + * @property integer $alias_id | |
16 | + * @property string $description | |
17 | + * | |
18 | + * @property Alias $alias | |
19 | + * @property Language $language | |
20 | + * @property Shop $shop | |
21 | + */ | |
22 | +class ShopLang extends \yii\db\ActiveRecord | |
23 | +{ | |
24 | + /** | |
25 | + * @inheritdoc | |
26 | + */ | |
27 | + public static function tableName() | |
28 | + { | |
29 | + return 'shop_lang'; | |
30 | + } | |
31 | + | |
32 | + /** | |
33 | + * @inheritdoc | |
34 | + */ | |
35 | + public function behaviors() | |
36 | + { | |
37 | + return [ | |
38 | + 'slug' => [ | |
39 | + 'class' => SlugBehavior::className(), | |
40 | + 'action' => 'shop/view', | |
41 | + 'params' => [ | |
42 | + 'id' => 'shop_id', | |
43 | + ], | |
44 | + 'fields' => [ | |
45 | + 'title' => \Yii::t('stock', 'Title'), | |
46 | + 'description' => \Yii::t('stock', 'Description'), | |
47 | + 'address' => \Yii::t('stock', 'Address'), | |
48 | + ], | |
49 | + ], | |
50 | + ]; | |
51 | + } | |
52 | + public function rules() | |
53 | + { | |
54 | + return [ | |
55 | + [['shop_id', 'language_id', 'title'], 'required'], | |
56 | + [['shop_id', 'language_id', 'alias_id'], 'integer'], | |
57 | + [['description'], 'string'], | |
58 | + [['title'], 'string', 'max' => 255], | |
59 | + [['address'], 'string', 'max' => 255], | |
60 | + [['alias_id'], 'unique'], | |
61 | + [['alias_id'], 'exist', 'skipOnError' => true, 'targetClass' => Alias::className(), 'targetAttribute' => ['alias_id' => 'id']], | |
62 | + [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'id']], | |
63 | + [['shop_id'], 'exist', 'skipOnError' => true, 'targetClass' => Shop::className(), 'targetAttribute' => ['shop_id' => 'id']], | |
64 | + ]; | |
65 | + } | |
66 | + | |
67 | + /** | |
68 | + * @inheritdoc | |
69 | + */ | |
70 | + public function attributeLabels() | |
71 | + { | |
72 | + return [ | |
73 | + 'shop_id' => 'Shop ID', | |
74 | + 'language_id' => 'Language ID', | |
75 | + 'title' => \Yii::t('stock', 'Title'), | |
76 | + 'alias_id' => 'Alias ID', | |
77 | + 'description' => \Yii::t('stock', 'Description'), | |
78 | + 'address' => \Yii::t('stock', 'Address'), | |
79 | + ]; | |
80 | + } | |
81 | + | |
82 | + /** | |
83 | + * @return \yii\db\ActiveQuery | |
84 | + */ | |
85 | + public function getAlias() | |
86 | + { | |
87 | + return $this->hasOne(Alias::className(), ['id' => 'alias_id']); | |
88 | + } | |
89 | + | |
90 | + /** | |
91 | + * @return \yii\db\ActiveQuery | |
92 | + */ | |
93 | + public function getLanguage() | |
94 | + { | |
95 | + return $this->hasOne(Language::className(), ['id' => 'language_id']); | |
96 | + } | |
97 | + | |
98 | + /** | |
99 | + * @return \yii\db\ActiveQuery | |
100 | + */ | |
101 | + public function getShop() | |
102 | + { | |
103 | + return $this->hasOne(Shop::className(), ['id' => 'shop_id']); | |
104 | + } | |
105 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | +use yii\widgets\ActiveForm; | |
5 | +use artbox\core\widgets\LanguageForm; | |
6 | + | |
7 | +/* @var $this yii\web\View */ | |
8 | +/* @var $model artbox\stock\models\City */ | |
9 | +/* @var $form yii\widgets\ActiveForm */ | |
10 | +?> | |
11 | + | |
12 | +<div class="city-form"> | |
13 | + | |
14 | + <?php $form = ActiveForm::begin(); ?> | |
15 | + <?= LanguageForm::widget( | |
16 | + [ | |
17 | + 'modelLangs' => $modelLangs, | |
18 | + 'formView' => '@artbox/stock/views/city/_form_language', | |
19 | + 'form' => $form, | |
20 | + ] | |
21 | + ) ?> | |
22 | + | |
23 | + <?= $form->field($model, 'sort')->textInput() ?> | |
24 | + | |
25 | + <?= $form->field($model, 'status')->checkbox() ?> | |
26 | + | |
27 | + <div class="form-group"> | |
28 | + <?= Html::submitButton($model->isNewRecord ? \Yii::t('stock', 'Create'): \Yii::t('stock', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | |
29 | + </div> | |
30 | + | |
31 | + <?php ActiveForm::end(); ?> | |
32 | + | |
33 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | +use yiister\gentelella\widgets\Panel; | |
5 | + | |
6 | + | |
7 | +/* @var $this yii\web\View */ | |
8 | +/* @var $model artbox\stock\models\City */ | |
9 | + | |
10 | +$this->title = \Yii::t('stock', 'Create City'); | |
11 | +$this->params['breadcrumbs'][] = ['label' => \Yii::t('stock', 'Cities'), 'url' => ['index']]; | |
12 | +$this->params['breadcrumbs'][] = \Yii::t('stock', $this->title); | |
13 | +?> | |
14 | +<div class="city-create"> | |
15 | + <?php | |
16 | + $xPanel = Panel::begin( | |
17 | + [ | |
18 | + 'header' => \Yii::t('stock', Html::encode($this->title)), | |
19 | + ] | |
20 | + ); | |
21 | + ?> | |
22 | + <h1><?= \Yii::t('stock', Html::encode($this->title)) ?></h1> | |
23 | + | |
24 | + <?= $this->render('_form', [ | |
25 | + 'model' => $model, | |
26 | + 'modelLangs' => $modelLangs, | |
27 | + ]) ?> | |
28 | + | |
29 | + | |
30 | + <?php | |
31 | + $xPanel::end(); | |
32 | + ?> | |
33 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | +use yii\grid\GridView; | |
5 | +use yiister\gentelella\widgets\Panel; | |
6 | +/* @var $this yii\web\View */ | |
7 | +/* @var $dataProvider yii\data\ActiveDataProvider */ | |
8 | + | |
9 | +$this->title = 'Cities'; | |
10 | +$this->params['breadcrumbs'][] = \Yii::t('stock', $this->title); | |
11 | +?> | |
12 | +<div class="city-index"> | |
13 | + <?php | |
14 | + $xPanel = Panel::begin( | |
15 | + [ | |
16 | + 'header' => \Yii::t('stock', Html::encode($this->title)), | |
17 | + ] | |
18 | + ); | |
19 | + ?> | |
20 | + <h1><?= \Yii::t('stock', Html::encode($this->title)) ?></h1> | |
21 | + | |
22 | + <p> | |
23 | + <?= Html::a(\Yii::t('stock', 'Create City'), ['create'], ['class' => 'btn btn-success']) ?> | |
24 | + </p> | |
25 | + <?= GridView::widget([ | |
26 | + 'dataProvider' => $dataProvider, | |
27 | + 'columns' => [ | |
28 | + ['class' => 'yii\grid\SerialColumn'], | |
29 | + | |
30 | + 'id', | |
31 | + [ | |
32 | + 'attribute' => \Yii::t('stock', 'Title'), | |
33 | + 'value' => 'lang.title', | |
34 | + ], | |
35 | + 'sort', | |
36 | + 'status:boolean', | |
37 | + | |
38 | + ['class' => 'yii\grid\ActionColumn'], | |
39 | + ], | |
40 | + ]); ?> | |
41 | + <?php | |
42 | + $xPanel::end(); | |
43 | + ?> | |
44 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | + | |
5 | +/* @var $this yii\web\View */ | |
6 | +/* @var $model artbox\stock\models\City */ | |
7 | + | |
8 | +$this->title = Yii::t( | |
9 | + 'catalog', | |
10 | + 'Update {modelClass}: ', | |
11 | + [ | |
12 | + 'modelClass' => 'City', | |
13 | + ] | |
14 | + ) . $model->lang->title; | |
15 | +$this->params[ 'breadcrumbs' ][] = [ | |
16 | + 'label' => Yii::t('stock', 'Cities'), | |
17 | + 'url' => [ 'index' ], | |
18 | +]; | |
19 | +$this->params[ 'breadcrumbs' ][] = [ | |
20 | + 'label' => $model->lang->title, | |
21 | + 'url' => [ | |
22 | + 'view', | |
23 | + 'id' => $model->id, | |
24 | + ], | |
25 | +]; | |
26 | +$this->params[ 'breadcrumbs' ][] = Yii::t('stock', 'Update'); | |
27 | +?> | |
28 | +<div class="city-update"> | |
29 | + | |
30 | + <h1><?= Html::encode($this->title) ?></h1> | |
31 | + | |
32 | + <?= $this->render('_form', [ | |
33 | + 'model' => $model, | |
34 | + 'modelLangs' => $modelLangs, | |
35 | + ]) ?> | |
36 | + | |
37 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | +use yii\widgets\DetailView; | |
5 | +use yiister\gentelella\widgets\Panel; | |
6 | +/* @var $this yii\web\View */ | |
7 | +/* @var $model artbox\stock\models\City */ | |
8 | + | |
9 | + | |
10 | +$this->title = $model->lang->title; | |
11 | +$this->params[ 'breadcrumbs' ][] = [ | |
12 | + 'label' => Yii::t('stock', 'Cities'), | |
13 | + 'url' => [ 'index' ], | |
14 | +]; | |
15 | +$this->params[ 'breadcrumbs' ][] = $this->title; | |
16 | +?> | |
17 | +<div class="city-view"> | |
18 | + <?php | |
19 | + $xPanel = Panel::begin( | |
20 | + [ | |
21 | + 'header' => Html::encode($this->title), | |
22 | + ] | |
23 | + ); | |
24 | + ?> | |
25 | + <h1><?= Html::encode($this->title) ?></h1> | |
26 | + | |
27 | + <p> | |
28 | + <?= Html::a(\Yii::t('stock', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> | |
29 | + <?= Html::a(\Yii::t('stock', 'Delete'), ['delete', 'id' => $model->id], [ | |
30 | + 'class' => 'btn btn-danger', | |
31 | + 'data' => [ | |
32 | + 'confirm' => 'Are you sure you want to delete this item?', | |
33 | + 'method' => 'post', | |
34 | + ], | |
35 | + ]) ?> | |
36 | + </p> | |
37 | + | |
38 | + <?= DetailView::widget([ | |
39 | + 'model' => $model, | |
40 | + 'attributes' => [ | |
41 | + 'id', | |
42 | + 'lang.title', | |
43 | + [ | |
44 | + 'attribute' => 'lang.alias.value', | |
45 | + 'label' => \Yii::t('catalog', 'Alias'), | |
46 | + ], | |
47 | + 'lang.description:html', | |
48 | + 'sort', | |
49 | + 'status:boolean', | |
50 | + ], | |
51 | + ]) ?> | |
52 | + | |
53 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | +use yii\widgets\ActiveForm; | |
5 | +use artbox\core\widgets\LanguageForm; | |
6 | +use kartik\select2\Select2; | |
7 | +/* @var $this yii\web\View */ | |
8 | +/* @var $model artbox\stock\models\Shop */ | |
9 | +/* @var $form yii\widgets\ActiveForm */ | |
10 | +$days = ['Пн', "Вт", "Ср", "Чт", "Пт", "Сб", "Вс"]; | |
11 | +//print_r($model->modeStr); die(); | |
12 | + | |
13 | +\artbox\stock\assets\StockAsset::register($this); | |
14 | + | |
15 | +?> | |
16 | +<div class="shop-form"> | |
17 | + <?php $form = ActiveForm::begin(); ?> | |
18 | + <?= LanguageForm::widget( | |
19 | + [ | |
20 | + 'modelLangs' => $modelLangs, | |
21 | + 'formView' => '@artbox/stock/views/shop/_form_language', | |
22 | + 'form' => $form, | |
23 | + ] | |
24 | + ) ?> | |
25 | + <?php foreach($days as $key => $day):?> | |
26 | + <?= Html::beginTag('div')?> | |
27 | + <?= Html::label($day.' c'); ?> | |
28 | + <?= Html::textInput("Shop[modeStr][$key][from]", (isset($model->modeStr[$key]['from'])) ? $model->modeStr[$key]['from'] : '09:00', [ | |
29 | + 'size' => 10, | |
30 | + 'type'=> 'time', | |
31 | + | |
32 | + ])?> | |
33 | + <?= Html::label(' до '); ?> | |
34 | + | |
35 | + <?= Html::textInput("Shop[modeStr][$key][to]", (isset($model->modeStr[$key]['to'])) ? $model->modeStr[$key]['to'] : '18:00', [ | |
36 | + 'size' => 10, | |
37 | + 'type'=> 'time', | |
38 | + ])?> | |
39 | + <?= Html::label(' выходной '); ?> | |
40 | + <?= Html::checkbox("Shop[modeStr][$key][off]", (isset($model->modeStr[$key]['off'])) ? true : false)?> | |
41 | + <?= Html::endTag('div');?> | |
42 | + <?php endforeach;?> | |
43 | + <?php if ($model->modeStr['data']):?> | |
44 | + | |
45 | + <?php foreach ($model->modeStr['data'] as $key => $data):?> | |
46 | + <?= Html::beginTag('div')?> | |
47 | + <?= Html::label(' Дата'); ?> | |
48 | + <?= Html::textInput("Shop[modeStr][data][$key][data]", (isset($data['data'])) ? $data['data'] : '', [ | |
49 | + 'size' => 10, | |
50 | + 'type'=> 'data', | |
51 | + ])?> | |
52 | + <?= Html::label(' c'); ?> | |
53 | + <?= Html::textInput("Shop[modeStr][data][$key][from]", (isset($data['from'])) ? $data['from'] : '', [ | |
54 | + 'size' => 10, | |
55 | + 'type'=> 'time', | |
56 | + | |
57 | + ])?> | |
58 | + <?= Html::label(' до '); ?> | |
59 | + | |
60 | + <?= Html::textInput("Shop[modeStr][data][$key][to]", (isset($data['to'])) ? $data['to'] : '', [ | |
61 | + 'size' => 10, | |
62 | + 'type'=> 'time', | |
63 | + ])?> | |
64 | + <?= Html::label(' выходной '); ?> | |
65 | + <?= Html::checkbox("Shop[modeStr][data][$key][off]", (isset($data['off'])) ? true : false)?> | |
66 | + <?= Html::endTag('div');?> | |
67 | + <?php endforeach;?> | |
68 | + <?php endif?> | |
69 | + <?= Html::button( | |
70 | + Html::tag( | |
71 | + 'li', | |
72 | + '', | |
73 | + [ | |
74 | + 'class' => 'fa fa-plus', | |
75 | + ] | |
76 | + ) . ' Добавить дату', | |
77 | + [ | |
78 | + 'id' => 'add-data', | |
79 | + 'class' => 'btn btn-success', | |
80 | + 'data-count' => (isset($model->modeStr['data'])) ? count($model->modeStr['data']) : 0, | |
81 | + ] | |
82 | + ) ?> | |
83 | + | |
84 | + | |
85 | + | |
86 | + <?= Select2::widget([ | |
87 | + 'name' => 'Shop[city_id]', | |
88 | + 'value' => array_keys($model->cities), | |
89 | + 'data' => $model->cities, | |
90 | + 'options' => ['placeholder' => 'Выберите город ...'] | |
91 | + ]); ?> | |
92 | + | |
93 | + <?= $form->field($model, 'sort')->textInput() ?> | |
94 | + | |
95 | + <?= $form->field($model, 'status')->checkbox() ?> | |
96 | + | |
97 | + <div class="form-group"> | |
98 | + <?= Html::submitButton($model->isNewRecord ? \Yii::t('stock', 'Create'): \Yii::t('stock', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | |
99 | + </div> | |
100 | + | |
101 | + <?php ActiveForm::end(); ?> | |
102 | +</div> | |
103 | +<!--<script>--> | |
104 | +<!-- window.onload = function () {--> | |
105 | +<!-- console.log('ololo');--> | |
106 | +<!-- --> | |
107 | +<!-- }--> | |
108 | +<!--</script>--> | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | +use yiister\gentelella\widgets\Panel; | |
5 | + | |
6 | +/* @var $this yii\web\View */ | |
7 | +/* @var $model artbox\stock\models\Shop */ | |
8 | + | |
9 | +$this->title = \Yii::t('stock', 'Create Shop'); | |
10 | +$this->params['breadcrumbs'][] = ['label' => \Yii::t('stock', 'Shops'), 'url' => ['index']]; | |
11 | +$this->params['breadcrumbs'][] = \Yii::t('stock', $this->title); | |
12 | +?> | |
13 | +<div class="shop-create"> | |
14 | + <?php | |
15 | + $xPanel = Panel::begin( | |
16 | + [ | |
17 | + 'header' => \Yii::t('stock', Html::encode($this->title)), | |
18 | + ] | |
19 | + ); | |
20 | + ?> | |
21 | + <h1><?= Html::encode($this->title) ?></h1> | |
22 | + | |
23 | + <?= $this->render('_form', [ | |
24 | + 'model' => $model, | |
25 | + 'modelLangs' => $modelLangs, | |
26 | + ]) ?> | |
27 | + <?php | |
28 | + $xPanel::end(); | |
29 | + ?> | |
30 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | +use yii\grid\GridView; | |
5 | +use yiister\gentelella\widgets\Panel; | |
6 | + | |
7 | +/* @var $this yii\web\View */ | |
8 | +/* @var $dataProvider yii\data\ActiveDataProvider */ | |
9 | + | |
10 | +$this->title = 'Shops'; | |
11 | +$this->params['breadcrumbs'][] = \Yii::t('stock', $this->title); | |
12 | +?> | |
13 | +<div class="shop-index"> | |
14 | + <?php | |
15 | + $xPanel = Panel::begin( | |
16 | + [ | |
17 | + 'header' => \Yii::t('stock', Html::encode($this->title)), | |
18 | + ] | |
19 | + ); | |
20 | + ?> | |
21 | + <h1><?= \Yii::t('stock', Html::encode($this->title)) ?></h1> | |
22 | + | |
23 | + <p> | |
24 | + <?= Html::a(\Yii::t('stock', 'Create Shop'), ['create'], ['class' => 'btn btn-success']) ?> | |
25 | + </p> | |
26 | + <?= GridView::widget([ | |
27 | + 'dataProvider' => $dataProvider, | |
28 | + 'columns' => [ | |
29 | + ['class' => 'yii\grid\SerialColumn'], | |
30 | + | |
31 | + 'id', | |
32 | + [ | |
33 | + 'attribute' => \Yii::t('stock', 'Address'), | |
34 | + 'value' => 'lang.address', | |
35 | + ], | |
36 | + 'sort', | |
37 | + 'status:boolean', | |
38 | + | |
39 | + ['class' => 'yii\grid\ActionColumn'], | |
40 | + ], | |
41 | + ]); ?> | |
42 | + <?php | |
43 | + $xPanel::end(); | |
44 | + ?> | |
45 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | +use yiister\gentelella\widgets\Panel; | |
5 | +/* @var $this yii\web\View */ | |
6 | +/* @var $model artbox\stock\models\Shop */ | |
7 | + | |
8 | +$this->title = Yii::t( | |
9 | + 'catalog', | |
10 | + 'Update {modelClass}: ', | |
11 | + [ | |
12 | + 'modelClass' => 'Shop', | |
13 | + ] | |
14 | + ) . $model->lang->title; | |
15 | +$this->params[ 'breadcrumbs' ][] = [ | |
16 | + 'label' => Yii::t('stock', 'Shop'), | |
17 | + 'url' => [ 'index' ], | |
18 | +]; | |
19 | +$this->params[ 'breadcrumbs' ][] = [ | |
20 | + 'label' => $model->lang->title, | |
21 | + 'url' => [ | |
22 | + 'view', | |
23 | + 'id' => $model->id, | |
24 | + ], | |
25 | +]; | |
26 | +$this->params[ 'breadcrumbs' ][] = Yii::t('stock', 'Update');?> | |
27 | +<div class="shop-update"> | |
28 | + <?php | |
29 | + $xPanel = Panel::begin( | |
30 | + [ | |
31 | + 'header' => \Yii::t('stock', Html::encode($this->title)), | |
32 | + ] | |
33 | + ); | |
34 | + ?> | |
35 | + <h1><?= Html::encode($this->title) ?></h1> | |
36 | + | |
37 | + <?= $this->render('_form', [ | |
38 | + 'model' => $model, | |
39 | + 'modelLangs' => $modelLangs, | |
40 | + ]) ?> | |
41 | + <?php | |
42 | + $xPanel::end(); | |
43 | + ?> | |
44 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | +use yii\widgets\DetailView; | |
5 | +use yiister\gentelella\widgets\Panel; | |
6 | +/* @var $this yii\web\View */ | |
7 | +/* @var $model artbox\stock\models\Shop */ | |
8 | + | |
9 | +$this->title = $model->lang->title; | |
10 | +$this->params[ 'breadcrumbs' ][] = [ | |
11 | + 'label' => Yii::t('stock', 'Shops'), | |
12 | + 'url' => [ 'index' ], | |
13 | +]; | |
14 | +$this->params[ 'breadcrumbs' ][] = $this->title; | |
15 | +?> | |
16 | +<div class="shop-view"> | |
17 | + <?php | |
18 | + $xPanel = Panel::begin( | |
19 | + [ | |
20 | + 'header' => \Yii::t('stock', Html::encode($this->title)), | |
21 | + ] | |
22 | + ); | |
23 | + ?> | |
24 | + <h1><?= Html::encode($this->title) ?></h1> | |
25 | + | |
26 | + <p> | |
27 | + <?= Html::a(\Yii::t('stock', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> | |
28 | + <?= Html::a(\Yii::t('stock', 'Delete'), ['delete', 'id' => $model->id], [ | |
29 | + 'class' => 'btn btn-danger', | |
30 | + 'data' => [ | |
31 | + 'confirm' => 'Are you sure you want to delete this item?', | |
32 | + 'method' => 'post', | |
33 | + ], | |
34 | + ]) ?> | |
35 | + </p> | |
36 | + | |
37 | + <?= DetailView::widget([ | |
38 | + 'model' => $model, | |
39 | + 'attributes' => [ | |
40 | + 'id', | |
41 | + 'lang.title', | |
42 | + [ | |
43 | + 'attribute' => 'lang.alias.value', | |
44 | + 'label' => \Yii::t('catalog', 'Alias'), | |
45 | + ], | |
46 | + 'lang.description:html', | |
47 | + 'lang.address', | |
48 | + 'sort', | |
49 | + 'status:boolean', | |
50 | + ], | |
51 | + ]) ?> | |
52 | + <?php | |
53 | + $xPanel::end(); | |
54 | + ?> | |
55 | +</div> | ... | ... |