src/Cms/Modules/AlertBundle/Model/Alert/AlertData.php line 47

Open in your IDE?
  1. <?php
  2. namespace Cms\Modules\AlertBundle\Model\Alert;
  3. use Cms\FileBundle\Entity\Nodes\File;
  4. use Cms\FileBundle\Model\Attachable\AttachableInterface;
  5. use Cms\FileBundle\Model\Attachable\AttachableModuleDataTrait;
  6. use Cms\ModuleBundle\Entity\Interfaces\RssFeedableInterface;
  7. use Cms\ModuleBundle\Entity\SocialMetadata;
  8. use Cms\ModuleBundle\Entity\StandardMetadata;
  9. use Cms\ModuleBundle\Model\Data;
  10. use Cms\ModuleBundle\Model\Interfaces\Sociable\SociableInterface;
  11. use Cms\Modules\AlertBundle\Entity\Alert\AlertRssFeedableTrait;
  12. use Cms\TagBundle\Model\Taggable\TaggableInterface;
  13. use Cms\TagBundle\Model\Taggable\TaggableModuleDataTrait;
  14. use Common\Util\Strings;
  15. use DateTime;
  16. use Reinder83\BinaryFlags\Bits;
  17. /**
  18.  * Class AlertData
  19.  * @package Cms\Modules\AlertBundle\Model\Alert
  20.  *
  21.  * @method string getTitle()
  22.  * @method string getSlug()
  23.  * @method DateTime getStartDate()
  24.  * @method DateTime getExpiryDate()
  25.  * @method string getAbstract()
  26.  * @method string getContent()
  27.  * @method SocialMetadata getSocial()
  28.  * @method StandardMetadata getStandardMetadata()
  29.  * @method string getExternalLink()
  30.  * @method File|null getSocialImage()
  31.  * @method int getLevel()
  32.  * @method int getBehavior()
  33.  * @method AlertData setTitle($value)
  34.  * @method AlertData setSlug($value)
  35.  * @method AlertData setStartDate($value)
  36.  * @method AlertData setExpiryDate($value)
  37.  * @method AlertData setAbstract($value)
  38.  * @method AlertData setContent($value)
  39.  * @method AlertData setExternalLink(string $value)
  40.  * @method AlertData setSocialImage(File|null $value)
  41.  * @method AlertData setLevel(int $value)
  42.  * @method AlertData setBehavior(int $value)
  43.  */
  44. final class AlertData extends Data implements TaggableInterfaceRssFeedableInterfaceAttachableInterfaceSociableInterface
  45. {
  46.     const TYPE 'Alert';
  47.     const LEVELS = [
  48.         'informative' => self::LEVELS__INFORMATIVE,
  49.         'important' => self::LEVELS__IMPORTANT,
  50.         'urgent' => self::LEVELS__URGENT,
  51.     ];
  52.     const LEVELS__INFORMATIVE 100;
  53.     const LEVELS__IMPORTANT 0;
  54.     const LEVELS__URGENT = -100;
  55.     const BEHAVIORS = [
  56.         'none' => self::BEHAVIORS__NONE,
  57.         'popup' => self::BEHAVIORS__POPUP,
  58.     ];
  59.     const BEHAVIORS__NONE 0;
  60.     const BEHAVIORS__POPUP Bits::BIT_1;
  61.     use TaggableModuleDataTrait;
  62.     use AlertRssFeedableTrait;
  63.     use AttachableModuleDataTrait;
  64.     /**
  65.      * {@inheritDoc}
  66.      */
  67.     public function getSocialMetadata(): array
  68.     {
  69.         return [
  70.             'og:type' => 'article',
  71.             'title' => $this->getStandardMetadata()->getTitle() ?: $this->getTitle(),
  72.             'image' => $this->getSocialImage(),
  73.             'cs:image-presized' => ( ! empty($this->getSocialImage())),
  74.             'description' => $this->getStandardMetadata()->getDescription() ?: Strings::htmltidytrim($this->getContent()),
  75.         ];
  76.     }
  77.     /**
  78.      * @return bool
  79.      */
  80.     public function isActive()
  81.     {
  82.         $now = new DateTime();
  83.         return ($this->getStartDate() < $now) && ($now $this->getExpiryDate());
  84.     }
  85.     /**
  86.      * {@inheritdoc}
  87.      */
  88.     public function ui()
  89.     {
  90.         return $this->getTitle();
  91.     }
  92. }