From b477d0439f84f8141630ebbdd3de0354a87b50dd Mon Sep 17 00:00:00 2001 From: Alexander Walther Date: Sat, 16 Dec 2023 16:15:47 +0100 Subject: [PATCH] update all neues_ lib class --- lib/neues_author.php | 42 ++++++++++----------- lib/neues_category.php | 74 ++++++++++++++++++++++++++++++++---- lib/neues_entry.php | 86 +++++++++++++++++++++++++----------------- 3 files changed, 140 insertions(+), 62 deletions(-) diff --git a/lib/neues_author.php b/lib/neues_author.php index a9fe12b..230b008 100644 --- a/lib/neues_author.php +++ b/lib/neues_author.php @@ -1,6 +1,6 @@ getValue('name'); + return $this->getValue("name"); } /** @@ -47,9 +47,9 @@ public function getName(): ?string * * @api */ - public function setName(string $value): self + public function setName(string $value) : self { - $this->setValue('name', $value); + $this->setValue("name", $value); return $this; } @@ -65,9 +65,9 @@ public function setName(string $value): self * * @api */ - public function getNickname(): ?string + public function getNickname() : ?string { - return $this->getValue('nickname'); + return $this->getValue("nickname"); } /** @@ -82,9 +82,9 @@ public function getNickname(): ?string * * @api */ - public function setNickname(string $value): self + public function setNickname(string $value) : self { - $this->setValue('nickname', $value); + $this->setValue("nickname", $value); return $this; } @@ -101,14 +101,14 @@ public function setNickname(string $value): self * * @api */ - public function getText(bool $asPlaintext = false): ?string + public function getText(bool $asPlaintext = false) : ?string { - if ($asPlaintext) { - return strip_tags($this->getValue('text')); + if($asPlaintext) { + return strip_tags($this->getValue("text")); } - return $this->getValue('text'); + return $this->getValue("text"); } - + /** * Setzt den Text des Autors. * Sets the text of the author. @@ -121,9 +121,9 @@ public function getText(bool $asPlaintext = false): ?string * * @api */ - public function setText(string $value): self + public function setText(string $value) : self { - $this->setValue('text', $value); + $this->setValue("text", $value); return $this; } @@ -139,9 +139,9 @@ public function setText(string $value): self * * @api */ - public function getBeUserId(): ?int + public function getBeUserId() : ?int { - return $this->getValue('be_user_id'); + return $this->getValue("be_user_id"); } /** @@ -156,9 +156,9 @@ public function getBeUserId(): ?int * * @api */ - public function setBeUserId(int $value): self + public function setBeUserId(int $value) : self { - $this->setValue('be_user_id', $value); + $this->setValue("be_user_id", $value); return $this; } @@ -171,7 +171,7 @@ public function setBeUserId(int $value): self * Beispiel / Example: * $beUser = $author->getBeUser(); */ - public function getBeUser(): ?rex_user + public function getBeUser() : ?rex_user { return rex_user::get($this->getBeUserId()); } diff --git a/lib/neues_category.php b/lib/neues_category.php index cc1b9c1..6c69743 100644 --- a/lib/neues_category.php +++ b/lib/neues_category.php @@ -1,22 +1,82 @@ setValue('name', 'Neue Kategorie'); + * $category->save(); + */ class neues_category extends \rex_yform_manager_dataset { - /** @api */ + /** + * Gibt den Namen der Kategorie zurück. + * Returns the name of the category. + * + * @return string Der Name der Kategorie. / The name of the category. + * + * Beispiel / Example: + * $name = $category->getName(); + * + * @api + */ public function getName(): string { return $this->getValue('name'); } - - public function setName(string $string): self + /** + * Setzt den Namen der Kategorie. + * Sets the name of the category. + * + * @param string $name Der neue Name der Kategorie. / The new name of the category. + * + * Beispiel / Example: + * $category->setName('Neuer Name'); + */ + public function setName(string $name): self { - $this->setValue('name', $string); + $this->setValue('name', $name); return $this; } - - /** @api */ + /** + * Gibt die Einträge der Kategorie zurück. + * Returns the entries of the category. + * + * @return rex_yform_manager_collection|null 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. + * + * Beispiel / Example: + * $entries = $category->getEntries(); + * + * @api + */ public function getEntries(): ?rex_yform_manager_collection { return $this->getRelatedDataset('entry_ids'); } + /** + * Gibt die URL der Kategorie zurück. + * Returns the URL of the category. + * + * @param string $profile Das Profil, das für die URL-Erstellung verwendet wird. Standardmäßig 'neues-category-id'. / The profile used for URL creation. Defaults to 'neues-category-id'. + * @return string Die URL der Kategorie oder ein leerer String, wenn keine URL gefunden wurde. / The URL of the category or an empty string if no URL was found. + * + * Beispiel / Example: + * $url = $category->getUrl(); + * + * @api + */ + public function getUrl(string $profile = 'neues-category-id'): ?string + { + if ($url = rex_getUrl(null, null, [$profile => $this->getId()])) { + return $url; + } + return null; + } } diff --git a/lib/neues_entry.php b/lib/neues_entry.php index b7e48f4..7539fcf 100644 --- a/lib/neues_entry.php +++ b/lib/neues_entry.php @@ -1,10 +1,27 @@ getName(); + */ public function getName(): string { return $this->getValue('name'); @@ -15,8 +32,16 @@ public function setName(string $name): self $this->setValue('name', $name); return $this; } - - /** @api */ + /** + * @api + * @return string + * + * Gibt den Autor des Eintrags zurück. + * Returns the author of the entry. + * + * Beispiel / Example: + * $author = $entry->getAuthor(); + */ public function getAuthor(): string { return $this->getValue('author'); @@ -27,8 +52,16 @@ public function setAuthor(string $author): self $this->setValue('author', $author); return $this; } - - /** @api */ + /** + * @api + * @return string + * + * Gibt die Domain des Eintrags zurück. + * Returns the domain of the entry. + * + * Beispiel / Example: + * $domain = $entry->getDomain(); + */ public function getDomain(): string { return $this->getValue('domain'); @@ -46,19 +79,10 @@ public function getTeaser(): string return $this->getValue('teaser'); } - public function setTeaser(string $teaser): self - { - $this->setValue('teaser', $teaser); - return $this; - } - /** @api */ public function getCategories(): ?rex_yform_manager_collection { - if (!$this->categories) { - $this->categories = $this->getRelatedCollection('category_ids'); - return $this->categories; - } + return $this->getRelatedCollection('category_ids'); } /** @api */ @@ -93,6 +117,9 @@ public function setImages(?array $images): self /** @api */ public function getMedia(): ?rex_media { + if(rex_addon::get('media_manager_resposnive')->isAvailable()) { + return rex_media_plus::get($this->getImage()); + } return rex_media::get($this->getImage()); } @@ -112,12 +139,6 @@ public function getDescriptionAsPlaintext(): string return strip_tags($this->getValue('description')); } - public function setDescriptionAsPlaintext(string $description): self - { - $this->setValue('description', $description); - return $this; - } - /** @api */ public function getDescription(): string { @@ -172,13 +193,13 @@ public function setPublishDate(string $publishdate): self } /** @api */ - public function getFormattedPublishDate(string $format_date = IntlDateFormatter::FULL): string + public function getFormattedPublishDate($format_date = IntlDateFormatter::FULL): string { return $this->getFormattedPublishDateTime([$format_date, IntlDateFormatter::NONE]); } /** @api */ - public function getFormattedPublishDateTime(string $format = [IntlDateFormatter::FULL, IntlDateFormatter::SHORT]): string + public function getFormattedPublishDateTime($format = [IntlDateFormatter::FULL, IntlDateFormatter::SHORT]): string { return rex_formatter::intlDateTime($this->getPublishDate(), $format); } @@ -195,12 +216,15 @@ public function setStatus(int $status): self return $this; } - public static function findOnline(): ?rex_yform_manager_collection + public static function findOnline(int $category_id = null): ?rex_yform_manager_collection { + if($category_id) { + return self::findByCategory($category_id); + } return self::query()->where('status', 1, '>=')->find(); } - public static function findByCategory(int $category_id, $status = 1): ?rex_yform_manager_collection + public static function findByCategory(int $category_id = null, int $status = 1): ?rex_yform_manager_collection { $query = self::query()->joinRelation('category_ids', 'c')->where('rex_neues_entry.status', $status, '>=')->where('c.id', $category_id); return $query->find(); @@ -214,10 +238,4 @@ public function getUrl(string $profile = 'neues-entry-id'): string } return ''; } - - public function setUrl(string $url): self - { - $this->setValue('url', $url); - return $this; - } }