Bristol SU Support Package
GroupTagged.php
Go to the documentation of this file.
1 <?php
2 
3 
5 
6 
7 use BristolSU\ControlDB\Contracts\Repositories\Tags\GroupTag as GroupTagRepositoryContract;
10 
14 class GroupTagged extends GroupFilter
15 {
16 
23 
27  public function __construct(GroupTagRepositoryContract $groupTagRepository)
28  {
29  $this->groupTagRepository = $groupTagRepository;
30  }
31 
39  public function evaluate($settings): bool
40  {
41  try {
42  $tags = $this->group()->tags();
43  } catch (\Exception $e) {
44  return false;
45  }
46  foreach ($tags as $tag) {
47  if ($tag->fullReference() === $settings['tag']) {
48  return true;
49  }
50  }
51  return false;
52  }
53 
63  public function options(): Form
64  {
65  $tags = $this->groupTagRepository->all();
66  $values = [];
67  foreach ($tags as $tag) {
68  $values[] = [
69  'id' => $tag->fullReference(),
70  'name' => sprintf('%s (%s)', $tag->name(), $tag->fullReference()),
71  'group' => $tag->category()->name()
72  ];
73  }
74  return \FormSchema\Generator\Form::make()->withField(
75  \FormSchema\Generator\Field::select('tag')->values($values)->label('Group Name')
76  ->required(true)
77  )->getSchema();
78  }
79 
85  public function name()
86  {
87  return 'Group Tagged';
88  }
89 
95  public function description()
96  {
97  return 'Returns true if a group is tagged';
98  }
99 
105  public function alias()
106  {
107  return 'group_tagged';
108  }
109 }
__construct(GroupTagRepositoryContract $groupTagRepository)
Definition: GroupTagged.php:27