From a6ba09379ea6ef11104e3122e2166ef0d5dd843c Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 26 Jul 2017 18:05:58 +0300 Subject: [PATCH] -Stocks prettified --- assets/StockAsset.php | 48 ++++++++++++++++++++++++------------------------ controllers/CityController.php | 311 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------------------------------------------------------------------------------------- models/City.php | 176 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------------- views/city/index.php | 77 ++++++++++++++++++++++++++++++++++++++++++----------------------------------- views/shop/_form.php | 179 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------ 5 files changed, 431 insertions(+), 360 deletions(-) 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); ?>
\Yii::t('stock', Html::encode($this->title)), - ] - ); - ?> -

title)) ?>

- -

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

- $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)), + ] + ); + ?> +

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' ], ], - 'sort', - 'status:boolean', - - ['class' => 'yii\grid\ActionColumn'], - ], - ]); ?> + ] + ); ?>
diff --git a/views/shop/_form.php b/views/shop/_form.php index a5c8fdd..edc7073 100644 --- a/views/shop/_form.php +++ b/views/shop/_form.php @@ -1,16 +1,24 @@ modeStr); die(); - -\artbox\stock\assets\StockAsset::register($this); + + use yii\helpers\Html; + use yii\widgets\ActiveForm; + use artbox\core\widgets\LanguageForm; + use kartik\select2\Select2; + + /* @var $this yii\web\View */ + /* @var $model artbox\stock\models\Shop */ + /* @var $form yii\widgets\ActiveForm */ + $days = [ + \Yii::t('stock', 'Пн'), + "Вт", + "Ср", + "Чт", + "Пт", + "Сб", + "Вс", + ]; + + \artbox\stock\assets\StockAsset::register($this); ?>
@@ -22,50 +30,70 @@ $days = ['Пн', "Вт", "Ср", "Чт", "Пт", "Сб", "Вс"]; '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', - ])?> + $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):?> - + modeStr[ $key ][ 'off' ]) ) ? true : false) ?> + + + modeStr[ 'data' ]): ?> + + modeStr[ 'data' ] as $key => $data): ?> + - 10, - 'type'=> 'data', - ])?> + 10, + 'type' => 'data', + ] + ) ?> - 10, - 'type'=> 'time', - - ])?> + 10, + 'type' => 'time', + + ] + ) ?> - - 10, - 'type'=> 'time', - ])?> + + 10, + 'type' => 'time', + ] + ) ?> - - - - + + + + 'add-data', - 'class' => 'btn btn-success', - 'data-count' => (isset($model->modeStr['data'])) ? count($model->modeStr['data']) : 0, + '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']) ?> -
- + + + + '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' ] + ) ?> +
+
-- libgit2 0.21.4