diff --git a/app/Http/Controllers/ClosetController.php b/app/Http/Controllers/ClosetController.php index d3ca918d..6a85e2c5 100644 --- a/app/Http/Controllers/ClosetController.php +++ b/app/Http/Controllers/ClosetController.php @@ -30,13 +30,30 @@ class ClosetController extends Controller $category = $request->input('category', 'skin'); $page = $request->input('page', 1); $page = $page <= 0 ? 1 : $page; + $q = $request->input('q', null); - $items = array_slice($this->closet->getItems($category), ($page-1)*6, 6); + if ($q) { + $result = []; - $total_pages = ceil(count($this->closet->getItems($category)) / 6); + foreach ($this->closet->getItems() as $item) { + if (strstr($item->name, $q)) { + $result[] = $item; + } + } + + $items = $result; + } else { + $items = $this->closet->getItems($category); + } + + // pagination + $items = array_slice($items, ($page-1)*6, 6); + + $total_pages = ceil(count($items) / 6); echo View::make('user.closet')->with('items', $items) ->with('page', $page) + ->with('q', $q) ->with('category', $category) ->with('total_pages', $total_pages) ->with('user', (new User(session('uid')))) diff --git a/app/Models/Closet.php b/app/Models/Closet.php index 1631d983..752bd983 100644 --- a/app/Models/Closet.php +++ b/app/Models/Closet.php @@ -87,13 +87,20 @@ class Closet /** * Get array of instances of App\Models\Texture. * - * @param string $category + * @param string $category skin|cape|all * @return array */ - public function getItems($category = "skin") + public function getItems($category = "all") { + if ($category == "all") { + $items = array_merge($this->textures_skin, $this->textures_cape); + } else { + $property = "textures_$category"; + $items = $this->$property; + } + // reverse the array to sort desc by add_at - return array_reverse(($category == "skin") ? $this->textures_skin : $this->textures_cape); + return array_reverse($items); } /** diff --git a/resources/views/user/closet.tpl b/resources/views/user/closet.tpl index 9e11b02d..755df1c2 100644 --- a/resources/views/user/closet.tpl +++ b/resources/views/user/closet.tpl @@ -27,10 +27,23 @@