diff --git a/backend/modules/project/controllers/ProjectUserController.php b/backend/modules/project/controllers/ProjectUserController.php
new file mode 100644
index 0000000..9b5c514
--- /dev/null
+++ b/backend/modules/project/controllers/ProjectUserController.php
@@ -0,0 +1,127 @@
+ [
+ 'class' => VerbFilter::className(),
+ 'actions' => [
+ 'delete' => ['POST'],
+ ],
+ ],
+ ];
+ }
+
+ /**
+ * Lists all ProjectUser models.
+ * @return mixed
+ */
+ public function actionIndex()
+ {
+ $searchModel = new ProjectUserSearch();
+ $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
+
+ return $this->render('index', [
+ 'searchModel' => $searchModel,
+ 'dataProvider' => $dataProvider,
+ ]);
+ }
+
+ /**
+ * Displays a single ProjectUser model.
+ * @param integer $id
+ * @return mixed
+ * @throws NotFoundHttpException if the model cannot be found
+ */
+ public function actionView($id)
+ {
+ return $this->render('view', [
+ 'model' => $this->findModel($id),
+ ]);
+ }
+
+ /**
+ * Creates a new ProjectUser model.
+ * If creation is successful, the browser will be redirected to the 'view' page.
+ * @return mixed
+ */
+ public function actionCreate()
+ {
+ $model = new ProjectUser();
+
+ if ($model->load(Yii::$app->request->post()) && $model->save()) {
+ return $this->redirect(['view', 'id' => $model->id]);
+ }
+
+ return $this->render('create', [
+ 'model' => $model,
+ ]);
+ }
+
+ /**
+ * Updates an existing ProjectUser 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)
+ {
+ $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,
+ ]);
+ }
+
+ /**
+ * Deletes an existing ProjectUser 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 ProjectUser model based on its primary key value.
+ * If the model is not found, a 404 HTTP exception will be thrown.
+ * @param integer $id
+ * @return ProjectUser the loaded model
+ * @throws NotFoundHttpException if the model cannot be found
+ */
+ protected function findModel($id)
+ {
+ if (($model = ProjectUser::findOne($id)) !== null) {
+ return $model;
+ }
+
+ throw new NotFoundHttpException('The requested page does not exist.');
+ }
+}
diff --git a/backend/modules/project/models/ProjectUser.php b/backend/modules/project/models/ProjectUser.php
new file mode 100644
index 0000000..c9c1a2e
--- /dev/null
+++ b/backend/modules/project/models/ProjectUser.php
@@ -0,0 +1,8 @@
+joinWith(['project', 'user']);
+
+ // 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,
+ 'project_id' => $this->project_id,
+ 'user_id' => $this->user_id,
+ ]);
+
+ return $dataProvider;
+ }
+}
diff --git a/backend/modules/project/views/project-user/_form.php b/backend/modules/project/views/project-user/_form.php
new file mode 100644
index 0000000..3a02810
--- /dev/null
+++ b/backend/modules/project/views/project-user/_form.php
@@ -0,0 +1,44 @@
+
+
+
diff --git a/backend/modules/project/views/project-user/_search.php b/backend/modules/project/views/project-user/_search.php
new file mode 100644
index 0000000..c8773ea
--- /dev/null
+++ b/backend/modules/project/views/project-user/_search.php
@@ -0,0 +1,31 @@
+
+
+
+
+ ['index'],
+ 'method' => 'get',
+ ]); ?>
+
+ = $form->field($model, 'id') ?>
+
+ = $form->field($model, 'project_id') ?>
+
+ = $form->field($model, 'user_id') ?>
+
+
+ = Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
+ = Html::resetButton('Reset', ['class' => 'btn btn-default']) ?>
+
+
+
+
+
diff --git a/backend/modules/project/views/project-user/create.php b/backend/modules/project/views/project-user/create.php
new file mode 100644
index 0000000..993ae8f
--- /dev/null
+++ b/backend/modules/project/views/project-user/create.php
@@ -0,0 +1,18 @@
+title = 'Назначить сотрудника на проект';
+$this->params['breadcrumbs'][] = ['label' => 'Project Users', 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+?>
+
+
+ = $this->render('_form', [
+ 'model' => $model,
+ ]) ?>
+
+
diff --git a/backend/modules/project/views/project-user/index.php b/backend/modules/project/views/project-user/index.php
new file mode 100644
index 0000000..5496edc
--- /dev/null
+++ b/backend/modules/project/views/project-user/index.php
@@ -0,0 +1,41 @@
+title = 'Сотрудники на проектах';
+$this->params['breadcrumbs'][] = $this->title;
+?>
+
+
+
+ = Html::a('Назначить сотрудника на проект', ['create'], ['class' => 'btn btn-success']) ?>
+
+
+ = GridView::widget([
+ 'dataProvider' => $dataProvider,
+ 'filterModel' => $searchModel,
+ 'columns' => [
+ ['class' => 'yii\grid\SerialColumn'],
+
+ [
+ 'attribute' => 'project_id',
+ 'filter' => Project::find()->select(['name', 'id'])->indexBy('id')->column(),
+ 'value' => 'project.name'
+ ],
+ [
+ 'attribute' => 'user_id',
+ 'filter' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
+ 'value' => 'user.username'
+ ],
+
+ ['class' => 'yii\grid\ActionColumn'],
+ ],
+ ]); ?>
+
diff --git a/backend/modules/project/views/project-user/update.php b/backend/modules/project/views/project-user/update.php
new file mode 100644
index 0000000..9e8439d
--- /dev/null
+++ b/backend/modules/project/views/project-user/update.php
@@ -0,0 +1,19 @@
+title = 'Изменить сотрудника на проекте';
+$this->params['breadcrumbs'][] = ['label' => 'Project Users', 'url' => ['index']];
+$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]];
+$this->params['breadcrumbs'][] = 'Update';
+?>
+
+
+ = $this->render('_form', [
+ 'model' => $model,
+ ]) ?>
+
+
diff --git a/backend/modules/project/views/project-user/view.php b/backend/modules/project/views/project-user/view.php
new file mode 100644
index 0000000..4af4631
--- /dev/null
+++ b/backend/modules/project/views/project-user/view.php
@@ -0,0 +1,44 @@
+title = 'Сотрудник проекта: ' . $model->project->name;
+$this->params['breadcrumbs'][] = ['label' => 'Project Users', 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+\yii\web\YiiAsset::register($this);
+?>
+
+
+
+ = Html::a('Список', ['index', 'id' => $model->id], ['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',
+ ],
+ ]) ?>
+
+
+ = DetailView::widget([
+ 'model' => $model,
+ 'attributes' => [
+ 'id',
+ [
+ 'attribute' => 'project_id',
+ 'value' => ArrayHelper::getValue($model, 'project.name' ),
+ ],
+ [
+ 'attribute' => 'user_id',
+ 'value' => ArrayHelper::getValue($model, 'user.username' ),
+ ],
+ ],
+ ]) ?>
+
+
diff --git a/backend/views/layouts/left.php b/backend/views/layouts/left.php
index 6c0e32e..0c3d06a 100755
--- a/backend/views/layouts/left.php
+++ b/backend/views/layouts/left.php
@@ -12,6 +12,7 @@
foreach ($projectStatuses as $key => $status) {
$projectItems[] = ['label' => $status, 'icon' => 'user', 'url' => ['/project/project?ProjectSearch[status]=' . $key]];
}
+ $projectItems[] = ['label' => 'Сотрудники на проектах', 'icon' => 'cubes', 'url' => ['/project/project-user']];
?>
= dmstr\widgets\Menu::widget(
diff --git a/common/models/ProjectUser.php b/common/models/ProjectUser.php
old mode 100755
new mode 100644
index eb27642..918c9db
--- a/common/models/ProjectUser.php
+++ b/common/models/ProjectUser.php
@@ -8,11 +8,13 @@ use Yii;
* This is the model class for table "project_user".
*
* @property int $id
- * @property int $card_id
* @property int $project_id
+ * @property int $user_id
*
* @property Project $project
- * @property UserCard $card
+ * @property User $user
+ * @property Task[] $tasks
+ * @property TaskUser[] $taskUsers
*/
class ProjectUser extends \yii\db\ActiveRecord
{
@@ -30,10 +32,10 @@ class ProjectUser extends \yii\db\ActiveRecord
public function rules()
{
return [
- [['card_id', 'project_id'], 'required'],
- [['card_id', 'project_id'], 'integer'],
+ [['project_id', 'user_id'], 'required'],
+ [['project_id', 'user_id'], 'integer'],
[['project_id'], 'exist', 'skipOnError' => true, 'targetClass' => Project::className(), 'targetAttribute' => ['project_id' => 'id']],
- [['card_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::className(), 'targetAttribute' => ['card_id' => 'id']],
+ [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],
];
}
@@ -44,8 +46,8 @@ class ProjectUser extends \yii\db\ActiveRecord
{
return [
'id' => 'ID',
- 'card_id' => 'Card ID',
- 'project_id' => 'Project ID',
+ 'project_id' => 'Проект',
+ 'user_id' => 'Сотрудник',
];
}
@@ -60,8 +62,24 @@ class ProjectUser extends \yii\db\ActiveRecord
/**
* @return \yii\db\ActiveQuery
*/
- public function getCard()
+ public function getUser()
{
- return $this->hasOne(UserCard::className(), ['id' => 'card_id']);
+ return $this->hasOne(User::className(), ['id' => 'user_id']);
+ }
+
+ /**
+ * @return \yii\db\ActiveQuery
+ */
+ public function getTasks()
+ {
+ return $this->hasMany(Task::className(), ['project_user_id' => 'id']);
+ }
+
+ /**
+ * @return \yii\db\ActiveQuery
+ */
+ public function getTaskUsers()
+ {
+ return $this->hasMany(TaskUser::className(), ['project_user_id' => 'id']);
}
}