ProjectsLocotech.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. namespace app\models\entity;
  3. /**
  4. * This is the model class for table "projects_locotech".
  5. *
  6. * @property int $id
  7. * @property int $action
  8. * @property int $company
  9. * @property int $status
  10. * @property string $loco_type
  11. * @property int $loco_number
  12. * @property string $depo
  13. * @property string $depo_service
  14. * @property string $created
  15. * @property string $tasks
  16. * @property int $projecttypes_id [smallint(11)] внешний ключ к таблице projecttypes
  17. * @property int $type [smallint(5) unsigned]
  18. * @property bool $urgent [tinyint(3) unsigned]
  19. * @property int $object_id [int(10)]
  20. * @property string $uuid [varchar(255)]
  21. * @property int $kind [int(10)]
  22. * @property int $section_id [int(10) unsigned]
  23. * @property string $result_id [char(40)]
  24. * @property string $finished_time [datetime] Время завершения проекта
  25. * @property int $finished_person [int(11)] ID пользователя закрывшего проект
  26. *
  27. * @property Sections[] $sections
  28. */
  29. class ProjectsLocotech extends \yii\db\ActiveRecord
  30. {
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public static function tableName()
  35. {
  36. return 'projects_locotech';
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function rules()
  42. {
  43. return [
  44. [['action', 'company', 'status', 'loco_number'], 'integer'],
  45. [['created'], 'safe'],
  46. [['loco_type', 'depo', 'depo_service'], 'string', 'max' => 255],
  47. ];
  48. }
  49. /**
  50. * {@inheritdoc}
  51. */
  52. public function attributeLabels()
  53. {
  54. return [
  55. 'id' => 'ID',
  56. 'action' => 'Action',
  57. 'company' => 'Company',
  58. 'status' => 'Status',
  59. 'loco_type' => 'Loco Type',
  60. 'loco_number' => 'Loco Number',
  61. 'depo' => 'Depo',
  62. 'depo_service' => 'Depo Service',
  63. 'created' => 'Created',
  64. 'tasks' => 'Tasks',
  65. 'actions_id' => 'Actions ID',
  66. ];
  67. }
  68. public function getTask()
  69. {
  70. return $this->hasMany(Tasks::class, ['input_id' => 'id']);
  71. }
  72. public function getProjecttypes()
  73. {
  74. return $this->hasOne(Projecttypes::class, ['id' => 'action']);
  75. }
  76. public function getSections()
  77. {
  78. return $this->hasOne(Sections::class, ['id' => 'section_id']);
  79. }
  80. /**
  81. * Возвращает время первой принятой задачи проекта
  82. *
  83. * @return string|null
  84. */
  85. public function getAcceptedTime()
  86. {
  87. $task = Tasks::find()
  88. ->select('min(accepted_time) as accepted_time')
  89. ->where(['input_id' => $this->id])
  90. ->one()
  91. ;
  92. return $task->accepted_time;
  93. }
  94. /**
  95. * Возвращает время завершения проекта
  96. *
  97. * @return string|null
  98. */
  99. public function getFinishedTime()
  100. {
  101. if ($this->finished_time) return $this->finished_time;
  102. if ($this->status == 5) {
  103. $task = Tasks::find()
  104. ->select('max(finished_time) as finished_time')
  105. ->where(['input_id' => $this->id])
  106. ->one()
  107. ;
  108. return $task->finished_time;
  109. }
  110. return null;
  111. }
  112. }