Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 1 | <?php |
| 2 | |
| 3 | namespace LdapRecord\Models\ActiveDirectory; |
| 4 | |
| 5 | class Group extends Entry |
| 6 | { |
| 7 | /** |
| 8 | * The object classes of the LDAP model. |
| 9 | * |
| 10 | * @var array |
| 11 | */ |
| 12 | public static $objectClasses = [ |
| 13 | 'top', |
| 14 | 'group', |
| 15 | ]; |
| 16 | |
| 17 | /** |
| 18 | * The groups relationship. |
| 19 | * |
| 20 | * Retrieves groups that the current group is apart of. |
| 21 | * |
| 22 | * @return \LdapRecord\Models\Relations\HasMany |
| 23 | */ |
| 24 | public function groups() |
| 25 | { |
| 26 | return $this->hasMany(static::class, 'member'); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * The members relationship. |
| 31 | * |
| 32 | * Retrieves members that are apart of the group. |
| 33 | * |
| 34 | * @return \LdapRecord\Models\Relations\HasMany |
| 35 | */ |
| 36 | public function members() |
| 37 | { |
| 38 | return $this->hasMany([ |
| 39 | static::class, User::class, Contact::class, Computer::class, |
| 40 | ], 'memberof') |
| 41 | ->using($this, 'member') |
| 42 | ->with($this->primaryGroupMembers()); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * The primary group members relationship. |
| 47 | * |
| 48 | * Retrieves members that are apart the primary group. |
| 49 | * |
| 50 | * @return \LdapRecord\Models\Relations\HasMany |
| 51 | */ |
| 52 | public function primaryGroupMembers() |
| 53 | { |
| 54 | return $this->hasMany([ |
| 55 | static::class, User::class, Contact::class, Computer::class, |
| 56 | ], 'primarygroupid', 'rid'); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Get the RID of the group. |
| 61 | * |
| 62 | * @return array |
| 63 | */ |
| 64 | public function getRidAttribute() |
| 65 | { |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame^] | 66 | $objectSidComponents = explode('-', (string) $this->getConvertedSid()); |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 67 | |
| 68 | return [end($objectSidComponents)]; |
| 69 | } |
| 70 | } |