Skip to content

Commit

Permalink
added images to Luigi's Box article feed
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasLudvik committed Feb 22, 2024
1 parent 3cfc89b commit 56de038
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/Model/LuigisBoxArticleFeedItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@

namespace Shopsys\ArticleFeed\LuigisBoxBundle\Model;

use Shopsys\FrameworkBundle\Component\Image\ImageUrlWithSizeHelper;
use Shopsys\FrameworkBundle\Model\Feed\FeedItemInterface;

class LuigisBoxArticleFeedItem implements FeedItemInterface
{
public const UNIQUE_BLOG_ARTICLE_IDENTIFIER_PREFIX = 'blog_article-';
public const UNIQUE_ARTICLE_IDENTIFIER_PREFIX = 'article-';
protected const SMALL_IMAGE_SIZE = 100;
protected const MEDIUM_IMAGE_SIZE = 200;
protected const LARGE_IMAGE_SIZE = 600;

/**
* @param int $id
Expand All @@ -18,6 +22,7 @@ class LuigisBoxArticleFeedItem implements FeedItemInterface
* @param string $link
* @param string|null $description
* @param string|null $perex
* @param string|null $imageUrl
*/
public function __construct(
protected readonly int $id,
Expand All @@ -26,6 +31,7 @@ public function __construct(
protected readonly string $link,
protected readonly ?string $description,
protected readonly ?string $perex,
protected readonly ?string $imageUrl = null,
) {
}

Expand Down Expand Up @@ -76,4 +82,40 @@ public function getAnnotation(): ?string
{
return $this->perex;
}

/**
* @return string|null
*/
public function getImageLinkS(): ?string
{
if ($this->imageUrl === null) {
return null;
}

return ImageUrlWithSizeHelper::limitSizeInImageUrl($this->imageUrl, static::SMALL_IMAGE_SIZE, static::SMALL_IMAGE_SIZE);
}

/**
* @return string|null
*/
public function getImageLinkM(): ?string
{
if ($this->imageUrl === null) {
return null;
}

return ImageUrlWithSizeHelper::limitSizeInImageUrl($this->imageUrl, static::MEDIUM_IMAGE_SIZE, static::MEDIUM_IMAGE_SIZE);
}

/**
* @return string|null
*/
public function getImageLinkL(): ?string
{
if ($this->imageUrl === null) {
return null;
}

return ImageUrlWithSizeHelper::limitSizeInImageUrl($this->imageUrl, static::LARGE_IMAGE_SIZE, static::LARGE_IMAGE_SIZE);
}
}
1 change: 1 addition & 0 deletions src/Model/LuigisBoxArticleFeedItemFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function create(array $articleData): LuigisBoxArticleFeedItem
$articleData['url'],
TransformString::convertHtmlToPlainText($articleData['text']),
TransformString::convertHtmlToPlainText($articleData['perex'] ?? null),
$articleData['imageUrl'] ?? null,
);
}
}
5 changes: 5 additions & 0 deletions src/Resources/views/feed.xml.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
{% if item.text is not null %}
<text>{{ item.text }}</text>
{% endif %}
{% if item.imageLinkS is not null -%}
<image_link_s>{{ item.imageLinkS }}</image_link_s>
<image_link_m>{{ item.imageLinkM }}</image_link_m>
<image_link_l>{{ item.imageLinkL }}</image_link_l>
{% endif -%}
</article>
{% endblock %}

Expand Down

0 comments on commit 56de038

Please sign in to comment.