ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilAccessibilityDocument.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
8 {
9  const TABLE_NAME = 'acc_documents';
10 
19  protected $id;
20 
27  protected $creation_ts = 0;
28 
35  protected $modification_ts = 0;
36 
43  protected $owner_usr_id = 0;
44 
51  protected $last_modified_usr_id = 0;
52 
59  protected $sorting = 0;
60 
67  protected $title = '';
68 
74  protected $text = '';
75 
79  protected $criteria = [];
80 
84  protected $initialPersistedCriteria = [];
85 
89  private $criteriaFetched = false;
90 
94  public static function returnDbTableName()
95  {
96  return self::TABLE_NAME;
97  }
98 
102  public function content() : string
103  {
104  return $this->text;
105  }
106 
110  public function title() : string
111  {
112  return $this->title;
113  }
114 
118  public function id() : int
119  {
120  return (int) $this->id;
121  }
122 
126  public function read()
127  {
128  parent::read();
129 
130  $this->fetchAllCriterionAssignments();
131  }
132 
136  public function buildFromArray(array $array)
137  {
138  $document = parent::buildFromArray($array);
139 
140  $this->fetchAllCriterionAssignments();
141 
142  return $document;
143  }
144 
148  public function create()
149  {
150  $this->setCreationTs(time());
151 
152  parent::create();
153 
154  foreach ($this->criteria as $criterionAssignment) {
156  $criterionAssignment->setDocId($this->getId());
157  $criterionAssignment->store();
158  }
159 
160  $this->initialPersistedCriteria = $this->criteria;
161  }
162 
166  public function update()
167  {
168  $this->setModificationTs(time());
169 
170  foreach ($this->criteria as $criterionAssignment) {
172  $criterionAssignment->setDocId($this->getId());
173  $criterionAssignment->store();
174  }
175 
176  foreach ($this->initialPersistedCriteria as $criterionAssignment) {
178  $found = array_filter(
179  $this->criteria,
180  function (ilAccessibilityDocumentCriterionAssignment $criterionToMatch) use ($criterionAssignment) {
181  return $criterionToMatch->getId() == $criterionAssignment->getId();
182  }
183  );
184 
185  if (0 === count($found)) {
186  $criterionAssignment->delete();
187  }
188  }
189 
190  $this->initialPersistedCriteria = $this->criteria;
191 
192  parent::update();
193  }
194 
198  public function delete()
199  {
200  foreach ($this->initialPersistedCriteria as $criterionAssignment) {
202  $criterionAssignment->delete();
203  }
204 
205  $this->initialPersistedCriteria = $this->criteria = [];
206 
207  parent::delete();
208  }
209 
213  public function criteria() : array
214  {
215  return $this->criteria;
216  }
217 
222  public function attachCriterion(ilAccessibilityDocumentCriterionAssignment $criterionAssignment) : void
223  {
224  foreach ($this->criteria as $currentAssignment) {
226  if ($currentAssignment->equals($criterionAssignment)) {
228  "Cannot attach duplicate criterion with criterion typeIdent %s and value: %s",
229  $criterionAssignment->getCriterionId(),
230  var_export($criterionAssignment->getCriterionValue(), true)
231  ));
232  }
233  }
234 
235  $this->criteria[] = $criterionAssignment;
236  }
237 
242  public function detachCriterion(ilAccessibilityDocumentCriterionAssignment $criterionAssignment) : void
243  {
244  $numCriteriaBeforeRemoval = count($this->criteria);
245 
246  $this->criteria = array_filter(
247  $this->criteria,
248  function (ilAccessibilityDocumentCriterionAssignment $currentAssignment) use ($criterionAssignment) {
249  return !$currentAssignment->equals($criterionAssignment);
250  }
251  );
252 
253  $numCriteriaAfterRemoval = count($this->criteria);
254 
255  if ($numCriteriaAfterRemoval === $numCriteriaBeforeRemoval) {
256  throw new OutOfBoundsException(sprintf(
257  "Could not find any criterion with criterion typeIdent %s and value: %s",
258  $criterionAssignment->getCriterionId(),
259  var_export($criterionAssignment->getCriterionValue(), true)
260  ));
261  }
262  }
263 
267  public function fetchAllCriterionAssignments() : void
268  {
269  if (!$this->criteriaFetched) {
270  $this->criteriaFetched = true;
271 
272  $this->initialPersistedCriteria = [];
273  $this->criteria = [];
274 
275  $criteria = ilAccessibilityDocumentCriterionAssignment::where(['doc_id' => $this->getId()])->get();
276  foreach ($criteria as $criterionAssignment) {
278  $this->criteria[] = $criterionAssignment;
279  }
280 
281  $this->initialPersistedCriteria = $this->criteria;
282  }
283  }
284 }
Interface ilAccessibilitySignableDocument.
Class ilAccessibilityDocument.
static where($where, $operator=null)
detachCriterion(ilAccessibilityDocumentCriterionAssignment $criterionAssignment)
criteria()
ilAccessibilityEvaluableCriterion[]