- echo '</pre>';\r
- }\r
- \r
- public function testAction($testArg)\r
- {\r
- $this->_response->setHeader('Content-Type', 'application/json')\r
- ->setBody(json_encode(array('testArg' => $testArg)))\r
- ->sendResponse();\r
+ foreach($filenames as $filename => $hash)\r
+ {\r
+ $za = new ZipArchive();\r
+ //XXX: We assume all files are zips. Should be enforced by validation elsewhere.\r
+ $res = $za->open('../files/StepMania/' . $hash . '.zip');\r
+ \r
+ if($res !== true) throw new Exception ('Could not open zip for reading.');\r
+ \r
+ for($i=0; $i<$za->numFiles; $i++)\r
+ {\r
+ $stat = $za->statIndex($i);\r
+ if(pathinfo($stat['name'], PATHINFO_EXTENSION) == 'sm')\r
+ {\r
+ $smData = file_get_contents('zip://../files/StepMania/' . $hash . '.zip#' . $stat['name']);\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ \r
+ if(!$smData) throw new Exception('Could not extract simfile.');\r
+ \r
+ /* @var $parser \Services\ISimfileParser */\r
+ $parser = $this->_simfileParser;\r
+ $parser->parse($smData);\r
+\r
+ //TODO: Instantiating VOs like this bad ?\r
+ $this->_simfileBuilder->With_Title($parser->title())\r
+ ->With_Artist(new \Domain\VOs\StepMania\Artist($parser->artist()))\r
+ ->With_Uploader($this->_userRepository->findByAuthToken($token)) //obj\r
+ ->With_BPM($bpm) //obj\r
+ ->With_BpmChanges($parser->bpmChanges())\r
+ ->With_Stops($parser->stops())\r
+ ->With_FgChanges($parser->fgChanges())\r
+ ->With_BgChanges($parser->bgChanges())\r
+ ->With_Steps($steps) //obj\r
+ ->build();\r
+\r
+ //parse .sm files and save to DB. should use SimfileParser service\r