diff --git a/assets/StockAsset.php b/assets/StockAsset.php index 1273982..3f130dc 100644 --- a/assets/StockAsset.php +++ b/assets/StockAsset.php @@ -1,28 +1,28 @@ [ - 'class' => AccessControl::className(), - 'rules' => [ - [ - 'actions' => [ - 'login', - 'error', + /** + * @inheritdoc + */ + public function getViewPath() + { + return '@artbox/stock/views/city'; + } + + 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 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( + ]; + } + + /** + * Lists all City models. + * + * @return mixed + */ + public function actionIndex() + { + $dataProvider = new ActiveDataProvider( + [ + 'query' => City::find() + ->with([ 'lang' ]), + ] + ); + + return $this->render( + 'index', [ - 'view', - 'id' => $model->id, + 'dataProvider' => $dataProvider, ] ); } - 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( + + /** + * Displays a single City 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 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.'); + + /** + * 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/models/City.php b/models/City.php index 200d2d8..63cabca 100644 --- a/models/City.php +++ b/models/City.php @@ -1,89 +1,99 @@ [ - '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']); - } + + namespace artbox\stock\models; + + use Yii; + use artbox\core\models\Language; + use artbox\core\behaviors\LanguageBehavior; + use yii\db\ActiveRecord; + use yii\web\Request; /** - * @return \yii\db\ActiveQuery + * This is the model class for table "city". + * + * @property integer $id + * @property integer $sort + * @property boolean $status + * @property CityLang[] $cityLangs + * @property Language[] $languages + * @property CityLang[] $modelLangs + * @property Shop[] $shops + * + * @method bool saveWithLangs() + * @method bool loadWithLangs( Request $request) + * @method void generateLangs() */ - public function getShops() + class City extends ActiveRecord { - return $this->hasMany(Shop::className(), ['city_id' => 'id']); + /** + * @inheritdoc + */ + public static function tableName() + { + return 'city'; + } + + public function behaviors() + { + return [ + 'language' => [ + '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/views/city/index.php b/views/city/index.php index b5853a3..15d78ab 100644 --- a/views/city/index.php +++ b/views/city/index.php @@ -1,44 +1,51 @@ title = 'Cities'; -$this->params['breadcrumbs'][] = \Yii::t('stock', $this->title); + + use yii\data\ActiveDataProvider; + use yii\helpers\Html; + use yii\grid\GridView; + use yii\web\View; + use yiister\gentelella\widgets\Panel; + + /** + * @var View $this + * @var ActiveDataProvider $dataProvider + */ + + $this->title = 'Cities'; + $this->params[ 'breadcrumbs' ][] = \Yii::t('stock', $this->title); ?>
- = Html::a(\Yii::t('stock', 'Create City'), ['create'], ['class' => 'btn btn-success']) ?> -
- = GridView::widget([ - 'dataProvider' => $dataProvider, - 'columns' => [ - ['class' => 'yii\grid\SerialColumn'], - - 'id', + $xPanel = Panel::begin( [ - 'attribute' => \Yii::t('stock', 'Title'), - 'value' => 'lang.title', + 'header' => \Yii::t('stock', Html::encode($this->title)), + ] + ); + ?> ++ = Html::a(\Yii::t('stock', 'Create City'), [ 'create' ], [ 'class' => 'btn btn-success' ]) ?> +
+ = GridView::widget( + [ + 'dataProvider' => $dataProvider, + 'columns' => [ + [ 'class' => 'yii\grid\SerialColumn' ], + + 'id', + [ + 'attribute' => \Yii::t('stock', 'Title'), + 'value' => 'lang.title', + ], + 'sort', + 'status:boolean', + + [ 'class' => 'yii\grid\ActionColumn' ], ], - 'sort', - 'status:boolean', - - ['class' => 'yii\grid\ActionColumn'], - ], - ]); ?> + ] + ); ?>