Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 28 |
CheckForm | |
0.00% |
0 / 1 |
|
0.00% |
0 / 4 |
90 | |
0.00% |
0 / 28 |
init | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 6 |
|||
rules | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 6 |
|||
validateCanCheck | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 5 |
|||
save | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 11 |
<?php | |
namespace humhub\modules\tasks\models\checklist; | |
use humhub\modules\tasks\models\Task; | |
use yii\base\Model; | |
use yii\web\HttpException; | |
class CheckForm extends Model | |
{ | |
public $checked; | |
public $taskId; | |
public $itemId; | |
/** | |
* @var TaskItem | |
*/ | |
public $item; | |
/** | |
* @var Task | |
*/ | |
private $task; | |
public $statusChanged; | |
public function init() | |
{ | |
$this->item = TaskItem::findOne(['id' => $this->itemId, 'task_id' => $this->taskId]); | |
if($this->item) { | |
$this->task = $this->item->task; | |
} | |
} | |
public function rules() | |
{ | |
return [ | |
[['checked'], 'boolean'], | |
[['item'], 'validateCanCheck'], | |
]; | |
} | |
public function validateCanCheck($attribute, $params) | |
{ | |
if(!$this->item || !$this->item->task->canCheckItems()) { | |
throw new HttpException(403); | |
} | |
} | |
public function save() | |
{ | |
if(!$this->validate()) { | |
return false; | |
} | |
$this->item->updateAttributes(['completed' => $this->checked]); | |
if($this->task->isPending()) { | |
$this->task->state->proceed(Task::STATUS_IN_PROGRESS); | |
$this->statusChanged = true; | |
} | |
return true; | |
} | |
} |