diff --git a/src/API/Kitsu/Model.php b/src/API/Kitsu/Model.php index fab6da52..a9919f1d 100644 --- a/src/API/Kitsu/Model.php +++ b/src/API/Kitsu/Model.php @@ -422,8 +422,14 @@ final class Model { $item['included'] = $included; } $transformed = $this->animeListTransformer->transformCollection($data['data']); + $keyed = []; - $cacheItem->set($transformed); + foreach($transformed as $item) + { + $keyed[$item['id']] = $item; + } + + $cacheItem->set($keyed); $cacheItem->save(); } diff --git a/src/Controller/Manga.php b/src/Controller/Manga.php index 9c97c1cb..771aeecc 100644 --- a/src/Controller/Manga.php +++ b/src/Controller/Manga.php @@ -66,7 +66,7 @@ final class Manga extends Controller { */ public function index($status = 'all', $view = ''): void { - if ( ! in_array($type, [ + if ( ! in_array($status, [ 'all', 'reading', 'plan_to_read', @@ -337,4 +337,4 @@ final class Manga extends Controller { // @TODO: implement } } -// End of MangaController.php \ No newline at end of file +// End of MangaController.php diff --git a/src/Model/API.php b/src/Model/API.php index 3f7ef776..a411b7ae 100644 --- a/src/Model/API.php +++ b/src/Model/API.php @@ -29,6 +29,11 @@ class API { */ protected function sortByName(array &$array, string $sortKey): void { + if (empty($array)) + { + return; + } + $sort = []; foreach ($array as $key => $item) @@ -37,5 +42,18 @@ class API { } array_multisort($sort, SORT_ASC, $array); + + // Re-key array items by their ids + if (array_key_exists('id', $array[0])) + { + $keyed = []; + + foreach($array as $item) + { + $keyed[$item['id']] = $item; + } + + $array = $keyed; + } } } \ No newline at end of file