Fix issues with simfile controller.
[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 $returnArray[] = array(
44 'artist' => $simfile->getArtist()->getName(),
45 'title' => $simfile->getTitle()
46 );
47 }
48
49 $this->_response->setHeader('Content-Type', 'application/json')
50 ->setBody(json_encode($returnArray))
51 ->sendResponse();
52 }
53
54 public function uploadAction()
55 {
56 //logic for if pack or individual file
57
58 //TODO: Put directory in config ?
59 $filenames = $this->_uploadManager->setDestination('../files/StepMania/')
60 ->process();
61
62 echo '<pre>';
63 print_r($filenames);
64 echo '</pre>';
65 }
66
67 public function testAction($testArg)
68 {
69 $this->_response->setHeader('Content-Type', 'application/json')
70 ->setBody(json_encode(array('testArg' => $testArg)))
71 ->sendResponse();
72 }
73 }