Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
88.89% |
8 / 9 |
CRAP | |
95.45% |
21 / 22 |
| InProgressState | |
0.00% |
0 / 1 |
|
88.89% |
8 / 9 |
17 | |
95.45% |
21 / 22 |
| getDefaultProceedStatusId | |
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
|||
| proceedConfig | |
100.00% |
1 / 1 |
1 | |
100.00% |
4 / 4 |
|||
| revertConfig | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| checkProceedRules | |
100.00% |
1 / 1 |
3 | |
100.00% |
1 / 1 |
|||
| checkRevertRules | |
100.00% |
1 / 1 |
3 | |
100.00% |
1 / 1 |
|||
| afterProceed | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
| notifyInProgress | |
100.00% |
1 / 1 |
2 | |
100.00% |
5 / 5 |
|||
| afterRevert | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
| notifyRejectedReview | |
0.00% |
0 / 1 |
3.07 | |
80.00% |
4 / 5 |
|||
| <?php | |
| namespace humhub\modules\tasks\models\state; | |
| use humhub\modules\tasks\activities\TaskStartActivity; | |
| use humhub\modules\tasks\models\Task; | |
| use humhub\modules\tasks\notifications\InProgressNotification; | |
| use humhub\modules\tasks\notifications\ReviewRejectedNotification; | |
| use Yii; | |
| class InProgressState extends TaskState | |
| { | |
| public static $status = Task::STATUS_IN_PROGRESS; | |
| public static $defaultRevertStatus = Task::STATUS_PENDING; | |
| protected function getDefaultProceedStatusId() | |
| { | |
| return $this->task->review ? Task::STATUS_PENDING_REVIEW : Task::STATUS_COMPLETED; | |
| } | |
| protected function proceedConfig($user = null) | |
| { | |
| return [ | |
| Task::STATUS_PENDING_REVIEW => [ | |
| 'label' => Yii::t('TasksModule.base', 'Ready For Review'), | |
| 'icon' => 'fa-eye' | |
| ], | |
| Task::STATUS_COMPLETED => [ | |
| 'label' => Yii::t('TasksModule.base', 'Finish Task'), | |
| 'icon' => 'fa-check-square-o' | |
| ], | |
| ]; | |
| } | |
| protected function revertConfig($user = null) | |
| { | |
| return [ | |
| Task::STATUS_PENDING => ['label' => Yii::t('TasksModule.base', 'Reset Task'), 'icon' => 'fa-undo'] | |
| ]; | |
| } | |
| public function checkProceedRules($newStatus = null, $user = null) | |
| { | |
| return $this->task->isTaskResponsible($user) || $this->task->isTaskAssigned($user) || $this->task->canProcess($user); | |
| } | |
| public function checkRevertRules($newStatus = null, $user = null) | |
| { | |
| return $this->task->isTaskResponsible($user) || $this->task->isTaskAssigned($user) || $this->task->canProcess($user); | |
| } | |
| public function afterProceed(TaskState $oldState) | |
| { | |
| $this->notifyInProgress(); | |
| } | |
| public function notifyInProgress() | |
| { | |
| $user = Yii::$app->user->getIdentity(); | |
| if ($this->task->hasTaskResponsible()) { | |
| InProgressNotification::instance()->from($user)->about($this->task)->sendBulk($this->task->taskResponsibleUsers); | |
| } | |
| TaskStartActivity::instance()->from($user)->about($this->task)->create(); | |
| } | |
| public function afterRevert(TaskState $oldState) | |
| { | |
| $this->notifyRejectedReview(); | |
| } | |
| public function notifyRejectedReview() | |
| { | |
| if ($this->task->review && $this->task->hasTaskAssigned()) { | |
| $this->task->deleteOldNotifications(ReviewRejectedNotification::class); | |
| ReviewRejectedNotification::instance()->from(Yii::$app->user->getIdentity())->about($this->task)->sendBulk($this->task->filterResponsibleAssigned()); | |
| } else { | |
| $this->notifyInProgress(); | |
| } | |
| } | |
| } |