Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type hinting setter #31

Merged
merged 10 commits into from
Dec 11, 2023
12 changes: 12 additions & 0 deletions lib/neues_category.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,21 @@ 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
{
return $this->getRelatedDataset('entry_ids');
}

public function setEntries(rex_yform_manager_collection $entries): self
{
$this->setValue('entry_ids', $entries);
return $this;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Da macht's keinen Sinn, denn Entries werden hier nur abgefragt.

alxndr-w marked this conversation as resolved.
Show resolved Hide resolved
}
102 changes: 98 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 @@ -37,6 +61,12 @@ public function getCategories(): ?rex_yform_manager_collection
}
}

public function setCategories(?rex_yform_manager_collection $categories): self
{
$this->categories = $categories;
return $this;
}

alxndr-w marked this conversation as resolved.
Show resolved Hide resolved
/** @api */
public function getImage(): string
{
Expand All @@ -48,36 +78,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 +159,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 +195,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