Total Complexity | 6 |
Total Lines | 37 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
9 | class DisambiguationSegmentFieldModifier extends AbstractSegmentFieldModifier |
||
10 | { |
||
11 | public function getPreview($value) |
||
12 | { |
||
13 | if ($this->form instanceof Form && $record = $this->form->getRecord()) { |
||
14 | $parent = $record->Parent(); |
||
15 | |||
16 | $try = $value; |
||
17 | |||
18 | $sibling = EditableFormField::get() |
||
19 | ->filter('ParentID', $parent->ID) |
||
20 | ->filter('Name', $try) |
||
21 | ->where('"ID" != ' . $record->ID) |
||
22 | ->first(); |
||
23 | |||
24 | $counter = 1; |
||
25 | |||
26 | while ($sibling !== null) { |
||
27 | $try = $value . '_' . $counter++; |
||
28 | |||
29 | $sibling = EditableFormField::get() |
||
30 | ->filter('ParentID', $parent->ID) |
||
31 | ->filter('Name', $try) |
||
32 | ->first(); |
||
33 | } |
||
34 | |||
35 | if ($try !== $value) { |
||
36 | return $try; |
||
37 | } |
||
38 | } |
||
39 | |||
40 | return $value; |
||
41 | } |
||
42 | |||
43 | public function getSuggestion($value) |
||
46 | } |
||
47 | } |
||
48 |