Task.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace ThurData\Servers\KerioEmail\Core\Models\Tasks;
  3. use ThurData\Servers\KerioEmail\Core\Models\ExtendedEloquentModel;
  4. /**
  5. * Class Task
  6. * @property $status
  7. * @property job_id
  8. * @property $model
  9. * @property $namespace
  10. * @property $rel_id
  11. * @package ThurData\Servers\KerioEmail\Core\Models\Tasks
  12. */
  13. class Task extends ExtendedEloquentModel
  14. {
  15. const CANCELLED = 'cancelled';
  16. const FINISHED = 'finished';
  17. const STARTED = 'started';
  18. const PENDING = 'pending';
  19. /**
  20. * @var null
  21. */
  22. protected $model = null;
  23. /**
  24. * @return $this
  25. */
  26. public function finish()
  27. {
  28. $this->setStatus(self::FINISHED);
  29. return $this;
  30. }
  31. /**
  32. * @return $this
  33. */
  34. public function cancel()
  35. {
  36. $this->setStatus(self::CANCELLED);
  37. return $this;
  38. }
  39. /**
  40. * @return $this
  41. */
  42. public function pending()
  43. {
  44. $this->setStatus(self::PENDING);
  45. return $this;
  46. }
  47. /**
  48. * @return $this
  49. */
  50. public function start()
  51. {
  52. $this->setStatus(self::STARTED);
  53. return $this;
  54. }
  55. /**
  56. * @param $status
  57. * @return $this
  58. */
  59. public function setStatus($status)
  60. {
  61. $this->status = $status;
  62. $this->save();
  63. return $this;
  64. }
  65. /**
  66. * @param $id
  67. * @return $this
  68. */
  69. public function setJobId($id)
  70. {
  71. $this->job_id = $id;
  72. $this->save();
  73. return $this;
  74. }
  75. /**
  76. * @return mixed
  77. */
  78. public function model()
  79. {
  80. if(!$this->model)
  81. {
  82. $this->model = new $this->namespace($this->rel_id);
  83. }
  84. return $this->model;
  85. }
  86. }