diff --git a/assets/StockAsset.php b/assets/StockAsset.php index 3f130dc..2ac77d9 100644 --- a/assets/StockAsset.php +++ b/assets/StockAsset.php @@ -1,8 +1,9 @@ [ - 'class' => AccessControl::className(), - 'rules' => [ - [ - 'actions' => [ - 'login', - 'error', + /** + * @inheritdoc + */ + public function getViewPath() + { + return '@artbox/stock/views/shop'; + } + public function behaviors() + { + return [ + 'access' => [ + 'class' => AccessControl::className(), + 'rules' => [ + [ + 'actions' => [ + 'login', + 'error', + ], + 'allow' => true, + ], + [ + 'allow' => true, + 'roles' => [ '@' ], ], - 'allow' => true, - ], - [ - 'allow' => true, - 'roles' => [ '@' ], ], ], - ], - 'verbs' => [ - 'class' => VerbFilter::className(), - 'actions' => [ - 'delete' => ['POST'], + '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( + ]; + } + + /** + * Lists all Shop models. + * + * @return mixed + */ + public function actionIndex() + { + $dataProvider = new ActiveDataProvider( + [ + 'query' => Shop::find(), + ] + ); + + return $this->render( + 'index', [ - 'view', - 'id' => $model->id, + 'dataProvider' => $dataProvider, ] ); } - 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( + + /** + * Displays a single Shop model. + * + * @param integer $id + * + * @return mixed + */ + public function actionView($id) + { + return $this->render( + 'view', [ - 'view', - 'id' => $model->id, + 'model' => $this->findModel($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.'); + + /** + * 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(); + 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/messages/ru/stock.php b/messages/ru/stock.php index 4a7167e..3bf82bf 100644 --- a/messages/ru/stock.php +++ b/messages/ru/stock.php @@ -1,18 +1,25 @@ 'Города', - 'Shops' => 'Магазины/склады', - 'Title' => 'Название', - 'Sort' => 'Сортировка', - 'Status' => 'Статус', - 'Description' => 'Описание', - 'Create City' => 'Добавить город', - 'Alias' => 'Алиас', - 'Update' => 'Обновить', - 'Address' => 'Адрес', - 'Create Shop' => 'Добавить магазин', - 'Mode' => "Расписание работы", - 'Delete' => 'Удалить', - 'Create' => "Добавить", -] + return [ + 'Cities' => 'Города', + 'Shops' => 'Магазины/склады', + 'Title' => 'Название', + 'Sort' => 'Сортировка', + 'Status' => 'Статус', + 'Description' => 'Описание', + 'Create City' => 'Добавить город', + 'Alias' => 'Алиас', + 'Update' => 'Обновить', + 'Address' => 'Адрес', + 'Create Shop' => 'Добавить магазин', + 'Mode' => "Расписание работы", + 'Delete' => 'Удалить', + 'Create' => "Добавить", + 'Mon' => 'Пн', + 'Tue' => 'Вт', + 'Wed' => 'Ср', + 'Thu' => 'Чт', + 'Fri' => 'Пт', + 'Sat' => 'Сб', + 'Sun' => 'Вс', + ] ?> \ No newline at end of file diff --git a/models/Shop.php b/models/Shop.php index 4206a16..2633558 100644 --- a/models/Shop.php +++ b/models/Shop.php @@ -1,118 +1,156 @@ [ - '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; + /** + * @inheritdoc + */ + public $cities = []; + public static function tableName() + { + return 'shop'; } - - } - - /** - * @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); + public function behaviors() + { + return [ + 'language' => [ + '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 index d038aff..157ca24 100644 --- a/models/ShopLang.php +++ b/models/ShopLang.php @@ -1,105 +1,151 @@ [ - 'class' => SlugBehavior::className(), - 'action' => 'shop/view', - 'params' => [ - 'id' => 'shop_id', + /** + * @inheritdoc + */ + public static function tableName() + { + return 'shop_lang'; + } + + /** + * @inheritdoc + */ + public function behaviors() + { + return [ + 'slug' => [ + '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'), + ], ], - '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', ], - ], - ]; - } - 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']); + [ + [ + '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 index 5221fb1..299ee28 100644 --- a/views/city/_form.php +++ b/views/city/_form.php @@ -1,16 +1,17 @@
- = Html::a(\Yii::t('stock', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> - = Html::a(\Yii::t('stock', 'Delete'), ['delete', 'id' => $model->id], [ - 'class' => 'btn btn-danger', - 'data' => [ - 'confirm' => 'Are you sure you want to delete this item?', - 'method' => 'post', - ], - ]) ?> -
- - = DetailView::widget([ - 'model' => $model, - 'attributes' => [ - 'id', - 'lang.title', + $xPanel = Panel::begin( [ - 'attribute' => 'lang.alias.value', - 'label' => \Yii::t('catalog', 'Alias'), + 'header' => Html::encode($this->title), + ] + ); + ?> ++ = Html::a( + \Yii::t('stock', 'Update'), + [ + 'update', + 'id' => $model->id, + ], + [ 'class' => 'btn btn-primary' ] + ) ?> + = Html::a( + \Yii::t('stock', 'Delete'), + [ + 'delete', + 'id' => $model->id, + ], + [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Are you sure you want to delete this item?', + 'method' => 'post', + ], + ] + ) ?> +
+ + = DetailView::widget( + [ + 'model' => $model, + 'attributes' => [ + 'id', + 'lang.title', + [ + 'attribute' => 'lang.alias.value', + 'label' => \Yii::t('catalog', 'Alias'), + ], + 'lang.description:html', + 'sort', + 'status:boolean', ], - 'lang.description:html', - 'sort', - 'status:boolean', - ], - ]) ?> + ] + ) ?>- = Html::a(\Yii::t('stock', 'Create Shop'), ['create'], ['class' => 'btn btn-success']) ?> -
- = GridView::widget([ - 'dataProvider' => $dataProvider, - 'columns' => [ - ['class' => 'yii\grid\SerialColumn'], - - 'id', + $xPanel = Panel::begin( [ - 'attribute' => \Yii::t('stock', 'Address'), - 'value' => 'lang.address', + 'header' => \Yii::t('stock', Html::encode($this->title)), + ] + ); + ?> ++ = Html::a(\Yii::t('stock', 'Create Shop'), [ 'create' ], [ 'class' => 'btn btn-success' ]) ?> +
+ = GridView::widget( + [ + 'dataProvider' => $dataProvider, + 'columns' => [ + [ 'class' => 'yii\grid\SerialColumn' ], + + 'id', + [ + 'attribute' => \Yii::t('stock', 'Address'), + 'value' => 'lang.address', + ], + 'sort', + 'status:boolean', + + [ 'class' => 'yii\grid\ActionColumn' ], ], - 'sort', - 'status:boolean', - - ['class' => 'yii\grid\ActionColumn'], - ], - ]); ?> + ] + ); ?>- = Html::a(\Yii::t('stock', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> - = Html::a(\Yii::t('stock', 'Delete'), ['delete', 'id' => $model->id], [ - 'class' => 'btn btn-danger', - 'data' => [ - 'confirm' => 'Are you sure you want to delete this item?', - 'method' => 'post', - ], - ]) ?> -
- - = DetailView::widget([ - 'model' => $model, - 'attributes' => [ - 'id', - 'lang.title', + $xPanel = Panel::begin( [ - 'attribute' => 'lang.alias.value', - 'label' => \Yii::t('catalog', 'Alias'), + 'header' => \Yii::t('stock', Html::encode($this->title)), + ] + ); + ?> ++ = Html::a( + \Yii::t('stock', 'Update'), + [ + 'update', + 'id' => $model->id, + ], + [ 'class' => 'btn btn-primary' ] + ) ?> + = Html::a( + \Yii::t('stock', 'Delete'), + [ + 'delete', + 'id' => $model->id, + ], + [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Are you sure you want to delete this item?', + 'method' => 'post', + ], + ] + ) ?> +
+ + = DetailView::widget( + [ + 'model' => $model, + 'attributes' => [ + 'id', + 'lang.title', + [ + 'attribute' => 'lang.alias.value', + 'label' => \Yii::t('catalog', 'Alias'), + ], + 'lang.description:html', + 'lang.address', + 'sort', + 'status:boolean', ], - 'lang.description:html', - 'lang.address', - 'sort', - 'status:boolean', - ], - ]) ?> + ] + ) ?>