megacommit
This commit is contained in:
		
							parent
							
								
									2451ab45cb
								
							
						
					
					
						commit
						34ed81516b
					
				
					 51 changed files with 1200 additions and 251 deletions
				
			
		
							
								
								
									
										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