1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MalScraper\Model\Lists; |
4
|
|
|
|
5
|
|
|
use MalScraper\Model\MainModel; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* AllGenreModel class. |
9
|
|
|
*/ |
10
|
|
|
class AllGenreModel extends MainModel |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Either anime or manga. |
14
|
|
|
* |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
private $_type; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Default constructor. |
21
|
|
|
* |
22
|
|
|
* @param string $type |
23
|
|
|
* @param string $parserArea |
24
|
|
|
* |
25
|
|
|
* @return void |
26
|
|
|
*/ |
27
|
|
|
public function __construct($type, $parserArea = '.anime-manga-search .genre-link') |
28
|
|
|
{ |
29
|
|
|
$this->_type = $type; |
30
|
|
|
if ($type == 'anime') { |
31
|
|
|
$this->_url = $this->_myAnimeListUrl.'/anime.php'; |
32
|
|
|
} else { |
33
|
|
|
$this->_url = $this->_myAnimeListUrl.'/manga.php'; |
34
|
|
|
} |
35
|
|
|
$this->_parserArea = $parserArea; |
36
|
|
|
|
37
|
|
|
parent::errorCheck($this); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Default call. |
42
|
|
|
* |
43
|
|
|
* @param string $method |
44
|
|
|
* @param array $arguments |
45
|
|
|
* |
46
|
|
|
* @return array|string|int |
47
|
|
|
*/ |
48
|
|
|
public function __call($method, $arguments) |
49
|
|
|
{ |
50
|
|
|
if ($this->_error) { |
51
|
|
|
return $this->_error; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return call_user_func_array([$this, $method], $arguments); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Get genre count. |
59
|
|
|
* |
60
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $each_genre |
61
|
|
|
* |
62
|
|
|
* @return string |
63
|
|
|
*/ |
64
|
|
|
private function getGenreCount($each_genre) |
65
|
|
|
{ |
66
|
|
|
$count = $each_genre->plaintext; |
67
|
|
|
preg_match('/\([0-9,]+\)/', $count, $cnt); |
68
|
|
|
$count = substr($cnt[0], 1, strlen($cnt[0]) - 2); |
69
|
|
|
|
70
|
|
|
return str_replace(',', '', $count); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Get list of all genre. |
75
|
|
|
* |
76
|
|
|
* @return array |
77
|
|
|
*/ |
78
|
|
|
private function getAllInfo() |
79
|
|
|
{ |
80
|
|
|
$data = []; |
81
|
|
|
foreach ($this->_parser->find('.genre-list a') as $each_genre) { |
82
|
|
|
$genre = []; |
83
|
|
|
|
84
|
|
|
$link = $each_genre->href; |
85
|
|
|
$link = explode('/', $link); |
86
|
|
|
$id = $link[3]; |
87
|
|
|
$genre['id'] = $id; |
88
|
|
|
|
89
|
|
|
$name = str_replace('_', ' ', $link[4]); |
90
|
|
|
$genre['name'] = $name; |
91
|
|
|
|
92
|
|
|
$genre['count'] = $this->getGenreCount($each_genre); |
93
|
|
|
|
94
|
|
|
$data[] = $genre; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return $data; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|