Skip to content

Commit

Permalink
Updated order/sort by on index pages
Browse files Browse the repository at this point in the history
Updated order/sort by on index pages
As using the relationship for price related sorts does not work this method does
  • Loading branch information
cp6 committed Oct 20, 2022
1 parent eda9d1b commit beaf9af
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 23 deletions.
8 changes: 7 additions & 1 deletion app/Models/Domains.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Session;

class Domains extends Model
{
Expand All @@ -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();
});
}

Expand Down
10 changes: 6 additions & 4 deletions app/Models/Misc.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ protected static function boot()
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();
});
}

Expand All @@ -49,9 +54,6 @@ public static function misc(string $misc_id)

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');
}

Expand Down
10 changes: 6 additions & 4 deletions app/Models/Reseller.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ protected static function boot()
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();
});
}

Expand Down Expand Up @@ -65,9 +70,6 @@ public function provider()

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');
}

Expand Down
10 changes: 6 additions & 4 deletions app/Models/SeedBoxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ protected static function boot()
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();
});
}

Expand All @@ -60,9 +65,6 @@ public function provider()

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');
}

Expand Down
19 changes: 13 additions & 6 deletions app/Models/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ protected static function boot()
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();
});
}

Expand All @@ -58,8 +63,13 @@ public static function server(string $server_id)
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();
});
}

Expand Down Expand Up @@ -216,9 +226,6 @@ public function os()

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');
}

Expand Down
10 changes: 6 additions & 4 deletions app/Models/Shared.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ protected static function boot()
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();
});
}

Expand Down Expand Up @@ -65,9 +70,6 @@ public function provider()

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');
}

Expand Down

0 comments on commit beaf9af

Please sign in to comment.