add to project email
This commit is contained in:
parent
ea588a8aee
commit
4845f7944b
10
common/mail/addToProjectByEmail-html.php
Normal file
10
common/mail/addToProjectByEmail-html.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $user common\models\User */
|
||||
/* @var $project \common\models\Project */
|
||||
|
||||
?>
|
||||
<p>Здравствуйте, <b><?= $user->username ?></b>,</p>
|
||||
|
||||
Вас добавили в проект <a href="https://itguild.info/tracker/project/<?= $project->id ?>"><?= $project->name ?></a> .
|
1
common/mail/addToProjectByEmail-text.php
Normal file
1
common/mail/addToProjectByEmail-text.php
Normal file
@ -0,0 +1 @@
|
||||
<?php
|
25
common/models/email/AddToProjectEmail.php
Normal file
25
common/models/email/AddToProjectEmail.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace common\models\email;
|
||||
|
||||
use common\models\Project;
|
||||
use common\models\ProjectUser;
|
||||
use common\models\User;
|
||||
use Yii;
|
||||
|
||||
class AddToProjectEmail extends Email
|
||||
{
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param Project $project
|
||||
*/
|
||||
public function __construct(User $user, Project $project)
|
||||
{
|
||||
$this->sendTo = $user->email;
|
||||
$this->subject = 'Вас добавили в проект';
|
||||
$this->mailLayout = ['html' => 'addToProjectByEmail-html', 'text' => 'addToProjectByEmail-text'];
|
||||
$this->params = ['user' => $user, 'project' => $project];
|
||||
}
|
||||
|
||||
}
|
@ -2,10 +2,12 @@
|
||||
|
||||
namespace frontend\modules\api\controllers;
|
||||
|
||||
use common\models\email\AddToProjectEmail;
|
||||
use common\models\ProjectTaskCategory;
|
||||
use common\models\Status;
|
||||
use common\models\User;
|
||||
use common\models\UseStatus;
|
||||
use common\services\EmailService;
|
||||
use frontend\modules\api\models\Manager;
|
||||
use frontend\modules\api\models\project\Project;
|
||||
use frontend\modules\api\models\project\ProjectStatistic;
|
||||
@ -20,12 +22,19 @@ use yii\web\NotFoundHttpException;
|
||||
|
||||
class ProjectController extends ApiController
|
||||
{
|
||||
public EmailService $emailService;
|
||||
public $modelClass = 'frontend\modules\api\models\Project';
|
||||
public $serializer = [
|
||||
'class' => 'yii\rest\Serializer',
|
||||
'collectionEnvelope' => 'projects',
|
||||
];
|
||||
|
||||
public function __construct($id, $module, EmailService $emailService, $config = [])
|
||||
{
|
||||
$this->emailService = $emailService;
|
||||
parent::__construct($id, $module, $config);
|
||||
}
|
||||
|
||||
public function behaviors(): array
|
||||
{
|
||||
return ArrayHelper::merge(parent::behaviors(), [
|
||||
@ -580,6 +589,7 @@ class ProjectController extends ApiController
|
||||
*
|
||||
* @return ProjectUser
|
||||
* @throws NotFoundHttpException
|
||||
* @throws BadRequestHttpException
|
||||
*/
|
||||
public function actionAddUserByEmail(): ProjectUser
|
||||
{
|
||||
@ -594,11 +604,17 @@ class ProjectController extends ApiController
|
||||
throw new NotFoundHttpException('The user not found');
|
||||
}
|
||||
|
||||
if (\common\models\ProjectUser::find()->where(['user_id' => $user->id, 'project_id' => $project->id])->exists()){
|
||||
throw new BadRequestHttpException('Пользователь уже добавлен в проект');
|
||||
}
|
||||
|
||||
$model = new ProjectUser();
|
||||
$model->user_id = $user->id;
|
||||
$model->project_id = $project->id;
|
||||
$model->save();
|
||||
|
||||
$this->emailService->sendEmail(new AddToProjectEmail($user, $project));
|
||||
|
||||
return $model;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user