From f5940a0c23c11903a386170e643ecfe92b1ea1a3 Mon Sep 17 00:00:00 2001 From: Andres Schmois Date: Wed, 8 Apr 2015 19:26:43 -0400 Subject: [PATCH] Add select to version tab --- app/controllers/ModController.php | 53 +++++++++++++++++++++++++++- app/views/mod/view.blade.php | 58 +++++++++++++++++++++++++++---- 2 files changed, 103 insertions(+), 8 deletions(-) diff --git a/app/controllers/ModController.php b/app/controllers/ModController.php index 39bff406..cac6b2ef 100644 --- a/app/controllers/ModController.php +++ b/app/controllers/ModController.php @@ -131,6 +131,57 @@ public function postDelete($mod_id = null) return Redirect::to('mod/list')->with('success','Mod deleted!'); } + public function getFileRefresh($mod_id = null) + { + if (Request::ajax()) + { + if (empty($mod_id)) + return Response::json(array( + 'status' => 'error', + 'reason' => 'Missing Post Data' + )); + + $mod = Mod::find($mod_id); + if (empty($mod)) + return Response::json(array( + 'status' => 'error', + 'reason' => 'Could not pull mod from database' + )); + $location = Config::get('solder.repo_location').'mods/'.$mod->name.'/'; + if(!file_exists($location)) + return Response::json(array( + 'status' => 'error', + 'reason' => 'Folder '.$mod->name.' does not exist.' + )); + $files = scandir($location); + if(!$files) + return Response::json(array( + 'status' => 'error', + 'reason' => 'Could not find mod folder' + )); + $existingVersionsObjects = $mod->versions()->get(); + $existingVersions = array(); + foreach ($existingVersionsObjects as $i => $version) { + $existingVersions[] = $version->version; + } + $versions = array(); + foreach ($files as $i => $file) { + if(strpos($file, ".zip") !== false) { + $version = str_replace(".zip", "", str_replace($mod->name."-", "", $file)); + if(!in_array($version, $existingVersions)) { + $versions[] = $version; + } + } + } + return Response::json(array( + 'versions' => $versions, + 'status' => 'success' + )); + + } + return App::abort(404); + } + public function getRehash($ver_id = null) { if (Request::ajax()) @@ -269,4 +320,4 @@ private function remote_mod_md5($mod, $version, $attempts = 0) return $this->remote_mod_md5($mod, $version, $attempts + 1); } } -} \ No newline at end of file +} diff --git a/app/views/mod/view.blade.php b/app/views/mod/view.blade.php index 67c2f4f5..87238be0 100644 --- a/app/views/mod/view.blade.php +++ b/app/views/mod/view.blade.php @@ -86,10 +86,11 @@ - +