src/Entity/Alert.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Business\Context;
  4. use App\Business\ContextableEntity;
  5. use App\Utils\Helper;
  6. use App\Application\Sonata\MediaBundle\Entity\Media;
  7. use DateTime;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Gedmo\Timestampable\Traits\TimestampableEntity;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. /**
  12.  * To use in many templates
  13.  * @ORM\Entity(repositoryClass="App\Repository\AlertRepository")
  14.  */
  15. class Alert implements ContextableEntity
  16. {
  17.     use TimestampableEntity;
  18.     use BlameableEntity;
  19.     const ALERT_EVENT "event";
  20.     const ALERT_GLOBAL "global";
  21.     /**
  22.      * @var int
  23.      *
  24.      * @ORM\Column(name="id", type="integer")
  25.      * @ORM\Id
  26.      * @ORM\GeneratedValue(strategy="AUTO")
  27.      */
  28.     public $id;
  29.     /**
  30.      * @var string $type
  31.      *
  32.      * @ORM\Column(name="reference_type", type="string", length=50, nullable=false)
  33.      * @Assert\NotBlank(message="Type cannot be blank",groups={"new"})
  34.      * @Assert\Choice(
  35.      *      choices = {
  36.      *          Alert::ALERT_EVENT: "event",
  37.      *          Alert::ALERT_GLOBAL: "global"
  38.      *      },
  39.      *      message = "Choose a valid type.", groups={"new"}
  40.      * )
  41.      */
  42.     private $referenceType;
  43.     /**
  44.      * @var string $referenceId
  45.      * @ORM\Column(name="reference_id", type="text", length=256, nullable = true)
  46.      */
  47.     private $referenceId;
  48.     /**
  49.      * @var string
  50.      * @Assert\NotBlank(message="Text cannot be blank",groups={"new"})
  51.      * @Assert\Length(max=280)
  52.      * @ORM\Column(name="text", type="string", length=280, nullable=false)
  53.      */
  54.     private $text;
  55.     /**
  56.      * @var string
  57.      * @ORM\Column(name="url", type="string", length=255, nullable=true)
  58.      */
  59.     private $url;
  60.     /**
  61.      * @var string
  62.      * @ORM\Column(name="twitter_id", type="string", length=50, nullable=true)
  63.      */
  64.     private $twitterId;
  65.     /**
  66.      * @var DateTime
  67.      *
  68.      * @ORM\Column(name="start_date", type="datetime", nullable=false)
  69.      */
  70.     private $startDate;
  71.     /**
  72.      * @var DateTime
  73.      *
  74.      * @ORM\Column(name="end_date", type="datetime", nullable=false)
  75.      */
  76.     private $endDate;
  77.     /**
  78.      * @var DateTime
  79.      *
  80.      * @ORM\Column(name="date_email_sent", type="datetime", nullable=true)
  81.      */
  82.     private $dateEmailSent;
  83.     /**
  84.      * @var DateTime
  85.      *
  86.      * @ORM\Column(name="date_twitter_done", type="datetime", nullable=true)
  87.      */
  88.     private $dateTwitterDone;
  89.     /**
  90.      * @var boolean
  91.      * @ORM\Column(name="show_banner", type="boolean", nullable = true)
  92.      */
  93.     private $showBanner true;
  94.     /**
  95.      * @var boolean
  96.      * @ORM\Column(name="send_mail", type="boolean", nullable = true)
  97.      */
  98.     private $sendMail false;
  99.     /**
  100.      * @var boolean
  101.      * @ORM\Column(name="create_tweet", type="boolean", nullable = true)
  102.      */
  103.     private $createTweet false;
  104.     /**
  105.      * @ORM\OneToOne(targetEntity="App\Application\Sonata\MediaBundle\Entity\Media", cascade={"persist"})
  106.      */
  107.     private $image;
  108.     /**
  109.      * @return bool
  110.      */
  111.     public function isShowBanner(): bool
  112.     {
  113.         return $this->showBanner === null false $this->showBanner;
  114.     }
  115.     /**
  116.      * @param bool $showBanner
  117.      */
  118.     public function setShowBanner(bool $showBanner): void
  119.     {
  120.         $this->showBanner $showBanner;
  121.     }
  122.     /**
  123.      * @return string Context::ALERTS
  124.      */
  125.     public function getContextId(): string
  126.     {
  127.         return Context::ALERTS;
  128.     }
  129.     public function getContextCategoryId(): string
  130.     {
  131.         return "";
  132.     }
  133.     public function getContextMainCategoryId(): string
  134.     {
  135.         return "Alerts";
  136.     }
  137.     public function getId()
  138.     {
  139.         return $this->id;
  140.     }
  141.     public function setId($id)
  142.     {
  143.         $this->id $id;
  144.         return $this;
  145.     }
  146.     public function getReferenceId()
  147.     {
  148.         return $this->referenceId;
  149.     }
  150.     /**
  151.      * @param string $referenceId
  152.      * @return Alert
  153.      */
  154.     public function setReferenceId(string $referenceId)
  155.     {
  156.         $this->referenceId $referenceId;
  157.         return $this;
  158.     }
  159.     /**
  160.      * @return string
  161.      */
  162.     public function getUrl()
  163.     {
  164.         return $this->url;
  165.     }
  166.     /**
  167.      * @param string $url
  168.      * @return Alert
  169.      */
  170.     public function setUrl(string $url)
  171.     {
  172.         $this->url $url;
  173.         return $this;
  174.     }
  175.     public function postedOnTwitter(): bool
  176.     {
  177.         return !empty($this->getTwitterId());
  178.     }
  179.     /**
  180.      * @return string
  181.      */
  182.     public function getTwitterId()
  183.     {
  184.         return $this->twitterId;
  185.     }
  186.     /**
  187.      * @param string $twitterId
  188.      * @return Alert
  189.      */
  190.     public function setTwitterId(string $twitterId null)
  191.     {
  192.         $this->twitterId $twitterId;
  193.         return $this;
  194.     }
  195.     public function isEvent(): bool
  196.     {
  197.         return $this->getReferenceType() == Alert::ALERT_EVENT;
  198.     }
  199.     public function getReferenceType()
  200.     {
  201.         return $this->referenceType;
  202.     }
  203.     /**
  204.      * @param string $referenceType
  205.      * @return Alert
  206.      */
  207.     public function setReferenceType(string $referenceType)
  208.     {
  209.         $this->referenceType $referenceType;
  210.         return $this;
  211.     }
  212.     public function getText()
  213.     {
  214.         return $this->text;
  215.     }
  216.     public function setText($text)
  217.     {
  218.         $this->text $text;
  219.         return $this;
  220.     }
  221.     public function getDateEmailSent()
  222.     {
  223.         return $this->dateEmailSent;
  224.     }
  225.     public function setDateEmailSent($dateEmailSent)
  226.     {
  227.         $this->dateEmailSent $dateEmailSent;
  228.         return $this;
  229.     }
  230.     public function getDateTwitterDone()
  231.     {
  232.         return $this->dateTwitterDone;
  233.     }
  234.     public function setDateTwitterDone($dateTwitterDone)
  235.     {
  236.         $this->dateTwitterDone $dateTwitterDone;
  237.         return $this;
  238.     }
  239.     public function getStartDate()
  240.     {
  241.         return $this->startDate;
  242.     }
  243.     public function setStartDate($startDate)
  244.     {
  245.         $this->startDate $startDate;
  246.         return $this;
  247.     }
  248.     public function getEndDate()
  249.     {
  250.         return $this->endDate;
  251.     }
  252.     public function setEndDate($endDate)
  253.     {
  254.         $this->endDate $endDate;
  255.         return $this;
  256.     }
  257.     public function toString(): string
  258.     {
  259.         return "{id=" $this->id ", text=" $this->text ", start_date=" Helper::toString($this->startDate) .
  260.             ", end_date=" Helper::toString($this->endDate) . "}";
  261.     }
  262.     public function __toString()
  263.     {
  264.         return $this->text " [" Helper::toString($this->startDate) . " - " Helper::toString($this->endDate) . "]";
  265.     }
  266.     /**
  267.      * Get sendMail
  268.      *
  269.      * @return boolean
  270.      */
  271.     public function getSendMail()
  272.     {
  273.         return $this->sendMail;
  274.     }
  275.     /**
  276.      * Set sendMail
  277.      *
  278.      * @param boolean $sendMail
  279.      *
  280.      * @return Alert
  281.      */
  282.     public function setSendMail(bool $sendMail null)
  283.     {
  284.         $this->sendMail $sendMail === null false $sendMail;
  285.         return $this;
  286.     }
  287.     /**
  288.      * Get createTweet
  289.      *
  290.      * @return boolean
  291.      */
  292.     public function getCreateTweet()
  293.     {
  294.         return $this->createTweet;
  295.     }
  296.     /**
  297.      * Set createTweet
  298.      *
  299.      * @param boolean $createTweet
  300.      *
  301.      * @return Alert
  302.      */
  303.     public function setCreateTweet(bool $createTweet null)
  304.     {
  305.         $this->createTweet $createTweet === null false $createTweet;
  306.         return $this;
  307.     }
  308.     /**
  309.      * Get image
  310.      *
  311.      * @return Media
  312.      */
  313.     public function getImage()
  314.     {
  315.         return $this->image;
  316.     }
  317.     /**
  318.      * Set image
  319.      *
  320.      * @param Media $image
  321.      *
  322.      * @return Alert
  323.      */
  324.     public function setImage(Media $image null)
  325.     {
  326.         $this->image $image;
  327.         return $this;
  328.     }
  329.     /**
  330.      * @return string|null
  331.      */
  332.     public function getBannerText(): ?string
  333.     {
  334.         return $this->text;
  335.     }
  336.     /**
  337.      * @return string|null
  338.      */
  339.     public function getBannerLink(): ?string
  340.     {
  341.         return $this->url;
  342.     }
  343. }