FOSSology  4.4.0
Open Source License Compliance by Open Source Software
Obligation.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2021 Siemens AG
4  Author: Gaurav Mishra <mishra.gaurav@siemens.com>
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
12 namespace Fossology\UI\Api\Models;
13 
20 {
25  private $id;
30  private $topic;
35  private $type;
40  private $text;
45  private $classification;
50  private $comment;
55  private $modification;
60  private $active;
65  private $textUpdatable;
70  private $hash;
75  private $licenses;
85  private $extended;
86 
98  public function __construct($id, $topic = "", $type = "", $text = "",
99  $classification = "", $comment = "", $extended = false)
100  {
101  $this->id = intval($id);
102  $this->setTopic($topic);
103  $this->setType($type);
104  $this->setText($text);
106  $this->setComment($comment);
107  $this->setExtended($extended);
108  $this->setHash(null);
109  $this->licenses = [];
110  $this->candidateLicenses = [];
111  }
112 
117  public function getJSON()
118  {
119  return json_encode($this->getArray());
120  }
121 
126  public function getArray()
127  {
128  $obligation = [
129  'id' => $this->id,
130  'topic' => $this->getTopic(),
131  'type' => $this->getType(),
132  'text' => $this->getText(),
133  'classification' => $this->getClassification(),
134  'comment' => $this->getComment()
135  ];
136  if ($this->getExtended()) {
137  $obligation['modification'] = $this->isModification();
138  $obligation['active'] = $this->isActive();
139  $obligation['textUpdatable'] = $this->isTextUpdatable();
140  $obligation['licenses'] = $this->getLicenses();
141  $obligation['candidateLicenses'] = $this->getCandidateLicenses();
142  $obligation['hash'] = $this->getHash();
143  }
144  return $obligation;
145  }
146 
151  public function getTopic()
152  {
153  if ($this->topic === null) {
154  return "";
155  }
156  return $this->topic;
157  }
158 
163  public function getType()
164  {
165  if ($this->type === null) {
166  return "";
167  }
168  return $this->type;
169  }
170 
175  public function getText()
176  {
177  if ($this->text === null) {
178  return "";
179  }
180  return $this->text;
181  }
182 
187  public function getClassification()
188  {
189  if ($this->classification === null) {
190  return "";
191  }
192  return $this->classification;
193  }
194 
199  public function getComment()
200  {
201  if ($this->comment === null) {
202  return "";
203  }
204  return $this->comment;
205  }
206 
210  public function isModification()
211  {
212  return $this->modification == true;
213  }
214 
218  public function isTextUpdatable()
219  {
220  return $this->textUpdatable == true;
221  }
222 
226  public function isActive()
227  {
228  return $this->active == true;
229  }
230 
234  public function getHash()
235  {
236  return $this->hash;
237  }
238 
242  public function getLicenses()
243  {
244  return $this->licenses;
245  }
246 
250  public function getCandidateLicenses()
251  {
253  }
254 
259  public function getExtended()
260  {
261  return $this->extended;
262  }
263 
268  public function setTopic($topic)
269  {
270  $this->topic = convertToUTF8($topic, false);
271  }
272 
277  public function setType($type)
278  {
279  $this->type = convertToUTF8($type, false);
280  }
281 
286  public function setText($text)
287  {
288  $this->text = convertToUTF8($text, false);
289  }
290 
296  {
297  $this->classification = convertToUTF8($classification, false);
298  }
299 
304  public function setComment($comment)
305  {
306  $this->comment = convertToUTF8($comment, false);
307  }
308 
313  {
314  if ($modification == "t") {
315  $modification = true;
316  }
317  $this->modification = filter_var($modification, FILTER_VALIDATE_BOOLEAN);
318  }
319 
324  {
325  if ($textUpdatable == "t") {
326  $textUpdatable = true;
327  }
328  $this->textUpdatable = filter_var($textUpdatable, FILTER_VALIDATE_BOOLEAN);
329  }
330 
334  public function setActive($active)
335  {
336  if ($active == "t") {
337  $active = true;
338  }
339  $this->active = filter_var($active, FILTER_VALIDATE_BOOLEAN);
340  }
341 
345  public function setHash($hash)
346  {
347  $this->hash = $hash;
348  }
349 
354  public function addLicense($shortname)
355  {
356  if (empty($shortname)) {
357  return;
358  }
359  $this->licenses[] = $shortname;
360  }
361 
366  public function addCandidateLicense($shortname)
367  {
368  if (empty($shortname)) {
369  return;
370  }
371  $this->candidateLicenses[] = $shortname;
372  }
373 
378  public function setExtended($extended)
379  {
380  $this->extended = filter_var($extended, FILTER_VALIDATE_BOOLEAN);
381  }
382 
392  public static function fromArray($db, $extended, $licenses, $candidateLicenses)
393  {
394  $obligation = new Obligation($db['ob_pk'], $db['ob_topic'], $db['ob_type'],
395  $db['ob_text'], $db['ob_classification'], $db['ob_comment'], $extended);
396  if ($extended) {
397  $obligation->setModification($db['ob_modifications']);
398  $obligation->setActive($db['ob_active']);
399  $obligation->setTextUpdatable($db['ob_text_updatable']);
400  $obligation->setHash($db['ob_md5']);
401  foreach ($licenses as $license) {
402  $obligation->addLicense($license);
403  }
404  foreach ($candidateLicenses as $candidateLicense) {
405  $obligation->addCandidateLicense($candidateLicense);
406  }
407  }
408  return $obligation;
409  }
410 }
static fromArray($db, $extended, $licenses, $candidateLicenses)
Definition: Obligation.php:392
__construct($id, $topic="", $type="", $text="", $classification="", $comment="", $extended=false)
Definition: Obligation.php:98
if(! defined('ENT_SUBSTITUTE')) convertToUTF8($content, $toHTML=true)