ILIAS  trunk Revision v11.0_alpha-1761-g6dbbfa7b760
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
Actions.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
28 
29 class Actions implements ActionsInterface
30 {
32  protected ControlledRepo $controlled_repo;
33  protected StandardRepo $standard_repo;
34 
35  public function __construct(
36  InfosInterface $infos,
37  ControlledRepo $controlled_repo,
38  StandardRepo $standard_repo
39  ) {
40  $this->infos = $infos;
41  $this->controlled_repo = $controlled_repo;
42  $this->standard_repo = $standard_repo;
43  }
44 
45  public function activate(VocabularyInterface $vocabulary): void
46  {
47  switch ($vocabulary->type()) {
48  case Type::STANDARD:
49  $this->standard_repo->activateVocabulary($vocabulary->slot());
50  break;
51 
52  case Type::CONTROLLED_STRING:
53  case Type::CONTROLLED_VOCAB_VALUE:
54  $this->controlled_repo->setActiveForVocabulary(
55  $vocabulary->id(),
56  true
57  );
58  break;
59 
60  default:
61  case Type::COPYRIGHT:
62  break;
63  }
64  }
65 
66  public function deactivate(VocabularyInterface $vocabulary): void
67  {
68  if (!$this->infos->isDeactivatable($vocabulary)) {
69  throw new \ilMDVocabulariesException('Vocabulary cannot be deactivated.');
70  }
71 
72  switch ($vocabulary->type()) {
73  case Type::STANDARD:
74  $this->standard_repo->deactivateVocabulary($vocabulary->slot());
75  break;
76 
77  case Type::CONTROLLED_STRING:
78  case Type::CONTROLLED_VOCAB_VALUE:
79  $this->controlled_repo->setActiveForVocabulary(
80  $vocabulary->id(),
81  false
82  );
83  break;
84 
85  default:
86  case Type::COPYRIGHT:
87  break;
88  }
89  }
90 
91  public function allowCustomInput(VocabularyInterface $vocabulary): void
92  {
93  if (!$this->infos->isCustomInputApplicable($vocabulary)) {
94  throw new \ilMDVocabulariesException('Custom input is not applicable for vocabulary.');
95  }
96 
97  switch ($vocabulary->type()) {
98  case Type::CONTROLLED_STRING:
99  $this->controlled_repo->setCustomInputsAllowedForVocabulary(
100  $vocabulary->id(),
101  true
102  );
103  break;
104 
105  default:
106  case Type::CONTROLLED_VOCAB_VALUE:
107  case Type::STANDARD:
108  case Type::COPYRIGHT:
109  break;
110  }
111  }
112 
113  public function disallowCustomInput(VocabularyInterface $vocabulary): void
114  {
115  if (
116  !$this->infos->isCustomInputApplicable($vocabulary) ||
117  !$this->infos->canDisallowCustomInput($vocabulary)
118  ) {
119  throw new \ilMDVocabulariesException('Custom input cannot be disallowed for vocabulary.');
120  }
121 
122  switch ($vocabulary->type()) {
123  case Type::CONTROLLED_STRING:
124  $this->controlled_repo->setCustomInputsAllowedForVocabulary(
125  $vocabulary->id(),
126  false
127  );
128  break;
129 
130  default:
131  case Type::CONTROLLED_VOCAB_VALUE:
132  case Type::STANDARD:
133  case Type::COPYRIGHT:
134  break;
135  }
136  }
137 
138  public function delete(VocabularyInterface $vocabulary): void
139  {
140  if (!$this->infos->canBeDeleted($vocabulary)) {
141  throw new \ilMDVocabulariesException('Vocabulary cannot be deleted.');
142  }
143 
144  switch ($vocabulary->type()) {
145  case Type::CONTROLLED_STRING:
146  case Type::CONTROLLED_VOCAB_VALUE:
147  $this->controlled_repo->deleteVocabulary($vocabulary->id());
148  break;
149 
150  default:
151  case Type::STANDARD:
152  case Type::COPYRIGHT:
153  break;
154  }
155  }
156 }
allowCustomInput(VocabularyInterface $vocabulary)
Definition: Actions.php:91
deactivate(VocabularyInterface $vocabulary)
Definition: Actions.php:66
activate(VocabularyInterface $vocabulary)
Definition: Actions.php:45
__construct(InfosInterface $infos, ControlledRepo $controlled_repo, StandardRepo $standard_repo)
Definition: Actions.php:35
disallowCustomInput(VocabularyInterface $vocabulary)
Definition: Actions.php:113