Pack entity builder stuff. Not tested yet.
[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\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 $_file;
18
19 public function __construct(
20 $title,
21 IUser $uploader,
22 array $simfiles,
23 IFile $file = null
24 ) {
25 $this->_title = $title;
26 $this->_uploader = $uploader;
27 $this->_file = $file;
28
29 foreach($simfiles as $simfile) {
30 if(!$simfile instanceof ISimfile) {
31 throw new Exception('Invalid Simfile array. All elements must be an instance of ISimfile.');
32 }
33 }
34
35 $this->_simfiles = $simfiles;
36 }
37
38 public function getContributors() {
39 $contributors = array();
40 foreach($this->_simfiles as $simfile)
41 {
42 /* @var $simfile \Domain\Entities\StepMania\Simfile */
43 $contributors = array_unique(
44 array_merge($contributors, $this->getAllStepArtistsFromSimfile($simfile))
45 );
46 }
47
48 return $contributors;
49 }
50
51 public function getFile()
52 {
53 return $this->_file;
54 }
55
56 public function getSimfiles()
57 {
58 return $this->_file;
59 }
60
61 public function getTitle()
62 {
63 return $this->_title;
64 }
65
66 public function getUploader()
67 {
68 return $this->_uploader;
69 }
70
71 private function getAllStepArtistsFromSimfile(ISimfile $simfile)
72 {
73 $artists = array();
74 foreach($simfile->getSteps() as $steps)
75 {
76 /* @var $steps \Domain\VOs\StepMania\IStepChart */
77 if(!in_array($steps->getArtist(), $artists)) $artists[] = $steps->getArtist ();
78 }
79
80 return $artists;
81 }
82 }