];
}
- /**
- * Просмотр конкретной записи
- * @param int $id
- * @return mixed
- * @throws NotFoundHttpException
- */
- public function actionView($id)
- {
- return $this->render('view', [
- 'model' => $this->findModel($id),
- ]);
- }
-
-
public function actionIndex()
{
$flash = 'info';
$this->updateStoreDynamic($postData['store_id'], 'territorial_manager', $postData['territorial_manager']);
}
- $model = !empty($postData['id']) ? $this->findModel($postData['id']) : new CityStoreParams();
+
+ if (!empty($postData['id'])) {
+ $model = $this->findModel($postData['id']);
+ } else {
+ $model = new CityStoreParams();
+ }
+
if ($model->load(Yii::$app->request->post())) {
$model->matrix_type = is_array($model->matrix_type) ? implode(',', $model->matrix_type) : $model->matrix_type;
$value = 'Ошибка при сохранении: ' . implode('. ', array_map(fn($error) => is_array($error) ? implode(', ', $error) : $error, $model->getErrors()));
}
}
+ return $this->redirect(Yii::$app->request->referrer);
}
Yii::$app->session->setFlash($flash, $value);
$territorialManager = $data['territorial_manager'] ?? null;
$bushChefFlorist = $data['bush_chef_florist'] ?? null;
- $query = CityStore::find()->andWhere(['visible' => CityStore::IS_VISIBLE])
- ->andFilterWhere(['city' => $data['address_city']])
- ->andFilterWhere(['region' => $data['address_region']])
- ->andFilterWhere(['district' => $data['address_district']])
- ->andFilterWhere(['type' => $data['store_type']]);
+ $query = CityStore::find()
+ ->andWhere(['visible' => CityStore::IS_VISIBLE]);
+
+ if (!empty($data['address_city'])) {
+ $query->andWhere(['id' => CityStoreParams::find()
+ ->andWhere(['address_city' => $data['address_city']])
+ ->select('store_id')
+ ->column()]);
+ }
+
+ if (!empty($data['address_region'])) {
+ $query->andWhere(['id' => CityStoreParams::find()
+ ->andWhere(['address_region' => $data['address_region']])
+ ->select('store_id')
+ ->column()]);
+ }
+
+ if (!empty($data['address_district'])) {
+ $query->andWhere(['id' => CityStoreParams::find()
+ ->andWhere(['address_district' => $data['address_district']])
+ ->select('store_id')
+ ->column()]);
+ }
+
+ if (!empty($data['store_type'])) {
+ $query->andWhere(['id' => CityStoreParams::find()
+ ->andWhere(['store_type' => $data['store_type']])
+ ->select('store_id')
+ ->column()]);
+ }
if (!empty($territorialManager)) {
$territorialManagerStoreIds = StoreDynamic::find()
$query->andWhere(['in', 'id', $bushChefFloristStoreIds ?: [-1]]);
}
- $stores = $query->orderBy('id')->all();
+ $stores = $query->all();
return [
'success' => true,
- 'data' => ArrayHelper::map($stores, 'id', fn($store) => $store->id . ' ' . $store->name),
+ 'data' => ArrayHelper::map($stores, 'id', function($store) {
+ return $store->id . ' ' . $store->name;
+ }),
];
}
];
}
- public function afterSave($insert, $changedAttributes)
- {
- $fields = [
- 'address_region' => 'region',
- 'address_city' => 'city',
- 'address_district' => 'district',
- 'store_type' => 'type'
- ];
-
- foreach ($fields as $attribute => $field) {
- $value = $insert ? $this->$attribute : ($changedAttributes[$attribute] ?? null);
-
- if (!empty($value)) {
- CityStore::updateAll([$field => $value], ['id' => $this->store_id]);
- }
- }
- }
-
public function getStore()
{
return $this->hasOne(CityStore::class, ['id' => 'store_id']);
$this->registerJsFile('/js/city-store-params/city-store-params.js', ['position' => \yii\web\View::POS_END]);
?>
-<div class="container mt-4 border-bottom">
+<div class="mx-4 mt-4 border-bottom">
<h1><?= Html::encode($this->title) ?></h1>
<div class="row">
</div>
</div>
<div class="row mt-3">
- <div class="col-md-8">
+ <div class="col-md-8 flash-column">
<?php if (Yii::$app->session->hasFlash($flash)): ?>
<?= Html::tag('div', Yii::$app->session->getFlash($flash), [
'class' => 'alert text-center flash-message mb-1 py-1 alert-' . Html::encode($flash),
</div>
</div>
<?php $form = \yii\widgets\ActiveForm::begin(); ?>
-<div class="container mt-4">
+<div class="mx-4 mt-4">
<div class="row">
<div class="col-md-3">
<?= Html::dropDownList('selected_store', $select_store,