1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sportic\Timing\RaceTecClient\Scrapers; |
4
|
|
|
|
5
|
|
|
use Sportic\Timing\RaceTecClient\Parsers\EventPage as Parser; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class CompanyPage |
9
|
|
|
* @package Sportic\Timing\RaceTecClient\Scrapers |
10
|
|
|
* |
11
|
|
|
* @method Parser execute() |
12
|
|
|
*/ |
13
|
|
|
class EventPage extends AbstractScraper |
14
|
|
|
{ |
15
|
|
|
protected $cId; |
16
|
|
|
protected $rId; |
17
|
|
|
protected $eId = 1; |
18
|
|
|
protected $page = 1; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* EventPage constructor. |
22
|
|
|
* |
23
|
|
|
* @param $cId |
24
|
|
|
* @param $rId |
25
|
|
|
* @param int $eId |
26
|
|
|
* @param int $page |
27
|
|
|
*/ |
28
|
2 |
|
public function __construct(int $cId, int $rId, int $eId = 1, int $page = 1) |
29
|
|
|
{ |
30
|
2 |
|
$this->cId = $cId; |
31
|
2 |
|
$this->rId = $rId; |
32
|
2 |
|
$this->eId = $eId; |
33
|
2 |
|
$this->page = $page; |
34
|
2 |
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return mixed |
39
|
|
|
*/ |
40
|
2 |
|
public function getCId() |
41
|
|
|
{ |
42
|
2 |
|
return $this->cId; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param mixed $cId |
47
|
|
|
*/ |
48
|
|
|
public function setCId($cId) |
49
|
|
|
{ |
50
|
|
|
$this->cId = $cId; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return mixed |
55
|
|
|
*/ |
56
|
2 |
|
public function getRId() |
57
|
|
|
{ |
58
|
2 |
|
return $this->rId; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param mixed $rId |
63
|
|
|
*/ |
64
|
|
|
public function setRId($rId) |
65
|
|
|
{ |
66
|
|
|
$this->rId = $rId; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return int |
71
|
|
|
*/ |
72
|
2 |
|
public function getEId(): int |
73
|
|
|
{ |
74
|
2 |
|
return $this->eId; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param int $eId |
79
|
|
|
*/ |
80
|
|
|
public function setEId(int $eId) |
81
|
|
|
{ |
82
|
|
|
$this->eId = $eId; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return int |
87
|
|
|
*/ |
88
|
2 |
|
public function getPage(): int |
89
|
|
|
{ |
90
|
2 |
|
return $this->page; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param int $page |
95
|
|
|
*/ |
96
|
|
|
public function setPage(int $page) |
97
|
|
|
{ |
98
|
|
|
$this->page = $page; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @inheritdoc |
103
|
|
|
*/ |
104
|
2 |
|
protected function generateCrawler() |
105
|
|
|
{ |
106
|
2 |
|
$client = $this->getClient(); |
107
|
2 |
|
$crawler = $client->request( |
108
|
2 |
|
'GET', |
109
|
2 |
|
$this->getCrawlerUri() |
110
|
|
|
); |
111
|
|
|
|
112
|
2 |
|
$cPage = $this->getPage(); |
113
|
2 |
|
if ($cPage > 1) { |
114
|
|
|
$link = $crawler->filter('#ctl00_Content_Main_grdTopPager')->selectLink($this->getPage())->first()->getNode(0); |
115
|
|
|
$href = $link->getAttribute('href'); |
116
|
|
|
$eventTarget = str_replace(["javascript:__doPostBack('", "','')"], '', $href); |
117
|
|
|
|
118
|
|
|
$crawler->filter('#__EVENTTARGET')->getNode(0)->setAttribute('value', $eventTarget); |
119
|
|
|
|
120
|
|
|
$form = $crawler->filter('#aspnetForm')->form(); |
121
|
|
|
$crawler = $client->submit($form); |
122
|
|
|
} |
123
|
|
|
|
124
|
2 |
|
return $crawler; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @return string |
129
|
|
|
*/ |
130
|
2 |
|
public function getCrawlerUri() |
131
|
|
|
{ |
132
|
2 |
|
return $this->getCrawlerUriHost().'/Results.aspx?' |
133
|
2 |
|
. 'CId=' . $this->getCId() |
134
|
2 |
|
. '&RId=' . $this->getRId() |
135
|
2 |
|
. '&EId=' . $this->getEId(); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|