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: | * @property int $Id Object primary key |
21: | * @property int $TenantId Tenant ID |
22: | * @property string $Name Tenant name |
23: | * @property bool $IsAll Defines whether the group represents all the users |
24: | * @property array $Properties Custom properties for use by other modules |
25: | * @property \Illuminate\Support\Carbon|null $CreatedAt |
26: | * @property \Illuminate\Support\Carbon|null $UpdatedAt |
27: | * @property-read \Illuminate\Database\Eloquent\Collection<int, \Aurora\Modules\Core\Models\User> $Users |
28: | * @property-read int|null $users_count |
29: | * @property-read mixed $entity_id |
30: | * @method static \Illuminate\Database\Eloquent\Builder|\Aurora\Modules\Core\Models\Group firstWhere(Closure|string|array|\Illuminate\Database\Query\Expression $column, mixed $operator = null, mixed $value = null, string $boolean = 'and') |
31: | * @method static \Illuminate\Database\Eloquent\Builder|Group newModelQuery() |
32: | * @method static \Illuminate\Database\Eloquent\Builder|Group newQuery() |
33: | * @method static \Illuminate\Database\Eloquent\Builder|Group query() |
34: | * @method static \Illuminate\Database\Eloquent\Builder|\Aurora\Modules\Core\Models\Group where(Closure|string|array|\Illuminate\Database\Query\Expression $column, mixed $operator = null, mixed $value = null, string $boolean = 'and') |
35: | * @method static \Illuminate\Database\Eloquent\Builder|Group whereCreatedAt($value) |
36: | * @method static \Illuminate\Database\Eloquent\Builder|Group whereId($value) |
37: | * @method static \Illuminate\Database\Eloquent\Builder|\Aurora\Modules\Core\Models\Group whereIn(string $column, mixed $values, string $boolean = 'and', bool $not = false) |
38: | * @method static \Illuminate\Database\Eloquent\Builder|Group whereIsAll($value) |
39: | * @method static \Illuminate\Database\Eloquent\Builder|Group whereName($value) |
40: | * @method static \Illuminate\Database\Eloquent\Builder|Group whereProperties($value) |
41: | * @method static \Illuminate\Database\Eloquent\Builder|Group whereTenantId($value) |
42: | * @method static \Illuminate\Database\Eloquent\Builder|Group whereUpdatedAt($value) |
43: | * @method static \Illuminate\Database\Eloquent\Builder|\Aurora\Modules\Core\Models\Group find(int|string $id, array|string $columns = ['*']) |
44: | * @method static int count(string $columns = '*') |
45: | * @method static \Illuminate\Database\Eloquent\Builder|\Aurora\Modules\Core\Models\Group findOrFail(int|string $id, mixed $id, Closure|array|string $columns = ['*'], Closure $callback = null) |
46: | * @method static \Illuminate\Database\Eloquent\Builder|\Aurora\Modules\Core\Models\Group first(array|string $columns = ['*']) |
47: | * @mixin \Eloquent |
48: | */ |
49: | class Group extends Model |
50: | { |
51: | protected $table = 'core_groups'; |
52: | protected $moduleName = 'Core'; |
53: | |
54: | protected $foreignModel = Tenant::class; |
55: | protected $foreignModelIdColumn = 'TenantId'; // Column that refers to an external table |
56: | |
57: | /** |
58: | * The attributes that are mass assignable. |
59: | * |
60: | * @var array |
61: | */ |
62: | protected $fillable = [ |
63: | 'Id', |
64: | 'TenantId', |
65: | 'Name', |
66: | 'IsAll', |
67: | 'Properties' |
68: | ]; |
69: | |
70: | /** |
71: | * The attributes that should be hidden for arrays. |
72: | * |
73: | * @var array |
74: | */ |
75: | protected $hidden = [ |
76: | ]; |
77: | |
78: | protected $casts = [ |
79: | 'Properties' => 'array', |
80: | ]; |
81: | |
82: | protected $attributes = [ |
83: | ]; |
84: | |
85: | /** |
86: | * Returns list of users which belong to this group |
87: | * |
88: | * return array |
89: | */ |
90: | public function Users() |
91: | { |
92: | return $this->belongsToMany(User::class, 'core_group_user', 'GroupId', 'UserId'); |
93: | } |
94: | |
95: | /** |
96: | * Returns a name of group, or special language constant if the group represents all the users |
97: | * |
98: | * return string |
99: | */ |
100: | public function getName() |
101: | { |
102: | return $this->IsAll ? CoreModule::getInstance()->i18N('LABEL_ALL_USERS_GROUP') : $this->Name; |
103: | } |
104: | } |
105: |