1 | <?php |
||
7 | abstract class PriorityJobManager extends AbstractJobManager |
||
8 | { |
||
9 | const PRIORITY_ASC = 'asc'; |
||
10 | const PRIORITY_DESC = 'desc'; |
||
11 | |||
12 | protected $maxPriority; |
||
13 | protected $priorityDirection = self::PRIORITY_DESC; |
||
14 | |||
15 | /** |
||
16 | * @return mixed |
||
17 | */ |
||
18 | 11 | public function getMaxPriority() |
|
19 | { |
||
20 | 11 | return $this->maxPriority; |
|
21 | } |
||
22 | |||
23 | /** |
||
24 | * @param mixed $maxPriority |
||
25 | */ |
||
26 | 8 | public function setMaxPriority($maxPriority) |
|
27 | { |
||
28 | 8 | $this->maxPriority = $maxPriority; |
|
29 | 8 | } |
|
30 | |||
31 | /** |
||
32 | * @return mixed |
||
33 | */ |
||
34 | 8 | public function getPriorityDirection() |
|
35 | { |
||
36 | 8 | return $this->priorityDirection; |
|
37 | } |
||
38 | |||
39 | /** |
||
40 | * @param mixed $priorityDirection |
||
41 | */ |
||
42 | 9 | public function setPriorityDirection($priorityDirection) |
|
46 | |||
47 | 22 | protected function validatePriority($priority) |
|
64 | |||
65 | 22 | protected function calculatePriority($priority) |
|
66 | { |
||
67 | 22 | if (null === $priority) { |
|
68 | 21 | return $priority; |
|
69 | } |
||
70 | 3 | if (self::PRIORITY_DESC === $this->priorityDirection) { |
|
71 | 3 | $priority = $this->maxPriority - $priority; |
|
72 | 3 | } |
|
73 | |||
74 | 3 | return $priority; |
|
75 | } |
||
76 | |||
77 | protected function findHigherPriority($priority1, $priority2) |
||
92 | |||
93 | abstract protected function prioritySave(Job $job); |
||
94 | |||
95 | 22 | public function save(Job $job) |
|
104 | } |
||
105 |