48 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			48 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
namespace App\Models;
 | 
						|
 | 
						|
use Illuminate\Database\Eloquent\Model;
 | 
						|
use Illuminate\Database\Eloquent\Relations\HasMany;
 | 
						|
use Illuminate\Database\Eloquent\Relations\HasOne;
 | 
						|
 | 
						|
class Calendar extends Model
 | 
						|
{
 | 
						|
    protected $table = 'calendars'; // Sabre table
 | 
						|
    public $timestamps = false;  // no created_at/updated_at
 | 
						|
 | 
						|
    /* add mass-assignment for these cols */
 | 
						|
    protected $fillable = [
 | 
						|
        'displayname',
 | 
						|
        'description',
 | 
						|
    ];
 | 
						|
 | 
						|
    /* all event components (VEVENT, VTODO, …) */
 | 
						|
    public function events(): HasMany
 | 
						|
    {
 | 
						|
        return $this->hasMany(Event::class, 'calendarid'); // FK in calendarobjects
 | 
						|
    }
 | 
						|
 | 
						|
    /* ui-specific metadata (color, sharing flags, json settings) */
 | 
						|
    public function meta(): HasOne
 | 
						|
    {
 | 
						|
        return $this->hasOne(CalendarMeta::class, 'calendar_id');
 | 
						|
    }
 | 
						|
 | 
						|
    /* get instances */
 | 
						|
    public function instances()
 | 
						|
    {
 | 
						|
        return $this->hasMany(CalendarInstance::class, 'calendarid');
 | 
						|
    }
 | 
						|
 | 
						|
    /* get the primary? instance for a user */
 | 
						|
    public function instanceForUser(?User $user = null)
 | 
						|
    {
 | 
						|
        $user = $user ?? auth()->user();
 | 
						|
 | 
						|
        return $this->instances()
 | 
						|
            ->where('principaluri', 'principals/' . $user->email)
 | 
						|
            ->first();
 | 
						|
    }
 | 
						|
}
 |