From a61ab7a733ebd6da980a5dc25a3db5753bcb292d Mon Sep 17 00:00:00 2001 From: stes Date: Wed, 26 Jul 2017 17:50:08 +0300 Subject: [PATCH] stock --- controllers/CityController.php | 164 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ controllers/ShopController.php | 166 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ models/City.php | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ models/CityLang.php | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ models/Shop.php | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ models/ShopLang.php | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ views/city/_form.php | 33 +++++++++++++++++++++++++++++++++ views/city/create.php | 33 +++++++++++++++++++++++++++++++++ views/city/index.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ views/city/update.php | 37 +++++++++++++++++++++++++++++++++++++ views/city/view.php | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ views/shop/_form.php | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ views/shop/create.php | 30 ++++++++++++++++++++++++++++++ views/shop/index.php | 45 +++++++++++++++++++++++++++++++++++++++++++++ views/shop/update.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ views/shop/view.php | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 16 files changed, 1237 insertions(+), 0 deletions(-) create mode 100644 controllers/CityController.php create mode 100644 controllers/ShopController.php create mode 100644 models/City.php create mode 100644 models/CityLang.php create mode 100644 models/Shop.php create mode 100644 models/ShopLang.php create mode 100644 views/city/_form.php create mode 100644 views/city/create.php create mode 100644 views/city/index.php create mode 100644 views/city/update.php create mode 100644 views/city/view.php create mode 100644 views/shop/_form.php create mode 100644 views/shop/create.php create mode 100644 views/shop/index.php create mode 100644 views/shop/update.php create mode 100644 views/shop/view.php diff --git a/controllers/CityController.php b/controllers/CityController.php new file mode 100644 index 0000000..fff2e2a --- /dev/null +++ b/controllers/CityController.php @@ -0,0 +1,164 @@ + [ + 'class' => AccessControl::className(), + 'rules' => [ + [ + 'actions' => [ + 'login', + 'error', + ], + 'allow' => true, + ], + [ + 'allow' => true, + 'roles' => [ '@' ], + ], + ], + ], + 'verbs' => [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all City models. + * @return mixed + */ + public function actionIndex() + { + $dataProvider = new ActiveDataProvider([ + 'query' => City::find()->with(['lang']), + ]); + + return $this->render('index', [ + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single City model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new City model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new City(); + $model->generateLangs(); + if ($model->loadWithLangs(\Yii::$app->request) && $model->saveWithLangs()) { + return $this->redirect( + [ + 'view', + 'id' => $model->id, + ] + ); + } + return $this->render( + 'create', + [ + 'model' => $model, + 'modelLangs' => $model->modelLangs, + ] + ); + } + + /** + * Updates an existing City model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + $model->generateLangs(); + + if ($model->loadWithLangs(\Yii::$app->request) && $model->saveWithLangs()) { + return $this->redirect( + [ + 'view', + 'id' => $model->id, + ] + ); + } + return $this->render( + 'update', + [ + 'model' => $model, + 'modelLangs' => $model->modelLangs, + ] + ); + } + + /** + * Deletes an existing City model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the City model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return City the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = City::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/controllers/ShopController.php b/controllers/ShopController.php new file mode 100644 index 0000000..f037afe --- /dev/null +++ b/controllers/ShopController.php @@ -0,0 +1,166 @@ + [ + 'class' => AccessControl::className(), + 'rules' => [ + [ + 'actions' => [ + 'login', + 'error', + ], + 'allow' => true, + ], + [ + 'allow' => true, + 'roles' => [ '@' ], + ], + ], + ], + 'verbs' => [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all Shop models. + * @return mixed + */ + public function actionIndex() + { + $dataProvider = new ActiveDataProvider([ + 'query' => Shop::find(), + ]); + + return $this->render('index', [ + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Shop model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Shop model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Shop(); + $model->generateLangs(); + $model->getCities(); + if ($model->loadWithLangs(\Yii::$app->request) && $model->saveWithLangs()) { + return $this->redirect( + [ + 'view', + 'id' => $model->id, + ] + ); + } + return $this->render( + 'create', + [ + 'model' => $model, + 'modelLangs' => $model->modelLangs, + ] + ); + + } + + /** + * Updates an existing Shop model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + $model->generateLangs(); + $model->getCities(); + $model->loadWithLangs(\Yii::$app->request); + //print_r(\Yii::$app->request); + if ($model->loadWithLangs(\Yii::$app->request) && $model->saveWithLangs()) { + return $this->redirect( + [ + 'view', + 'id' => $model->id, + ] + ); + } + return $this->render( + 'update', + [ + 'model' => $model, + 'modelLangs' => $model->modelLangs, + ] + ); + } + + /** + * Deletes an existing Shop model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the Shop model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Shop the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Shop::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/models/City.php b/models/City.php new file mode 100644 index 0000000..200d2d8 --- /dev/null +++ b/models/City.php @@ -0,0 +1,89 @@ + [ + 'class' => LanguageBehavior::className(), + ], + ]; + } + + /** + * @inheritdoc + */ + public function rules() + { + return [ + [['sort'], 'integer'], + [['status'], 'boolean'], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'sort' => Yii::t('stock', 'Sort'), + 'status' => Yii::t('stock', 'Status'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getCityLangs() + { + return $this->hasMany(CityLang::className(), ['city_id' => 'id']) + ->inverseOf('city'); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguages() + { + return $this->hasMany(Language::className(), ['id' => 'language_id'])->viaTable('city_lang', ['city_id' => 'id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getShops() + { + return $this->hasMany(Shop::className(), ['city_id' => 'id']); + } +} diff --git a/models/CityLang.php b/models/CityLang.php new file mode 100644 index 0000000..20b63cc --- /dev/null +++ b/models/CityLang.php @@ -0,0 +1,113 @@ + [ + 'class' => SlugBehavior::className(), + 'action' => 'city/view', + 'params' => [ + 'id' => 'city_id', + ], + 'fields' => [ + 'title' => \Yii::t('stock', 'Title'), + 'description' => \Yii::t('stock', 'Description'), + ], + ], + ]; + } + public function rules() + { + return [ + [ + [ + 'title', + ], + 'required', + ], + [ + [ 'description' ], + 'string', + ], + [ + [ + 'title', + 'aliasValue', + ], + 'string', + 'max' => 255, + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'city_id' => 'City ID', + 'language_id' => 'Language ID', + 'title' => \Yii::t('stock', 'Title'), + 'alias_id' => 'Alias ID', + 'description' => \Yii::t('stock', 'Description'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getAlias() + { + return $this->hasOne(Alias::className(), ['id' => 'alias_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getCity() + { + return $this->hasOne(City::className(), ['id' => 'city_id'])->inverseOf('cityLangs'); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(Language::className(), ['id' => 'language_id']); + } +} diff --git a/models/Shop.php b/models/Shop.php new file mode 100644 index 0000000..4206a16 --- /dev/null +++ b/models/Shop.php @@ -0,0 +1,118 @@ + [ + 'class' => LanguageBehavior::className(), + ], + ]; + } + /** + * @inheritdoc + */ + public function rules() + { + return [ + [['city_id', 'sort'], 'integer'], + [['status'], 'boolean'], + [['mode', 'modeStr'], 'safe'], + [['coords', 'coordsArr'], 'safe'], + [['city_id'], 'exist', 'skipOnError' => true, 'targetClass' => City::className(), 'targetAttribute' => ['city_id' => 'id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'mode' => \Yii::t('stock', 'Mode'), + 'city_id' => 'City ID', + 'sort' => \Yii::t('stock', 'Sort'), + 'status' => \Yii::t('stock', 'Status'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getCity() + { + return $this->hasOne(City::className(), ['id' => 'city_id']); + } + + public function getCities(){ + $cities = City::find()->with(['lang'])->all(); + foreach($cities as $city){ + $this->cities[$city->id] = $city->lang->title; + } + + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getShopLangs() + { + return $this->hasMany(ShopLang::className(), ['shop_id' => 'id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguages() + { + return $this->hasMany(Language::className(), ['id' => 'language_id'])->viaTable('shop_lang', ['shop_id' => 'id']); + } + + public function setModeStr($value){ + $this->mode = Json::encode($value); + } + + public function getModeStr(){ + return Json::decode($this->mode); + } + + public function setCoordsArr($value){ + $this->coords = Json::encode($value); + } + + public function getCoordsArr(){ + return Json::decode($this->coords); + } + + +} diff --git a/models/ShopLang.php b/models/ShopLang.php new file mode 100644 index 0000000..d038aff --- /dev/null +++ b/models/ShopLang.php @@ -0,0 +1,105 @@ + [ + 'class' => SlugBehavior::className(), + 'action' => 'shop/view', + 'params' => [ + 'id' => 'shop_id', + ], + 'fields' => [ + 'title' => \Yii::t('stock', 'Title'), + 'description' => \Yii::t('stock', 'Description'), + 'address' => \Yii::t('stock', 'Address'), + ], + ], + ]; + } + public function rules() + { + return [ + [['shop_id', 'language_id', 'title'], 'required'], + [['shop_id', 'language_id', 'alias_id'], 'integer'], + [['description'], 'string'], + [['title'], 'string', 'max' => 255], + [['address'], 'string', 'max' => 255], + [['alias_id'], 'unique'], + [['alias_id'], 'exist', 'skipOnError' => true, 'targetClass' => Alias::className(), 'targetAttribute' => ['alias_id' => 'id']], + [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'id']], + [['shop_id'], 'exist', 'skipOnError' => true, 'targetClass' => Shop::className(), 'targetAttribute' => ['shop_id' => 'id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'shop_id' => 'Shop ID', + 'language_id' => 'Language ID', + 'title' => \Yii::t('stock', 'Title'), + 'alias_id' => 'Alias ID', + 'description' => \Yii::t('stock', 'Description'), + 'address' => \Yii::t('stock', 'Address'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getAlias() + { + return $this->hasOne(Alias::className(), ['id' => 'alias_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(Language::className(), ['id' => 'language_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getShop() + { + return $this->hasOne(Shop::className(), ['id' => 'shop_id']); + } +} diff --git a/views/city/_form.php b/views/city/_form.php new file mode 100644 index 0000000..5221fb1 --- /dev/null +++ b/views/city/_form.php @@ -0,0 +1,33 @@ + + +
+ + + $modelLangs, + 'formView' => '@artbox/stock/views/city/_form_language', + 'form' => $form, + ] + ) ?> + + field($model, 'sort')->textInput() ?> + + field($model, 'status')->checkbox() ?> + +
+ isNewRecord ? \Yii::t('stock', 'Create'): \Yii::t('stock', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> +
+ + + +
diff --git a/views/city/create.php b/views/city/create.php new file mode 100644 index 0000000..1dea311 --- /dev/null +++ b/views/city/create.php @@ -0,0 +1,33 @@ +title = \Yii::t('stock', 'Create City'); +$this->params['breadcrumbs'][] = ['label' => \Yii::t('stock', 'Cities'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = \Yii::t('stock', $this->title); +?> +
+ \Yii::t('stock', Html::encode($this->title)), + ] + ); + ?> +

title)) ?>

+ + render('_form', [ + 'model' => $model, + 'modelLangs' => $modelLangs, + ]) ?> + + + +
diff --git a/views/city/index.php b/views/city/index.php new file mode 100644 index 0000000..b5853a3 --- /dev/null +++ b/views/city/index.php @@ -0,0 +1,44 @@ +title = 'Cities'; +$this->params['breadcrumbs'][] = \Yii::t('stock', $this->title); +?> +
+ \Yii::t('stock', Html::encode($this->title)), + ] + ); + ?> +

title)) ?>

+ +

+ 'btn btn-success']) ?> +

+ $dataProvider, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'id', + [ + 'attribute' => \Yii::t('stock', 'Title'), + 'value' => 'lang.title', + ], + 'sort', + 'status:boolean', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> + +
diff --git a/views/city/update.php b/views/city/update.php new file mode 100644 index 0000000..660e1e4 --- /dev/null +++ b/views/city/update.php @@ -0,0 +1,37 @@ +title = Yii::t( + 'catalog', + 'Update {modelClass}: ', + [ + 'modelClass' => 'City', + ] + ) . $model->lang->title; +$this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('stock', 'Cities'), + 'url' => [ 'index' ], +]; +$this->params[ 'breadcrumbs' ][] = [ + 'label' => $model->lang->title, + 'url' => [ + 'view', + 'id' => $model->id, + ], +]; +$this->params[ 'breadcrumbs' ][] = Yii::t('stock', 'Update'); +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + 'modelLangs' => $modelLangs, + ]) ?> + +
diff --git a/views/city/view.php b/views/city/view.php new file mode 100644 index 0000000..4bd637d --- /dev/null +++ b/views/city/view.php @@ -0,0 +1,53 @@ +title = $model->lang->title; +$this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('stock', 'Cities'), + 'url' => [ 'index' ], +]; +$this->params[ 'breadcrumbs' ][] = $this->title; +?> +
+ Html::encode($this->title), + ] + ); + ?> +

title) ?>

+ +

+ $model->id], ['class' => 'btn btn-primary']) ?> + $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Are you sure you want to delete this item?', + 'method' => 'post', + ], + ]) ?> +

+ + $model, + 'attributes' => [ + 'id', + 'lang.title', + [ + 'attribute' => 'lang.alias.value', + 'label' => \Yii::t('catalog', 'Alias'), + ], + 'lang.description:html', + 'sort', + 'status:boolean', + ], + ]) ?> + +
diff --git a/views/shop/_form.php b/views/shop/_form.php new file mode 100644 index 0000000..a5c8fdd --- /dev/null +++ b/views/shop/_form.php @@ -0,0 +1,108 @@ +modeStr); die(); + +\artbox\stock\assets\StockAsset::register($this); + +?> +
+ + $modelLangs, + 'formView' => '@artbox/stock/views/shop/_form_language', + 'form' => $form, + ] + ) ?> + $day):?> + + + modeStr[$key]['from'])) ? $model->modeStr[$key]['from'] : '09:00', [ + 'size' => 10, + 'type'=> 'time', + + ])?> + + + modeStr[$key]['to'])) ? $model->modeStr[$key]['to'] : '18:00', [ + 'size' => 10, + 'type'=> 'time', + ])?> + + modeStr[$key]['off'])) ? true : false)?> + + + modeStr['data']):?> + + modeStr['data'] as $key => $data):?> + + + 10, + 'type'=> 'data', + ])?> + + 10, + 'type'=> 'time', + + ])?> + + + 10, + 'type'=> 'time', + ])?> + + + + + + 'fa fa-plus', + ] + ) . ' Добавить дату', + [ + 'id' => 'add-data', + 'class' => 'btn btn-success', + 'data-count' => (isset($model->modeStr['data'])) ? count($model->modeStr['data']) : 0, + ] + ) ?> + + + + 'Shop[city_id]', + 'value' => array_keys($model->cities), + 'data' => $model->cities, + 'options' => ['placeholder' => 'Выберите город ...'] + ]); ?> + + field($model, 'sort')->textInput() ?> + + field($model, 'status')->checkbox() ?> + +
+ isNewRecord ? \Yii::t('stock', 'Create'): \Yii::t('stock', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> +
+ + +
+ + + + + + diff --git a/views/shop/create.php b/views/shop/create.php new file mode 100644 index 0000000..014f0cf --- /dev/null +++ b/views/shop/create.php @@ -0,0 +1,30 @@ +title = \Yii::t('stock', 'Create Shop'); +$this->params['breadcrumbs'][] = ['label' => \Yii::t('stock', 'Shops'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = \Yii::t('stock', $this->title); +?> +
+ \Yii::t('stock', Html::encode($this->title)), + ] + ); + ?> +

title) ?>

+ + render('_form', [ + 'model' => $model, + 'modelLangs' => $modelLangs, + ]) ?> + +
diff --git a/views/shop/index.php b/views/shop/index.php new file mode 100644 index 0000000..73cf048 --- /dev/null +++ b/views/shop/index.php @@ -0,0 +1,45 @@ +title = 'Shops'; +$this->params['breadcrumbs'][] = \Yii::t('stock', $this->title); +?> +
+ \Yii::t('stock', Html::encode($this->title)), + ] + ); + ?> +

title)) ?>

+ +

+ 'btn btn-success']) ?> +

+ $dataProvider, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'id', + [ + 'attribute' => \Yii::t('stock', 'Address'), + 'value' => 'lang.address', + ], + 'sort', + 'status:boolean', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> + +
diff --git a/views/shop/update.php b/views/shop/update.php new file mode 100644 index 0000000..c838cc6 --- /dev/null +++ b/views/shop/update.php @@ -0,0 +1,44 @@ +title = Yii::t( + 'catalog', + 'Update {modelClass}: ', + [ + 'modelClass' => 'Shop', + ] + ) . $model->lang->title; +$this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('stock', 'Shop'), + 'url' => [ 'index' ], +]; +$this->params[ 'breadcrumbs' ][] = [ + 'label' => $model->lang->title, + 'url' => [ + 'view', + 'id' => $model->id, + ], +]; +$this->params[ 'breadcrumbs' ][] = Yii::t('stock', 'Update');?> +
+ \Yii::t('stock', Html::encode($this->title)), + ] + ); + ?> +

title) ?>

+ + render('_form', [ + 'model' => $model, + 'modelLangs' => $modelLangs, + ]) ?> + +
diff --git a/views/shop/view.php b/views/shop/view.php new file mode 100644 index 0000000..ea97724 --- /dev/null +++ b/views/shop/view.php @@ -0,0 +1,55 @@ +title = $model->lang->title; +$this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('stock', 'Shops'), + 'url' => [ 'index' ], +]; +$this->params[ 'breadcrumbs' ][] = $this->title; +?> +
+ \Yii::t('stock', Html::encode($this->title)), + ] + ); + ?> +

title) ?>

+ +

+ $model->id], ['class' => 'btn btn-primary']) ?> + $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Are you sure you want to delete this item?', + 'method' => 'post', + ], + ]) ?> +

+ + $model, + 'attributes' => [ + 'id', + 'lang.title', + [ + 'attribute' => 'lang.alias.value', + 'label' => \Yii::t('catalog', 'Alias'), + ], + 'lang.description:html', + 'lang.address', + 'sort', + 'status:boolean', + ], + ]) ?> + +
-- libgit2 0.21.4