|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MalScraper\Model\Top; |
|
4
|
|
|
|
|
5
|
|
|
use MalScraper\Helper\Helper; |
|
6
|
|
|
use MalScraper\Model\MainModel; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* TopPeopleModel class. |
|
10
|
|
|
*/ |
|
11
|
|
|
class TopPeopleModel extends MainModel |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* Page number. |
|
15
|
|
|
* |
|
16
|
|
|
* @var string |
|
17
|
|
|
*/ |
|
18
|
|
|
private $_page; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Default constructor. |
|
22
|
|
|
* |
|
23
|
|
|
* @param string|int $page |
|
24
|
|
|
* @param string $parserArea |
|
25
|
|
|
* |
|
26
|
|
|
* @return void |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct($page, $parserArea = '#content') |
|
29
|
|
|
{ |
|
30
|
|
|
$this->_page = 50 * ($page - 1); |
|
31
|
|
|
$this->_url = $this->_myAnimeListUrl.'/people.php?limit='.$this->_page; |
|
32
|
|
|
$this->_parserArea = $parserArea; |
|
33
|
|
|
|
|
34
|
|
|
parent::errorCheck($this); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Default call. |
|
39
|
|
|
* |
|
40
|
|
|
* @param string $method |
|
41
|
|
|
* @param array $arguments |
|
42
|
|
|
* |
|
43
|
|
|
* @return array|string|int |
|
44
|
|
|
*/ |
|
45
|
|
|
public function __call($method, $arguments) |
|
46
|
|
|
{ |
|
47
|
|
|
if ($this->_error) { |
|
48
|
|
|
return $this->_error; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
return call_user_func_array([$this, $method], $arguments); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Get rank. |
|
56
|
|
|
* |
|
57
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $each_char |
|
58
|
|
|
* |
|
59
|
|
|
* @return string |
|
60
|
|
|
*/ |
|
61
|
|
|
private function getRank($each_char) |
|
62
|
|
|
{ |
|
63
|
|
|
$rank = $each_char->find('td span', 0)->plaintext; |
|
64
|
|
|
|
|
65
|
|
|
return trim($rank); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Get id. |
|
70
|
|
|
* |
|
71
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $name_area |
|
72
|
|
|
* |
|
73
|
|
|
* @return string |
|
74
|
|
|
*/ |
|
75
|
|
|
private function getId($name_area) |
|
76
|
|
|
{ |
|
77
|
|
|
$id = $name_area->find('a', 0)->href; |
|
78
|
|
|
$id = explode('/', $id); |
|
79
|
|
|
|
|
80
|
|
|
return $id[4]; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Get name. |
|
85
|
|
|
* |
|
86
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $name_area |
|
87
|
|
|
* |
|
88
|
|
|
* @return string |
|
89
|
|
|
*/ |
|
90
|
|
|
private function getName($name_area) |
|
91
|
|
|
{ |
|
92
|
|
|
return $name_area->find('.information', 0)->find('a', 0)->plaintext; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Get japanese name. |
|
97
|
|
|
* |
|
98
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $name_area |
|
99
|
|
|
* |
|
100
|
|
|
* @return string |
|
101
|
|
|
*/ |
|
102
|
|
|
private function getJapaneseName($name_area) |
|
103
|
|
|
{ |
|
104
|
|
|
$name = $name_area->find('.information', 0)->find('span', 0); |
|
105
|
|
|
if ($name) { |
|
106
|
|
|
$name = $name->plaintext; |
|
107
|
|
|
return substr($name, 1, strlen($name)-3); |
|
108
|
|
|
} |
|
109
|
|
|
return ''; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Get image. |
|
114
|
|
|
* |
|
115
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $name_area |
|
116
|
|
|
* |
|
117
|
|
|
* @return string |
|
118
|
|
|
*/ |
|
119
|
|
|
private function getImage($name_area) |
|
120
|
|
|
{ |
|
121
|
|
|
$image = $name_area->find('img', 0)->getAttribute('data-src'); |
|
122
|
|
|
return Helper::imageUrlCleaner($image); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Get birthday. |
|
127
|
|
|
* |
|
128
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $each_char |
|
129
|
|
|
* |
|
130
|
|
|
* @return array |
|
131
|
|
|
*/ |
|
132
|
|
|
private function getBirthday($each_char) |
|
133
|
|
|
{ |
|
134
|
|
|
$day = $each_char->find('.birthday', 0)->plaintext; |
|
135
|
|
|
$day = preg_replace('/\s+/', ' ', $day); |
|
136
|
|
|
$day = trim($day); |
|
137
|
|
|
return $day == 'Unknown' ? '' : $day; |
|
|
|
|
|
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Get favorite. |
|
142
|
|
|
* |
|
143
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $each_char |
|
144
|
|
|
* |
|
145
|
|
|
* @return string |
|
146
|
|
|
*/ |
|
147
|
|
|
private function getFavorite($each_char) |
|
148
|
|
|
{ |
|
149
|
|
|
$fav = $each_char->find('.favorites', 0)->plaintext; |
|
150
|
|
|
$fav = str_replace(',', '', $fav); |
|
151
|
|
|
return trim($fav); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* Get result list. |
|
156
|
|
|
* |
|
157
|
|
|
* @return array |
|
158
|
|
|
*/ |
|
159
|
|
|
private function getAllInfo() |
|
160
|
|
|
{ |
|
161
|
|
|
$data = []; |
|
162
|
|
|
$data_index = 0; |
|
163
|
|
|
$top_table = $this->_parser->find('.people-favorites-ranking-table', 0); |
|
164
|
|
|
foreach ($top_table->find('tr[class=ranking-list]') as $each_char) { |
|
165
|
|
|
|
|
166
|
|
|
$name_area = $each_char->find('.people', 0); |
|
167
|
|
|
|
|
168
|
|
|
$data[$data_index]['rank'] = $this->getRank($each_char); |
|
169
|
|
|
$data[$data_index]['id'] = $this->getId($name_area); |
|
170
|
|
|
$data[$data_index]['name'] = $this->getName($name_area); |
|
171
|
|
|
$data[$data_index]['japanese_name'] = $this->getJapaneseName($name_area); |
|
172
|
|
|
$data[$data_index]['image'] = $this->getImage($name_area); |
|
173
|
|
|
$data[$data_index]['birthday'] = $this->getBirthday($each_char); |
|
174
|
|
|
$data[$data_index]['favorite'] = $this->getFavorite($each_char); |
|
175
|
|
|
|
|
176
|
|
|
$data_index++; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
return $data; |
|
180
|
|
|
} |
|
181
|
|
|
} |
|
182
|
|
|
|