complete the manager module
This commit is contained in:
parent
957e777da5
commit
12648f16f8
@ -54,14 +54,6 @@ class ManagerController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function actionView($id)
|
public function actionView($id)
|
||||||
{
|
{
|
||||||
// $model = $this->findModel($id);
|
|
||||||
// $questionSearchModel = new QuestionSearch();
|
|
||||||
// $questionDataProvider = new ActiveDataProvider([
|
|
||||||
// 'query' => $model->getQuestions()->with('questionType'),
|
|
||||||
// 'pagination' => [
|
|
||||||
// 'pageSize' => 20,
|
|
||||||
// ],
|
|
||||||
// ]);
|
|
||||||
$model = $this->findModel($id);
|
$model = $this->findModel($id);
|
||||||
$managerEmployeeSearchModel = new ManagerEmployeeSearch();
|
$managerEmployeeSearchModel = new ManagerEmployeeSearch();
|
||||||
$managerEmployeeDataProvider = new ActiveDataProvider([
|
$managerEmployeeDataProvider = new ActiveDataProvider([
|
||||||
|
@ -82,11 +82,15 @@ class ManagerEmployeeController extends Controller
|
|||||||
* @return mixed
|
* @return mixed
|
||||||
* @throws NotFoundHttpException if the model cannot be found
|
* @throws NotFoundHttpException if the model cannot be found
|
||||||
*/
|
*/
|
||||||
public function actionUpdate($id)
|
public function actionUpdate($id, $manager_id = null)
|
||||||
{
|
{
|
||||||
$model = $this->findModel($id);
|
$model = $this->findModel($id);
|
||||||
|
|
||||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||||
|
if ($manager_id !== null)
|
||||||
|
{
|
||||||
|
return $this->redirect(['manager/view', 'id' => $manager_id]);
|
||||||
|
}
|
||||||
return $this->redirect(['view', 'id' => $model->id]);
|
return $this->redirect(['view', 'id' => $model->id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,10 +106,15 @@ class ManagerEmployeeController extends Controller
|
|||||||
* @return mixed
|
* @return mixed
|
||||||
* @throws NotFoundHttpException if the model cannot be found
|
* @throws NotFoundHttpException if the model cannot be found
|
||||||
*/
|
*/
|
||||||
public function actionDelete($id)
|
public function actionDelete($id, $manager_id = null)
|
||||||
{
|
{
|
||||||
$this->findModel($id)->delete();
|
$this->findModel($id)->delete();
|
||||||
|
|
||||||
|
if ($manager_id !== null)
|
||||||
|
{
|
||||||
|
return $this->redirect(['manager/view', 'id' => $manager_id]);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->redirect(['index']);
|
return $this->redirect(['index']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,6 @@ YiiAsset::register($this);
|
|||||||
|
|
||||||
<?= GridView::widget([
|
<?= GridView::widget([
|
||||||
'dataProvider' => $managerEmployeeDataProvider,
|
'dataProvider' => $managerEmployeeDataProvider,
|
||||||
// 'filterModel' => $managerEmployeeSearchModel,
|
|
||||||
'columns' => [
|
'columns' => [
|
||||||
['class' => 'yii\grid\SerialColumn'],
|
['class' => 'yii\grid\SerialColumn'],
|
||||||
[
|
[
|
||||||
@ -52,7 +51,30 @@ YiiAsset::register($this);
|
|||||||
'filter' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
|
'filter' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
|
||||||
'value' => 'user.username',
|
'value' => 'user.username',
|
||||||
],
|
],
|
||||||
['class' => 'yii\grid\ActionColumn'],
|
[
|
||||||
|
'class' => 'yii\grid\ActionColumn',
|
||||||
|
'template' => '{view} {update} {delete}',
|
||||||
|
'controller' => 'manager-employee',
|
||||||
|
'buttons' => [
|
||||||
|
|
||||||
|
'update' => function ($url,$model) {
|
||||||
|
return Html::a(
|
||||||
|
'<span class="glyphicon glyphicon-pencil"></span>',
|
||||||
|
['manager-employee/update', 'id' => $model['id'], 'manager_id' => $model['manager_id']]);
|
||||||
|
},
|
||||||
|
'delete' => function ($url,$model) {
|
||||||
|
return Html::a(
|
||||||
|
'<span class="glyphicon glyphicon-trash"></span>',
|
||||||
|
[
|
||||||
|
'manager-employee/delete', 'id' => $model['id'], 'manager_id' => $model['manager_id']
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'data' => ['confirm' => 'Вы уверены, что хотите удалить этого сотрудника?', 'method' => 'post']
|
||||||
|
]
|
||||||
|
);
|
||||||
|
},
|
||||||
|
],
|
||||||
|
],
|
||||||
],
|
],
|
||||||
]); ?>
|
]); ?>
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace common\models;
|
namespace common\models;
|
||||||
|
|
||||||
use Yii;
|
use Yii;
|
||||||
|
use yii\db\ActiveQuery;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the model class for table "manager".
|
* This is the model class for table "manager".
|
||||||
@ -45,8 +46,16 @@ class Manager extends \yii\db\ActiveRecord
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function beforeDelete()
|
||||||
|
{
|
||||||
|
foreach ($this->managerEmployees as $employee){
|
||||||
|
$employee->delete();
|
||||||
|
}
|
||||||
|
return parent::beforeDelete();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \yii\db\ActiveQuery
|
* @return ActiveQuery
|
||||||
*/
|
*/
|
||||||
public function getUser()
|
public function getUser()
|
||||||
{
|
{
|
||||||
@ -54,7 +63,7 @@ class Manager extends \yii\db\ActiveRecord
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \yii\db\ActiveQuery
|
* @return ActiveQuery
|
||||||
*/
|
*/
|
||||||
public function getManagerEmployees()
|
public function getManagerEmployees()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user