From 1a2f73ba9ca28ba237e9b5c85e5334f542e0d1be Mon Sep 17 00:00:00 2001 From: christophboecker Date: Sun, 15 Sep 2024 11:57:46 +0200 Subject: [PATCH] API getuned, neue Methoden findBy/queryBy --- CHANGELOG.md | 38 ++++++ docs/03_neues_entry.md | 4 +- fragments/neues/entry.php | 2 +- lib/Author.php | 43 +++--- lib/Category.php | 7 +- lib/Entry.php | 273 +++++++++++++++++++++++++++++++------- lib/EntryLang.php | 14 +- 7 files changed, 312 insertions(+), 69 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..89b95a9 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,38 @@ +# Changelog + +## xx-xx-2024 x.x.x (**Breacking Changes ⚠**) + +> Work in Progress !!! + +Version x.x.x ist an vielen Ständen überarbeitet, was auch die Schnittstellen der +Klassen/Methoden betrifft. Beim Update von Versionen vor x.x.x müssen ggf. Anpassungen +im eigenen Code vorgenommen werden: + +- Klasse `Author`: + - alter Klassenname: `neues_author` => neu: `FriendsOfRedaxo\Neues\Author` + - `$author->getName`: liefert immer einen ggf. leeren `string`; `null` als Rückgabe ist entfernt + - `$author->getNickName`: liefert immer einen ggf. leeren `string`; `null` als Rückgabe ist entfernt + - `$author->geText`: liefert immer einen ggf. leeren `string`; `null` als Rückgabe ist entfernt + - `$author->getBeUserId`: liefert immer eine Id vom Typ`int` (0=unbekannt); `null` als Rückgabe ist entfernt +- Klasse `Category`: + - alter Klassenname: `neues_category` => neu: `FriendsOfRedaxo\Neues\Category` + - `$cat->getName`: liefert immer einen ggf. leeren `string`; `null` als Rückgabe ist entfernt +- Klasse `Entry`: + - alter Klassenname: `neues_entry` => neu: `FriendsOfRedaxo\Neues\Entry` + - `$post->getImages`: API angepasst auf `array`, da ohnehin stets ein ggf. leeres Array geliefert wurde, aber nie `null` + - `$post->setImages`: `null` für "leer also löschen" wird nicht mehr akzeptiert; statt dessen `[]`benutzen oder den Parameter weglassen. + - `$post->getExternalUrl`: liefert immer einen ggf. leeren `string`; `null` als Rückgabe ist entfernt. + - `$post->getStatus`: liefert nun richtigerweise `int` statt `string` + - `Entry::findOnline`: `null` als "suche alle"-Kennung durch `0`ersetzt. + - `Entry::findByCategory`: `null` als "suche alle"-Kennung durch `0`ersetzt. + - `Entry::findByCategoryIds`: `null` als "suche alle"-Kennung durch `0`ersetzt. + - neu: `$post->getCanonicalUrl` + - neu: `$post->setCanonicalUrl` + - neu: `Entry::queryBy` + - neu: `Entry::findBy` +- Klasse `EntryLang` + - alter Klassenname: `neues_entry_lang` => neu: `FriendsOfRedaxo\Neues\EntryLang` + - `$cat->getCode`: liefert immer einen ggf. leeren `string`; `null` als Rückgabe ist entfernt + - `$cat->geName`: liefert immer einen ggf. leeren `string`; `null` als Rückgabe ist entfernt +- Klasse `Entry`: + - alter Klassenname: `neues` => neu: `FriendsOfRedaxo\Neues\Neues` diff --git a/docs/03_neues_entry.md b/docs/03_neues_entry.md index 0f3c5ab..07a9531 100644 --- a/docs/03_neues_entry.md +++ b/docs/03_neues_entry.md @@ -236,7 +236,7 @@ Setzt den Status des Eintrags. $entry = $entry->setStatus(1); ``` -### findOnline(?int $category_id = null) +### findOnline(int $category_id = 0) Findet Online-Einträge. Wenn eine Kategorie-ID angegeben ist, werden nur Einträge aus dieser Kategorie zurückgegeben. @@ -244,7 +244,7 @@ Findet Online-Einträge. Wenn eine Kategorie-ID angegeben ist, werden nur Eintr $entries = FriendsOfRedaxo\Neues\Entry::findOnline(1); ``` -### findByCategory(?int $category_id = null, int $status = Entry::ONLINE) +### findByCategory(int $category_id = 0, int $status = Entry::ONLINE) Findet Einträge nach Kategorie. diff --git a/fragments/neues/entry.php b/fragments/neues/entry.php index d0b0b08..703e1ac 100644 --- a/fragments/neues/entry.php +++ b/fragments/neues/entry.php @@ -25,7 +25,7 @@ getAuthor()) : ?> - getAuthor()->getName()) : ?> + getAuthor()->getName()) : ?> von getAuthor()->getName()) ?> getAuthor()->getNickname()): ?> von getAuthor()->getNickname()) ?> diff --git a/lib/Author.php b/lib/Author.php index 83530e9..cb2fb10 100644 --- a/lib/Author.php +++ b/lib/Author.php @@ -29,16 +29,19 @@ class Author extends rex_yform_manager_dataset * Gibt den Namen des Autors zurück. * Returns the name of the author. * - * @return string|null Der Name des Autors oder null, wenn kein Name gesetzt ist. / The name of the author or null if no name is set. + * @return string Der Name des Autors oder '', wenn kein Name gesetzt ist. / The name of the author or '' if no name is set. * * Beispiel / Example: * $name = $author->getName(); * * @api */ - public function getName(): ?string + public function getName(): string { - return $this->getValue('name'); + if ($this->hasValue('name')) { + return $this->getValue('name'); + } + return ''; } /** @@ -60,16 +63,19 @@ public function setName(string $value): self * Gibt den Spitznamen des Autors zurück. * Returns the nickname of the author. * - * @return string|null Der Spitzname des Autors oder null, wenn kein Spitzname gesetzt ist. / The nickname of the author or null if no nickname is set. + * @return string Der Spitzname des Autors oder '', wenn kein Spitzname gesetzt ist. / The nickname of the author or '' if no nickname is set. * * Beispiel / Example: * $nickname = $author->getNickname(); * * @api */ - public function getNickname(): ?string + public function getNickname(): string { - return $this->getValue('nickname'); + if ($this->hasValue('nickname')) { + return $this->getValue('nickname'); + } + return ''; } /** @@ -92,19 +98,19 @@ public function setNickname(string $value): self * Returns the text of the author. * * @param bool $asPlaintext Wenn true, wird der Text ohne HTML-Tags zurückgegeben. / If true, the text is returned without HTML tags. - * @return string|null Der Text des Autors oder null, wenn kein Text gesetzt ist. / The text of the author or null if no text is set. + * @return string Der Text des Autors oder '', wenn kein Text gesetzt ist. / The text of the author or '' if no text is set. * * Beispiel / Example: * $text = $author->getText(true); * * @api */ - public function getText(bool $asPlaintext = false): ?string + public function getText(bool $asPlaintext = false): string { - if ($asPlaintext) { - return strip_tags($this->getValue('text')); + if ($this->hasValue('text')) { + return $asPlaintext ? strip_tags($this->getValue('text')) : $this->getValue('text'); } - return $this->getValue('text'); + return ''; } /** @@ -126,16 +132,19 @@ public function setText(string $value): self * Gibt die Benutzer-ID des Autors zurück. * Returns the user ID of the author. * - * @return int|null Die Benutzer-ID des Autors oder null, wenn keine Benutzer-ID gesetzt ist. / The user ID of the author or null if no user ID is set. + * @return int Die Benutzer-ID des Autors oder 0, wenn keine Benutzer-ID gesetzt ist. / The user ID of the author or 0 if no user ID is set. * * Beispiel / Example: * $beUserId = $author->getBeUserId(); * * @api */ - public function getBeUserId(): ?int + public function getBeUserId(): int { - return (int) $this->getValue('be_user_id'); + if ($this->hasValue('be_user_id')) { + return (int) $this->getValue('be_user_id'); + } + return 0; } /** @@ -165,6 +174,10 @@ public function setBeUserId(int $value): self */ public function getBeUser(): ?rex_user { - return rex_user::get($this->getBeUserId()); + $userId = $this->getBeUserId(); + if (0 !== $userId) { + return rex_user::get($userId); + } + return null; } } diff --git a/lib/Category.php b/lib/Category.php index 51411c5..5cbc7b8 100644 --- a/lib/Category.php +++ b/lib/Category.php @@ -41,7 +41,10 @@ class Category extends rex_yform_manager_dataset */ public function getName(): string { - return $this->getValue('name'); + if ($this->hasValue('name')) { + return $this->getValue('name'); + } + return ''; } /** @@ -65,7 +68,7 @@ public function setName(string $name): self * Gibt die Einträge der Kategorie zurück. * Returns the entries of the Category. * - * @return rex_yform_manager_collection Die Einträge der Kategorie oder null, wenn keine Einträge vorhanden sind. / The entries of the Category or null if no entries are present. + * @return rex_yform_manager_collection Die Einträge der Kategorie oder leere Liste, wenn keine Einträge vorhanden sind. / The entries of the Category or empty list if no entries are present. * * Beispiel / Example: * $entries = $category->getEntries(); diff --git a/lib/Entry.php b/lib/Entry.php index ff2e34e..11580e6 100644 --- a/lib/Entry.php +++ b/lib/Entry.php @@ -16,8 +16,12 @@ use rex_yform_list; use rex_yform_manager_collection; use rex_yform_manager_dataset; +use rex_yform_manager_query; use rex_yform_manager_table; +use function count; +use function is_bool; +use function is_int; use function is_string; /** @@ -162,8 +166,8 @@ static function ($a) { */ public function getAuthor(): ?Author { - if ($this->getRelatedDataset('author_id')) { - return Author::get($this->getRelatedDataset('author_id')->getId()); + if ($this->hasValue('author_id')) { + return Author::get($this->getValue('author_id')); } return null; } @@ -173,7 +177,10 @@ public function getAuthor(): ?Author */ public function getDomain(): string { - return $this->getValue('domain'); + if ($this->hasValue('domain')) { + return (string) $this->getValue('domain'); + } + return ''; } /** @@ -203,7 +210,10 @@ public function setDomain(mixed $domain): self */ public function getTeaser(): string { - return $this->getValue('teaser'); + if ($this->hasValue('teaser')) { + return $this->getValue('teaser'); + } + return ''; } /** @@ -235,12 +245,16 @@ public function getCategories(): rex_yform_manager_collection */ public function getImage(): string { - if ('' == $this->getValue('image')) { - $this->image = rex_config::get('neues', 'default_thumbnail'); + if ($this->hasValue('image')) { + $image = $this->getValue('image'); } else { - $this->image = $this->getValue('image'); + $image = ''; } - return $this->image; + if ('' == $image) { + $image = rex_config::get('neues', 'default_thumbnail'); + $this->setImage($image); + } + return $image; } /** @@ -261,27 +275,30 @@ public function setImage(string $image): self * Gibt die Bilder des Eintrags zurück. * Returns the images of the entry. * - * @return array|null Die Bilder des Eintrags oder null, wenn keine Bilder gesetzt sind. / The images of the entry or null if no images are set. + * @return array Die Bilder des Eintrags oder [], wenn keine Bilder gesetzt sind. / The images of the entry or [] if no images are set. * * Beispiel / Example: * $images = $entry->getImages(); - * TODO: null kommt nicht vor * @api */ - public function getImages(): ?array + public function getImages(): array { - return array_filter(explode(',', $this->getValue('images'))); + if ($this->hasValue('images')) { + $images = $this->getValue('images'); + return array_filter(explode(',', $images)); + } + return []; } /** * Setzt die Bilder des Eintrags. * Sets the images of the entry. * - * @param array|null $images Die neuen Bilder des Eintrags. / The new images of the entry. + * @param array $images Die neuen Bilder des Eintrags. / The new images of the entry. * * @api */ - public function setImages(?array $images): self + public function setImages(array $images = []): self { $this->setValue('images', implode(',', $images)); return $this; @@ -300,17 +317,21 @@ public function setImages(?array $images): self */ public function getMedia(): ?rex_media { - if (rex_addon::get('media_manager_responsive')->isAvailable()) { - return rex_media_plus::get($this->getImage()); + $image = $this->getImage(); + if ('' !== $image) { + if (rex_addon::get('media_manager_responsive')->isAvailable()) { + return rex_media_plus::get($image); + } + return rex_media::get($image); } - return rex_media::get($this->getImage()); + return null; } /** * Setzt das Medium des Eintrags. * Sets the media of the entry. * - * @param rex_media|null $media Das neue Medium des Eintrags. / The new media of the entry. + * @param rex_media|null $media Das neue Medium des Eintrags oer null für Entfernen. / The new media of the entry or null to delete. * * @api */ @@ -319,7 +340,7 @@ public function setMedia(?rex_media $media): self if (null !== $media) { $this->setValue('image', $media->getFileName()); } else { - $this->setValue('image', null); + $this->setValue('image', ''); } return $this; } @@ -337,7 +358,7 @@ public function setMedia(?rex_media $media): self */ public function getDescriptionAsPlaintext(): string { - return strip_tags($this->getValue('description')); + return strip_tags($this->getDescription()); } /** @@ -353,7 +374,10 @@ public function getDescriptionAsPlaintext(): string */ public function getDescription(): string { - return $this->getValue('description'); + if ($this->hasValue('description')) { + return $this->getValue('description'); + } + return ''; } /** @@ -374,16 +398,19 @@ public function setDescription(string $description): self * Gibt die externe URL des Eintrags zurück. * Returns the external URL of the entry. * - * @return string|null Die externe URL des Eintrags oder null, wenn keine URL gesetzt ist. / The external URL of the entry or null if no URL is set. + * @return string Die externe URL des Eintrags oder '', wenn keine URL gesetzt ist. / The external URL of the entry or '' if no URL is set. * * Beispiel / Example: * $externalUrl = $entry->getExternalUrl(); * * @api */ - public function getExternalUrl(): ?string + public function getExternalUrl(): string { - return $this->getValue('url'); + if ($this->hasValue('url')) { + return $this->getValue('url'); + } + return ''; } /** @@ -404,16 +431,19 @@ public function setExternalUrl(string $url): self * Gibt die Canonical URL des Eintrags zurück. * Returns the canonical URL of the entry. * - * @return string|null Die Canonical URL des Eintrags oder null, wenn keine URL gesetzt ist. / The canonical URL of the entry or null if no URL is set. + * @return string Die Canonical URL des Eintrags oder '', wenn keine URL gesetzt ist. / The canonical URL of the entry or '' if no URL is set. * * Beispiel / Example: * $canonicalUrl = $entry->getCanonicalUrl(); * * @api */ - public function getCanonicalUrl(): ?string + public function getCanonicalUrl(): string { - return $this->getValue('canonical_url'); + if ($this->hasValue('canonical_url')) { + return $this->getValue('canonical_url'); + } + return ''; } /** @@ -443,7 +473,10 @@ public function setCanonicalUrl(string $url): self */ public function getPublishDate(): string { - return $this->getValue('publishdate'); + if ($this->hasValue('publishdate')) { + return $this->getValue('publishdate'); + } + return ''; } /** @@ -481,7 +514,7 @@ public function getFormattedPublishDate($format_date = IntlDateFormatter::FULL): * Gibt das formatierte Veröffentlichungsdatum und -zeit des Eintrags zurück. * Returns the formatted publish date and time of the entry. * - * @param array $format Das Format des Datums und der Zeit. Standardmäßig [IntlDateFormatter::FULL, IntlDateFormatter::SHORT]. / The format of the date and time. Defaults to [IntlDateFormatter::FULL, IntlDateFormatter::SHORT]. + * @param array{int,int} $format Das Format des Datums und der Zeit. Standardmäßig [IntlDateFormatter::FULL, IntlDateFormatter::SHORT]. / The format of the date and time. Defaults to [IntlDateFormatter::FULL, IntlDateFormatter::SHORT]. * @return string Das formatierte Veröffentlichungsdatum und -zeit des Eintrags. / The formatted publish date and time of the entry. * * Beispiel / Example: @@ -491,23 +524,30 @@ public function getFormattedPublishDate($format_date = IntlDateFormatter::FULL): */ public function getFormattedPublishDateTime($format = [IntlDateFormatter::FULL, IntlDateFormatter::SHORT]): string { - return rex_formatter::intlDateTime($this->getPublishDate(), $format); + $date = $this->getPublishDate(); + if ('' !== $date) { + return rex_formatter::intlDateTime($date, $format); + } + return ''; } /** * Gibt den Status des Eintrags zurück. * Returns the status of the entry. * - * @return string Der Status des Eintrags. / The status of the entry. + * @return int Der Status des Eintrags. / The status of the entry. * * Beispiel / Example: * $status = $entry->getStatus(); * * @api */ - public function getStatus(): string + public function getStatus(): int { - return $this->getValue('status'); + if ($this->hasValue('status')) { + return $this->getValue('status'); + } + return self::VOID; } /** @@ -524,11 +564,144 @@ public function setStatus(int $status): self return $this; } + /** + * Allgemeine Suche nach Einträgen über Kategorien, Status, Autor und Sprachen + * General Search for Entries by category, language, author, and status. + * + * Anwendungsbeispiele / Usage examples + * $allEntries = Entry::findBy(); + * $entries = Entry::findBy (status: Entry::IS_ONLINE, category: '1,2'); + * $entries = Entry::findBy (status: Entry::PLANNED, category: [1,2], lang: 'de'); + * + * @api + * @param int|array|string $category + * @param int|array|bool $status + * @param int|array|string $author + * @return rex_yform_manager_collection + */ + public static function findBy(int|array|string $category = [], int|array|bool $status = [], string|int $lang = -1, int|array|string $author = []): rex_yform_manager_collection + { + $query = self::queryBy($category, $status, $lang, $author); + return $query->find(); + } + + /** + * Allgemeine Suche nach Einträgen über Kategorien, Status, Autor und Sprachen vorbereiten. + * An die erzeugte Query können weitere Conditions oder Sortierungen angefügt werden. + * + * Prepare a general search for entries by category, language, author, and status + * Add further conditions or sorts + * + * Anwendungsbeispiele / Usage examples + * $query = Entry::queryBy(); + * $query = Entry::queryBy (status: Entry::IS_ONLINE, category: '1,2'); + * $query = Entry::queryBy (status: Entry::PLANNED, category: [1,2], lang: 'de'); + * + * $query->sortBy('publishdate', 'desc'); + * $entries = $query->find(); + * + * @api + * @param int|array|string $category + * @param int|array|bool $status + * @param int|array|string $author + * @return rex_yform_manager_query + */ + public static function queryBy(int|array|string $category = [], int|array|bool $status = [], string|int $lang = -1, int|array|string $author = []): rex_yform_manager_query + { + /** + * Die Abfrage vorbereiten. + */ + $query = self::query(); + $alias = $query->getTableAlias(); + // Als Beifang wird ein Zusatzfeld mit den IDs der zugeordneten Kategorien + // erzeugt (categories), das für die Filterung auf Kategorien erforderlich ist + $query->leftJoinRelation('category_ids', 'c'); + $query->selectRaw('IFNULL(GROUP_CONCAT(c.id),"0")', 'categories'); + $query->groupBy($alias . '.id'); + + /** + * Kategorie in einen normierten Wert umwandeln und ggf. die Query anpassen + * - String in ein Array umwandeln + * - Einzelwert in ein Array umandeln + * - Default ist [] => kein Filter + * - 0 ist "alle ohne Kategorie". + */ + if (is_string($category)) { + $category = array_filter(explode(',', $category)); + } + if (is_int($category)) { + $category = [$category]; + } + if (0 < count($category)) { + $query->havingListContains('categories', $category); + } + + /** + * Status berücksichtigen + * - Bool-Wert (Entry::IS_ONLINE) + * - Int-Wert für einen speziellen Status + * - Array mit mehreren Int-Werten eines Status. + * - Default ist [] => kein Filter. + */ + $boolStatus = is_bool($status); + if (is_bool($status)) { + $operator = $status ? '>=' : '<'; + $query->where($alias . '.status', self::ONLINE, $operator); + } elseif (is_int($status)) { + $query->where($alias . '.status', $status); + } elseif (0 < count($status)) { + $query->whereListContains($alias . '.status', $status); + } + + /** + * Sprache berücksichtigen + * - string verweist auf das Feld rex_neues_entry_lang.code (in ID auflösen) + * - int verweist auf die ID, die aber auch direkt im Datensatz steht. + * - Default: -1 => keine Einschränkung, alle suchen + * - Abfrage nur der Entries ohne Sprachzuordnung mit lang=0 + * Immer im Ergebnisset: "alle Sprachen", also Texte ohne spezifische Sprachzuordnung (0). + */ + if (is_string($lang)) { + $language = EntryLang::query()->where('code', $lang)->findOne(); + $lang = null === $language ? -1 : $language->getId(); + } + if (-1 !== $lang) { + $condition = [0]; + if (0 !== $lang) { + $condition[] = $lang; + } + $query->whereListContains('lang_id', $condition); + } + + /** + * Autor eingrenzen + * - String in ein Array umwandeln + * - int ist die ID genau eines Autors + * - array ist eine Autorenliste + * - 0 liefert die Entries ohne zugeordneten Autor + * - Default: [] steht für alle Einträge, kein Filter. + */ + if (is_string($author)) { + $author = array_filter(explode(',', $author)); + } + if (is_int($author)) { + $author = [$author]; + } + if (0 < count($author)) { + $query->whereListContains('author_id', $author); + } + + /** + * Abfrage bereitstellen. + */ + return $query; + } + /** * Findet Online-Einträge. Wenn eine Kategorie-ID angegeben ist, werden nur Einträge aus dieser Kategorie zurückgegeben. * Finds online entries. If a Category ID is provided, only entries from this Category are returned. * - * @param int|null $category_id Die ID der Kategorie. / The ID of the Category. + * @param int $category_id Die ID der Kategorie. / The ID of the Category. * @return rex_yform_manager_collection Die gefundenen Einträge bzw. eine leere Liste. / The found entries or empty list. * * Beispiel / Example: @@ -536,8 +709,12 @@ public function setStatus(int $status): self * * @api */ - public static function findOnline(?int $category_id = null): rex_yform_manager_collection + public static function findOnline(int $category_id = 0): rex_yform_manager_collection { + /** + * TODO: auf Entry::findBy zurückgreifen oder die Methode entfernen weil durch findBy obsolet + * return Entry::findBy (category: $category, status: self::IS_ONLINE);. + */ if (null !== $category_id) { return self::findByCategory($category_id); } @@ -548,7 +725,7 @@ public static function findOnline(?int $category_id = null): rex_yform_manager_c * Findet Einträge nach Kategorie. * Finds entries by Category. * - * @param int|null $category_id Die ID der Kategorie. / The ID of the Category. + * @param int $category_id Die ID der Kategorie. / The ID of the Category. * @param int $status Der Status der Einträge. / The status of the entries. * @return rex_yform_manager_collection Die gefundenen Einträge bzw. eine leere Liste. / The found entries or empty list. * @@ -557,8 +734,12 @@ public static function findOnline(?int $category_id = null): rex_yform_manager_c * * @api */ - public static function findByCategory(?int $category_id = null, int $status = self::ONLINE): rex_yform_manager_collection + public static function findByCategory(int $category_id = 0, int $status = self::ONLINE): rex_yform_manager_collection { + /** + * TODO: auf Entry::findBy zurückgreifen oder die Methode entfernen weil durch findBy obsolet + * return Entry::findBy (category: $category, status: $status);. + */ $query = self::query(); $alias = $query->getTableAlias(); $query->joinRelation('category_ids', 'c')->where($alias . '.status', $status, '>=')->where('c.id', $category_id); @@ -569,7 +750,7 @@ public static function findByCategory(?int $category_id = null, int $status = se * Findet Einträge durch IDs mehrerer Kategorien. * Finds entries by multiple Categories. * - * @param string|array|null $category_ids Die IDs der Kategorien als String oder Array. / The IDs of the Categories as a String or Array. + * @param string|array $category_ids Die IDs der Kategorien als String oder Array. / The IDs of the Categories as a String or Array. * @param int $status Der Status der Einträge. / The status of the entries. * @return rex_yform_manager_collection Die gefundenen Einträge bzw. eine leere Liste. / The found entries or empty list. * @@ -578,16 +759,18 @@ public static function findByCategory(?int $category_id = null, int $status = se * * @api */ - public static function findByCategoryIds(string|array|null $category_ids = null, int $status = self::ONLINE): rex_yform_manager_collection + public static function findByCategoryIds(string|array $category_ids = [], int $status = self::ONLINE): rex_yform_manager_collection { + /** + * TODO: auf Entry::findBy zurückgreifen oder die Methode entfernen weil durch findBy obsolet + * return Entry::findBy (category: $category, status: $status);. + */ $query = self::query()->where('status', $status, '>='); - if ($category_ids) { - // Wenn es ein String ist, in ein Array umwandeln - if (is_string($category_ids)) { - $category_ids = explode(',', $category_ids); - } - + if (is_string($category_ids)) { + $category_ids = explode(',', $category_ids); + } + if (0 < count($category_ids)) { $query->whereListContains('category_ids', $category_ids); } diff --git a/lib/EntryLang.php b/lib/EntryLang.php index 89bbf3a..4cb7f70 100644 --- a/lib/EntryLang.php +++ b/lib/EntryLang.php @@ -38,16 +38,19 @@ public function getEntries(): ?rex_yform_manager_collection * Gibt den Code der Sprache zurück. * Returns the code of the language. * - * @return string|null Der Code der Sprache oder null, wenn kein Code gesetzt ist. / The code of the language or null if no code is set. + * @return string Der Code der Sprache oder '', wenn kein Code gesetzt ist. / The code of the language or '' if no code is set. * * Beispiel / Example: * $code = $language->getCode(); * * @api */ - public function getCode(): ?string + public function getCode(): string { - return $this->getValue('code'); + if ($this->hasValue('code')) { + return $this->getValue('code'); + } + return ''; } /** @@ -77,7 +80,10 @@ public function setCode(string $value): self */ public function getName(): string { - return $this->getValue('name'); + if ($this->hasValue('name')) { + return $this->getValue('name'); + } + return ''; } /**