addMonth(1), function () { return Server::with(['location', 'provider', 'os', 'price', 'ips', 'yabs', 'yabs.disk_speed', 'yabs.network_speed', 'labels', 'labels.label'])->get(); }); } public static function server(string $server_id) {//Single server and relationships (no using joins) return Cache::remember("server.$server_id", now()->addMonth(1), function () use ($server_id) { return Server::where('id', $server_id) ->with(['location', 'provider', 'os', 'price', 'ips', 'yabs', 'yabs.disk_speed', 'yabs.network_speed', 'labels', 'labels.label'])->first(); }); } 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', 'price', 'ips', 'yabs', 'yabs.disk_speed', 'yabs.network_speed', 'labels', 'labels.label']) ->get(); }); } public static function allNonActiveServers() {//All NON ACTIVE servers and relationships replaces nonActiveServersDataIndexPage() return Cache::remember("non_active_servers", now()->addMonth(1), function () { return Server::where('active', '=', 0) ->with(['location', 'provider', 'os', 'price', 'ips', 'yabs', 'yabs.disk_speed', 'yabs.network_speed', 'labels', 'labels.label']) ->get(); }); } public static function allPublicServers() {//server data that will be publicly viewable (values in settings) return Cache::remember("public_server_data", now()->addMonth(1), function () { return Server::where('show_public', '=', 1) ->with(['location', 'provider', 'os', 'price', 'ips', 'yabs', 'yabs.disk_speed', 'yabs.network_speed', 'labels', 'labels.label']) ->get(); }); } public static function serviceServerType(int $type, bool $short = true): string { if ($type === 1) { return "KVM"; } elseif ($type === 2) { return "OVZ"; } elseif ($type === 3) { if (!$short) { return "Dedicated"; } return "DEDI"; } elseif ($type === 4) { return "LXC"; } elseif ($type === 6) { return "VMware"; } elseif ($type === 7) { return "NAT"; } else { if (!$short) { return "Semi-dedicated"; } return "SEMI-DEDI"; } } public static function osIntToIcon(int $os, string $os_name) { if ($os === 1) {//None return ""; } else if ($os <= 3) {//Centos return ""; } elseif ($os > 7 && $os <= 11) {//Debain return ""; } elseif ($os > 12 && $os < 15) {//Fedora return ""; } elseif ($os > 14 && $os < 18) {//FreeBSD return ""; } elseif ($os > 17 && $os < 21) {//OpenBSD return ""; } elseif ($os > 25 && $os < 32) {//Ubuntu return ""; } elseif ($os > 32 && $os < 38) {//Windows return ""; } else {//OTHER ISO CUSTOM etc return ""; } } public static function osIdAsString($os) { if ($os === "0") { return "None"; } elseif ($os === "1") { return "CentOS 7"; } elseif ($os === "2") { return "CentOS 8"; } elseif ($os === "3") { return "CentOS"; } elseif ($os === "4") { return "Debian 9"; } elseif ($os === "5") { return "Debian 10"; } elseif ($os === "6") { return "Debian"; } elseif ($os === "7") { return "Fedora 32"; } elseif ($os === "8") { return "Fedora 33"; } elseif ($os === "9") { return "Fedora"; } elseif ($os === "10") { return "FreeBSD 11.4"; } elseif ($os === "11") { return "FreeBSD 12.1"; } elseif ($os === "12") { return "FreeBSD"; } elseif ($os === "13") { return "OpenBSD 6.7"; } elseif ($os === "14") { return "OpenBSD 6.8"; } elseif ($os === "15") { return "OpenBSD"; } elseif ($os == "16") { return "Ubuntu 16.04"; } elseif ($os === "17") { return "Ubuntu 18.04"; } elseif ($os === "18") { return "Ubuntu 20.04"; } elseif ($os === "19") { return "Ubuntu 20.10"; } elseif ($os === "20") { return "Ubuntu"; } elseif ($os === "21") { return "Windows Server 2008"; } elseif ($os === "22") { return "Windows Server 2012"; } elseif ($os === "23") { return "Windows Server 2016"; } elseif ($os === "24") { return "Windows Server 2019"; } elseif ($os === "25") { return "Windows 10"; } elseif ($os === "26") { return "Custom"; } elseif ($os === "27") { return "Other"; } else { return "Unknown"; } } public static function tableRowCompare(string $val1, string $val2, string $value_type = '', bool $is_int = true) { //+303MBps $str = '' . $value_type . ''; if ($is_int) { $val1 = (int)$val1; $val2 = (int)$val2; } if ($val1 > $val2) {//val1 is greater than val2 $result = '+' . ($val1 - $val2); if (!empty($value_type)) { $result = '+' . ($val1 - $val2) . $value_append; } $str .= 'plus-td">' . $result . ''; } elseif ($val1 < $val2) {//val1 is less than val2 $result = '-' . ($val2 - $val1); if (!empty($value_type)) { $result = '-' . ($val2 - $val1) . $value_append; } $str .= 'neg-td">' . $result . ''; } else {//Equal $result = 0; if (!empty($value_type)) { $result = '0' . $value_append; } $str .= 'equal-td">' . $result . ''; } return $str; } public static function serverRelatedCacheForget(): void { Cache::forget('all_servers');//All servers Cache::forget('services_count');//Main page services_count cache Cache::forget('due_soon');//Main page due_soon cache Cache::forget('recently_added');//Main page recently_added cache Cache::forget('all_active_servers');//all active servers cache Cache::forget('non_active_servers');//all non active servers cache Cache::forget('servers_summary');//servers summary cache Cache::forget('public_server_data');//public servers Cache::forget('all_pricing');//All pricing Cache::forget('services_count_all'); Cache::forget('pricing_breakdown'); } public static function serverSpecificCacheForget(string $server_id): void { Cache::forget("server.$server_id");//Will replace one below Cache::forget("service_pricing.$server_id");//Pricing } public static function serverYabsAmount(string $server_id): int {//Returns amount of YABs a server has return DB::table('yabs') ->where('server_id', '=', $server_id) ->get()->count(); } public function yabs() { return $this->hasMany(Yabs::class, 'server_id', 'id'); } public function ips() { return $this->hasMany(IPs::class, 'service_id', 'id'); } public function location() { return $this->hasOne(Locations::class, 'id', 'location_id'); } public function provider() { return $this->hasOne(Providers::class, 'id', 'provider_id'); } public function os() { return $this->hasOne(OS::class, 'id', 'os_id'); } public function price() { return $this->hasOne(Pricing::class, 'service_id', 'id'); } public function labels() { return $this->hasMany(LabelsAssigned::class, 'service_id', 'id'); } }