CheckPointTypeModel.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace app\models;
  3. use Yii;
  4. use yii\base\Model;
  5. use app\models\entity\ProjectsLocotech;
  6. use app\models\entity\CheckpointTypesForTasks;
  7. use app\models\entity\CheckpointTypeHierarchy;
  8. use app\models\entity\Tasks;
  9. use app\models\entity\Tasktypes;
  10. use app\models\entity\CheckpointTypes;
  11. class CheckPointTypeModel extends Model
  12. {
  13. public $id;
  14. public $priority;
  15. public $name;
  16. public $parentTaskTypeId;
  17. public $parentCheckpointTypeId;
  18. public $childrenCheckpointTypes;
  19. public $class;
  20. // работает
  21. public function getCheckPointTypesByTask($task_type = null)
  22. {
  23. $checkpointTypes = array(); //массив значений чекпойнтов
  24. if ($task_type != null){
  25. $resultTasks = CheckpointTypesForTasks::find()->where(['tasktype_id' => $task_type ])->all();
  26. } else {
  27. $resultTasks = CheckpointTypesForTasks::find()->all();
  28. }
  29. return $resultTasks;
  30. }
  31. // работает
  32. public function createFromID($id)
  33. {
  34. $checkpointTypesEntity = CheckpointTypes::findOne($id);
  35. if ( $checkpointTypesEntity ) {
  36. $cpType = self::CreateFromArray($checkpointTypesEntity);
  37. return $cpType;
  38. }
  39. return null;
  40. }
  41. // работает
  42. public static function CreateFromArray($checkpointArr)
  43. {
  44. $checkpointType = new CheckPointTypeModel();
  45. $checkpointType->id = $checkpointArr->id;
  46. $checkpointType->name = $checkpointArr->name;
  47. $checkpointType->class = $checkpointArr->class;
  48. $checkpointType->childrenCheckpointTypes = array();
  49. $checkpointType->FillChildren();
  50. return $checkpointType;
  51. }
  52. // работает
  53. function FillChildren()
  54. {
  55. $checkpointTypeHierarchy = CheckpointTypeHierarchy::find()->where(['parent_cp_type' => $this->id] );
  56. foreach ($checkpointTypeHierarchy as $hierarchy) {
  57. $checkpointTypes = CheckPointTypes::find()->where(['id' => $child->cp_type])->all();
  58. foreach ($checkpointTypes as $type) {
  59. $child = self::CreateFromArray($checkarr);
  60. array_push($this->childrenCheckpointTypes, $child);
  61. }
  62. }
  63. }
  64. }