requests
This commit is contained in:
24
backend/modules/request/Request.php
Normal file
24
backend/modules/request/Request.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace backend\modules\request;
|
||||
|
||||
/**
|
||||
* request module definition class
|
||||
*/
|
||||
class Request extends \yii\base\Module
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public $controllerNamespace = 'backend\modules\request\controllers';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
// custom initialization code goes here
|
||||
}
|
||||
}
|
20
backend/modules/request/controllers/DefaultController.php
Normal file
20
backend/modules/request/controllers/DefaultController.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace backend\modules\request\controllers;
|
||||
|
||||
use yii\web\Controller;
|
||||
|
||||
/**
|
||||
* Default controller for the `request` module
|
||||
*/
|
||||
class DefaultController extends Controller
|
||||
{
|
||||
/**
|
||||
* Renders the index view for the module
|
||||
* @return string
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('index');
|
||||
}
|
||||
}
|
147
backend/modules/request/controllers/RequestController.php
Normal file
147
backend/modules/request/controllers/RequestController.php
Normal file
@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
namespace backend\modules\request\controllers;
|
||||
|
||||
use common\classes\Debug;
|
||||
use common\services\RequestService;
|
||||
use Yii;
|
||||
use backend\modules\request\models\Request;
|
||||
use backend\modules\request\models\RequestSearch;
|
||||
use yii\data\ArrayDataProvider;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
|
||||
/**
|
||||
* RequestController implements the CRUD actions for Request model.
|
||||
*/
|
||||
class RequestController extends Controller
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
'verbs' => [
|
||||
'class' => VerbFilter::className(),
|
||||
'actions' => [
|
||||
'delete' => ['POST'],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all Request models.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
$searchModel = new RequestSearch();
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||
|
||||
return $this->render('index', [
|
||||
'searchModel' => $searchModel,
|
||||
'dataProvider' => $dataProvider,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a single Request model.
|
||||
* @param integer $id
|
||||
* @return mixed
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
public function actionView(int $id)
|
||||
{
|
||||
$res = RequestService::run($id)->getById();
|
||||
|
||||
$search = RequestService::run($id)->search(3);
|
||||
|
||||
$searchDataProvider = new ArrayDataProvider([
|
||||
'allModels' => $search,
|
||||
'pagination' => [
|
||||
'pageSize' => 10,
|
||||
],
|
||||
'sort' => [
|
||||
'attributes' => ['id', 'fio'],
|
||||
],
|
||||
]);
|
||||
|
||||
return $this->render('view', [
|
||||
'model' => $res,
|
||||
'searchDataProvider' => $searchDataProvider,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Request model.
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionCreate()
|
||||
{
|
||||
$req = RequestService::run()->load(Yii::$app->request->post());
|
||||
|
||||
if ($req->isLoad) {
|
||||
$req->save();
|
||||
return $this->redirect(['view', 'id' => $req->model->id]);
|
||||
}
|
||||
|
||||
return $this->render('create', [
|
||||
'model' => $req->model,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an existing Request model.
|
||||
* If update is successful, the browser will be redirected to the 'view' page.
|
||||
* @param integer $id
|
||||
* @return mixed
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
public function actionUpdate($id)
|
||||
{
|
||||
$req = RequestService::run($id)->load(Yii::$app->request->post());
|
||||
|
||||
if ($req->isLoad) {
|
||||
$req->save();
|
||||
return $this->redirect(['view', 'id' => $req->model->id]);
|
||||
}
|
||||
|
||||
return $this->render('update', [
|
||||
'model' => $req->model,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an existing Request model.
|
||||
* If deletion is successful, the browser will be redirected to the 'index' page.
|
||||
* @param integer $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 Request model based on its primary key value.
|
||||
* If the model is not found, a 404 HTTP exception will be thrown.
|
||||
* @param integer $id
|
||||
* @return Request the loaded model
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
protected function findModel($id)
|
||||
{
|
||||
if (($model = Request::findOne($id)) !== null) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
throw new NotFoundHttpException('The requested page does not exist.');
|
||||
}
|
||||
}
|
8
backend/modules/request/models/Request.php
Normal file
8
backend/modules/request/models/Request.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace backend\modules\request\models;
|
||||
|
||||
class Request extends \common\models\Request
|
||||
{
|
||||
|
||||
}
|
79
backend/modules/request/models/RequestSearch.php
Normal file
79
backend/modules/request/models/RequestSearch.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace backend\modules\request\models;
|
||||
|
||||
use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use backend\modules\request\models\Request;
|
||||
|
||||
/**
|
||||
* RequestSearch represents the model behind the search form of `backend\modules\request\models\Request`.
|
||||
*/
|
||||
class RequestSearch extends Request
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id', 'user_id', 'position_id', 'knowledge_level_id', 'specialist_count', 'status'], 'integer'],
|
||||
[['created_at', 'updated_at', 'title', 'skill_ids', 'descr'], '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 = Request::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,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
'user_id' => $this->user_id,
|
||||
'position_id' => $this->position_id,
|
||||
'knowledge_level_id' => $this->knowledge_level_id,
|
||||
'specialist_count' => $this->specialist_count,
|
||||
'status' => $this->status,
|
||||
]);
|
||||
|
||||
$query->andFilterWhere(['like', 'title', $this->title])
|
||||
->andFilterWhere(['like', 'skill_ids', $this->skill_ids])
|
||||
->andFilterWhere(['like', 'descr', $this->descr]);
|
||||
|
||||
$query->orderBy('id DESC');
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
}
|
12
backend/modules/request/views/default/index.php
Normal file
12
backend/modules/request/views/default/index.php
Normal file
@ -0,0 +1,12 @@
|
||||
<div class="request-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>
|
63
backend/modules/request/views/request/_form.php
Normal file
63
backend/modules/request/views/request/_form.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
use kartik\select2\Select2;
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\modules\request\models\Request */
|
||||
/* @var $form yii\widgets\ActiveForm */
|
||||
?>
|
||||
|
||||
<div class="request-form">
|
||||
|
||||
<?php $form = ActiveForm::begin(); ?>
|
||||
|
||||
<?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>
|
||||
|
||||
<?= $form->field($model, 'user_id')->widget(
|
||||
Select2::class,
|
||||
[
|
||||
'data' => \common\models\UserCard::getListUserWithUserId(),
|
||||
'options' => ['placeholder' => '...', 'class' => 'form-control'],
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true
|
||||
],
|
||||
]
|
||||
); ?>
|
||||
|
||||
<?= $form->field($model, 'position_id')->dropDownList(\common\models\Position::getList(), [
|
||||
'prompt' => 'Выберите'
|
||||
]) ?>
|
||||
|
||||
<?= $form->field($model, 'skill_ids')->widget(
|
||||
Select2::class,
|
||||
[
|
||||
'data' => \yii\helpers\ArrayHelper::map(\common\models\Skill::find()->all(), 'id', 'name'),
|
||||
'options' => ['placeholder' => '...', 'class' => 'form-control', 'multiple' => true],
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true
|
||||
],
|
||||
]
|
||||
)->label('Навыки'); ?>
|
||||
|
||||
<?= $form->field($model, 'knowledge_level_id')->dropDownList(
|
||||
\common\models\UserCard::getLevelList(),
|
||||
['prompt' => '...']
|
||||
) ?>
|
||||
|
||||
<?= $form->field($model, 'descr')->textarea(['rows' => 6]) ?>
|
||||
|
||||
<?= $form->field($model, 'specialist_count')->textInput() ?>
|
||||
|
||||
<?= $form->field($model, 'status')->dropDownList(\common\models\Request::getStatus(), [
|
||||
'prompt' => 'Выберите'
|
||||
]) ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
47
backend/modules/request/views/request/_search.php
Normal file
47
backend/modules/request/views/request/_search.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\modules\request\models\RequestSearch */
|
||||
/* @var $form yii\widgets\ActiveForm */
|
||||
?>
|
||||
|
||||
<div class="request-search">
|
||||
|
||||
<?php $form = ActiveForm::begin([
|
||||
'action' => ['index'],
|
||||
'method' => 'get',
|
||||
]); ?>
|
||||
|
||||
<?= $form->field($model, 'id') ?>
|
||||
|
||||
<?= $form->field($model, 'created_at') ?>
|
||||
|
||||
<?= $form->field($model, 'updated_at') ?>
|
||||
|
||||
<?= $form->field($model, 'user_id') ?>
|
||||
|
||||
<?= $form->field($model, 'title') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'position_id') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'skill_ids') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'knowledge_level_id') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'descr') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'specialist_count') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'status') ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
|
||||
<?= Html::resetButton('Reset', ['class' => 'btn btn-default']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
18
backend/modules/request/views/request/create.php
Normal file
18
backend/modules/request/views/request/create.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\modules\request\models\Request */
|
||||
|
||||
$this->title = 'Добавить';
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Запросы', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="request-create">
|
||||
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
]) ?>
|
||||
|
||||
</div>
|
62
backend/modules/request/views/request/index.php
Normal file
62
backend/modules/request/views/request/index.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\grid\GridView;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $searchModel backend\modules\request\models\RequestSearch */
|
||||
/* @var $dataProvider yii\data\ActiveDataProvider */
|
||||
|
||||
$this->title = 'Запросы';
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="request-index">
|
||||
|
||||
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
|
||||
|
||||
<p>
|
||||
<?= Html::a('Добавить запрос', ['create'], ['class' => 'btn btn-success']) ?>
|
||||
</p>
|
||||
|
||||
<?= GridView::widget([
|
||||
'dataProvider' => $dataProvider,
|
||||
'filterModel' => $searchModel,
|
||||
'columns' => [
|
||||
['class' => 'yii\grid\SerialColumn'],
|
||||
|
||||
//'id',
|
||||
'created_at',
|
||||
//'updated_at',
|
||||
[
|
||||
'attribute' => 'user_id',
|
||||
'value' => function(\common\models\Request $model){
|
||||
return $model->user->userCard->fio ?? 'Не задано';
|
||||
}
|
||||
],
|
||||
'title',
|
||||
[
|
||||
'attribute' => 'position_id',
|
||||
'value' => function(\common\models\Request $model){
|
||||
return $model->position->name ?? 'Не задано';
|
||||
}
|
||||
],
|
||||
//'skill_ids',
|
||||
[
|
||||
'attribute' => 'knowledge_level_id',
|
||||
'value' => function(\common\models\Request $model){
|
||||
return \common\models\UserCard::getLevelList()[$model->knowledge_level_id];
|
||||
}
|
||||
],
|
||||
//'descr:ntext',
|
||||
'specialist_count',
|
||||
[
|
||||
'attribute' => 'status',
|
||||
'value' => function(\common\models\Request $model){
|
||||
return \common\models\KnowledgeLevel::getStatus()[$model->status];
|
||||
}
|
||||
],
|
||||
|
||||
['class' => 'yii\grid\ActionColumn'],
|
||||
],
|
||||
]); ?>
|
||||
</div>
|
19
backend/modules/request/views/request/update.php
Normal file
19
backend/modules/request/views/request/update.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\modules\request\models\Request */
|
||||
|
||||
$this->title = 'Редактировать запрос: ' . $model->title;
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Запросы', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->id]];
|
||||
$this->params['breadcrumbs'][] = 'Ред.';
|
||||
?>
|
||||
<div class="request-update">
|
||||
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
]) ?>
|
||||
|
||||
</div>
|
88
backend/modules/request/views/request/view.php
Normal file
88
backend/modules/request/views/request/view.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
use yii\grid\GridView;
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\DetailView;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\modules\request\models\Request */
|
||||
/* @var $searchDataProvider \yii\data\ArrayDataProvider */
|
||||
|
||||
$this->title = $model->title;
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Requests', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
\yii\web\YiiAsset::register($this);
|
||||
?>
|
||||
<div class="request-view">
|
||||
|
||||
<p>
|
||||
<?= Html::a('Редактировать', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
|
||||
<?= Html::a('Список', ['index'], ['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',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
[
|
||||
'attribute' => 'user_id',
|
||||
'value' => function (\common\models\Request $model) {
|
||||
return $model->user->userCard->fio ?? 'Не задано';
|
||||
}
|
||||
],
|
||||
'title',
|
||||
[
|
||||
'attribute' => 'position_id',
|
||||
'value' => function (\common\models\Request $model) {
|
||||
return $model->position->name ?? 'Не задано';
|
||||
}
|
||||
],
|
||||
// 'skill_ids',
|
||||
[
|
||||
'attribute' => 'skill_ids',
|
||||
'value' => function (\common\models\Request $model) {
|
||||
$skillStr = '';
|
||||
foreach ($model->skills as $skill) {
|
||||
$skillStr .= $skill['name'] . ", ";
|
||||
}
|
||||
return $skillStr;
|
||||
}
|
||||
],
|
||||
[
|
||||
'attribute' => 'knowledge_level_id',
|
||||
'value' => function (\common\models\Request $model) {
|
||||
return \common\models\UserCard::getLevelList()[$model->knowledge_level_id];
|
||||
}
|
||||
],
|
||||
'descr:ntext',
|
||||
'specialist_count',
|
||||
[
|
||||
'attribute' => 'status',
|
||||
'value' => function (\common\models\Request $model) {
|
||||
return \common\models\Request::getStatus()[$model->status] ?? 'Не задано';
|
||||
}
|
||||
],
|
||||
],
|
||||
]) ?>
|
||||
|
||||
<h3>Подходящие кандидаты</h3>
|
||||
|
||||
<?= GridView::widget([
|
||||
'dataProvider' => $searchDataProvider,
|
||||
'columns' => [['class' => 'yii\grid\SerialColumn'],
|
||||
'id',
|
||||
'fio',
|
||||
],
|
||||
]); ?>
|
||||
|
||||
|
||||
</div>
|
Reference in New Issue
Block a user