Cockpit integration

This commit is contained in:
2024-11-07 21:34:32 +01:00
parent d3eccf99f0
commit a4b336b3fd
8 changed files with 153 additions and 41 deletions

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Application\Models;
use Exception;
use JMS\Serializer\Annotation\SerializedName;
use JMS\Serializer\Annotation\Type;
@@ -13,39 +14,95 @@ class Article
#[SerializedName('authors')]
#[Type('array<' . Author::class . '>')]
protected array $authors;
protected ?array $authors = null;
#[SerializedName('headline')]
#[Type('string')]
protected string $headline;
protected ?string $headline = null;
#[SerializedName('excerpt')]
#[Type('string')]
protected string $excerpt;
protected ?string $excerpt = null;
#[SerializedName('image')]
#[Type(Image::class)]
protected Image $image;
protected ?Image $image = null;
#[SerializedName('text')]
#[Type('string')]
protected string $text;
protected ?string $text = null;
/**
* Return the title / headline.
*
* @return string
* @return string|null
*/
public function getTitle(): string {
public function getTitle(): string|null
{
return $this->headline;
}
/**
* Return the text / article body text.
*
* @return string
* @return string|null
*/
public function getText(): string {
public function getText(): string|null
{
return $this->text;
}
/**
* Get the excerpt / teaser text.
*
* @return string|null
*/
public function getExcerpt(): string|null
{
return $this->excerpt;
}
public function getImage(): Image|null
{
return $this->image;
}
public function getTeaserData(): array
{
return [
'headline' => $this->getHeadline(),
'kicker' => $this->getKicker(),
'excerpt' => $this->getExcerpt(),
'teaserImage' => $this->getTeaserImage(),
'url' => $this->getUrl(),
];
}
private function getIdentifier(): string
{
return $this->metaId;
}
private function getHeadline(): ?string
{
return $this->headline;
}
private function getKicker(): ?string
{
return $this->excerpt;
}
/**
* @throws Exception
*/
private function getTeaserImage(): array
{
return $this->image->getTeaserData();
}
public function getUrl(): string
{
return '/article/test_article-' . $this->getIdentifier();
}
}

View File

@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace Application\Models;
use Application\AppEnvironment;
use Exception;
use JMS\Serializer\Annotation\SerializedName;
use JMS\Serializer\Annotation\Type;
@@ -44,12 +46,12 @@ class Image
private array $colors;
#[SerializedName('width')]
#[Type('string')]
private string $width;
#[Type('int')]
private int $width;
#[SerializedName('height')]
#[Type('string')]
private string $height;
#[Type('int')]
private int $height;
#[SerializedName('altText')]
#[Type('string')]
@@ -62,4 +64,56 @@ class Image
#[SerializedName('folder')]
#[Type('string')]
private string $folder;
/**
* Return the URL to the original asset.
*
* @return string
* @throws Exception
*/
public function getImageUrl(): string
{
$apiPath = AppEnvironment::getInstance()->getVariable('COCKPIT_API_PATH');
$url = parse_url($apiPath, PHP_URL_SCHEME) . '://';
$url .= parse_url($apiPath, PHP_URL_HOST) . '/storage/uploads';
$url .= $this->path;
return $url;
}
/**
* Return original image width in pixel.
*
* @return int
*/
public function getWidth(): int
{
return $this->width;
}
/**
* Return original image height in pixel.
*
* @return int
*/
public function getHeight(): int
{
return $this->height;
}
/**
* Get teaser data array ready to be used within the template.
*
* @return array
* @throws Exception
*/
public function getTeaserData(): array
{
return [
'src' => $this->getImageUrl(),
'width' => $this->getWidth(),
'height' => $this->getHeight(),
'alt' => $this->altText,
];
}
}