src/Service/CIC/Legacy/Batchmailer/QueueConfig.php line 5

Open in your IDE?
  1. <?php
  2. namespace App\Service\CIC\Legacy\Batchmailer;
  3. class QueueConfig implements \Serializable\JsonSerializable
  4. {
  5.     private ?int $id=null;
  6.     private $queue;
  7.     private int $authId=3;
  8.     private string $subject='';
  9.     private string $name='Columbia International College';
  10.     private string $fromCompany='Columbia International College';
  11.     private string $fromEmail='no-reply@cic-totalcare.com';
  12.     private string $fromName='Columbia International College';
  13.     private string $bodyHtml='';
  14.     private string $bodyText='';
  15.     private string $baseHtml='';
  16.     private ?array $replacements=[];
  17.     private ?array $attachment_url=[];
  18.     private \DateTimeInterface $startdate;
  19.     private \DateTimeInterface $enddate;
  20.     public function __construct(?array $data=[])
  21.     {
  22.         $this->startdate=new \DateTime();
  23.         $this->enddate=new \DateTime();
  24.         if(!empty($data))
  25.             $this->unserialize($data);
  26.     }
  27.     /**
  28.      * @return mixed
  29.      */
  30.     public function getId()
  31.     {
  32.         return $this->id;
  33.     }
  34.     /**
  35.      * @param mixed $id
  36.      *
  37.      * @return QueueConfig
  38.      */
  39.     public function setId($id)
  40.     {
  41.         $this->id $id;
  42.         return $this;
  43.     }
  44.     /**
  45.      * @return mixed
  46.      */
  47.     public function getQueue()
  48.     {
  49.         return $this->queue;
  50.     }
  51.     /**
  52.      * @param mixed $queue
  53.      *
  54.      * @return QueueConfig
  55.      */
  56.     public function setQueue($queue)
  57.     {
  58.         $this->queue $queue;
  59.         return $this;
  60.     }
  61.     /**
  62.      * @return int
  63.      */
  64.     public function getAuthId(): int
  65.     {
  66.         return $this->authId;
  67.     }
  68.     /**
  69.      * @param int $authId
  70.      *
  71.      * @return QueueConfig
  72.      */
  73.     public function setAuthId(int $authId): QueueConfig
  74.     {
  75.         $this->authId $authId;
  76.         return $this;
  77.     }
  78.     /**
  79.      * @return string
  80.      */
  81.     public function getSubject(): string
  82.     {
  83.         return $this->subject;
  84.     }
  85.     /**
  86.      * @param string $subject
  87.      *
  88.      * @return QueueConfig
  89.      */
  90.     public function setSubject(string $subject): QueueConfig
  91.     {
  92.         $this->subject $subject;
  93.         return $this;
  94.     }
  95.     /**
  96.      * @return string
  97.      */
  98.     public function getName(): string
  99.     {
  100.         return $this->name;
  101.     }
  102.     /**
  103.      * @param string $name
  104.      *
  105.      * @return QueueConfig
  106.      */
  107.     public function setName(string $name): QueueConfig
  108.     {
  109.         $this->name $name;
  110.         return $this;
  111.     }
  112.     /**
  113.      * @return string
  114.      */
  115.     public function getFromCompany(): string
  116.     {
  117.         return $this->fromCompany;
  118.     }
  119.     /**
  120.      * @param string $fromCompany
  121.      *
  122.      * @return QueueConfig
  123.      */
  124.     public function setFromCompany(string $fromCompany): QueueConfig
  125.     {
  126.         $this->fromCompany $fromCompany;
  127.         return $this;
  128.     }
  129.     /**
  130.      * @return string
  131.      */
  132.     public function getFromEmail(): string
  133.     {
  134.         return $this->fromEmail;
  135.     }
  136.     /**
  137.      * @param string $fromEmail
  138.      *
  139.      * @return QueueConfig
  140.      */
  141.     public function setFromEmail(string $fromEmail): QueueConfig
  142.     {
  143.         $this->fromEmail $fromEmail;
  144.         return $this;
  145.     }
  146.     /**
  147.      * @return string
  148.      */
  149.     public function getFromName(): string
  150.     {
  151.         return $this->fromName;
  152.     }
  153.     /**
  154.      * @param string $fromName
  155.      *
  156.      * @return QueueConfig
  157.      */
  158.     public function setFromName(string $fromName): QueueConfig
  159.     {
  160.         $this->fromName $fromName;
  161.         return $this;
  162.     }
  163.     /**
  164.      * @return string
  165.      */
  166.     public function getBodyHtml(): string
  167.     {
  168.         return $this->bodyHtml;
  169.     }
  170.     /**
  171.      * @param string $bodyHtml
  172.      *
  173.      * @return QueueConfig
  174.      */
  175.     public function setBodyHtml(string $bodyHtml): QueueConfig
  176.     {
  177.         $this->bodyHtml $bodyHtml;
  178.         return $this;
  179.     }
  180.     /**
  181.      * @return string
  182.      */
  183.     public function getBodyText(): string
  184.     {
  185.         return $this->bodyText;
  186.     }
  187.     /**
  188.      * @param string $bodyText
  189.      *
  190.      * @return QueueConfig
  191.      */
  192.     public function setBodyText(string $bodyText): QueueConfig
  193.     {
  194.         $this->bodyText $bodyText;
  195.         return $this;
  196.     }
  197.     /**
  198.      * @return string
  199.      */
  200.     public function getBaseHtml(): string
  201.     {
  202.         return $this->baseHtml;
  203.     }
  204.     /**
  205.      * @param string $baseHtml
  206.      *
  207.      * @return QueueConfig
  208.      */
  209.     public function setBaseHtml(?string $baseHtml): QueueConfig
  210.     {
  211.         if(is_null($baseHtml))
  212.             $baseHtml='';
  213.         $this->baseHtml $baseHtml;
  214.         return $this;
  215.     }
  216.     /**
  217.      * @return array|null
  218.      */
  219.     public function getReplacements(): ?array
  220.     {
  221.         return $this->replacements;
  222.     }
  223.     /**
  224.      * @param array|null $replacements
  225.      *
  226.      * @return QueueConfig
  227.      */
  228.     public function setReplacements(?array $replacements): QueueConfig
  229.     {
  230.         $this->replacements $replacements;
  231.         return $this;
  232.     }
  233.     /**
  234.      * @return array|null
  235.      */
  236.     public function getAttachmentUrl(): ?array
  237.     {
  238.         return $this->attachment_url;
  239.     }
  240.     /**
  241.      * @param array|null $attachment_url
  242.      *
  243.      * @return QueueConfig
  244.      */
  245.     public function setAttachmentUrl(?array $attachment_url): QueueConfig
  246.     {
  247.         $this->attachment_url $attachment_url;
  248.         return $this;
  249.     }
  250.     /**
  251.      * @return \DateTimeInterface
  252.      */
  253.     public function getStartdate(): \DateTimeInterface
  254.     {
  255.         return $this->startdate;
  256.     }
  257.     /**
  258.      * @param \DateTimeInterface $startdate
  259.      *
  260.      * @return QueueConfig
  261.      */
  262.     public function setStartdate(\DateTimeInterface $startdate): QueueConfig
  263.     {
  264.         $this->startdate $startdate;
  265.         return $this;
  266.     }
  267.     /**
  268.      * @return \DateTimeInterface
  269.      */
  270.     public function getEnddate(): \DateTimeInterface
  271.     {
  272.         return $this->enddate;
  273.     }
  274.     /**
  275.      * @param \DateTimeInterface $enddate
  276.      *
  277.      * @return QueueConfig
  278.      */
  279.     public function setEnddate(\DateTimeInterface $enddate): QueueConfig
  280.     {
  281.         $this->enddate $enddate;
  282.         return $this;
  283.     }
  284.     
  285.     
  286.     
  287.     
  288.     
  289.     
  290.     
  291.     
  292.     
  293.     
  294.     
  295.     /*****************************/
  296.     // Serialers
  297.     public function jsonSerialize()
  298.     {
  299.         return $this->serialize();
  300.     }
  301.     
  302.     public function serialize(){
  303.         $map=$this->getPropertyMap();
  304.         $data=[];
  305.         foreach($map as $prop=>$key) {
  306.             $method=implode('',['get',ucfirst($prop)]);
  307.             if(method_exists($this,$method)) {
  308.             switch($prop) {
  309.                 case "attachmentUrl":
  310.                 case "replacements":
  311. //                    dump([
  312. //                        $prop,$method,$key
  313. //                    ]);
  314.                     $data[$key]=json_encode($this->$method());
  315.                     break;
  316.                 case "startdate":
  317.                 case "enddate":
  318.                     /** @var \DateTime $method */
  319.                     $data[$key]=$this->$method()->format('Y-m-d H:i:s');
  320.                     break;
  321.                 default:
  322.                     $data[$key]=$this->$method();
  323.                     break;
  324.             }}
  325.         }
  326.         return $data;
  327.     }
  328.     
  329.     public function unserialize($serialized)
  330.     {
  331.         $map=$this->getArrayMap();
  332.         foreach($map as $key=>$prop) {
  333.             $method=implode('',['set',ucfirst($prop)]);
  334.             if(method_exists($this,$method) and array_key_exists($key$serialized)) {
  335.                 switch($prop) {
  336.                     case "attachmentUrl":
  337.                     case "replacements":
  338.                         $this->$method(json_decode($serialized[$key],true));
  339.                         break;
  340.                     case "startdate":
  341.                     case "enddate":
  342.                         /** @var \DateTime $method */
  343.                         $this->$method(new \DateTime($serialized[$key]));
  344.                         break;
  345.                     default:
  346.                         $this->$method($serialized[$key]);
  347.                         break;
  348.                 }}
  349.         }
  350.     }
  351.     function getPropertyMap()
  352.     {
  353.      return array_flip($this->getArrayMap());
  354.     }
  355.     function getArrayMap() {
  356.         return [
  357.             'id' => 'id',
  358.             'QUEUE' => 'queue',
  359.             'authID' => 'authId',
  360.             'SUBJECT' => 'subject',
  361.             'NAME' => 'name',
  362.             'FROM_COMPANY' => 'fromCompany',
  363.             'FROM_EMAIL' => 'fromEmail',
  364.             'FROM_NAME' => 'fromName',
  365.             'BODY_HTML_TEMPLATE' => 'bodyHtml',
  366.             'base_html' => 'baseHtml',
  367.             'BODY_PLAIN_TEMPLATE' => 'bodyText',
  368.             'GLOBAL_REPLACEMENTS' => 'replacements',
  369.             'ATTACHMENTS' => 'attachmentUrl',
  370.             'STARTDATE' => 'startdate',
  371.             'ENDDATE' => 'enddate',
  372.         ];
  373.     }
  374.     
  375.     
  376.     public function __toString()
  377.     {
  378.         return json_encode($this);
  379.     }
  380. }