1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MalScraper\Model\User; |
4
|
|
|
|
5
|
|
|
use MalScraper\Helper\Helper; |
6
|
|
|
use MalScraper\Model\MainModel; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* UserListModel class. |
10
|
|
|
*/ |
11
|
|
|
class UserListModel extends MainModel |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* Username. |
15
|
|
|
* |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
private $_user; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Either anime or manga. |
22
|
|
|
* |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
private $_type; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Anime/manga status. |
29
|
|
|
* |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
private $_status; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Default constructor. |
36
|
|
|
* |
37
|
|
|
* @param string $user |
38
|
|
|
* @param string $type |
39
|
|
|
* @param string $status |
40
|
|
|
* @param string $parserArea |
41
|
|
|
* |
42
|
|
|
* @return void |
43
|
|
|
*/ |
44
|
|
|
public function __construct($user, $type, $status, $parserArea = '#content') |
45
|
|
|
{ |
46
|
|
|
$this->_user = $user; |
47
|
|
|
$this->_type = $type; |
48
|
|
|
$this->_status = $status; |
49
|
|
|
$this->_url = $this->_myAnimeListUrl.'/'.$type.'list/'.$user.'?status='.$status; |
50
|
|
|
$this->_parserArea = $parserArea; |
51
|
|
|
|
52
|
|
|
parent::errorCheck($this); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Default call. |
57
|
|
|
* |
58
|
|
|
* @param string $method |
59
|
|
|
* @param array $arguments |
60
|
|
|
* |
61
|
|
|
* @return array|string|int |
62
|
|
|
*/ |
63
|
|
|
public function __call($method, $arguments) |
64
|
|
|
{ |
65
|
|
|
if ($this->_error) { |
66
|
|
|
return $this->_error; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return call_user_func_array([$this, $method], $arguments); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Get user list. |
74
|
|
|
* |
75
|
|
|
* @return array |
76
|
|
|
*/ |
77
|
|
|
private function getAllInfo() |
78
|
|
|
{ |
79
|
|
|
$data = []; |
80
|
|
|
$offset = 0; |
81
|
|
|
while (true) { |
82
|
|
|
$url = $this->_myAnimeListUrl.'/'.$this->_type.'list/'.$this->_user.'/load.json?offset='.$offset.'&status='.$this->_status; |
83
|
|
|
|
84
|
|
|
$content = json_decode(file_get_contents($url), true); |
85
|
|
|
|
86
|
|
|
if ($content) { |
87
|
|
|
$count = count($content); |
88
|
|
|
for ($i = 0; $i < $count; $i++) { |
89
|
|
|
if (!empty($content[$i]['anime_image_path'])) { |
90
|
|
|
$content[$i]['anime_image_path'] = Helper::imageUrlCleaner($content[$i]['anime_image_path']); |
91
|
|
|
} else { |
92
|
|
|
$content[$i]['manga_image_path'] = Helper::imageUrlCleaner($content[$i]['manga_image_path']); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
$data = array_merge($data, $content); |
97
|
|
|
|
98
|
|
|
$offset += 300; |
99
|
|
|
} else { |
100
|
|
|
break; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return $data; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|