CheckPointType.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. namespace CheckPointTypes;
  3. class CheckPointType
  4. {
  5. public $id;
  6. public $priority;
  7. public $name;
  8. public $parentTaskTypeId;
  9. public $parentCheckpointTypeId;
  10. public $childrenCheckpointTypes;
  11. public $class;
  12. private $write_to_twx;
  13. function __construct(){}
  14. public function setWriteToTWX(int $val)
  15. {
  16. global $link;
  17. $this->write_to_twx = $val;
  18. mysqli_query($link, "update checkpoint_types set write_to_twx=$val where id=$this->id");
  19. }
  20. public function getWriteToTWX()
  21. {
  22. return $this->write_to_twx;
  23. }
  24. public static function CreateFromArray($checkpointArr)
  25. {
  26. $checkpointType = new CheckPointType();
  27. $checkpointType->id = $checkpointArr['id'];
  28. $checkpointType->name = $checkpointArr['name'];
  29. $checkpointType->class = $checkpointArr['class'];
  30. $checkpointType->write_to_twx = $checkpointArr['write_to_twx'];
  31. $checkpointType->childrenCheckpointTypes = array();
  32. $checkpointType->FillChildren();
  33. return $checkpointType;
  34. }
  35. public static function CreateFromScratch($class, $name, $parentTaskTypeId = null, $write_to_twx = 0)
  36. {
  37. global $link;
  38. $checkpointType = new CheckPointType();
  39. $checkpointType->name = $name;
  40. $checkpointType->class = $class;
  41. $checkpointType->childrenCheckpointTypes = array();
  42. mysqli_query($link, "insert into checkpoint_types (class, name, write_to_twx) values ('$class', '$name', $write_to_twx)");
  43. $checkpointType->id = mysqli_insert_id($link);
  44. if ($parentTaskTypeId != null) {
  45. mysqli_query($link, "insert into checkpoint_type_hierarchy (parent_cp_type, cp_type) values ($parentTaskTypeId, $checkpointType->id)");
  46. //mysqli_query($link, "update checkpoint_type_hierarchy set parent_cp_type=$parentTaskTypeId, cp_type=$checkpointType->id");
  47. }
  48. return $checkpointType;
  49. }
  50. static function AddChildToDB($id, $parentTaskTypeId)
  51. {
  52. global $link;
  53. mysqli_query($link, "insert into checkpoint_type_hierarchy (parent_cp_type, cp_type) values ($parentTaskTypeId, $id)");
  54. }
  55. function RemoveChildFromDB($id)
  56. {
  57. global $link;
  58. mysqli_query($link, "delete from checkpoint_type_hierarchy where parent_cp_type=$this->id and cp_type=$id");
  59. }
  60. public static function CreateFromID($id)
  61. {
  62. global $link;
  63. $query = mysqli_query($link, "select * from checkpoint_types where id=$id");
  64. if ($checkpoint_arr = mysqli_fetch_array($query))
  65. {
  66. $cpType = CheckPointType::CreateFromArray($checkpoint_arr);
  67. return $cpType;
  68. }
  69. return null;
  70. }
  71. public static function GetCheckPointTypes($class = null)
  72. {
  73. global $link;
  74. $checkpointTypes = array(); //массив значений чекпойнтов
  75. $add = '';
  76. if ($class != null)
  77. $add = "where class='$class'";
  78. $query = mysqli_query($link, "select * from checkpoint_types $add ORDER BY name");
  79. while ($checkpoint_arr = mysqli_fetch_array($query))
  80. {
  81. $cpType = CheckPointType::CreateFromArray($checkpoint_arr);
  82. array_push($checkpointTypes, $cpType);
  83. }
  84. return $checkpointTypes;
  85. }
  86. public static function GetCheckPointTypesByTask($task_type = null)
  87. {
  88. global $link;
  89. $checkpointTypes = array(); //массив значений чекпойнтов
  90. $add = '';
  91. if ($task_type != null)
  92. $add = "where tasktype_id=$task_type";
  93. $query = mysqli_query($link, "select * from checkpoint_types_for_tasks $add");
  94. while ($checkpoint_arr = mysqli_fetch_array($query))
  95. {
  96. array_push($checkpointTypes, $checkpoint_arr);
  97. }
  98. return $checkpointTypes;
  99. }
  100. public static function CheckPointTemplate($parent_checkpoint_type)
  101. {
  102. global $link;
  103. $checkpointTypes = array(); //массив значений чекпойнтов
  104. $query = mysqli_query($link, "select * from checkpoint_hierarchy where parent_cp_type=$parent_checkpoint_type");
  105. while ($checkpoint_arr = mysqli_fetch_array($query))
  106. {
  107. array_push($checkpointTypes, $checkpoint_arr);
  108. }
  109. return $checkpointTypes;
  110. }
  111. public static function Delete($id)
  112. {
  113. $cpt = self::CreateFromID($id);
  114. foreach ($cpt->childrenCheckpointTypes as $child)
  115. {
  116. $cpt->RemoveChildFromDB($child->id);
  117. }
  118. $cpt->DeleteFromDB();
  119. }
  120. function DeleteFromDB()
  121. {
  122. global $link;
  123. mysqli_query($link, "delete from checkpoint_types where id=$this->id");
  124. mysqli_query($link, "delete from checkpoint_types_for_tasks where cp_type_id=$this->id");
  125. }
  126. function GetChildrenIDs()
  127. {
  128. global $link;
  129. $children_ids = array();
  130. $query = mysqli_query($link, "select * from checkpoint_type_hierarchy where parent_cp_type=".$this->id);
  131. while ($checkarr = mysqli_fetch_array($query))
  132. {
  133. array_push($children_ids, $checkarr);
  134. }
  135. return $children_ids;
  136. }
  137. function FillChildren()
  138. {
  139. global $link;
  140. $children_ids = array();
  141. $query = mysqli_query($link, "select * from checkpoint_type_hierarchy where parent_cp_type=".$this->id);
  142. while ($checkarr = mysqli_fetch_array($query))
  143. {
  144. array_push($children_ids, $checkarr);
  145. }
  146. foreach ($children_ids as $child)
  147. {
  148. $query = mysqli_query($link, "select * from checkpoint_types where id=".$child['cp_type']);
  149. while ($checkarr = mysqli_fetch_array($query))
  150. {
  151. $child = CheckPointType::CreateFromArray($checkarr);
  152. array_push($this->childrenCheckpointTypes, $child);
  153. }
  154. }
  155. }
  156. }