Job.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\App\Models;
  3. /**
  4. * Class Job
  5. * @package ModulesGarden\ProxmoxAddon\App\Models
  6. * @method static $this waiting()
  7. * @method static $this finished()
  8. * @method $this ofJob($job)
  9. * @method $this ofHostingId($hostingId)
  10. * @method static $this ofParentId($parentId)
  11. * @method static $this ofId($parentId)
  12. * @method $this ofJobs($jobs)
  13. * @method $this ofCustomId($id)
  14. */
  15. class Job extends \ModulesGarden\ProxmoxAddon\Core\Queue\Models\Job
  16. {
  17. public function scopeOfJob($query, $job)
  18. {
  19. return $query->where("job", $job . '@handle');
  20. }
  21. public function scopeOfJobs($query, $jobs)
  22. {
  23. foreach ($jobs as &$job)
  24. {
  25. $job .= '@handle';
  26. }
  27. return $query->whereIn("job", $jobs);
  28. }
  29. public function scopeOfHostingId($query, $hostingId)
  30. {
  31. return $query->where("rel_id", $hostingId)
  32. ->where("rel_type", "hosting");
  33. }
  34. public function scopeOfCustomId($query, $id)
  35. {
  36. return $query->where("custom_id", $id);
  37. }
  38. public function scopeWaiting($query)
  39. {
  40. return $query->whereIn("status", ['waiting', "running", ""]);
  41. }
  42. public function scopeFinished($query)
  43. {
  44. return $query->where("status", "finished");
  45. }
  46. public function scopeOfParentId($query, $parentId)
  47. {
  48. return $query->where("parent_id", $parentId);
  49. }
  50. public function scopeOfId($query, $id)
  51. {
  52. return $query->where("id", $id);
  53. }
  54. }