blob: 6076f2fdeea918abea37571f93feb0c452c75c65 [file] [log] [blame]
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +02001<?php
2
3namespace LdapRecord\Models\ActiveDirectory;
4
5class 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 {
66 $objectSidComponents = explode('-', $this->getConvertedSid());
67
68 return [end($objectSidComponents)];
69 }
70}