Konstruktoren zum erstellen von neuen Objekten eingebaut
This commit is contained in:
committed by
Eric Blommel
parent
b81068b701
commit
ff92b4c875
@@ -40,6 +40,25 @@ class SubjectData
|
||||
*/
|
||||
public array $topics;
|
||||
|
||||
/**
|
||||
* Erstellt ein neues Fach. Es wird noch nichts gespeichert
|
||||
* @param string $id Ein eindeutiger Bezeichner für das Fach, darf nur A-Z, a-Z, 0-9 sowie _ und - enthalten
|
||||
* @param string $displayName Der für User angezeigte Name des Faches, nur reiner Text
|
||||
* @param string $description Eine kurze Beschreibung des Faches, z.B. für den Text auf der Startseite, kann HTML enthalten
|
||||
* @param string $color Themenfarbe des Faches als hexcode
|
||||
* @param string $icon Icon des Faches als Font-Awesome CSS-Klasse
|
||||
* @param array $topics Alle Themen des Faches als TopicData Objekt
|
||||
*/
|
||||
public function __construct(string $id, string $displayName, string $description, string $color, string $icon, array $topics)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->displayName = $displayName;
|
||||
$this->description = $description;
|
||||
$this->color = $color;
|
||||
$this->icon = $icon;
|
||||
$this->topics = $topics;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt alle Fächer als SubjectData Objekt zurück
|
||||
* @return array Alle Fächer als SubjectData
|
||||
@@ -77,8 +96,6 @@ class SubjectData
|
||||
*/
|
||||
public static function fromName(string $subjectId): SubjectData|null
|
||||
{
|
||||
$result = new SubjectData();
|
||||
|
||||
if (Util::containsIllegalCharacters($subjectId)) {
|
||||
return null;
|
||||
}
|
||||
@@ -89,35 +106,23 @@ class SubjectData
|
||||
return null;
|
||||
}
|
||||
|
||||
$result->id = $subjectId;
|
||||
|
||||
if (isset($data->displayName)) {
|
||||
$result->displayName = $data->displayName;
|
||||
} else {
|
||||
if (!isset($data->displayName)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isset($data->description)) {
|
||||
$result->description = $data->description;
|
||||
} else {
|
||||
if (!isset($data->description)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isset($data->color)) {
|
||||
$result->color = $data->color;
|
||||
} else {
|
||||
if (!isset($data->color)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isset($data->icon)) {
|
||||
$result->icon = $data->icon;
|
||||
} else {
|
||||
if (!isset($data->icon)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$result->topics = TopicData::getAll($subjectId);
|
||||
|
||||
return $result;
|
||||
return new SubjectData($subjectId, $data->displayName, $data->description, $data->color, $data->icon, TopicData::getAll($subjectId));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,7 +160,7 @@ class SubjectData
|
||||
*/
|
||||
public function delete(): bool
|
||||
{
|
||||
if(!Util::delete(Config::getSubjectDirectory($this->getId()))) {
|
||||
if (!Util::delete(Config::getSubjectDirectory($this->getId()))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user