| 
									
										
										
										
											2021-08-28 15:47:33 +02:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2021-09-16 14:21:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* | 
					
						
							|  |  |  |  * GroupMembership.php | 
					
						
							|  |  |  |  * Copyright (c) 2021 james@firefly-iii.org | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This file is part of Firefly III (https://github.com/firefly-iii). | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  |  * it under the terms of the GNU Affero General Public License as | 
					
						
							|  |  |  |  * published by the Free Software Foundation, either version 3 of the | 
					
						
							|  |  |  |  * License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU Affero General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU Affero General Public License | 
					
						
							|  |  |  |  * along with this program.  If not, see <https://www.gnu.org/licenses/>. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | declare(strict_types=1); | 
					
						
							| 
									
										
										
										
											2021-08-28 15:47:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace FireflyIII\Models; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-10 06:51:59 +01:00
										 |  |  | use FireflyIII\Support\Models\ReturnsIntegerIdTrait; | 
					
						
							| 
									
										
										
										
											2023-11-05 19:41:37 +01:00
										 |  |  | use FireflyIII\Support\Models\ReturnsIntegerUserIdTrait; | 
					
						
							| 
									
										
										
										
											2021-08-28 15:47:33 +02:00
										 |  |  | use FireflyIII\User; | 
					
						
							| 
									
										
										
										
											2023-11-05 19:41:37 +01:00
										 |  |  | use Illuminate\Database\Eloquent\Casts\Attribute; | 
					
						
							| 
									
										
										
										
											2021-08-28 15:47:33 +02:00
										 |  |  | use Illuminate\Database\Eloquent\Model; | 
					
						
							|  |  |  | use Illuminate\Database\Eloquent\Relations\BelongsTo; | 
					
						
							| 
									
										
										
										
											2023-12-10 06:51:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-28 15:47:33 +02:00
										 |  |  | class GroupMembership extends Model | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2023-11-05 19:41:37 +01:00
										 |  |  |     use ReturnsIntegerIdTrait; | 
					
						
							|  |  |  |     use ReturnsIntegerUserIdTrait; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-28 15:47:33 +02:00
										 |  |  |     protected $fillable = ['user_id', 'user_group_id', 'user_role_id']; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function user(): BelongsTo | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->belongsTo(User::class); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function userGroup(): BelongsTo | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->belongsTo(UserGroup::class); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function userRole(): BelongsTo | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->belongsTo(UserRole::class); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-11-05 19:41:37 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     protected function userRoleId(): Attribute | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return Attribute::make( | 
					
						
							| 
									
										
										
										
											2024-12-22 08:43:12 +01:00
										 |  |  |             get: static fn ($value) => (int) $value, | 
					
						
							| 
									
										
										
										
											2023-11-05 19:41:37 +01:00
										 |  |  |         ); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-05-29 19:58:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-29 15:01:06 +02:00
										 |  |  |     protected function casts(): array | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return [ | 
					
						
							|  |  |  |             'created_at'    => 'datetime', | 
					
						
							|  |  |  |             'updated_at'    => 'datetime', | 
					
						
							|  |  |  |             'user_id'       => 'integer', | 
					
						
							|  |  |  |             'user_group_id' => 'integer', | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-09-16 14:21:35 +02:00
										 |  |  | } |