1 | <?php |
||
17 | class ListCommand extends AbstractCommand |
||
18 | { |
||
19 | const DEFAULT_VALUE_JOB_NAME = 'all'; |
||
20 | |||
21 | /** |
||
22 | * Configures the current command. |
||
23 | */ |
||
24 | 3 | protected function configure() |
|
32 | |||
33 | /** |
||
34 | * @return int |
||
35 | * @throws \LogicException |
||
36 | */ |
||
37 | 3 | protected function process() |
|
38 | { |
||
39 | /** @var JobRepositoryInterface $_oJobRepositoryChronos */ |
||
40 | 3 | $_oJobRepositoryChronos = $this->getContainer()->get(JobRepositoryInterface::DIC_NAME_CHRONOS); |
|
41 | |||
42 | 3 | $_bOnlyFailed = (bool) $this->oInput->getOption('onlyFailed'); |
|
43 | 3 | $_bOnlyDisabled = (bool) $this->oInput->getOption('onlyDisabled'); |
|
44 | |||
45 | 3 | $_oTable = new Table($this->oOutput); |
|
46 | 3 | $_oTable->setHeaders(array( |
|
47 | 3 | 'Job', |
|
48 | 'Info' |
||
49 | 3 | )); |
|
50 | |||
51 | /** @var JobEntity $_oJobEntity */ |
||
52 | 3 | foreach ($_oJobRepositoryChronos->getJobs() as $_oJobEntity) |
|
53 | { |
||
54 | 3 | if ($this->hasJobToPrint($_oJobEntity, $_bOnlyFailed, $_bOnlyDisabled)) |
|
55 | 3 | { |
|
56 | 3 | $this->printJobTableRow($_oTable, $_oJobEntity); |
|
57 | 3 | } |
|
58 | 3 | } |
|
59 | |||
60 | 3 | $_oTable->render(); |
|
61 | |||
62 | 3 | return 0; |
|
63 | } |
||
64 | |||
65 | /** |
||
66 | * @param JobEntity $oJobEntity |
||
67 | * @param bool $bOnlyFailed |
||
68 | * @param bool $bOnlyDisabled |
||
69 | * @return bool |
||
70 | */ |
||
71 | 3 | private function hasJobToPrint(JobEntity $oJobEntity, $bOnlyFailed, $bOnlyDisabled) |
|
72 | { |
||
73 | 3 | $_bPrintAllJobs = (false === $bOnlyFailed && false === $bOnlyDisabled); |
|
74 | if ($_bPrintAllJobs) |
||
75 | 3 | { |
|
76 | 1 | return true; |
|
77 | } |
||
78 | |||
79 | 2 | $_bHasToPrint = false; |
|
80 | |||
81 | 2 | if (true === $bOnlyFailed && $oJobEntity->errorsSinceLastSuccess > 0) |
|
82 | 2 | { |
|
83 | 1 | $_bHasToPrint = true; |
|
84 | 1 | } |
|
85 | |||
86 | 2 | if (true === $bOnlyDisabled && true === $oJobEntity->disabled) |
|
87 | 2 | { |
|
88 | 1 | $_bHasToPrint = true; |
|
89 | 1 | } |
|
90 | |||
91 | 2 | return $_bHasToPrint; |
|
92 | } |
||
93 | |||
94 | /** |
||
95 | * @param Table $oTable |
||
96 | * @param JobEntity $oJobEntity |
||
97 | */ |
||
98 | 3 | private function printJobTableRow(Table $oTable, JobEntity $oJobEntity) |
|
112 | |||
113 | /** |
||
114 | * @param JobEntity $oJobEntity |
||
115 | * @return string |
||
116 | */ |
||
117 | 3 | private function getOutputLabel(JobEntity $oJobEntity) |
|
144 | |||
145 | /** |
||
146 | * @param JobEntity $oJobEntity |
||
147 | * @return string |
||
148 | */ |
||
149 | 3 | private function getOutputFormat(JobEntity $oJobEntity) |
|
164 | } |