From 3ccdbc7e6c3bafefc7c87ab029ad737da5ad1d55 Mon Sep 17 00:00:00 2001 From: DariusIII Date: Fri, 2 Feb 2018 11:36:13 +0100 Subject: [PATCH] Replace all of getById functions with Model::find --- Changelog | 1 + app/Models/Category.php | 15 --------------- nntmux/Releases.php | 2 +- public/admin/category-edit.php | 2 +- public/admin/menu-edit.php | 2 +- public/pages/books.php | 2 +- public/pages/browse.php | 4 ++-- public/pages/console.php | 2 +- public/pages/games.php | 4 ++-- public/pages/movies.php | 4 ++-- public/pages/music.php | 4 ++-- public/pages/xxx.php | 2 +- 12 files changed, 15 insertions(+), 29 deletions(-) diff --git a/Changelog b/Changelog index 7f0de565e..f250fc95b 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2018-02-02 DariusIII + * Chg: Replace all of getById functions with Model::find * Fix: Fix getByIdAndRssToken function * Chg: Use replace getById user lookup with User model find built in function(does the same thing as custom function) 2018-02-01 DariusIII diff --git a/app/Models/Category.php b/app/Models/Category.php index 620c0c534..5baeed196 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -325,21 +325,6 @@ class Category extends Model ->get(['id']); } - /** - * Get a category row by its id. - * - * - * @param $id - * @return \Illuminate\Database\Eloquent\Model|null|static - */ - public static function getById($id) - { - return self::query() - ->with('parent') - ->where('id', $id) - ->first(); - } - /** * Get multiple categories. * diff --git a/nntmux/Releases.php b/nntmux/Releases.php index 5eb42f32f..69367f252 100755 --- a/nntmux/Releases.php +++ b/nntmux/Releases.php @@ -1098,7 +1098,7 @@ class Releases { // Get the category for the parent of this release. $currRow = Release::getCatByRelId($currentID); - $catRow = Category::getById($currRow['categories_id']); + $catRow = Category::find($currRow['categories_id']); $parentCat = $catRow['parentid']; $results = $this->search( diff --git a/public/admin/category-edit.php b/public/admin/category-edit.php index 7d6a90137..b9d3a86b1 100644 --- a/public/admin/category-edit.php +++ b/public/admin/category-edit.php @@ -21,7 +21,7 @@ switch ($action) { if (isset($_GET['id'])) { $page->title = 'Category Edit'; $id = $_GET['id']; - $cat = Category::getById($id); + $cat = Category::find($id); $page->smarty->assign('category', $cat); } break; diff --git a/public/admin/menu-edit.php b/public/admin/menu-edit.php index 6a1d20e98..1948d037a 100644 --- a/public/admin/menu-edit.php +++ b/public/admin/menu-edit.php @@ -37,7 +37,7 @@ switch ($action) { ]; if (isset($_GET['id'])) { $id = $_GET['id']; - $menuRow = Menu::getById($id); + $menuRow = Menu::find($id); } $page->title = 'Menu Edit'; $page->smarty->assign('menu', $menuRow); diff --git a/public/pages/books.php b/public/pages/books.php index 5a3061f19..7c801afee 100644 --- a/public/pages/books.php +++ b/public/pages/books.php @@ -65,7 +65,7 @@ $page->smarty->assign('pager', $pager); if ((int) $category === -1) { $page->smarty->assign('catname', 'All'); } else { - $cdata = Category::getById($category); + $cdata = Category::find($category); if ($cdata) { $page->smarty->assign('catname', $cdata->parent !== null ? $cdata->parent->title.' > '.$cdata->title : $cdata->title); } else { diff --git a/public/pages/browse.php b/public/pages/browse.php index 1046c470b..4c274bf14 100644 --- a/public/pages/browse.php +++ b/public/pages/browse.php @@ -47,10 +47,10 @@ $pager = $page->smarty->fetch('pager.tpl'); $page->smarty->assign('pager', $pager); $covgroup = ''; -if ($category === -1 && (int) $grp === -1) { +if ((int) $category === -1 && (int) $grp === -1) { $page->smarty->assign('catname', 'All'); } elseif ((int) $category !== -1 && (int) $grp === -1) { - $cdata = Category::getById($category); + $cdata = Category::find($category); if ($cdata) { $page->smarty->assign('catname', $cdata->parent !== null ? $cdata->parent->title.' > '.$cdata->title : $cdata->title); if ($cdata['parentid'] === Category::GAME_ROOT || $cdata['id'] === Category::GAME_ROOT) { diff --git a/public/pages/console.php b/public/pages/console.php index e1d0cffad..1f84e2269 100644 --- a/public/pages/console.php +++ b/public/pages/console.php @@ -76,7 +76,7 @@ $page->smarty->assign('pager', $pager); if ((int) $category === -1) { $page->smarty->assign('catname', 'All'); } else { - $cdata = Category::getById($category); + $cdata = Category::find($category); if ($cdata) { $page->smarty->assign('catname', $cdata->parent !== null ? $cdata->parent->title.' > '.$cdata->title : $cdata->title); } else { diff --git a/public/pages/games.php b/public/pages/games.php index 439313850..e43b65d01 100644 --- a/public/pages/games.php +++ b/public/pages/games.php @@ -81,10 +81,10 @@ $page->smarty->assign('pagerquerysuffix', '#results'); $pager = $page->smarty->fetch('pager.tpl'); $page->smarty->assign('pager', $pager); -if ($category == -1) { +if ((int) $category === -1) { $page->smarty->assign('catname', 'All'); } else { - $cdata = Category::getById($category); + $cdata = Category::find($category); if ($cdata) { $page->smarty->assign('catname', $cdata->parent !== null ? $cdata->parent->title.' > '.$cdata->title : $cdata->title); } else { diff --git a/public/pages/movies.php b/public/pages/movies.php index 36a863926..ae549edb3 100644 --- a/public/pages/movies.php +++ b/public/pages/movies.php @@ -86,10 +86,10 @@ $page->smarty->assign('pagerquerysuffix', '#results'); $pager = $page->smarty->fetch('pager.tpl'); $page->smarty->assign('pager', $pager); -if ($category == -1) { +if ((int) $category === -1) { $page->smarty->assign('catname', 'All'); } else { - $cdata = Category::getById($category); + $cdata = Category::find($category); if ($cdata) { $page->smarty->assign('catname', $cdata->parent !== null ? $cdata->parent->title.' > '.$cdata->title : $cdata->title); } else { diff --git a/public/pages/music.php b/public/pages/music.php index eb120c0bb..9572a9743 100644 --- a/public/pages/music.php +++ b/public/pages/music.php @@ -73,10 +73,10 @@ $page->smarty->assign('pagerquerysuffix', '#results'); $pager = $page->smarty->fetch('pager.tpl'); $page->smarty->assign('pager', $pager); -if ($category == -1) { +if ((int) $category === -1) { $page->smarty->assign('catname', 'All'); } else { - $cdata = Category::getById($category); + $cdata = Category::find($category); if ($cdata) { $page->smarty->assign('catname', $cdata->parent !== null ? $cdata->parent->title.' > '.$cdata->title : $cdata->title); } else { diff --git a/public/pages/xxx.php b/public/pages/xxx.php index 783e7cb78..f65e8151d 100644 --- a/public/pages/xxx.php +++ b/public/pages/xxx.php @@ -65,7 +65,7 @@ $page->smarty->assign('pager', $pager); if ((int) $category === -1) { $page->smarty->assign('catname', 'All'); } else { - $cdata = Category::getById($category); + $cdata = Category::find($category); if ($cdata) { $page->smarty->assign('catname', $cdata->parent !== null ? $cdata->parent->title.' > '.$cdata->title : $cdata->title); } else {