|
1
|
|
|
<?php |
|
2
|
|
|
/******************************************************************************* |
|
3
|
|
|
* This file is part of the Pbxg33k\MusicInfo package. |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
6
|
|
|
* file that was distributed with this source code. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) 2017 Oguzhan uysal. All rights reserved |
|
9
|
|
|
******************************************************************************/ |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Created by PhpStorm. |
|
13
|
|
|
* User: PBX_g33k |
|
14
|
|
|
* Date: 22-May-16 |
|
15
|
|
|
* Time: 22:21 |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace Pbxg33k\MusicInfo\Service\VocaDB\Endpoint; |
|
19
|
|
|
|
|
20
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
21
|
|
|
use Pbxg33k\MusicInfo\Model\Artist as ArtistModel; |
|
22
|
|
|
use Pbxg33k\MusicInfo\Model\IMusicServiceEndpoint; |
|
23
|
|
|
use Pbxg33k\VocaDB\Album as AlbumEndpoint; |
|
24
|
|
|
use Pbxg33k\MusicInfo\Model\Album as AlbumModel; |
|
25
|
|
|
use Pbxg33k\VocaDB\Models\Collections\AlbumCollection; |
|
26
|
|
|
use Pbxg33k\VocaDB\Models\Album as VocaDBModel; |
|
27
|
|
|
|
|
28
|
|
|
class Album extends AlbumEndpoint implements IMusicServiceEndpoint |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* @return mixed |
|
32
|
|
|
*/ |
|
33
|
|
|
public function getParent() |
|
34
|
|
|
{ |
|
35
|
|
|
// TODO: Implement getApiService() method. |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Aliases getById |
|
40
|
|
|
* |
|
41
|
|
|
* @param $guid |
|
42
|
|
|
* |
|
43
|
|
|
* @return mixed |
|
44
|
|
|
*/ |
|
45
|
|
|
public function getByGuid($guid) |
|
46
|
|
|
{ |
|
47
|
|
|
return $this->getById($guid); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @return mixed |
|
52
|
|
|
*/ |
|
53
|
|
|
public function setParent($apiService) |
|
54
|
|
|
{ |
|
55
|
|
|
// TODO: Implement setApiService() method. |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @param VocaDBModel $raw |
|
60
|
|
|
* @return AlbumModel |
|
61
|
|
|
*/ |
|
62
|
|
|
public function transformSingle($raw) |
|
63
|
|
|
{ |
|
64
|
|
|
$object = new AlbumModel(); |
|
65
|
|
|
$object |
|
66
|
|
|
->setId($raw->getId()) |
|
67
|
|
|
->setName($raw->getName()) |
|
68
|
|
|
->setArtists(new ArrayCollection([ |
|
69
|
|
|
(new ArtistModel())->setName($raw->getName()) |
|
70
|
|
|
])) |
|
71
|
|
|
->setType($raw->getDiscType()) |
|
72
|
|
|
->setImage($raw->getMainPicture()->urlThumb) |
|
73
|
|
|
->setReleaseDate(new \DateTime($raw->getReleaseDate()->formatted)) |
|
74
|
|
|
->setDataSource('vocadb') |
|
75
|
|
|
->setRawData($raw); |
|
76
|
|
|
|
|
77
|
|
|
return $object; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function transformCollection($raw) |
|
81
|
|
|
{ |
|
82
|
|
|
$collection = new ArrayCollection(); |
|
83
|
|
|
if($raw instanceof AlbumCollection) { |
|
84
|
|
|
foreach($raw->collection as $album) { |
|
85
|
|
|
$collection->add($this->transformSingle($album)); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
return $collection; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
throw new \Exception('Transform failed. Object is not an instance of AlbumCollection'); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function transform($raw) |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->transformCollection($raw); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function getByName($name, $complete = true) |
|
100
|
|
|
{ |
|
101
|
|
|
return $this->transform(parent::getByName($name, $complete)); |
|
102
|
|
|
} |
|
103
|
|
|
} |