2023-07-31 11:08:29 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Activity\Models;
|
|
|
|
|
2023-08-14 08:11:18 -04:00
|
|
|
use BookStack\Activity\WatchLevels;
|
2023-07-31 11:08:29 -04:00
|
|
|
use BookStack\Permissions\Models\JointPermission;
|
|
|
|
use Carbon\Carbon;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
2023-08-14 08:11:18 -04:00
|
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
2023-07-31 11:08:29 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property int $id
|
|
|
|
* @property int $user_id
|
|
|
|
* @property int $watchable_id
|
|
|
|
* @property string $watchable_type
|
|
|
|
* @property int $level
|
|
|
|
* @property Carbon $created_at
|
|
|
|
* @property Carbon $updated_at
|
|
|
|
*/
|
|
|
|
class Watch extends Model
|
|
|
|
{
|
2023-08-02 08:14:00 -04:00
|
|
|
protected $guarded = [];
|
2023-07-31 11:08:29 -04:00
|
|
|
|
2023-08-14 08:11:18 -04:00
|
|
|
public function watchable(): MorphTo
|
2023-07-31 11:08:29 -04:00
|
|
|
{
|
2023-08-14 08:11:18 -04:00
|
|
|
return $this->morphTo();
|
2023-07-31 11:08:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function jointPermissions(): HasMany
|
|
|
|
{
|
|
|
|
return $this->hasMany(JointPermission::class, 'entity_id', 'watchable_id')
|
2023-08-14 08:11:18 -04:00
|
|
|
->whereColumn('watches.watchable_type', '=', 'joint_permissions.entity_type');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getLevelName(): string
|
|
|
|
{
|
|
|
|
return WatchLevels::levelValueToName($this->level);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ignoring(): bool
|
|
|
|
{
|
|
|
|
return $this->level === WatchLevels::IGNORE;
|
2023-07-31 11:08:29 -04:00
|
|
|
}
|
|
|
|
}
|