From beaf9af041c56701f3f12c1517485a75ca4020b4 Mon Sep 17 00:00:00 2001 From: cp6 Date: Thu, 20 Oct 2022 13:57:04 +1100 Subject: [PATCH] Updated order/sort by on index pages Updated order/sort by on index pages As using the relationship for price related sorts does not work this method does --- app/Models/Domains.php | 8 +++++++- app/Models/Misc.php | 10 ++++++---- app/Models/Reseller.php | 10 ++++++---- app/Models/SeedBoxes.php | 10 ++++++---- app/Models/Server.php | 19 +++++++++++++------ app/Models/Shared.php | 10 ++++++---- 6 files changed, 44 insertions(+), 23 deletions(-) diff --git a/app/Models/Domains.php b/app/Models/Domains.php index 0fd0150..5172992 100644 --- a/app/Models/Domains.php +++ b/app/Models/Domains.php @@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Session; class Domains extends Model { @@ -23,7 +24,12 @@ class Domains extends Model public static function allDomains() {//All domains and relationships (no using joins) return Cache::remember("all_domains", now()->addMonth(1), function () { - return Domains::with(['provider', 'price', 'labels'])->get(); + $query = Domains::with(['provider', 'price', 'labels']); + if (in_array(Session::get('sort_on'), [3, 4, 5, 6], true)) { + $options = Settings::orderByProcess(Session::get('sort_on')); + $query->orderBy(Pricing::select("pricings.$options[0]")->whereColumn("pricings.service_id", "domains.id"), $options[1]); + } + return $query->get(); }); } diff --git a/app/Models/Misc.php b/app/Models/Misc.php index 859c303..008b47c 100644 --- a/app/Models/Misc.php +++ b/app/Models/Misc.php @@ -35,7 +35,12 @@ class Misc extends Model public static function allMisc() {//All misc and relationships (no using joins) return Cache::remember("all_misc", now()->addMonth(1), function () { - return Misc::with(['price'])->get(); + $query = Misc::with(['price']); + if (in_array(Session::get('sort_on'), [3, 4, 5, 6], true)) { + $options = Settings::orderByProcess(Session::get('sort_on')); + $query->orderBy(Pricing::select("pricings.$options[0]")->whereColumn("pricings.service_id", "misc_services.id"), $options[1]); + } + return $query->get(); }); } @@ -49,9 +54,6 @@ class Misc extends Model public function price() { - if (in_array(Session::get('sort_on'), [3, 4, 5, 6], true)) { - return $this->hasOne(Pricing::class, 'service_id', 'id')->orderBy(Settings::orderByProcess(Session::get('sort_on'))[0], Settings::orderByProcess(Session::get('sort_on'))[1]); - } return $this->hasOne(Pricing::class, 'service_id', 'id'); } diff --git a/app/Models/Reseller.php b/app/Models/Reseller.php index 312e8c5..b6f31bd 100644 --- a/app/Models/Reseller.php +++ b/app/Models/Reseller.php @@ -36,7 +36,12 @@ class Reseller extends Model public static function allResellerHosting() {//All reseller hosting and relationships (no using joins) return Cache::remember("all_reseller", now()->addMonth(1), function () { - return Reseller::with(['location', 'provider', 'price', 'ips', 'labels'])->get(); + $query = Reseller::with(['location', 'provider', 'price', 'ips', 'labels']); + if (in_array(Session::get('sort_on'), [3, 4, 5, 6], true)) { + $options = Settings::orderByProcess(Session::get('sort_on')); + $query->orderBy(Pricing::select("pricings.$options[0]")->whereColumn("pricings.service_id", "reseller_hosting.id"), $options[1]); + } + return $query->get(); }); } @@ -65,9 +70,6 @@ class Reseller extends Model public function price() { - if (in_array(Session::get('sort_on'), [3, 4, 5, 6], true)) { - return $this->hasOne(Pricing::class, 'service_id', 'id')->orderBy(Settings::orderByProcess(Session::get('sort_on'))[0], Settings::orderByProcess(Session::get('sort_on'))[1]); - } return $this->hasOne(Pricing::class, 'service_id', 'id'); } diff --git a/app/Models/SeedBoxes.php b/app/Models/SeedBoxes.php index 3fe0d32..712de5b 100644 --- a/app/Models/SeedBoxes.php +++ b/app/Models/SeedBoxes.php @@ -36,7 +36,12 @@ class SeedBoxes extends Model public static function allSeedboxes() {//All seedboxes and relationships (no using joins) return Cache::remember("all_seedboxes", now()->addMonth(1), function () { - return SeedBoxes::with(['location', 'provider', 'price'])->get(); + $query = SeedBoxes::with(['location', 'provider', 'price']); + if (in_array(Session::get('sort_on'), [3, 4, 5, 6], true)) { + $options = Settings::orderByProcess(Session::get('sort_on')); + $query->orderBy(Pricing::select("pricings.$options[0]")->whereColumn("pricings.service_id", "seedboxes.id"), $options[1]); + } + return $query->get(); }); } @@ -60,9 +65,6 @@ class SeedBoxes extends Model public function price() { - if (in_array(Session::get('sort_on'), [3, 4, 5, 6], true)) { - return $this->hasOne(Pricing::class, 'service_id', 'id')->orderBy(Settings::orderByProcess(Session::get('sort_on'))[0], Settings::orderByProcess(Session::get('sort_on'))[1]); - } return $this->hasOne(Pricing::class, 'service_id', 'id'); } diff --git a/app/Models/Server.php b/app/Models/Server.php index f34357e..8925718 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -43,7 +43,12 @@ class Server extends Model public static function allServers() {//All servers and relationships (no using joins) return Cache::remember("all_servers", now()->addMonth(1), function () { - return Server::with(['location', 'provider', 'os', 'price', 'ips', 'yabs', 'yabs.disk_speed', 'yabs.network_speed', 'labels'])->get(); + $query = Server::with(['location', 'provider', 'os', 'price', 'ips', 'yabs', 'yabs.disk_speed', 'yabs.network_speed', 'labels']); + if (in_array(Session::get('sort_on'), [3, 4, 5, 6], true)) { + $options = Settings::orderByProcess(Session::get('sort_on')); + $query->orderBy(Pricing::select("pricings.$options[0]")->whereColumn("pricings.service_id", "servers.id"), $options[1]); + } + return $query->get(); }); } @@ -58,8 +63,13 @@ class Server extends Model public static function allActiveServers() {//All ACTIVE servers and relationships replaces activeServersDataIndexPage() return Cache::remember("all_active_servers", now()->addMonth(1), function () { - return Server::where('active', '=', 1) - ->with(['location', 'provider', 'os', 'ips', 'yabs', 'yabs.disk_speed', 'yabs.network_speed', 'labels', 'price'])->get(); + $query = Server::where('active', '=', 1) + ->with(['location', 'provider', 'os', 'ips', 'yabs', 'yabs.disk_speed', 'yabs.network_speed', 'labels', 'price']); + if (in_array(Session::get('sort_on'), [3, 4, 5, 6], true)) { + $options = Settings::orderByProcess(Session::get('sort_on')); + $query->orderBy(Pricing::select("pricings.$options[0]")->whereColumn("pricings.service_id", "servers.id"), $options[1]); + } + return $query->get(); }); } @@ -216,9 +226,6 @@ class Server extends Model public function price() { - if (in_array(Session::get('sort_on'), [3, 4, 5, 6], true)) { - return $this->hasOne(Pricing::class, 'service_id', 'id')->orderBy(Settings::orderByProcess(Session::get('sort_on'))[0], Settings::orderByProcess(Session::get('sort_on'))[1]); - } return $this->hasOne(Pricing::class, 'service_id', 'id'); } diff --git a/app/Models/Shared.php b/app/Models/Shared.php index c5b116b..953e433 100644 --- a/app/Models/Shared.php +++ b/app/Models/Shared.php @@ -36,7 +36,12 @@ class Shared extends Model public static function allSharedHosting() {//All shared hosting and relationships (no using joins) return Cache::remember("all_shared", now()->addMonth(1), function () { - return Shared::with(['location', 'provider', 'price', 'ips', 'labels'])->get(); + $query = Shared::with(['location', 'provider', 'price', 'ips', 'labels']); + if (in_array(Session::get('sort_on'), [3, 4, 5, 6], true)) { + $options = Settings::orderByProcess(Session::get('sort_on')); + $query->orderBy(Pricing::select("pricings.$options[0]")->whereColumn("pricings.service_id", "shared_hosting.id"), $options[1]); + } + return $query->get(); }); } @@ -65,9 +70,6 @@ class Shared extends Model public function price() { - if (in_array(Session::get('sort_on'), [3, 4, 5, 6], true)) { - return $this->hasOne(Pricing::class, 'service_id', 'id')->orderBy(Settings::orderByProcess(Session::get('sort_on'))[0], Settings::orderByProcess(Session::get('sort_on'))[1]); - } return $this->hasOne(Pricing::class, 'service_id', 'id'); }