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\Jobs\Catalog; |
13
|
|
|
|
14
|
|
|
use LaravelMeetups\Contracts\Jobs\Search as Contract; |
15
|
|
|
use LaravelMeetups\Http\Client\Catalog\Strategy; |
16
|
|
|
use LaravelMeetups\Http\Client\Query; |
17
|
|
|
use LaravelMeetups\Http\Client\Transporter; |
18
|
|
|
use LaravelMeetups\Jobs\AbstractSearch; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class Search. |
22
|
|
|
*/ |
23
|
|
|
class Search extends AbstractSearch implements Contract |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
|
|
public function execute() |
29
|
|
|
{ |
30
|
|
|
if ($maxRadius = $this->input->getArgument('max_radius')) { |
31
|
|
|
$this->config->setMaxRadius($maxRadius); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
return array_map(function ($event) { |
35
|
|
|
$dom = $this->dom->load($event->innerHtml); |
36
|
|
|
|
37
|
|
|
return new Bag(clone $dom, array_map(function ($elem) use ($dom) { |
38
|
|
|
return (new $elem())->find($dom); |
39
|
|
|
}, $this->config->getCatalogProviders())); |
40
|
|
|
}, $this->getRows()); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Returns the catalog in rows. |
45
|
|
|
* |
46
|
|
|
* @return array |
47
|
|
|
*/ |
48
|
|
|
private function getRows() |
49
|
|
|
{ |
50
|
|
|
$radius = $this->config->getRadiusInterval(); |
51
|
|
|
$rows = []; |
52
|
|
|
|
53
|
|
|
while ($radius < $this->config->getMaxRadius()) { |
54
|
|
|
$this->config->setRadius($radius); |
55
|
|
|
$body = (new Transporter())->execute(new Query(new Strategy($this->config))); |
56
|
|
|
$rows = $this->dom->load($body)->getElementsByClass('event-listing-container-li') ?: []; |
57
|
|
|
$radius += $this->config->getRadiusInterval(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return is_array($rows) ? $rows : $rows->toArray(); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|