megacommit
This commit is contained in:
parent
2451ab45cb
commit
34ed81516b
51 changed files with 1200 additions and 251 deletions
19
app/Http/Controllers/Main/CinemaController.php
Normal file
19
app/Http/Controllers/Main/CinemaController.php
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Main;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CinemaController extends Controller
|
||||
{
|
||||
public function showAllCinemas()
|
||||
{
|
||||
return view('main.cinemas.index', ['title' => "Cinemas", 'cinemas' => \App\Models\Cinema::all()]);
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
return view('main.cinemas.cinema', ['title' => "Cinema", 'cinema' => \App\Models\Cinema::findOrfail($id)]);
|
||||
}
|
||||
}
|
19
app/Http/Controllers/Main/GenreController.php
Normal file
19
app/Http/Controllers/Main/GenreController.php
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Main;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class GenreController extends Controller
|
||||
{
|
||||
public function show($id)
|
||||
{
|
||||
return view('main.genres.genre', ['title' => "Genre", 'genre' => \App\Models\Genre::findOrfail($id)]);
|
||||
}
|
||||
|
||||
public function showAllGenres()
|
||||
{
|
||||
return view('main.genres.index', ['title' => "Genres", 'genres' => \App\Models\Genre::all()]);
|
||||
}
|
||||
}
|
35
app/Http/Controllers/Main/MovieController.php
Normal file
35
app/Http/Controllers/Main/MovieController.php
Normal file
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Main;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class MovieController extends Controller
|
||||
{
|
||||
public function showAllMovies()
|
||||
{
|
||||
return view('main.movies.index', ['title' => "Movies", 'movies' => \App\Models\Movie::all(), 'genres' => \App\Models\Genre::all(), 'showings' => \App\Models\Showing::all()]);
|
||||
}
|
||||
|
||||
public function moviesNowShowing()
|
||||
{
|
||||
// map showings that are in the future to movies
|
||||
$showings = \App\Models\Showing::all()->filter(function ($showing) {
|
||||
return $showing->showing_start > now();
|
||||
});
|
||||
// $movies must be a collection of unique movies
|
||||
$movies = collect();
|
||||
foreach ($showings as $showing) {
|
||||
if (!$movies->contains($showing->movie)) {
|
||||
$movies->push($showing->movie);
|
||||
}
|
||||
}
|
||||
return view('main.movies.index', ['title' => "Movies Now Showing", 'movies' => $movies, 'genres' => \App\Models\Genre::all(), 'showings' => \App\Models\Showing::all()]);
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
return view('main.movies.movie', ['title' => "Movie", 'movie' => \App\Models\Movie::findOrfail($id)]);
|
||||
}
|
||||
}
|
24
app/Http/Controllers/Main/ShowingController.php
Normal file
24
app/Http/Controllers/Main/ShowingController.php
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Main;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ShowingController extends Controller
|
||||
{
|
||||
public function show($id)
|
||||
{
|
||||
return view('main.showings.showing', ['title' => "Showing", 'showing' => \App\Models\Showing::findOrfail($id)]);
|
||||
}
|
||||
|
||||
public function showAllShowings()
|
||||
{
|
||||
return view('main.showings.index', ['title' => "Showings", 'showings' => \App\Models\Showing::all()]);
|
||||
}
|
||||
|
||||
public function order($id)
|
||||
{
|
||||
return view('main.order', ['title' => "Order Tickets", 'showing' => \App\Models\Showing::findOrfail($id)]);
|
||||
}
|
||||
}
|
|
@ -8,12 +8,15 @@ class CinemaController extends \App\Http\Controllers\Controller
|
|||
{
|
||||
$this->middleware('auth');
|
||||
$this->middleware('atleast:employee');
|
||||
$this->middleware('permission:manage_cinemas')->only(['create', 'store', 'edit', 'update', 'destroy']);
|
||||
$this->middleware('permission:READ_CINEMAS')->only('index', 'show');
|
||||
$this->middleware('permission:CREATE_CINEMAS')->only('create', 'store');
|
||||
$this->middleware('permission:UPDATE_CINEMAS')->only('edit', 'update');
|
||||
$this->middleware('permission:DELETE_CINEMAS')->only('destroy');
|
||||
}
|
||||
|
||||
public function showAllCinemas()
|
||||
public function index()
|
||||
{
|
||||
return view('manage.cinemas.index', ['title' => "Manage Cinemas", 'cinemas' => \App\Models\Cinema::all()]);
|
||||
return view('manage.cinemas.index', ['title' => "Manage Cinemas", 'cinemas' => \App\Models\Cinema::all(), 'users' => \App\Models\User::all()]);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
|
|
|
@ -10,10 +10,13 @@ class GenreController extends Controller
|
|||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('atleast:employee');
|
||||
$this->middleware('permission:manage_genres')->only(['create', 'store', 'edit', 'update', 'destroy']);
|
||||
$this->middleware('permission:READ_GENRES')->only('index', 'show');
|
||||
$this->middleware('permission:CREATE_GENRES')->only('create', 'store');
|
||||
$this->middleware('permission:UPDATE_GENRES')->only('edit', 'update');
|
||||
$this->middleware('permission:DELETE_GENRES')->only('destroy');
|
||||
}
|
||||
|
||||
public function showAllGenres() {
|
||||
public function index() {
|
||||
return view('manage.genres.index', ['title' => "Manage Genres", 'genres' => \App\Models\Genre::all()]);
|
||||
}
|
||||
|
||||
|
|
|
@ -11,14 +11,13 @@ class MovieController extends Controller
|
|||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('atleast:employee');
|
||||
$this->middleware('permission:manage_movies')->only(['create', 'store', 'edit', 'update', 'destroy']);
|
||||
$this->middleware('permission:READ_MOVIES')->only('index', 'show');
|
||||
$this->middleware('permission:CREATE_MOVIES')->only('create', 'store');
|
||||
$this->middleware('permission:UPDATE_MOVIES')->only('edit', 'update');
|
||||
$this->middleware('permission:DELETE_MOVIES')->only('destroy');
|
||||
}
|
||||
|
||||
public function showAllMovies() {
|
||||
// has permission READ_MOVIES ?
|
||||
if(!Auth::user()->allowedTo('READ_MOVIES')) {
|
||||
abort(403);
|
||||
}
|
||||
public function index() {
|
||||
return view('manage.movies.index', ['title' => "Manage Movies", 'movies' => \App\Models\Movie::all()]);
|
||||
}
|
||||
|
||||
|
@ -37,6 +36,8 @@ class MovieController extends Controller
|
|||
$movie->movie_description = request('movie_description');
|
||||
$movie->movie_year = request('movie_year');
|
||||
$movie->movie_image = request('movie_image');
|
||||
$movie->movie_length = request('movie_length');
|
||||
$movie->movie_age_limit = request('movie_age_limit');
|
||||
// $movie->user_id = auth()->user()->user_id;
|
||||
$movie->genre_id = request('genre_id');
|
||||
$movie->save();
|
||||
|
|
66
app/Http/Controllers/Managing/ShowingsController.php
Normal file
66
app/Http/Controllers/Managing/ShowingsController.php
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Managing;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class ShowingsController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
$this->middleware('atleast:employee');
|
||||
$this->middleware('permission:READ_SHOWINGS')->only('index', 'show');
|
||||
$this->middleware('permission:CREATE_SHOWINGS')->only('create', 'store');
|
||||
$this->middleware('permission:UPDATE_SHOWINGS')->only('edit', 'update');
|
||||
$this->middleware('permission:DELETE_SHOWINGS')->only('destroy');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return view('manage.showings.index', ['title' => "Manage Showings", 'showings' => \App\Models\Showing::all()]);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$s = \App\Models\Showing::findOrfail($id);
|
||||
return view('manage.showings.showing', ['title' => "Manage Showing", 'showing' => $s, 'movies' => \App\Models\Movie::all(), 'rooms' => \App\Models\Room::all(), 'cinemas' => \App\Models\Cinema::all()]);
|
||||
}
|
||||
|
||||
public function createShowing()
|
||||
{
|
||||
return view('manage.showings.create', ['title' => "Create Showing", 'movies' => \App\Models\Movie::all(), 'rooms' => \App\Models\Room::all()]);
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
$showing = new \App\Models\Showing();
|
||||
$showing->movie_id = request('movie_id');
|
||||
$showing->room_id = request('room_id');
|
||||
$showing->start_time = request('start_time');
|
||||
$showing->save();
|
||||
return redirect()->route('manage.showings');
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
return view('main.showings.showing', ['title' => "Edit Showing", 'showing' => \App\Models\Showing::findOrfail($id)]);
|
||||
}
|
||||
|
||||
public function update($id)
|
||||
{
|
||||
$showing = \App\Models\Showing::findOrfail($id);
|
||||
$showing->movie_id = request('movie_id');
|
||||
$showing->room_id = request('room_id');
|
||||
$showing->showing_start = request('showing_start');
|
||||
$showing->save();
|
||||
return redirect()->route('manage.showings');
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$showing = \App\Models\Showing::findOrfail($id);
|
||||
$showing->delete();
|
||||
return redirect()->route('manage.showings');
|
||||
}
|
||||
}
|
81
app/Http/Controllers/Managing/UsersController.php
Normal file
81
app/Http/Controllers/Managing/UsersController.php
Normal file
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Managing;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class UsersController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
$this->middleware('atleast:manage');
|
||||
$this->middleware('permission:READ_USERS')->only('index', 'show');
|
||||
$this->middleware('permission:CREATE_USERS')->only('create', 'store');
|
||||
$this->middleware('permission:UPDATE_USERS')->only('edit', 'update');
|
||||
$this->middleware('permission:DELETE_USERS')->only('destroy');
|
||||
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return view('manage.users.index', ['title' => "Manage Users", 'users' => \App\Models\User::all()]);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('manage.users.create');
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
$user = new \App\Models\User();
|
||||
$user->name = request('name');
|
||||
$user->email = request('email');
|
||||
$user->password = request('password');
|
||||
$user->role = request('role');
|
||||
$user->save();
|
||||
|
||||
// user assignments (user_assignments.user_id, user_assignments.cinema_id)
|
||||
$cinemas = request('cinemas');
|
||||
if ($cinemas) {
|
||||
foreach ($cinemas as $cinema) {
|
||||
$user->cinemas()->attach($cinema);
|
||||
}
|
||||
}
|
||||
|
||||
return redirect()->route('manage.users');
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
return view('manage.users.user', ['user' => \App\Models\User::findOrfail($id)]);
|
||||
}
|
||||
|
||||
public function update($id)
|
||||
{
|
||||
$user = \App\Models\User::findOrfail($id);
|
||||
$user->name = request('name');
|
||||
$user->email = request('email');
|
||||
$user->password = request('password');
|
||||
$user->role = request('role');
|
||||
$user->save();
|
||||
|
||||
// user assignments (user_assignments.user_id, user_assignments.cinema_id)
|
||||
$cinemas = request('cinemas');
|
||||
if ($cinemas) {
|
||||
foreach ($cinemas as $cinema) {
|
||||
$user->cinemas()->attach($cinema);
|
||||
}
|
||||
}
|
||||
|
||||
return redirect()->route('manage.users');
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$user = \App\Models\User::findOrfail($id);
|
||||
$user->delete();
|
||||
return redirect()->route('manage.users');
|
||||
}
|
||||
}
|
|
@ -55,6 +55,7 @@ class Kernel extends HttpKernel
|
|||
protected $routeMiddleware = [
|
||||
'auth' => \App\Http\Middleware\Authenticate::class,
|
||||
'atleast' => \App\Http\Middleware\AtleastRole::class,
|
||||
'permission' => \App\Http\Middleware\Permission::class,
|
||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||
'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
|
||||
|
|
33
app/Http/Middleware/CinemaAccess.php
Normal file
33
app/Http/Middleware/CinemaAccess.php
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CinemaAccess
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
|
||||
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, $cinema_id)
|
||||
{
|
||||
// does the user have access to the cinema (or is admin)
|
||||
|
||||
if (auth()->user()->atleast('admin')) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
if (auth()->user()->cinemas->contains($cinema_id)) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
28
app/Http/Middleware/Permission.php
Normal file
28
app/Http/Middleware/Permission.php
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class Permission
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
|
||||
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, $permission)
|
||||
{
|
||||
// if user.role is admin, allow
|
||||
if ($request->user()->role == 'admin') {
|
||||
return $next($request);
|
||||
}
|
||||
if (auth()->user()->hasPermission($permission)) {
|
||||
return $next($request);
|
||||
}
|
||||
abort(403, "You need \"$permission\" permission");
|
||||
}
|
||||
}
|
53
app/Models/Cinema.php
Normal file
53
app/Models/Cinema.php
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Cinema extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'cinemas';
|
||||
protected $primaryKey = 'cinema_id';
|
||||
public $timestamps = false;
|
||||
protected $fillable = [
|
||||
'cinema_name',
|
||||
'address_id',
|
||||
'user_id', // who created this cinema
|
||||
'cinema_open',
|
||||
'cinema_close',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
public function address()
|
||||
{
|
||||
return $this->belongsTo(Address::class, 'address_id', 'address_id');
|
||||
}
|
||||
|
||||
public function rooms()
|
||||
{
|
||||
return $this->hasMany(Room::class, 'cinema_id', 'cinema_id');
|
||||
}
|
||||
|
||||
public function showings()
|
||||
{
|
||||
return $this->hasManyThrough(Showing::class, Room::class, 'cinema_id', 'room_id', 'cinema_id', 'room_id');
|
||||
}
|
||||
|
||||
public function find($id)
|
||||
{
|
||||
return $this->where('cinema_id', $id)->first();
|
||||
}
|
||||
|
||||
public function users() {
|
||||
//users associated
|
||||
return $this->belongsToMany('App\Models\User', 'user_assignments', 'cinema_id', 'user_id');
|
||||
}
|
||||
|
||||
}
|
|
@ -22,4 +22,16 @@ class Permission extends Model
|
|||
return $this->belongsToMany('App\Models\User', 'user_permissions', 'permission_id', 'user_id');
|
||||
}
|
||||
|
||||
public function find(mixed $permission_id)
|
||||
{
|
||||
return $this->where('permission_id', $permission_id)->first();
|
||||
}
|
||||
|
||||
public function create(array $array)
|
||||
{
|
||||
$this->permission_name = $array['permission_name'];
|
||||
$this->save();
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -41,12 +41,17 @@ class Showing extends Model
|
|||
return $this->belongsTo(Movie::class, 'movie_id', 'movie_id');
|
||||
}
|
||||
|
||||
public function prices()
|
||||
{
|
||||
return $this->hasMany(Price::class, 'showing_id', 'showing_id');
|
||||
}
|
||||
|
||||
public function nowPlaying()
|
||||
{
|
||||
return $this->where('showing_start', '>=', now())->get();
|
||||
}
|
||||
|
||||
public function end_time() {
|
||||
public function showing_end() {
|
||||
$date = new Carbon($this->showing_start);
|
||||
$date->addMinutes($this->movie->movie_length);
|
||||
return $date;
|
||||
|
|
|
@ -54,14 +54,17 @@ class User extends Authenticatable
|
|||
// 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');
|
||||
});
|
||||
// $query->where('user_permission_start', '<=', now())->where(function ($query) {
|
||||
// $query->where('user_permission_end', '>=', now())->orWhereNull('user_permission_end');
|
||||
// });
|
||||
});
|
||||
}
|
||||
|
||||
public function allowedTo($permission): bool
|
||||
public function hasPermission($permission): bool
|
||||
{
|
||||
if ($this->role == 'admin') {
|
||||
return true;
|
||||
}
|
||||
if ($this->permissions()->where('permission_name', $permission)->first()) {
|
||||
return true;
|
||||
}
|
||||
|
@ -73,7 +76,8 @@ class User extends Authenticatable
|
|||
$hierarchy = [
|
||||
'default' => 0,
|
||||
'employee' => 1,
|
||||
'manage' => 2
|
||||
'manage' => 2,
|
||||
'admin' => 3
|
||||
];
|
||||
return $hierarchy[$this->role] >= $hierarchy[$role];
|
||||
}
|
||||
|
@ -83,4 +87,21 @@ class User extends Authenticatable
|
|||
return User::all()->where('user_id', $id)->first();
|
||||
}
|
||||
|
||||
public function cinemas()
|
||||
{
|
||||
// check user_assignments table for all assignments for this user
|
||||
if ($this->atleast('admin')) {
|
||||
// if user is a manager or admin, return all cinemas
|
||||
return Cinema::all();
|
||||
} else {
|
||||
// if user is an employee, return only the cinemas they are assigned to
|
||||
return $this->belongsToMany('App\Models\Cinema', 'user_assignments', 'user_id', 'cinema_id')->get();
|
||||
}
|
||||
}
|
||||
|
||||
public function orders()
|
||||
{
|
||||
return $this->hasMany('App\Models\Order', 'user_id', 'user_id');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue