<?php
namespace Cms\Modules\AlertBundle\Model\Alert;
use Cms\FileBundle\Entity\Nodes\File;
use Cms\FileBundle\Model\Attachable\AttachableInterface;
use Cms\FileBundle\Model\Attachable\AttachableModuleDataTrait;
use Cms\ModuleBundle\Entity\Interfaces\RssFeedableInterface;
use Cms\ModuleBundle\Entity\SocialMetadata;
use Cms\ModuleBundle\Entity\StandardMetadata;
use Cms\ModuleBundle\Model\Data;
use Cms\ModuleBundle\Model\Interfaces\Sociable\SociableInterface;
use Cms\Modules\AlertBundle\Entity\Alert\AlertRssFeedableTrait;
use Cms\TagBundle\Model\Taggable\TaggableInterface;
use Cms\TagBundle\Model\Taggable\TaggableModuleDataTrait;
use Common\Util\Strings;
use DateTime;
use Reinder83\BinaryFlags\Bits;
/**
* Class AlertData
* @package Cms\Modules\AlertBundle\Model\Alert
*
* @method string getTitle()
* @method string getSlug()
* @method DateTime getStartDate()
* @method DateTime getExpiryDate()
* @method string getAbstract()
* @method string getContent()
* @method SocialMetadata getSocial()
* @method StandardMetadata getStandardMetadata()
* @method string getExternalLink()
* @method File|null getSocialImage()
* @method int getLevel()
* @method int getBehavior()
* @method AlertData setTitle($value)
* @method AlertData setSlug($value)
* @method AlertData setStartDate($value)
* @method AlertData setExpiryDate($value)
* @method AlertData setAbstract($value)
* @method AlertData setContent($value)
* @method AlertData setExternalLink(string $value)
* @method AlertData setSocialImage(File|null $value)
* @method AlertData setLevel(int $value)
* @method AlertData setBehavior(int $value)
*/
final class AlertData extends Data implements TaggableInterface, RssFeedableInterface, AttachableInterface, SociableInterface
{
const TYPE = 'Alert';
const LEVELS = [
'informative' => self::LEVELS__INFORMATIVE,
'important' => self::LEVELS__IMPORTANT,
'urgent' => self::LEVELS__URGENT,
];
const LEVELS__INFORMATIVE = 100;
const LEVELS__IMPORTANT = 0;
const LEVELS__URGENT = -100;
const BEHAVIORS = [
'none' => self::BEHAVIORS__NONE,
'popup' => self::BEHAVIORS__POPUP,
];
const BEHAVIORS__NONE = 0;
const BEHAVIORS__POPUP = Bits::BIT_1;
use TaggableModuleDataTrait;
use AlertRssFeedableTrait;
use AttachableModuleDataTrait;
/**
* {@inheritDoc}
*/
public function getSocialMetadata(): array
{
return [
'og:type' => 'article',
'title' => $this->getStandardMetadata()->getTitle() ?: $this->getTitle(),
'image' => $this->getSocialImage(),
'cs:image-presized' => ( ! empty($this->getSocialImage())),
'description' => $this->getStandardMetadata()->getDescription() ?: Strings::htmltidytrim($this->getContent()),
];
}
/**
* @return bool
*/
public function isActive()
{
$now = new DateTime();
return ($this->getStartDate() < $now) && ($now < $this->getExpiryDate());
}
/**
* {@inheritdoc}
*/
public function ui()
{
return $this->getTitle();
}
}