241b1f2f014b938756952f379d93248008540a82
[rock.divinelegy.git] / Domain / Entities / StepMania / Pack.php
1 <?php
2
3 namespace Domain\Entities\StepMania;
4
5 use Exception;
6 use Domain\Entities\StepMania\ISimfile;
7 use Domain\Entities\IUser;
8 use Domain\Entities\IFile;
9 use Domain\Entities\StepMania\IPack;
10 use Domain\Entities\AbstractEntity;
11
12 class Pack extends AbstractEntity implements IPack
13 {
14 private $_title;
15 private $_uploader;
16 private $_simfiles;
17 private $_banner;
18 private $_file;
19
20 public function __construct(
21 $title,
22 IUser $uploader,
23 array $simfiles,
24 IFile $banner = null,
25 IFile $file = null
26 ) {
27 $this->_title = $title;
28 $this->_uploader = $uploader;
29 $this->_banner = $banner;
30 $this->_file = $file;
31
32 foreach($simfiles as $simfile) {
33 if(!$simfile instanceof ISimfile) {
34 throw new Exception('Invalid Simfile array. All elements must be an instance of ISimfile.');
35 }
36 }
37
38 $this->_simfiles = $simfiles;
39 }
40
41 public function getContributors() {
42 $contributors = array();
43 foreach($this->_simfiles as $simfile)
44 {
45 /* @var $simfile \Domain\Entities\StepMania\Simfile */
46 $contributors = array_unique(
47 array_merge($contributors, $this->getAllStepArtistsFromSimfile($simfile))
48 );
49 }
50
51 return $contributors;
52 }
53
54 public function getFile()
55 {
56 return $this->_file;
57 }
58
59 public function getSimfiles()
60 {
61 return $this->_simfiles;
62 }
63
64 public function getTitle()
65 {
66 return $this->_title;
67 }
68
69 public function getUploader()
70 {
71 return $this->_uploader;
72 }
73
74 public function getBanner()
75 {
76 return $this->_banner;
77 }
78
79 private function getAllStepArtistsFromSimfile(ISimfile $simfile)
80 {
81 $artists = array();
82 foreach($simfile->getSteps() as $steps)
83 {
84 /* @var $steps \Domain\VOs\StepMania\StepChart */
85 if($steps->getArtist()->getTag() && !in_array($steps->getArtist()->getTag(), $artists)) $artists[] = $steps->getArtist()->getTag();
86 }
87
88 return $artists;
89 }
90 }