|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of Laravel Meetups. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Nuno Maduro <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace LaravelMeetups\Interactions; |
|
13
|
|
|
|
|
14
|
|
|
use LaravelMeetups\Contracts\Config; |
|
15
|
|
|
use LaravelMeetups\Contracts\Interactions\Catalog as Contract; |
|
16
|
|
|
use LaravelMeetups\Jobs; |
|
17
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
18
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
19
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Class Catalog. |
|
23
|
|
|
*/ |
|
24
|
|
|
class Catalog implements Contract |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* Holds a instance of config. |
|
28
|
|
|
* |
|
29
|
|
|
* @var Config |
|
30
|
|
|
*/ |
|
31
|
|
|
private $config; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Holds a instance of InputInterface. |
|
35
|
|
|
* |
|
36
|
|
|
* @var InputInterface |
|
37
|
|
|
*/ |
|
38
|
|
|
private $input; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Holds a instance of OutputInterface. |
|
42
|
|
|
* |
|
43
|
|
|
* @var OutputInterface |
|
44
|
|
|
*/ |
|
45
|
|
|
private $output; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Holds an array of instances of Bag. |
|
49
|
|
|
* |
|
50
|
|
|
* @var array |
|
51
|
|
|
*/ |
|
52
|
|
|
private $bags; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @var Jobs\Catalog\Writer |
|
56
|
|
|
*/ |
|
57
|
|
|
private $catalogWriter; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* {@inheritdoc} |
|
61
|
|
|
*/ |
|
62
|
|
|
public function __construct(Config $config, InputInterface $input, OutputInterface $output) |
|
63
|
|
|
{ |
|
64
|
|
|
$this->config = $config; |
|
65
|
|
|
$this->input = $input; |
|
66
|
|
|
$this->output = $output; |
|
67
|
|
|
$this->bags = (new Jobs\Catalog\Search($config, $input))->execute(); |
|
68
|
|
|
|
|
69
|
|
|
$rows = array_map(function ($bag) { |
|
70
|
|
|
return $bag->getRows(); |
|
71
|
|
|
}, $this->bags); |
|
72
|
|
|
|
|
73
|
|
|
$this->catalogWriter = (new Jobs\Catalog\Writer($config, new SymfonyStyle($input, $output)))->setRows($rows); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Checks if the catalog is empty. |
|
78
|
|
|
* |
|
79
|
|
|
* @return bool |
|
80
|
|
|
*/ |
|
81
|
|
|
public function isEmpty() |
|
82
|
|
|
{ |
|
83
|
|
|
return empty($this->catalogWriter->getRows()); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* {@inheritdoc} |
|
88
|
|
|
*/ |
|
89
|
|
|
public function displayTable() |
|
90
|
|
|
{ |
|
91
|
|
|
$this->catalogWriter->write(); |
|
92
|
|
|
|
|
93
|
|
|
return $this; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* {@inheritdoc} |
|
98
|
|
|
*/ |
|
99
|
|
|
public function displayDetail($rowKey) |
|
100
|
|
|
{ |
|
101
|
|
|
if (isset($this->bags[$rowKey - 1])) { |
|
102
|
|
|
$rows = (new Jobs\Detail\Search($this->config, $this->input, $this->bags[$rowKey - 1] |
|
103
|
|
|
->getDom())) |
|
104
|
|
|
->execute(); |
|
105
|
|
|
(new Jobs\Detail\Writer($this->config, new SymfonyStyle($this->input, $this->output))) |
|
106
|
|
|
->setRows($rows) |
|
107
|
|
|
->write(); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
return $this; |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|