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