Skip to content

Commit

Permalink
Merge pull request #31 from alexplusde/type-hinting-setter
Browse files Browse the repository at this point in the history
Type hinting setter
  • Loading branch information
alxndr-w authored Dec 11, 2023
2 parents 7b548c7 + c5fe1b1 commit 3f6b6f5
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 6 deletions.
6 changes: 6 additions & 0 deletions lib/neues_category.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ public function getName(): string
return $this->getValue('name');
}

public function setName(string $string): self
{
$this->setValue('name', $string);
return $this;
}

/** @api */
public function getEntries(): ?rex_yform_manager_collection
{
Expand Down
96 changes: 92 additions & 4 deletions lib/neues_entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,48 @@ public function getName(): string
return $this->getValue('name');
}

public function setName(string $name): self
{
$this->setValue('name', $name);
return $this;
}

/** @api */
public function getAuthor(): string
{
return $this->getValue('author');
}

public function setAuthor(string $author): self
{
$this->setValue('author', $author);
return $this;
}

/** @api */
public function getDomain(): string
{
return $this->getValue('domain');
}

public function setDomain(string $domain): self
{
$this->setValue('domain', $domain);
return $this;
}

/** @api */
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
{
Expand All @@ -48,36 +72,76 @@ public function getImage(): string
return $this->image;
}

public function setImage(string $image): self
{
$this->setValue('image', $image);
return $this;
}

/** @api */
public function getImages(): ?array
{
return array_filter(explode(',', $this->getValue('images')));
}

public function setImages(?array $images): self
{
$this->setValue('images', implode(',', $images));
return $this;
}

/** @api */
public function getMedia(): ?rex_media
{
return rex_media::get($this->getImage());
}

public function setMedia(?rex_media $media): self
{
if (null !== $media) {
$this->setValue('image', $media->getFileName());
} else {
$this->setValue('image', null);
}
return $this;
}

/** @api */
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
{
return $this->getValue('description');
}

public function setDescription(string $description): self
{
$this->setValue('description', $description);
return $this;
}

/** @api */
public function getExternalUrl(): ?string
{
return $this->getValue('url');
}

public function setExternalUrl(string $url): self
{
$this->setValue('url', $url);
return $this;
}

/** @api */
public function getExternalLabel(): string
{
Expand All @@ -89,20 +153,32 @@ public function getExternalLabel(): string
return $this->externalLabel;
}

public function setExternalLabel(string $label): self
{
$this->setValue('url_label', $label);
return $this;
}

/** @api */
public function getPublishDate(): string
{
return $this->getValue('publishdate');
}

public function setPublishDate(string $publishdate): self
{
$this->setValue('publishdate', $publishdate);
return $this;
}

/** @api */
public function getFormattedPublishDate($format_date = IntlDateFormatter::FULL): string
public function getFormattedPublishDate(string $format_date = IntlDateFormatter::FULL): string
{
return $this->getFormattedPublishDateTime([$format_date, IntlDateFormatter::NONE]);
}

/** @api */
public function getFormattedPublishDateTime($format = [IntlDateFormatter::FULL, IntlDateFormatter::SHORT]): string
public function getFormattedPublishDateTime(string $format = [IntlDateFormatter::FULL, IntlDateFormatter::SHORT]): string
{
return rex_formatter::intlDateTime($this->getPublishDate(), $format);
}
Expand All @@ -113,23 +189,35 @@ public function getStatus(): string
return $this->getValue('status');
}

public function setStatus(int $status): self
{
$this->setValue('status', $status);
return $this;
}

public static function findOnline(): ?rex_yform_manager_collection
{
return self::query()->where('status', 1, '>=')->find();
}

public static function findByCategory($category_id, $status = 1): ?rex_yform_manager_collection
public static function findByCategory(int $category_id, $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();
}

/** @api */
public function getUrl($profile = 'neues-entry-id'): string
public function getUrl(string $profile = 'neues-entry-id'): string
{
if ($url = rex_getUrl(null, null, [$profile => $this->getId()])) {
return $url;
}
return '';
}

public function setUrl(string $url): self
{
$this->setValue('url', $url);
return $this;
}
}
4 changes: 2 additions & 2 deletions lib/rex_api_neues_rss.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public function execute(): void
exit(self::getRssFeed(neues_entry::findOnline()));
}

public static function getRssFeed($collection, $domain, $lang, $filename)
public static function getRssFeed(array $collection, string $domain, string $lang, string $filename): array
{
return self::createRssFeed($collection, $domain, $lang, $filename);
}

public static function createRssFeed($collection = null, $domain = null, $lang = null, $filename = 'rss.neues.xml')
public static function createRssFeed(?array $collection = null, ?string $domain = null, ?string $lang = null, string $filename = 'rss.neues.xml'): void
{
if (!$collection) {
$collection = neues_entry::findOnline();
Expand Down

0 comments on commit 3f6b6f5

Please sign in to comment.