AsusgAddMeasurementToTaskModel.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace app\models\procedure;
  3. use Yii;
  4. use yii\base\Model;
  5. //use app\models\entity\Accounts;
  6. //use app\models\entity\Projecttypes;
  7. //use app\models\entity\ProjectsLocotech;
  8. use app\models\entity\Tasks;
  9. use app\models\entity\Checkpoints;
  10. /*
  11. measurement_add: BEGIN
  12. declare tmp integer;
  13. select id into tmp
  14. from tasks t
  15. where id = task_id;
  16. if tmp is null then leave measurement_add; end if;
  17. #Добавляем чекпойнт для ручного замера.
  18. insert into checkpoints
  19. (type, text, parent_task_id, parent_checkpoint_id, is_set, measurement_field, measurement_id)
  20. values
  21. (819, measure_text, task_id, 0, 0, 'measurement_value', measure_id);
  22. END
  23. */
  24. class AsusgAddMeasurementToTaskModel extends Model
  25. {
  26. private $measure_text;
  27. private $measure_id;
  28. private $task_id;
  29. private $initiator;
  30. private $extra;
  31. private $typesCheckpointsArray;
  32. private $typesCheckpoint;
  33. public function execute($task_id, $measure_id, $measure_text, $extra = false )
  34. {
  35. //$this->initiator = $initiator;
  36. $this->task_id = $task_id;
  37. $this->measure_id = $measure_id;
  38. $this->measure_text = $measure_text;
  39. $this->extra = $extra;
  40. $this->typesCheckpointsArray = [293,294]; // это типы чекпоинтов ( да, нет )
  41. $this->typesCheckpoint = 819;
  42. #Проверка на существование таска.
  43. if( !$this->isTask() ) {
  44. return false;
  45. }
  46. if ( !$extra ) {
  47. #Добавляем чекпойнт для ручного замера.
  48. if( !$this->addCheckpoint() ) {
  49. return false;
  50. }
  51. } else {
  52. foreach ( $this->typesCheckpointsArray as $type) {
  53. $this->typesCheckpoint = $type;
  54. $this->addCheckpoint();
  55. }
  56. }
  57. }
  58. #Проверка на существование таска.
  59. private function isTask()
  60. {
  61. $result = false;
  62. $tasksEntity = Tasks::findOne($this->task_id);
  63. if( null !== $tasksEntity) {
  64. $result = true;
  65. }
  66. return $result;
  67. }
  68. #Добавляем чекпойнт для ручного замера.
  69. private function addCheckpoint()
  70. {
  71. $checkpointsEntity = new Checkpoints();
  72. $checkpointsEntity->type = $this->typesCheckpoint;
  73. $checkpointsEntity->text = $this->measure_text;
  74. $checkpointsEntity->parent_task_id = $this->task_id;
  75. $checkpointsEntity->parent_checkpoint_id = 0;
  76. $checkpointsEntity->is_set = 0;
  77. $checkpointsEntity->measurement_field = 'measurement_value';
  78. $checkpointsEntity->measurement_id = $this->measure_id;
  79. $checkpointsEntity->save();
  80. return true;
  81. }
  82. }