Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
16 / 16 |
| PendingReviewState | |
100.00% |
1 / 1 |
|
100.00% |
7 / 7 |
9 | |
100.00% |
16 / 16 |
| proceedConfig | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
| revertConfig | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
| checkProceedRules | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| checkRevertRules | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| afterRevert | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
| afterProceed | |
100.00% |
1 / 1 |
1 | |
100.00% |
4 / 4 |
|||
| notifyPendingReview | |
100.00% |
1 / 1 |
3 | |
100.00% |
4 / 4 |
|||
| <?php | |
| namespace humhub\modules\tasks\models\state; | |
| use humhub\modules\tasks\models\Task; | |
| use humhub\modules\tasks\notifications\PendingReviewNotification; | |
| use Yii; | |
| class PendingReviewState extends TaskState | |
| { | |
| public static $status = Task::STATUS_PENDING_REVIEW; | |
| public static $defaultProceedStatus = Task::STATUS_COMPLETED; | |
| public static $defaultRevertStatus = Task::STATUS_IN_PROGRESS; | |
| protected function proceedConfig($user = null) | |
| { | |
| return [ | |
| Task::STATUS_COMPLETED => [ | |
| 'label' => Yii::t('TasksModule.base', 'Accept Task'), | |
| 'icon' => 'fa-check-square-o' | |
| ] | |
| ]; | |
| } | |
| protected function revertConfig($user = null) | |
| { | |
| return [ | |
| Task::STATUS_IN_PROGRESS => [ | |
| 'label' => Yii::t('TasksModule.base', 'Reject Task'), | |
| 'icon' => 'fa-times-circle-o' | |
| ] | |
| ]; | |
| } | |
| public function checkProceedRules($newStatus = null, $user = null) | |
| { | |
| return $this->task->isTaskResponsible($user); | |
| } | |
| public function checkRevertRules($newStatus = null, $user = null) | |
| { | |
| return $this->task->isTaskResponsible($user); | |
| } | |
| public function afterRevert(TaskState $oldState) | |
| { | |
| $this->notifyPendingReview(); | |
| } | |
| public function afterProceed(TaskState $oldState) | |
| { | |
| $this->notifyPendingReview(); | |
| $this->task->checklist->checkAll(); | |
| $this->task->updateAttributes(['request_sent' => 0]); | |
| } | |
| /** | |
| * Notify users about status change | |
| * @throws \yii\base\InvalidConfigException | |
| */ | |
| public function notifyPendingReview() | |
| { | |
| if ($this->task->review && $this->task->hasTaskResponsible()) { | |
| // remove old notifications | |
| $this->task->deleteOldNotifications(PendingReviewNotification::class); | |
| PendingReviewNotification::instance()->from(Yii::$app->user->getIdentity())->about($this->task)->sendBulk($this->task->taskResponsibleUsers); | |
| } | |
| } | |
| } |