mega-commit: migrations, controllers, models, etc.
This commit is contained in:
parent
9732135e90
commit
2c6745e812
70 changed files with 2124 additions and 400 deletions
58
app/Http/Controllers/Managing/CinemaController.php
Normal file
58
app/Http/Controllers/Managing/CinemaController.php
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Managing;
|
||||
|
||||
class CinemaController extends \App\Http\Controllers\Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
$this->middleware('atleast:employee');
|
||||
}
|
||||
|
||||
public function showAllCinemas()
|
||||
{
|
||||
return view('manage.cinemas.index', ['title' => "Manage Cinemas", 'cinemas' => \App\Models\Cinema::all()]);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$c = \App\Models\Cinema::findOrfail($id);
|
||||
return view('manage.cinemas.cinema', ['title' => "Manage Cinema", 'cinema' => $c, 'rooms' => $c->rooms]);
|
||||
}
|
||||
|
||||
public function createCinema()
|
||||
{
|
||||
return view('manage.cinemas.create', ['title' => "Create Cinema"]);
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
$cinema = new \App\Models\Cinema();
|
||||
$cinema->cinema_name = request('cinema_name');
|
||||
$cinema->address_id = request('address_id');
|
||||
$cinema->save();
|
||||
return redirect()->route('manage.cinemas');
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
return view('main.cinemas.cinema', ['title' => "Edit Cinema", 'cinema' => \App\Models\Cinema::findOrfail($id)]);
|
||||
}
|
||||
|
||||
public function update($id)
|
||||
{
|
||||
$cinema = \App\Models\Cinema::findOrfail($id);
|
||||
$cinema->cinema_name = request('cinema_name');
|
||||
$cinema->address_id = request('address_id');
|
||||
$cinema->save();
|
||||
return redirect()->route('manage.cinemas');
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$cinema = \App\Models\Cinema::findOrfail($id);
|
||||
$cinema->delete();
|
||||
return redirect()->route('manage.cinemas');
|
||||
}
|
||||
}
|
52
app/Http/Controllers/Managing/GenreController.php
Normal file
52
app/Http/Controllers/Managing/GenreController.php
Normal file
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Managing;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class GenreController extends Controller
|
||||
{
|
||||
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('atleast:employee');
|
||||
}
|
||||
|
||||
public function showAllGenres() {
|
||||
return view('manage.genres.index', ['title' => "Manage Genres", 'genres' => \App\Models\Genre::all()]);
|
||||
}
|
||||
|
||||
public function edit($id) {
|
||||
$g = \App\Models\Genre::findOrfail($id);
|
||||
return view('manage.genres.genre', ['title' => "Manage Genre", 'genre' => $g, 'movies' => $g->movies]);
|
||||
}
|
||||
|
||||
public function createGenre() {
|
||||
return view('manage.genres.create', ['title' => "Create Genre"]);
|
||||
}
|
||||
|
||||
public function store() {
|
||||
$genre = new \App\Models\Genre();
|
||||
$genre->genre_name = request('genre_name');
|
||||
$genre->save();
|
||||
return redirect()->route('manage.genres');
|
||||
}
|
||||
|
||||
public function show($id) {
|
||||
return view('main.genres.genre', ['title' => "Edit Genre", 'genre' => \App\Models\Genre::findOrfail($id)]);
|
||||
}
|
||||
|
||||
public function update($id) {
|
||||
$genre = \App\Models\Genre::findOrfail($id);
|
||||
$genre->genre_name = request('genre_name');
|
||||
$genre->save();
|
||||
return redirect()->route('manage.genres');
|
||||
}
|
||||
|
||||
public function destroy($id) {
|
||||
$genre = \App\Models\Genre::findOrfail($id);
|
||||
$genre->delete();
|
||||
return redirect()->route('manage.genres');
|
||||
}
|
||||
|
||||
}
|
67
app/Http/Controllers/Managing/MovieController.php
Normal file
67
app/Http/Controllers/Managing/MovieController.php
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Managing;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class MovieController extends Controller
|
||||
{
|
||||
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('atleast:employee');
|
||||
}
|
||||
|
||||
public function showAllMovies() {
|
||||
// has permission READ_MOVIES ?
|
||||
if(!Auth::user()->allowedTo('READ_MOVIES')) {
|
||||
abort(403);
|
||||
}
|
||||
return view('manage.movies.index', ['title' => "Manage Movies", 'movies' => \App\Models\Movie::all()]);
|
||||
}
|
||||
|
||||
public function edit($id) {
|
||||
$m = \App\Models\Movie::findOrfail($id);
|
||||
return view('manage.movies.movie', ['title' => "Manage Movie", 'movie' => $m, 'showings' => $m->showings]);
|
||||
}
|
||||
|
||||
public function createMovie() {
|
||||
return view('manage.movies.create', ['title' => "Create Movie", 'genres' => \App\Models\Genre::all()]);
|
||||
}
|
||||
|
||||
public function store() {
|
||||
$movie = new \App\Models\Movie();
|
||||
$movie->movie_name = request('movie_name');
|
||||
$movie->movie_description = request('movie_description');
|
||||
$movie->movie_year = request('movie_year');
|
||||
$movie->movie_image = request('movie_image');
|
||||
// $movie->user_id = auth()->user()->user_id;
|
||||
$movie->genre_id = request('genre_id');
|
||||
$movie->save();
|
||||
return redirect()->route('manage.movies');
|
||||
}
|
||||
|
||||
public function show($id) {
|
||||
return view('main.movies.movie', ['title' => "Edit Movie", 'movie' => \App\Models\Movie::findOrfail($id)]);
|
||||
}
|
||||
|
||||
public function update($id) {
|
||||
$movie = \App\Models\Movie::findOrfail($id);
|
||||
$movie->movie_name = request('movie_name');
|
||||
$movie->movie_description = request('movie_description');
|
||||
$movie->movie_year = request('movie_year');
|
||||
$movie->movie_image = request('movie_image');
|
||||
// $movie->user_id = auth()->user()->user_id;
|
||||
$movie->genre_id = request('genre_id') !== null ? request('genre_id') : $movie->genre_id;
|
||||
$movie->save();
|
||||
return redirect()->route('manage.movies');
|
||||
}
|
||||
|
||||
public function destroy($id) {
|
||||
$movie = \App\Models\Movie::findOrfail($id);
|
||||
$movie->delete();
|
||||
return redirect()->route('manage.movies');
|
||||
}
|
||||
|
||||
}
|
|
@ -23,6 +23,6 @@ class UserDashController extends Controller
|
|||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('dash');
|
||||
return view('dash', ['title'=>"Dashboard", 'user'=>auth()->user()]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,6 +54,7 @@ class Kernel extends HttpKernel
|
|||
*/
|
||||
protected $routeMiddleware = [
|
||||
'auth' => \App\Http\Middleware\Authenticate::class,
|
||||
'atleast' => \App\Http\Middleware\AtleastRole::class,
|
||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||
'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
|
||||
|
|
18
app/Http/Middleware/AtleastRole.php
Normal file
18
app/Http/Middleware/AtleastRole.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
|
||||
class AtleastRole
|
||||
{
|
||||
|
||||
public function handle($request, Closure $next, $role)
|
||||
{
|
||||
if (!auth()->user()->atleast($role)) {
|
||||
return redirect()->route('home');
|
||||
}
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
}
|
|
@ -4,7 +4,7 @@ namespace App\Models;
|
|||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MovieGenre extends Model
|
||||
class Genre extends Model
|
||||
{
|
||||
protected $table = 'genres';
|
||||
protected $primaryKey = 'genre_id';
|
||||
|
@ -13,9 +13,14 @@ class MovieGenre extends Model
|
|||
'genre_name',
|
||||
];
|
||||
|
||||
public function findGenreByName($genre_name)
|
||||
{
|
||||
return Genre::where('genre_name', $genre_name)->first();
|
||||
}
|
||||
|
||||
public function movies()
|
||||
{
|
||||
return $this->belongsToMany(Movie::class, 'movie_genres', 'genre_id', 'movie_id');
|
||||
return $this->hasMany('App\Models\Movie', 'genre_id');
|
||||
}
|
||||
|
||||
}
|
|
@ -24,9 +24,14 @@ class Movie extends Model
|
|||
'updated_at',
|
||||
];
|
||||
|
||||
public static function findOrfail($id)
|
||||
{
|
||||
return Movie::where('movie_id', $id)->firstOrFail();
|
||||
}
|
||||
|
||||
public function genre()
|
||||
{
|
||||
return $this->belongsTo(MovieGenre::class, 'genre_id', 'genre_id');
|
||||
return $this->belongsTo(Genre::class, 'genre_id', 'genre_id');
|
||||
}
|
||||
|
||||
public function showings()
|
||||
|
|
|
@ -17,11 +17,9 @@ class Permission extends Model
|
|||
'updated_at',
|
||||
];
|
||||
|
||||
// Permissions are linked to users by the user_permissions table
|
||||
// User permissions are linked to users by the user_id and are valid per date
|
||||
public function users()
|
||||
{
|
||||
return $this->belongsToMany(User::class, 'user_permissions', 'permission_id', 'user_id');
|
||||
return $this->belongsToMany('App\Models\User', 'user_permissions', 'permission_id', 'user_id');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ class Room extends Model
|
|||
'room_rows',
|
||||
'room_columns',
|
||||
'user_id', // who added the room?
|
||||
'cinema_id',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
|
@ -22,10 +23,24 @@ class Room extends Model
|
|||
'updated_at',
|
||||
];
|
||||
|
||||
public static function find(int $room_id)
|
||||
{
|
||||
return self::where('room_id', $room_id)->first();
|
||||
}
|
||||
|
||||
public function showings()
|
||||
{
|
||||
return $this->hasMany(Showing::class, 'room_id', 'room_id');
|
||||
}
|
||||
|
||||
public function seats()
|
||||
{
|
||||
return $this->hasMany(Seat::class, 'room_id', 'room_id');
|
||||
}
|
||||
|
||||
public function cinema()
|
||||
{
|
||||
return $this->belongsTo(Cinema::class, 'cinema_id', 'cinema_id');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,5 +32,23 @@ class Seat extends Model
|
|||
return $this->belongsToMany(Order::class, 'order_seats', 'seat_id', 'order_id');
|
||||
}
|
||||
|
||||
public function tickets()
|
||||
{
|
||||
return $this->hasMany(Ticket::class, 'seat_id', 'seat_id');
|
||||
}
|
||||
|
||||
// isReserved(int showing_id) method
|
||||
// Looks at showing / order / ticket if it's reserved
|
||||
// Returns true if it is reserved, false if it isn't
|
||||
public function is_reserved(int $showing_id)
|
||||
{
|
||||
$tickets = $this->tickets()->where('showing_id', $showing_id)->get();
|
||||
foreach ($tickets as $ticket) {
|
||||
if ($ticket->order->order_status == 'pending' || $ticket->order->order_status == 'paid') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ class Showing extends Model
|
|||
protected $fillable = [
|
||||
'movie_id',
|
||||
'showing_start',
|
||||
'showing_end',
|
||||
'room_id', // which room is showing the movie?
|
||||
'user_id', // who added the showing?
|
||||
];
|
||||
|
@ -26,6 +25,16 @@ class Showing extends Model
|
|||
'updated_at',
|
||||
];
|
||||
|
||||
public static function findOrfail($id)
|
||||
{
|
||||
return Showing::where('showing_id', $id)->firstOrFail();
|
||||
}
|
||||
|
||||
public function room()
|
||||
{
|
||||
return $this->belongsTo(Room::class, 'room_id', 'room_id');
|
||||
}
|
||||
|
||||
public function movie()
|
||||
{
|
||||
return $this->belongsTo(Movie::class, 'movie_id', 'movie_id');
|
||||
|
|
|
@ -32,6 +32,4 @@ class Ticket extends Model
|
|||
return $this->belongsTo(Showing::class, 'showing_id', 'showing_id');
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -14,10 +14,6 @@ class User extends Authenticatable
|
|||
|
||||
protected $primaryKey = 'user_id';
|
||||
|
||||
// User can be a customer or an employee
|
||||
// If customer, then there'll be a customer_id in the users table
|
||||
// If employee, then there'll be an employee_id in the users table
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
|
@ -26,10 +22,8 @@ class User extends Authenticatable
|
|||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
'customer_id', // if this is filled, then this user is a customer
|
||||
'employee_id', // if this is filled, then this user is an employee
|
||||
// if both are filled, then this user is both a customer and an employee
|
||||
'role', // default, employee, manage
|
||||
'password'
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -53,5 +47,43 @@ class User extends Authenticatable
|
|||
'email_verified_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function permissions()
|
||||
{
|
||||
// get permissions for this user
|
||||
// note: permissions are linked to users by the user_permissions table
|
||||
// the permissions are in the permissions table
|
||||
// only return valid permissions
|
||||
return $this->belongsToMany('App\Models\Permission', 'user_permissions', 'user_id', 'permission_id')->where(function ($query) {
|
||||
$query->where('user_permission_start', '<=', now())->where(function ($query) {
|
||||
$query->where('user_permission_end', '>=', now())->orWhereNull('user_permission_end');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public function allowedTo($permission): bool
|
||||
{
|
||||
if($this->role === 'manage') {
|
||||
return true;
|
||||
}
|
||||
if ($this->permissions()->where('permission_name', $permission)->first()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function atleast($role): bool
|
||||
{
|
||||
$hierarchy = [
|
||||
'default' => 0,
|
||||
'employee' => 1,
|
||||
'manage' => 2
|
||||
];
|
||||
return $hierarchy[$this->role] >= $hierarchy[$role];
|
||||
}
|
||||
|
||||
public static function find($id)
|
||||
{
|
||||
return User::all()->where('user_id', $id)->first();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ class RouteServiceProvider extends ServiceProvider
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
public const HOME = '/home';
|
||||
public const HOME = '/dash';
|
||||
|
||||
/**
|
||||
* Define your route model bindings, pattern filters, and other route configuration.
|
||||
|
|
51
app/View/Components/SeatChooser.php
Normal file
51
app/View/Components/SeatChooser.php
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace App\View\Components;
|
||||
|
||||
use App\Models\Room;
|
||||
use Illuminate\View\Component;
|
||||
|
||||
class SeatChooser extends Component
|
||||
{
|
||||
|
||||
public int $room_id;
|
||||
public int $showing_id;
|
||||
public Room $room;
|
||||
|
||||
/**
|
||||
* Create a new component instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(int $room_id, int $showing_id)
|
||||
{
|
||||
$this->room_id = $room_id;
|
||||
$this->room = Room::find($room_id);
|
||||
$this->showing_id = $showing_id;
|
||||
}
|
||||
|
||||
public function matrixGenerate() {
|
||||
$matrix = [];
|
||||
for ($row = 1; $row <= $this->room->room_rows; $row++) {
|
||||
$matrix[$row] = [];
|
||||
for ($column = 1; $column <= $this->room->room_columns; $column++) {
|
||||
$matrix[$row][$column] = 0;
|
||||
}
|
||||
}
|
||||
return $matrix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View|\Closure|string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return view('components.seat-chooser', [
|
||||
'room' => $this->room,
|
||||
'seatmatrix' => $this->matrixGenerate(),
|
||||
'showing_id' => $this->showing_id,
|
||||
]);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue