2022-03-05 16:02:12 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Models\Server;
|
|
|
|
use App\Models\Yabs;
|
|
|
|
use Illuminate\Http\Request;
|
2022-03-05 16:58:25 +01:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
2022-03-05 16:02:12 +01:00
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
class YabsController extends Controller
|
|
|
|
{
|
|
|
|
public function index()
|
|
|
|
{
|
2022-11-05 02:48:07 +01:00
|
|
|
return view('yabs.index', ['yabs' => Yabs::allYabs()]);
|
2022-03-05 16:02:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function show(Yabs $yab)
|
|
|
|
{
|
2022-11-05 02:48:07 +01:00
|
|
|
return view('yabs.show', ['yabs' => Yabs::yabs($yab->id)]);
|
2022-03-05 16:02:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function destroy(Yabs $yab)
|
|
|
|
{
|
2022-11-09 05:18:25 +01:00
|
|
|
if ($yab->delete()) {
|
|
|
|
if (Server::serverYabsAmount($yab->server_id) === 0) {
|
|
|
|
DB::table('servers')
|
|
|
|
->where('id', $yab->server_id)
|
|
|
|
->update(['has_yabs' => 0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
Cache::forget('all_yabs');
|
|
|
|
Cache::forget("yabs.{$yab->id}");
|
|
|
|
|
|
|
|
return redirect()->route('yabs.index')
|
|
|
|
->with('success', 'YABS was deleted Successfully.');
|
2022-07-18 06:27:11 +02:00
|
|
|
}
|
|
|
|
|
2022-03-05 16:02:12 +01:00
|
|
|
return redirect()->route('yabs.index')
|
2022-11-09 05:18:25 +01:00
|
|
|
->with('error', 'YABS was not deleted.');
|
2022-03-05 16:02:12 +01:00
|
|
|
}
|
2022-07-18 06:27:11 +02:00
|
|
|
|
|
|
|
public function chooseYabsCompare()
|
|
|
|
{
|
|
|
|
$all_yabs = Yabs::allYabs();
|
2022-09-22 04:24:47 +02:00
|
|
|
|
2022-11-09 05:18:25 +01:00
|
|
|
if (isset($all_yabs[1])) {
|
2022-09-22 04:24:47 +02:00
|
|
|
return view('yabs.choose-compare', compact('all_yabs'));
|
|
|
|
}
|
|
|
|
|
|
|
|
return redirect()->route('yabs.index')
|
|
|
|
->with('error', 'You need atleast 2 YABS to do a compare');
|
2022-07-18 06:27:11 +02:00
|
|
|
}
|
|
|
|
|
2022-10-13 05:21:27 +02:00
|
|
|
public function compareYabs(string $yabs1, string $yabs2)
|
2022-07-18 06:27:11 +02:00
|
|
|
{
|
|
|
|
$yabs1_data = Yabs::yabs($yabs1);
|
|
|
|
|
2022-11-05 02:48:07 +01:00
|
|
|
if (is_null($yabs1_data)) {
|
2022-10-13 05:21:27 +02:00
|
|
|
abort(404);
|
2022-07-18 06:27:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$yabs2_data = Yabs::yabs($yabs2);
|
|
|
|
|
2022-11-05 02:48:07 +01:00
|
|
|
if (is_null($yabs2_data)) {
|
2022-10-13 05:21:27 +02:00
|
|
|
abort(404);
|
2022-07-18 06:27:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return view('yabs.compare', compact('yabs1_data', 'yabs2_data'));
|
|
|
|
}
|
|
|
|
|
2022-07-19 16:20:15 +02:00
|
|
|
public function yabsToJson(Yabs $yab): array
|
|
|
|
{
|
|
|
|
$all_yabs = Yabs::yabs($yab->id)[0];
|
|
|
|
return Yabs::buildYabsArray($all_yabs);
|
|
|
|
}
|
|
|
|
|
2022-03-05 16:02:12 +01:00
|
|
|
}
|