5 use Controllers\IDivineController
;
6 use Services\Http\IHttpResponse
;
7 use Services\Uploads\IUploadManager
;
8 use Services\IUserSession
;
9 use Services\IZipParser
;
10 use DataAccess\StepMania\ISimfileRepository
;
11 use DataAccess\StepMania\IPackRepository
;
12 use DataAccess\IFileRepository
;
13 use Domain\Entities\StepMania\ISimfile
;
14 use Domain\Entities\StepMania\IPack
;
16 class SimfileController
implements IDivineController
18 private $_simfileRepository;
19 private $_packRepository;
20 private $_fileRepository;
22 private $_uploadManager;
23 private $_userSession;
26 public function __construct(
27 IHttpResponse
$response,
28 IUploadManager
$uploadManager,
29 ISimfileRepository
$simfileRepository,
30 IPackRepository
$packRepository,
31 IFileRepository
$fileRepository,
32 IUserSession
$userSession,
35 $this->_response
= $response;
36 $this->_uploadManager
= $uploadManager;
37 $this->_simfileRepository
= $simfileRepository;
38 $this->_packRepository
= $packRepository;
39 $this->_fileRepository
= $fileRepository;
40 $this->_userSession
= $userSession;
41 $this->_zipParser
= $zipParser;
44 public function indexAction() {
49 public function listAction()
51 /* @var $simfile Domain\Entities\StepMania\ISimfile */
52 $simfiles = $this->_simfileRepository
->findRange(1, 10);
53 $returnArray = array();
55 foreach($simfiles as $simfile)
57 $singleSteps = array();
58 $doubleSteps = array();
60 foreach($simfile->getSteps() as $steps)
63 'artist' => $steps->getArtist()->getTag(),
64 'difficulty' => $steps->getDifficulty()->getITGName(),
65 'rating' => $steps->getRating()
68 if($steps->getMode()->getPrettyName() == 'Single')
70 $singleSteps[] = $stepDetails;
72 $doubleSteps[] = $stepDetails;
76 $returnArray[] = array(
77 'title' => $simfile->getTitle(),
78 'artist' => $simfile->getArtist()->getName(),
80 'single' => $singleSteps,
81 'double' => $doubleSteps
83 'bgChanges' => $simfile->hasBgChanges() ?
'Yes' : 'No',
84 'fgChanges' => $simfile->hasFgChanges() ?
'Yes' : 'No',
85 'bpmChanges' => $simfile->hasBPMChanges() ?
'Yes' : 'No',
86 'banner' => $simfile->getBanner() ?
'files/banner/' . $simfile->getBanner()->getHash() : 'files/banner/default'
90 $this->_response
->setHeader('Content-Type', 'application/json')
91 ->setBody(json_encode($returnArray))
95 public function uploadAction()
97 //TODO: Put directory in config ?
98 $files = $this->_uploadManager
->setFilesDirectory('../files')
99 ->setDestination('StepMania/')
102 foreach($files as $file)
104 $zipParser = $this->_zipParser
;
105 $zipParser->parse($file);
107 //save the actual zip in the db
108 $this->_fileRepository
->save($file);
110 if($zipParser->isPack())
112 //XXX: Tricky! pack() uses packbuilder and so returns a new pack each time.
113 //I tried to be clever and call pack() multiple times thinking I was getting the same
114 //object. Should I cache it in zipparser?
115 $pack = $zipParser->pack();
116 $this->_fileRepository
->save($pack->getBanner());
117 $this->_packRepository
->save($pack);
120 foreach($zipParser->simfiles() as $simfile)
122 $banner = $simfile->getBanner() ?
$this->_fileRepository
->save($simfile->getBanner()) : null
;
123 $simfileZip = $simfile->getSimfile() ?
$this->_fileRepository
->save($simfile->getSimfile()) : null
;
125 if(isset($pack)) $simfile->addToPack($pack);
126 $this->_simfileRepository
->save($simfile);