Added Shows, ActionFoto's and Attraction Status
This commit is contained in:
parent
b105bd7db7
commit
ad320963fc
30 changed files with 1190 additions and 503 deletions
52
app/Color/MinecraftColor.php
Normal file
52
app/Color/MinecraftColor.php
Normal file
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
namespace App\Color;
|
||||
|
||||
class MinecraftColor {
|
||||
|
||||
private static $array = [
|
||||
"&0" => "#333",
|
||||
"&1" => "#2980b9",
|
||||
"&2" => "#27ae60",
|
||||
"&3" => "#01a3a4",
|
||||
"&4" => "#c0392b",
|
||||
"&5" => "#8e44ad",
|
||||
"&6" => "#f39c12",
|
||||
"&7" => "#95a5a6",
|
||||
"&8" => "#7f8c8d",
|
||||
"&9" => "#3498db",
|
||||
"&a" => "#2ecc71",
|
||||
"&b" => "#00d2d3",
|
||||
"&c" => "#e74c3c",
|
||||
"&d" => "#f368e0",
|
||||
"&e" => "#f1c40f",
|
||||
"&f" => "#bdc3c7"
|
||||
];
|
||||
|
||||
private static $none = [
|
||||
"&l", "&m", "&n", "&o", "&r",
|
||||
];
|
||||
|
||||
public static function color($text) {
|
||||
foreach(self::$array as $key => $value) {
|
||||
$str = str_replace($key, $value, $text);
|
||||
if($str !== $text) {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public static function stripColor($text) {
|
||||
foreach(self::$array as $key => $value) {
|
||||
$text = str_replace($key, "", $text);
|
||||
}
|
||||
|
||||
foreach(self::$none as $key) {
|
||||
$text = str_replace($key, "", $text);
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
}
|
|
@ -2,12 +2,8 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Order;
|
||||
use App\OrderedProject;
|
||||
use App\Project;
|
||||
use App\Status;
|
||||
use App\Utils\Numbers;
|
||||
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class HomeController extends Controller
|
||||
|
@ -34,6 +30,21 @@ class HomeController extends Controller
|
|||
]);
|
||||
}
|
||||
|
||||
public function status()
|
||||
{
|
||||
return view('status');
|
||||
}
|
||||
|
||||
public function photo() {
|
||||
$photos = DB::table('actionfotos')
|
||||
->join('attraction', 'attraction.id', '=', 'actionfotos.ride')
|
||||
->where('actionfotos.uuid', '=', Auth::user()->uuid)
|
||||
->select('actionfotos.base64')
|
||||
->get()->all();
|
||||
|
||||
return view('photo', [
|
||||
'photos' => $photos
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,12 +3,6 @@
|
|||
namespace App\Http\Controllers\Panel;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Order;
|
||||
use App\OrderedProject;
|
||||
use App\Project;
|
||||
use App\Status;
|
||||
use App\Utils\Numbers;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
|
@ -34,6 +28,4 @@ class HomeController extends Controller
|
|||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Panel;
|
||||
namespace App\Http\Controllers\Profile;
|
||||
|
||||
use App\ChangeEmail;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
@ -32,7 +32,7 @@ class ChangeController extends Controller
|
|||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('change');
|
||||
return view('profile.change');
|
||||
}
|
||||
|
||||
public function changePassword(Request $request) {
|
|
@ -1,11 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Panel;
|
||||
namespace App\Http\Controllers\Profile;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AccountController extends Controller
|
||||
class HomeController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
|
@ -20,11 +19,13 @@ class AccountController extends Controller
|
|||
/**
|
||||
* Show the application dashboard.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\Support\Renderable
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('account');
|
||||
return view('profile.home');
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Panel;
|
||||
namespace App\Http\Controllers\Profile;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Session;
|
||||
|
@ -25,7 +25,7 @@ class SecurityController extends Controller
|
|||
*
|
||||
* @param Request $request
|
||||
* @param int $page
|
||||
* @return \Illuminate\Contracts\Support\Renderable
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @throws \PragmaRX\Google2FA\Exceptions\IncompatibleWithGoogleAuthenticatorException
|
||||
* @throws \PragmaRX\Google2FA\Exceptions\InvalidCharactersException
|
||||
*/
|
||||
|
@ -36,7 +36,7 @@ class SecurityController extends Controller
|
|||
$pages = Session::where('user_id', Auth::id())->count();
|
||||
$pages = (int) ceil($pages/10);
|
||||
if($page > $pages)
|
||||
return redirect()->route('security', ['page' => $pages]);
|
||||
return redirect()->route('profile.security', ['page' => $pages]);
|
||||
|
||||
$sessions = Session::where('user_id', Auth::id())->where('id', '!=', session()->getId())->skip(($page - 1)*10)->take(($page != 1 ? 10 : 9))->orderBy('last_activity', 'desc')->get();
|
||||
$array = ['TFA' => $tfa, 'pages' => $pages, 'page' => $page, 'sessions' => $sessions, 'agent' => new Agent()];
|
||||
|
@ -58,19 +58,19 @@ class SecurityController extends Controller
|
|||
);
|
||||
|
||||
$array['QRCode'] = $QR;
|
||||
return view('security')->with($array);
|
||||
return view('profile.security')->with($array);
|
||||
}
|
||||
|
||||
return view('security')->with($array);
|
||||
return view('profile.security')->with($array);
|
||||
}
|
||||
|
||||
public function session($id)
|
||||
{
|
||||
if(session()->getId() === $id)
|
||||
return redirect()->route('security');
|
||||
return redirect()->route('profile.security');
|
||||
|
||||
Session::where(['id' => $id, 'user_id' => Auth::id()])->forceDelete();
|
||||
return redirect()->route('security');
|
||||
return redirect()->route('profile.security');
|
||||
}
|
||||
|
||||
}
|
54
app/Http/Controllers/RidecountController.php
Normal file
54
app/Http/Controllers/RidecountController.php
Normal file
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class RidecountController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware(['auth', 'verified', '2fa']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the application dashboard.
|
||||
*
|
||||
* @param $attraction_id
|
||||
* @return \Illuminate\Contracts\Support\Renderable
|
||||
*/
|
||||
public function index($attraction_id)
|
||||
{
|
||||
$name = DB::table('attraction')->select('name')->where('id', '=', $attraction_id)->first()->name;
|
||||
$top10 = DB::table(DB::raw('ridecount, (SELECT @row_number:=0) AS t'))->select('uuid', DB::raw('SUM(`count`) AS `count`'), DB::raw('(@row_number:=@row_number + 1) AS `num`'))
|
||||
->where('attractionId', '=', $attraction_id)
|
||||
->whereRaw('YEARWEEK(date, 1) = YEARWEEK(CURDATE(), 1)')
|
||||
->groupBy('uuid')
|
||||
->orderByDesc('count')
|
||||
->take(10)->get()->all();
|
||||
|
||||
$personal = DB::table('ridecount')
|
||||
->where('attractionId', '=', $attraction_id)
|
||||
->where('uuid', '=', Auth::user()->uuid)
|
||||
->sum('count');
|
||||
|
||||
$total = DB::table('ridecount')
|
||||
->where('attractionId', '=', $attraction_id)
|
||||
->sum('count');
|
||||
|
||||
return view('ridecount')->with([
|
||||
'name' => $name,
|
||||
'top10' => $top10,
|
||||
'personal' => $personal,
|
||||
'total' => $total
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
125
app/Http/Controllers/ShowController.php
Normal file
125
app/Http/Controllers/ShowController.php
Normal file
|
@ -0,0 +1,125 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Show;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ShowController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware(['auth', 'verified', '2fa']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the application dashboard.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Support\Renderable
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$shows = Show::join('show_dates', 'show_dates.show_id', '=', 'shows.id')
|
||||
->whereRaw('`show_dates`.`date` > CURDATE()')
|
||||
->select('shows.*')->get()->all();
|
||||
|
||||
$data = [];
|
||||
foreach($shows as $show)
|
||||
if(!empty($show->getShowDates(Auth::user()->uuid)))
|
||||
array_push($data, $show);
|
||||
|
||||
return view('show')->with([
|
||||
'shows' => $shows
|
||||
]);
|
||||
}
|
||||
|
||||
public function order($show_id) {
|
||||
$show = Show::join('show_dates', 'show_dates.show_id', '=', 'shows.id')->select('shows.*')->where('shows.id', '=', $show_id)->firstOrFail();
|
||||
$dates = $show->getShowDates(Auth::user()->uuid);
|
||||
|
||||
return view('order')->with([
|
||||
'show' => $show,
|
||||
'dates' => $dates
|
||||
]);
|
||||
}
|
||||
|
||||
public function makeOrder(Request $request) {
|
||||
if(!$request->has('id')) {
|
||||
session()->flash('error', 'Incorrect form data');
|
||||
return Redirect::back();
|
||||
}
|
||||
|
||||
$show = Show::find($request->get('id'));
|
||||
if(empty($show)) {
|
||||
session()->flash('error', 'Incorrect form data');
|
||||
return Redirect::back();
|
||||
}
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'id' => ['required', 'numeric'],
|
||||
'date' => ['required', 'date']
|
||||
]);
|
||||
|
||||
if(!$validator->passes()) {
|
||||
session()->flash('error', 'Incorrect show date');
|
||||
return Redirect::back();
|
||||
}
|
||||
|
||||
$data = DB::table('show_dates')
|
||||
->leftJoin('seats', 'seats.date', '=','show_dates.date')
|
||||
->where('show_dates.date', '=', $request->get('date'))
|
||||
->where('show_dates.show_id', '=', $show->id)
|
||||
->select('show_dates.date', DB::raw('COUNT(`seats`.`id`) AS `filled_seats`'), DB::raw('GROUP_CONCAT(`seats`.`uuid`) AS `uuids`'), DB::raw('GROUP_CONCAT(`seats`.`seat`) AS `used_seats`'))
|
||||
->groupBy('show_dates.date')
|
||||
->first();
|
||||
|
||||
if(empty($data)) {
|
||||
session()->flash('error', 'Incorrect show date');
|
||||
return Redirect::back();
|
||||
}
|
||||
|
||||
$time = strtotime($request->get('date'));
|
||||
if(strpos($data->uuids, Auth::user()->uuid) !== false) {
|
||||
session()->flash('error', 'You already booked the show on '.date('d-m-Y', $time).' at '.date('H:m', $time));
|
||||
return Redirect::back();
|
||||
}
|
||||
|
||||
if($data->filled_seats >= $show->seats) {
|
||||
session()->flash('error', 'This show is already fully booked on '.date('d-m-Y', $time).' at '.date('H:m', $time));
|
||||
return Redirect::back();
|
||||
}
|
||||
|
||||
$array = [];
|
||||
$seats = explode(',', $data->used_seats);
|
||||
for($i = 1; $i <= $show->seats; $i++)
|
||||
if(!in_array($i, $seats))
|
||||
array_push($array, $i);
|
||||
|
||||
$result = DB::table('seats')->insert([
|
||||
'uuid' => Auth::user()->uuid,
|
||||
'show_id' => $show->id,
|
||||
'seat' => $array[array_rand($array)],
|
||||
'voucher' => Str::random(8),
|
||||
'date' => $request->date
|
||||
]);
|
||||
|
||||
if(empty($result)) {
|
||||
session()->flash('error', 'Unable to book show on '.date('d-m-Y', $time).' at '.date('H:m', $time));
|
||||
return Redirect::back();
|
||||
}
|
||||
|
||||
session()->flash('success', 'Successfully reserved seat for show on '.date('d-m-Y', $time).' at '.date('H:m', $time));
|
||||
return Redirect::back();
|
||||
}
|
||||
|
||||
}
|
55
app/Show.php
Normal file
55
app/Show.php
Normal file
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class Show extends Model
|
||||
{
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'shows';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'title', 'description', 'price', 'vault_price', 'image', 'seats'
|
||||
];
|
||||
|
||||
private $data = null;
|
||||
public function getShowDates($uuid = null) {
|
||||
if($this->data !== null)
|
||||
return $this->data;
|
||||
|
||||
$data = DB::table('show_dates')
|
||||
->leftJoin('seats', 'seats.date', '=','show_dates.date')
|
||||
->havingRaw('COUNT(`seats`.`id`) < '.$this->seats)
|
||||
->whereRaw('`show_dates`.`date` > CURDATE()')
|
||||
->where('show_dates.show_id', '=', $this->id)
|
||||
->select('show_dates.date', DB::raw('COUNT(`seats`.`id`) AS `filled_seats`'))
|
||||
->groupBy('show_dates.date');
|
||||
|
||||
if($uuid !== null)
|
||||
$data = $data->where('seats.uuid', '!=', $uuid);
|
||||
|
||||
$data = $data->get()->all();
|
||||
$dates = [];
|
||||
foreach ($data as $row)
|
||||
array_push($dates, [
|
||||
'date' => $row->date,
|
||||
'free_seats' => $this->seats - $row->filled_seats
|
||||
]);
|
||||
|
||||
$this->data = $dates;
|
||||
return $dates;
|
||||
}
|
||||
|
||||
}
|
44
app/Status.php
Normal file
44
app/Status.php
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class Status {
|
||||
|
||||
private static $data = null;
|
||||
public static function loadData() {
|
||||
if(self::$data !== null)
|
||||
return self::$data;
|
||||
|
||||
$regions = DB::table('region')->get()->all();
|
||||
$attractions = DB::table('attraction')->select(['id', 'name', 'status', 'region_id'])->where('status', '!=', 'GLOBAL')->get()->all();
|
||||
$statuses = DB::table('status')->get()->all(); //TODO
|
||||
|
||||
$data = [];
|
||||
foreach($regions as $region) {
|
||||
$region->attractions = [];
|
||||
$data[$region->id] = $region;
|
||||
}
|
||||
|
||||
$status = [];
|
||||
foreach ($statuses as $stat)
|
||||
$status[$stat->statusId] = $stat->statusName;
|
||||
|
||||
foreach ($attractions as $attraction) {
|
||||
$region_id = $attraction->region_id;
|
||||
$attraction->status = $status[$attraction->status];
|
||||
if(array_key_exists($region_id, $data))
|
||||
array_push($data[$region_id]->attractions, $attraction);
|
||||
}
|
||||
|
||||
$temp = $data;
|
||||
$data = [];
|
||||
foreach ($temp as $key => $value)
|
||||
if(!empty($value->attractions))
|
||||
array_push($data, $value);
|
||||
|
||||
self::$data = $data;
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
31
app/User.php
31
app/User.php
|
@ -51,6 +51,37 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||
return $username;
|
||||
}
|
||||
|
||||
private $shows = null;
|
||||
public function hasShows() {
|
||||
if($this->shows !== null)
|
||||
return true;
|
||||
|
||||
$shows = Show::join('seats', 'seats.show_id', '=', 'shows.id')
|
||||
->select([
|
||||
'shows.title', 'shows.description', 'shows.image', 'seats.*'
|
||||
])
|
||||
->where('seats.uuid', '=', $this->uuid)
|
||||
->where('seats.date', '>', 'CURRENT_TIMESTAMP()')
|
||||
->get()->all();
|
||||
$this->shows = $shows;
|
||||
return !empty($shows);
|
||||
}
|
||||
|
||||
public function getShows() {
|
||||
if($this->shows !== null)
|
||||
return $this->shows;
|
||||
|
||||
$shows = Show::join('seats', 'seats.show_id', '=', 'shows.id')
|
||||
->select([
|
||||
'shows.title', 'shows.description', 'shows.image', 'seats.*'
|
||||
])
|
||||
->where('seats.uuid', '=', $this->uuid)
|
||||
->where('seats.date', '>', 'CURRENT_TIMESTAMP()')
|
||||
->get()->all();
|
||||
$this->shows = $shows;
|
||||
return $shows;
|
||||
}
|
||||
|
||||
public function photo() {
|
||||
return 'https://crafatar.com/avatars/'.$this->uuid.'?overlay';
|
||||
}
|
||||
|
|
Reference in a new issue