1: | <?php |
2: | /** |
3: | * This code is licensed under AGPLv3 license or Afterlogic Software License |
4: | * if commercial version of the product was purchased. |
5: | * For full statements of the licenses see LICENSE-AFTERLOGIC and LICENSE-AGPL3 files. |
6: | */ |
7: | |
8: | namespace Aurora\Modules\Core\Models; |
9: | |
10: | use Aurora\System\Classes\Model; |
11: | use Aurora\Modules\Core\Models\Tenant; |
12: | use Aurora\Modules\Core\Module as CoreModule; |
13: | |
14: | /** |
15: | * The Core Group class. |
16: | * |
17: | * @license https://www.gnu.org/licenses/agpl-3.0.html AGPL-3.0 |
18: | * @license https://afterlogic.com/products/common-licensing Afterlogic Software License |
19: | * @copyright Copyright (c) 2023, Afterlogic Corp. |
20: | * |
21: | * @property int $Id Object primary key |
22: | * @property int $TenantId Tenant ID |
23: | * @property string $Name Tenant name |
24: | * @property bool $IsAll Defines whether the group represents all the users |
25: | * @property array $Properties Custom properties for use by other modules |
26: | */ |
27: | class Group extends Model |
28: | { |
29: | protected $table = 'core_groups'; |
30: | protected $moduleName = 'Core'; |
31: | |
32: | protected $foreignModel = Tenant::class; |
33: | protected $foreignModelIdColumn = 'TenantId'; // Column that refers to an external table |
34: | |
35: | /** |
36: | * The attributes that are mass assignable. |
37: | * |
38: | * @var array |
39: | */ |
40: | protected $fillable = [ |
41: | 'Id', |
42: | 'TenantId', |
43: | 'Name', |
44: | 'IsAll', |
45: | 'Properties' |
46: | ]; |
47: | |
48: | /** |
49: | * The attributes that should be hidden for arrays. |
50: | * |
51: | * @var array |
52: | */ |
53: | protected $hidden = [ |
54: | ]; |
55: | |
56: | protected $casts = [ |
57: | 'Properties' => 'array', |
58: | ]; |
59: | |
60: | protected $attributes = [ |
61: | ]; |
62: | |
63: | /** |
64: | * Returns list of users which belong to this group |
65: | * |
66: | * return array |
67: | */ |
68: | public function Users() |
69: | { |
70: | return $this->belongsToMany(User::class, 'core_group_user', 'GroupId', 'UserId'); |
71: | } |
72: | |
73: | /** |
74: | * Returns a name of group, or special language constant if the group represents all the users |
75: | * |
76: | * return string |
77: | */ |
78: | public function getName() |
79: | { |
80: | return $this->IsAll ? CoreModule::getInstance()->i18N('LABEL_ALL_USERS_GROUP') : $this->Name; |
81: | } |
82: | } |
83: |