123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- namespace app\models\procedure;
- use Yii;
- use yii\base\Model;
- use app\models\entity\Tasks;
- use app\models\entity\Checkpoints;
- class AsusgAddMeasurementToTaskModel extends Model
- {
- private $measure_text;
- private $measure_id;
- private $task_id;
- private $initiator;
- private $extra;
- private $typesCheckpointsArray;
- private $typesCheckpoint;
- public function execute($task_id, $measure_id, $measure_text, $extra = false )
- {
-
- $this->task_id = $task_id;
- $this->measure_id = $measure_id;
- $this->measure_text = $measure_text;
- $this->extra = $extra;
- $this->typesCheckpointsArray = [293,294];
- $this->typesCheckpoint = 819;
-
-
- if( !$this->isTask() ) {
- return false;
- }
-
- if ( !$extra ) {
-
- if( !$this->addCheckpoint() ) {
- return false;
- }
- } else {
- foreach ( $this->typesCheckpointsArray as $type) {
- $this->typesCheckpoint = $type;
- $this->addCheckpoint();
- }
- }
-
- }
-
-
- private function isTask()
- {
- $result = false;
- $tasksEntity = Tasks::findOne($this->task_id);
-
- if( null !== $tasksEntity) {
- $result = true;
- }
- return $result;
- }
-
-
-
- private function addCheckpoint()
- {
-
- $checkpointsEntity = new Checkpoints();
- $checkpointsEntity->type = $this->typesCheckpoint;
- $checkpointsEntity->text = $this->measure_text;
- $checkpointsEntity->parent_task_id = $this->task_id;
- $checkpointsEntity->parent_checkpoint_id = 0;
- $checkpointsEntity->is_set = 0;
- $checkpointsEntity->measurement_field = 'measurement_value';
- $checkpointsEntity->measurement_id = $this->measure_id;
- $checkpointsEntity->save();
- return true;
- }
- }
|