3a042d7dc252b501129d152217c3596866710296
[rock.divinelegy.git] / Controllers / SimfileController.php
1 <?php
2
3 namespace Controllers;
4
5 use Controllers\IDivineController;
6 use Services\Http\IHttpRequest;
7 use Services\Http\IHttpResponse;
8 use Services\Uploads\IUploadManager;
9 use DataAccess\StepMania\ISimfileRepository;
10
11 class SimfileController implements IDivineController
12 {
13 private $_simfileRepository;
14 private $_response;
15 private $_request;
16 private $_uploadManager;
17
18 public function __construct(
19 IHttpRequest $request,
20 IHttpResponse $response,
21 IUploadManager $uploadManager,
22 ISimfileRepository $repository
23 ) {
24 $this->_request = $request;
25 $this->_response = $response;
26 $this->_uploadManager = $uploadManager;
27 $this->_simfileRepository = $repository;
28 }
29
30 public function indexAction() {
31 ;
32 }
33
34 // list simfiles
35 public function listAction()
36 {
37 /* @var $simfile Domain\Entities\StepMania\ISimfile */
38 $simfiles = $this->_simfileRepository->findRange(1, 10);
39 $returnArray = array();
40
41 foreach($simfiles as $simfile)
42 {
43 $singleSteps = array();
44 $doubleSteps = array();
45
46 foreach($simfile->getSteps() as $steps)
47 {
48 $stepDetails = array(
49 'artist' => $steps->getArtist()->getTag(),
50 'difficulty' => $steps->getDifficulty()->getITGName(),
51 'rating' => $steps->getRating()
52 );
53
54 if($steps->getMode()->getPrettyName() == 'Single')
55 {
56 $singleSteps[] = $stepDetails;
57 } else {
58 $doubleSteps[] = $stepDetails;
59 }
60 }
61
62 $returnArray[] = array(
63 'title' => $simfile->getTitle(),
64 'artist' => $simfile->getArtist()->getName(),
65 'steps' => array(
66 'single' => $singleSteps,
67 'double' => $doubleSteps
68 ),
69 'bgChanges' => $simfile->hasBgChanges() ? 'Yes' : 'No',
70 'fgChanges' => $simfile->hasFgChanges() ? 'Yes' : 'No',
71 'bpmChanges' => $simfile->hasBPMChanges() ? 'Yes' : 'No',
72 'banner' => $simfile->getBanner() ? 'files/banner/' . $simfile->getBanner()->getHash() : 'files/banner/default'
73 );
74 }
75
76 $this->_response->setHeader('Content-Type', 'application/json')
77 ->setBody(json_encode($returnArray))
78 ->sendResponse();
79 }
80
81 public function uploadAction()
82 {
83 //logic for if pack or individual file
84
85 //TODO: Put directory in config ?
86 $filenames = $this->_uploadManager->setDestination('../files/StepMania/')
87 ->process();
88
89 //parse .sm files and save to DB. should use SimfileParser service
90
91 echo '<pre>';
92 print_r($filenames);
93 echo '</pre>';
94 }
95
96 public function testAction($testArg)
97 {
98 $this->_response->setHeader('Content-Type', 'application/json')
99 ->setBody(json_encode(array('testArg' => $testArg)))
100 ->sendResponse();
101 }
102 }