blob: 540ec7717337fe15da7dec79d1f554f6a1732a03 [file] [log] [blame]
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +02001<?php
2
3namespace LdapRecord\Models\ActiveDirectory\Relations;
4
5use LdapRecord\Models\Model;
6use LdapRecord\Models\Relations\HasOne;
7
8class HasOnePrimaryGroup extends HasOne
9{
10 /**
11 * Get the foreign model by the given value.
12 *
13 * @param string $value
14 *
15 * @return Model|null
16 */
17 protected function getForeignModelByValue($value)
18 {
19 return $this->query->findBySid(
20 $this->getParentModelObjectSid()
21 );
22 }
23
24 /**
25 * Get the foreign value from the given model.
26 *
27 * Retrieves the last RID from the models Object SID.
28 *
29 * @param Model $model
30 *
31 * @return string
32 */
33 protected function getForeignValueFromModel(Model $model)
34 {
35 $objectSidComponents = explode('-', $model->getConvertedSid());
36
37 return end($objectSidComponents);
38 }
39
40 /**
41 * Get the parent relationship models converted object sid.
42 *
43 * @return string
44 */
45 protected function getParentModelObjectSid()
46 {
47 return preg_replace(
48 '/\d+$/',
49 $this->parent->getFirstAttribute($this->relationKey),
50 $this->parent->getConvertedSid()
51 );
52 }
53}