From 4bd62ce88106321f7480a16a1465439cf5181c27 Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Mon, 10 Apr 2017 15:31:35 -0400 Subject: [PATCH] Fix various edge cases --- public/js/anime_edit.js | 2 +- public/js/manga_edit.js | 2 +- src/API/Kitsu/Model.php | 9 +++++++-- src/API/Kitsu/Transformer/AnimeListTransformer.php | 6 +++++- src/API/Kitsu/Transformer/MangaListTransformer.php | 8 ++++++-- src/Controller/Index.php | 4 ++++ 6 files changed, 24 insertions(+), 7 deletions(-) diff --git a/public/js/anime_edit.js b/public/js/anime_edit.js index 911cd4d3..d09c028b 100644 --- a/public/js/anime_edit.js +++ b/public/js/anime_edit.js @@ -8,7 +8,7 @@ // Action to increment episode count _.on('body.anime.list', 'click', '.plus_one', (e) => { let parentSel = _.closestParent(e.target, 'article'); - let watchedCount = parseInt(_.$('.completed_number', parentSel)[0].textContent, 10); + let watchedCount = parseInt(_.$('.completed_number', parentSel)[0].textContent, 10) || 0; let totalCount = parseInt(_.$('.total_number', parentSel)[0].textContent, 10); let title = _.$('.name a', parentSel)[0].textContent; diff --git a/public/js/manga_edit.js b/public/js/manga_edit.js index e010d681..85a488ab 100644 --- a/public/js/manga_edit.js +++ b/public/js/manga_edit.js @@ -9,7 +9,7 @@ let thisSel = e.target; let parentSel = _.closestParent(e.target, 'article'); let type = thisSel.classList.contains('plus_one_chapter') ? 'chapter' : 'volume'; - let completed = parseInt(_.$(`.${type}s_read`, parentSel)[0].textContent, 10); + let completed = parseInt(_.$(`.${type}s_read`, parentSel)[0].textContent, 10) || 0; let total = parseInt(_.$(`.${type}_count`, parentSel)[0].textContent, 10); let mangaName = _.$('.name', parentSel)[0].textContent; diff --git a/src/API/Kitsu/Model.php b/src/API/Kitsu/Model.php index 634a4ea8..fbb07305 100644 --- a/src/API/Kitsu/Model.php +++ b/src/API/Kitsu/Model.php @@ -238,9 +238,9 @@ class Model { * * @param string $malId * @param string $type "anime" or "manga" - * @return string + * @return string|NULL */ - public function getKitsuIdFromMALId(string $malId, string $type="anime"): string + public function getKitsuIdFromMALId(string $malId, string $type="anime") { $options = [ 'query' => [ @@ -257,6 +257,11 @@ class Model { $raw = $this->getRequest('mappings', $options); + if ( ! array_key_exists('included', $raw)) + { + return NULL; + } + return $raw['included'][0]['id']; } diff --git a/src/API/Kitsu/Transformer/AnimeListTransformer.php b/src/API/Kitsu/Transformer/AnimeListTransformer.php index 45af8f55..a628b510 100644 --- a/src/API/Kitsu/Transformer/AnimeListTransformer.php +++ b/src/API/Kitsu/Transformer/AnimeListTransformer.php @@ -120,11 +120,15 @@ class AnimeListTransformer extends AbstractTransformer { 'reconsuming' => $rewatching, 'reconsumeCount' => $item['rewatched'], 'notes' => $item['notes'], - 'progress' => $item['episodes_watched'], 'private' => $privacy ] ]; + if (is_numeric($item['episodes_watched']) && $item['episodes_watched'] > 0) + { + $untransformed['data']['progress'] = (int) $item['episodes_watched']; + } + if (is_numeric($item['user_rating']) && $item['user_rating'] > 0) { $untransformed['data']['rating'] = $item['user_rating'] / 2; diff --git a/src/API/Kitsu/Transformer/MangaListTransformer.php b/src/API/Kitsu/Transformer/MangaListTransformer.php index 7d2152ce..d241c4a4 100644 --- a/src/API/Kitsu/Transformer/MangaListTransformer.php +++ b/src/API/Kitsu/Transformer/MangaListTransformer.php @@ -117,14 +117,18 @@ class MangaListTransformer extends AbstractTransformer { 'mal_id' => $item['mal_id'], 'data' => [ 'status' => $item['status'], - 'progress' => (int)$item['chapters_read'], 'reconsuming' => $rereading, 'reconsumeCount' => (int)$item['reread_count'], 'notes' => $item['notes'], ], ]; - if (is_numeric($item['new_rating'])) + if (is_numeric($item['chapters_read']) && $item['chapters_read'] > 0) + { + $map['data']['progress'] = (int)$item['chapters_read']; + } + + if (is_numeric($item['new_rating']) && $item['new_rating'] > 0) { $map['data']['rating'] = $item['new_rating'] / 2; } diff --git a/src/Controller/Index.php b/src/Controller/Index.php index b9a9f08f..411aac26 100644 --- a/src/Controller/Index.php +++ b/src/Controller/Index.php @@ -118,6 +118,10 @@ class Index extends BaseController { // return $rawfavorites; $output = []; + unset($rawfavorites['data']); + + // dump($rawfavorites); + foreach($rawfavorites as $item) { $rank = $item['attributes']['favRank'];