Bristol SU Support Package
RoleHasPosition.php
Go to the documentation of this file.
1 <?php
2 
3 
5 
6 
11 
16 {
23 
27  public function __construct(Position $positionRepository)
28  {
29  $this->positionRepository = $positionRepository;
30  }
31 
38  public function evaluate($settings): bool
39  {
40  if ($this->role()->positionId() === (int) $settings['position']) {
41  return true;
42  }
43  return false;
44  }
45 
55  public function options(): Form
56  {
57  $positions = $this->positionRepository->all();
58  $values = [];
59  foreach ($positions as $position)
60  {
61  $values[] = [
62  'id' => $position->id(),
63  'name' => $position->data()->name(),
64  ];
65  }
66  return \FormSchema\Generator\Form::make()->withField(
67  \FormSchema\Generator\Field::select('position')->values($values)->label('Position')
68  ->required(true)
69  )->getSchema();
70  }
71 
77  public function name()
78  {
79  return 'Role has a position';
80  }
81 
87  public function description()
88  {
89  return 'Returns true if a role has a specific position';
90  }
91 
97  public function alias()
98  {
99  return 'role_has_position';
100  }
101 
102 }