| 
									
										
										
										
											2023-07-31 23:08:29 +08:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace BookStack\Activity\Models; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-14 20:11:18 +08:00
										 |  |  | use BookStack\Activity\WatchLevels; | 
					
						
							| 
									
										
										
										
											2023-07-31 23:08:29 +08:00
										 |  |  | use BookStack\Permissions\Models\JointPermission; | 
					
						
							|  |  |  | use Carbon\Carbon; | 
					
						
							|  |  |  | use Illuminate\Database\Eloquent\Model; | 
					
						
							|  |  |  | use Illuminate\Database\Eloquent\Relations\HasMany; | 
					
						
							| 
									
										
										
										
											2023-08-14 20:11:18 +08:00
										 |  |  | use Illuminate\Database\Eloquent\Relations\MorphTo; | 
					
						
							| 
									
										
										
										
											2023-07-31 23:08:29 +08: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 20:14:00 +08:00
										 |  |  |     protected $guarded = []; | 
					
						
							| 
									
										
										
										
											2023-07-31 23:08:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-14 20:11:18 +08:00
										 |  |  |     public function watchable(): MorphTo | 
					
						
							| 
									
										
										
										
											2023-07-31 23:08:29 +08:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2023-08-14 20:11:18 +08:00
										 |  |  |         return $this->morphTo(); | 
					
						
							| 
									
										
										
										
											2023-07-31 23:08:29 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function jointPermissions(): HasMany | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->hasMany(JointPermission::class, 'entity_id', 'watchable_id') | 
					
						
							| 
									
										
										
										
											2023-08-14 20:11:18 +08: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 23:08:29 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | } |