create project
This commit is contained in:
24
frontend/modules/addresses/Addresses.php
Normal file
24
frontend/modules/addresses/Addresses.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\modules\addresses;
|
||||
|
||||
/**
|
||||
* addresses module definition class
|
||||
*/
|
||||
class Addresses extends \yii\base\Module
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public $controllerNamespace = 'frontend\modules\addresses\controllers';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
// custom initialization code goes here
|
||||
}
|
||||
}
|
140
frontend/modules/addresses/controllers/AddressesController.php
Normal file
140
frontend/modules/addresses/controllers/AddressesController.php
Normal file
@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\modules\addresses\controllers;
|
||||
|
||||
use common\services\CompanyService;
|
||||
use Yii;
|
||||
use frontend\modules\addresses\models\Addresses;
|
||||
use frontend\modules\addresses\models\AddressesSearch;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
|
||||
/**
|
||||
* AddressesController implements the CRUD actions for Addresses model.
|
||||
*/
|
||||
class AddressesController extends Controller
|
||||
{
|
||||
public CompanyService $companyService;
|
||||
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
$this->companyService = new CompanyService();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
'verbs' => [
|
||||
'class' => VerbFilter::className(),
|
||||
'actions' => [
|
||||
'delete' => ['POST'],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all Addresses models.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
$searchModel = new AddressesSearch();
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||
|
||||
return $this->render('index', [
|
||||
'searchModel' => $searchModel,
|
||||
'dataProvider' => $dataProvider,
|
||||
'companyService' => $this->companyService,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a single Addresses model.
|
||||
* @param int $id ID
|
||||
* @return mixed
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
public function actionView($id)
|
||||
{
|
||||
return $this->render('view', [
|
||||
'model' => $this->findModel($id),
|
||||
'companyService' => $this->companyService,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Addresses model.
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionCreate()
|
||||
{
|
||||
$model = new Addresses();
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
}
|
||||
|
||||
return $this->render('create', [
|
||||
'model' => $model,
|
||||
'companyService' => $this->companyService,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an existing Addresses model.
|
||||
* If update is successful, the browser will be redirected to the 'view' page.
|
||||
* @param int $id ID
|
||||
* @return mixed
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
public function actionUpdate($id)
|
||||
{
|
||||
$model = $this->findModel($id);
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
}
|
||||
|
||||
return $this->render('update', [
|
||||
'model' => $model,
|
||||
'companyService' => $this->companyService
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an existing Addresses model.
|
||||
* If deletion is successful, the browser will be redirected to the 'index' page.
|
||||
* @param int $id ID
|
||||
* @return mixed
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
public function actionDelete($id)
|
||||
{
|
||||
$this->findModel($id)->delete();
|
||||
|
||||
return $this->redirect(['index']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the Addresses model based on its primary key value.
|
||||
* If the model is not found, a 404 HTTP exception will be thrown.
|
||||
* @param int $id ID
|
||||
* @return Addresses the loaded model
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
protected function findModel($id)
|
||||
{
|
||||
if (($model = Addresses::findOne($id)) !== null) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
throw new NotFoundHttpException('The requested page does not exist.');
|
||||
}
|
||||
}
|
20
frontend/modules/addresses/controllers/DefaultController.php
Normal file
20
frontend/modules/addresses/controllers/DefaultController.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\modules\addresses\controllers;
|
||||
|
||||
use yii\web\Controller;
|
||||
|
||||
/**
|
||||
* Default controller for the `addresses` module
|
||||
*/
|
||||
class DefaultController extends Controller
|
||||
{
|
||||
/**
|
||||
* Renders the index view for the module
|
||||
* @return string
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('index');
|
||||
}
|
||||
}
|
8
frontend/modules/addresses/models/Addresses.php
Normal file
8
frontend/modules/addresses/models/Addresses.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\modules\addresses\models;
|
||||
|
||||
class Addresses extends \common\models\Addresses
|
||||
{
|
||||
|
||||
}
|
70
frontend/modules/addresses/models/AddressesSearch.php
Normal file
70
frontend/modules/addresses/models/AddressesSearch.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\modules\addresses\models;
|
||||
|
||||
use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use frontend\modules\addresses\models\Addresses;
|
||||
|
||||
/**
|
||||
* AddressesSearch represents the model behind the search form of `frontend\modules\addresses\models\Addresses`.
|
||||
*/
|
||||
class AddressesSearch extends Addresses
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id', 'company_id'], 'integer'],
|
||||
[['address', 'name'], 'safe'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function scenarios()
|
||||
{
|
||||
// bypass scenarios() implementation in the parent class
|
||||
return Model::scenarios();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates data provider instance with search query applied
|
||||
*
|
||||
* @param array $params
|
||||
*
|
||||
* @return ActiveDataProvider
|
||||
*/
|
||||
public function search($params)
|
||||
{
|
||||
$query = Addresses::find();
|
||||
|
||||
// add conditions that should always apply here
|
||||
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => $query,
|
||||
]);
|
||||
|
||||
$this->load($params);
|
||||
|
||||
if (!$this->validate()) {
|
||||
// uncomment the following line if you do not want to return any records when validation fails
|
||||
// $query->where('0=1');
|
||||
return $dataProvider;
|
||||
}
|
||||
|
||||
// grid filtering conditions
|
||||
$query->andFilterWhere([
|
||||
'id' => $this->id,
|
||||
'company_id' => $this->company_id,
|
||||
]);
|
||||
|
||||
$query->andFilterWhere(['like', 'address', $this->address])
|
||||
->andFilterWhere(['like', 'name', $this->name]);
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
}
|
29
frontend/modules/addresses/views/addresses/_form.php
Normal file
29
frontend/modules/addresses/views/addresses/_form.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use common\services\CompanyService;
|
||||
use yii\helpers\Html;
|
||||
use yii\bootstrap4\ActiveForm;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model frontend\modules\addresses\models\Addresses */
|
||||
/* @var $form yii\bootstrap4\ActiveForm */
|
||||
/* @var $companyService CompanyService */
|
||||
?>
|
||||
|
||||
<div class="addresses-form">
|
||||
|
||||
<?php $form = ActiveForm::begin(); ?>
|
||||
|
||||
<?= $form->field($model, 'address')->textInput(['maxlength' => true]) ?>
|
||||
|
||||
<?= $form->field($model, 'company_id')->dropDownList($companyService->getCompaniesByUserArr()) ?>
|
||||
|
||||
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
36
frontend/modules/addresses/views/addresses/_search.php
Normal file
36
frontend/modules/addresses/views/addresses/_search.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model frontend\modules\addresses\models\AddressesSearch */
|
||||
/* @var $form yii\widgets\ActiveForm */
|
||||
?>
|
||||
|
||||
<div class="row mt-2">
|
||||
<div class="col-md-12">
|
||||
|
||||
<?php $form = ActiveForm::begin([
|
||||
'action' => ['index'],
|
||||
'method' => 'get',
|
||||
]); ?>
|
||||
|
||||
<?= $form->field($model, 'id') ?>
|
||||
|
||||
<?= $form->field($model, 'address') ?>
|
||||
|
||||
<?= $form->field($model, 'company_id') ?>
|
||||
|
||||
<?= $form->field($model, 'name') ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
|
||||
<?= Html::resetButton('Reset', ['class' => 'btn btn-outline-secondary']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
||||
<!--.col-md-12-->
|
||||
</div>
|
30
frontend/modules/addresses/views/addresses/create.php
Normal file
30
frontend/modules/addresses/views/addresses/create.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use common\services\CompanyService;
|
||||
use yii\helpers\Html;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model frontend\modules\addresses\models\Addresses */
|
||||
/* @var $companyService CompanyService */
|
||||
|
||||
$this->title = 'Добавить отделение';
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Отделения', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
|
||||
<div class="container-fluid">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<?=$this->render('_form', [
|
||||
'model' => $model,
|
||||
'companyService' => $companyService,
|
||||
]) ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!--.card-body-->
|
||||
</div>
|
||||
<!--.card-->
|
||||
</div>
|
62
frontend/modules/addresses/views/addresses/index.php
Normal file
62
frontend/modules/addresses/views/addresses/index.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
use common\services\CompanyService;
|
||||
use yii\helpers\Html;
|
||||
use yii\grid\GridView;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $searchModel frontend\modules\addresses\models\AddressesSearch */
|
||||
/* @var $dataProvider yii\data\ActiveDataProvider */
|
||||
/* @var $companyService CompanyService */
|
||||
|
||||
$this->title = 'Отделения';
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="row mb-2">
|
||||
<div class="col-md-12">
|
||||
<?= Html::a('Добавить', ['create'], ['class' => 'btn btn-success']) ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
|
||||
|
||||
<?= GridView::widget([
|
||||
'dataProvider' => $dataProvider,
|
||||
'filterModel' => $searchModel,
|
||||
'columns' => [
|
||||
['class' => 'yii\grid\SerialColumn'],
|
||||
|
||||
'id',
|
||||
'address',
|
||||
[
|
||||
'attribute' => 'company_id',
|
||||
'value' => function($model) use ($companyService){
|
||||
return $companyService->getCompany($model->company_id)->name ?? null;
|
||||
}
|
||||
],
|
||||
'name',
|
||||
|
||||
['class' => 'hail812\adminlte3\yii\grid\ActionColumn'],
|
||||
],
|
||||
'summaryOptions' => ['class' => 'summary mb-2'],
|
||||
'pager' => [
|
||||
'class' => 'yii\bootstrap4\LinkPager',
|
||||
]
|
||||
]); ?>
|
||||
|
||||
|
||||
</div>
|
||||
<!--.card-body-->
|
||||
</div>
|
||||
<!--.card-->
|
||||
</div>
|
||||
<!--.col-md-12-->
|
||||
</div>
|
||||
<!--.row-->
|
||||
</div>
|
30
frontend/modules/addresses/views/addresses/update.php
Normal file
30
frontend/modules/addresses/views/addresses/update.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model frontend\modules\addresses\models\Addresses */
|
||||
/* @var $companyService CompanyService */
|
||||
|
||||
use common\services\CompanyService;
|
||||
|
||||
$this->title = 'Update Addresses: ' . $model->name;
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Addresses', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]];
|
||||
$this->params['breadcrumbs'][] = 'Update';
|
||||
?>
|
||||
|
||||
<div class="container-fluid">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<?=$this->render('_form', [
|
||||
'model' => $model,
|
||||
'companyService' => $companyService,
|
||||
]) ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!--.card-body-->
|
||||
</div>
|
||||
<!--.card-->
|
||||
</div>
|
53
frontend/modules/addresses/views/addresses/view.php
Normal file
53
frontend/modules/addresses/views/addresses/view.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
use common\services\CompanyService;
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\DetailView;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model frontend\modules\addresses\models\Addresses */
|
||||
/* @var $companyService CompanyService */
|
||||
|
||||
$this->title = $model->name;
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Addresses', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
\yii\web\YiiAsset::register($this);
|
||||
?>
|
||||
|
||||
<div class="container-fluid">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<p>
|
||||
<?= Html::a('Список', ['index'], ['class' => 'btn btn-primary']) ?>
|
||||
<?= Html::a('Редактировать', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
|
||||
<?= Html::a('Удалить', ['delete', 'id' => $model->id], [
|
||||
'class' => 'btn btn-danger',
|
||||
'data' => [
|
||||
'confirm' => 'Are you sure you want to delete this item?',
|
||||
'method' => 'post',
|
||||
],
|
||||
]) ?>
|
||||
</p>
|
||||
<?= DetailView::widget([
|
||||
'model' => $model,
|
||||
'attributes' => [
|
||||
'id',
|
||||
'address',
|
||||
[
|
||||
'attribute' => 'company_id',
|
||||
'value' => $companyService->getCompany($model->company_id)->name ?? null,
|
||||
],
|
||||
'name',
|
||||
],
|
||||
]) ?>
|
||||
</div>
|
||||
<!--.col-md-12-->
|
||||
</div>
|
||||
<!--.row-->
|
||||
</div>
|
||||
<!--.card-body-->
|
||||
</div>
|
||||
<!--.card-->
|
||||
</div>
|
12
frontend/modules/addresses/views/default/index.php
Normal file
12
frontend/modules/addresses/views/default/index.php
Normal file
@ -0,0 +1,12 @@
|
||||
<div class="addresses-default-index">
|
||||
<h1><?= $this->context->action->uniqueId ?></h1>
|
||||
<p>
|
||||
This is the view content for action "<?= $this->context->action->id ?>".
|
||||
The action belongs to the controller "<?= get_class($this->context) ?>"
|
||||
in the "<?= $this->context->module->id ?>" module.
|
||||
</p>
|
||||
<p>
|
||||
You may customize this page by editing the following file:<br>
|
||||
<code><?= __FILE__ ?></code>
|
||||
</p>
|
||||
</div>
|
Reference in New Issue
Block a user