<?php
namespace App\Service\CIC\Legacy\Batchmailer;
class QueueConfig implements \Serializable, \JsonSerializable
{
private ?int $id=null;
private $queue;
private int $authId=3;
private string $subject='';
private string $name='Columbia International College';
private string $fromCompany='Columbia International College';
private string $fromEmail='no-reply@cic-totalcare.com';
private string $fromName='Columbia International College';
private string $bodyHtml='';
private string $bodyText='';
private string $baseHtml='';
private ?array $replacements=[];
private ?array $attachment_url=[];
private \DateTimeInterface $startdate;
private \DateTimeInterface $enddate;
public function __construct(?array $data=[])
{
$this->startdate=new \DateTime();
$this->enddate=new \DateTime();
if(!empty($data))
$this->unserialize($data);
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @param mixed $id
*
* @return QueueConfig
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return mixed
*/
public function getQueue()
{
return $this->queue;
}
/**
* @param mixed $queue
*
* @return QueueConfig
*/
public function setQueue($queue)
{
$this->queue = $queue;
return $this;
}
/**
* @return int
*/
public function getAuthId(): int
{
return $this->authId;
}
/**
* @param int $authId
*
* @return QueueConfig
*/
public function setAuthId(int $authId): QueueConfig
{
$this->authId = $authId;
return $this;
}
/**
* @return string
*/
public function getSubject(): string
{
return $this->subject;
}
/**
* @param string $subject
*
* @return QueueConfig
*/
public function setSubject(string $subject): QueueConfig
{
$this->subject = $subject;
return $this;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @param string $name
*
* @return QueueConfig
*/
public function setName(string $name): QueueConfig
{
$this->name = $name;
return $this;
}
/**
* @return string
*/
public function getFromCompany(): string
{
return $this->fromCompany;
}
/**
* @param string $fromCompany
*
* @return QueueConfig
*/
public function setFromCompany(string $fromCompany): QueueConfig
{
$this->fromCompany = $fromCompany;
return $this;
}
/**
* @return string
*/
public function getFromEmail(): string
{
return $this->fromEmail;
}
/**
* @param string $fromEmail
*
* @return QueueConfig
*/
public function setFromEmail(string $fromEmail): QueueConfig
{
$this->fromEmail = $fromEmail;
return $this;
}
/**
* @return string
*/
public function getFromName(): string
{
return $this->fromName;
}
/**
* @param string $fromName
*
* @return QueueConfig
*/
public function setFromName(string $fromName): QueueConfig
{
$this->fromName = $fromName;
return $this;
}
/**
* @return string
*/
public function getBodyHtml(): string
{
return $this->bodyHtml;
}
/**
* @param string $bodyHtml
*
* @return QueueConfig
*/
public function setBodyHtml(string $bodyHtml): QueueConfig
{
$this->bodyHtml = $bodyHtml;
return $this;
}
/**
* @return string
*/
public function getBodyText(): string
{
return $this->bodyText;
}
/**
* @param string $bodyText
*
* @return QueueConfig
*/
public function setBodyText(string $bodyText): QueueConfig
{
$this->bodyText = $bodyText;
return $this;
}
/**
* @return string
*/
public function getBaseHtml(): string
{
return $this->baseHtml;
}
/**
* @param string $baseHtml
*
* @return QueueConfig
*/
public function setBaseHtml(?string $baseHtml): QueueConfig
{
if(is_null($baseHtml))
$baseHtml='';
$this->baseHtml = $baseHtml;
return $this;
}
/**
* @return array|null
*/
public function getReplacements(): ?array
{
return $this->replacements;
}
/**
* @param array|null $replacements
*
* @return QueueConfig
*/
public function setReplacements(?array $replacements): QueueConfig
{
$this->replacements = $replacements;
return $this;
}
/**
* @return array|null
*/
public function getAttachmentUrl(): ?array
{
return $this->attachment_url;
}
/**
* @param array|null $attachment_url
*
* @return QueueConfig
*/
public function setAttachmentUrl(?array $attachment_url): QueueConfig
{
$this->attachment_url = $attachment_url;
return $this;
}
/**
* @return \DateTimeInterface
*/
public function getStartdate(): \DateTimeInterface
{
return $this->startdate;
}
/**
* @param \DateTimeInterface $startdate
*
* @return QueueConfig
*/
public function setStartdate(\DateTimeInterface $startdate): QueueConfig
{
$this->startdate = $startdate;
return $this;
}
/**
* @return \DateTimeInterface
*/
public function getEnddate(): \DateTimeInterface
{
return $this->enddate;
}
/**
* @param \DateTimeInterface $enddate
*
* @return QueueConfig
*/
public function setEnddate(\DateTimeInterface $enddate): QueueConfig
{
$this->enddate = $enddate;
return $this;
}
/*****************************/
// Serialers
public function jsonSerialize()
{
return $this->serialize();
}
public function serialize(){
$map=$this->getPropertyMap();
$data=[];
foreach($map as $prop=>$key) {
$method=implode('',['get',ucfirst($prop)]);
if(method_exists($this,$method)) {
switch($prop) {
case "attachmentUrl":
case "replacements":
// dump([
// $prop,$method,$key
// ]);
$data[$key]=json_encode($this->$method());
break;
case "startdate":
case "enddate":
/** @var \DateTime $method */
$data[$key]=$this->$method()->format('Y-m-d H:i:s');
break;
default:
$data[$key]=$this->$method();
break;
}}
}
return $data;
}
public function unserialize($serialized)
{
$map=$this->getArrayMap();
foreach($map as $key=>$prop) {
$method=implode('',['set',ucfirst($prop)]);
if(method_exists($this,$method) and array_key_exists($key, $serialized)) {
switch($prop) {
case "attachmentUrl":
case "replacements":
$this->$method(json_decode($serialized[$key],true));
break;
case "startdate":
case "enddate":
/** @var \DateTime $method */
$this->$method(new \DateTime($serialized[$key]));
break;
default:
$this->$method($serialized[$key]);
break;
}}
}
}
function getPropertyMap()
{
return array_flip($this->getArrayMap());
}
function getArrayMap() {
return [
'id' => 'id',
'QUEUE' => 'queue',
'authID' => 'authId',
'SUBJECT' => 'subject',
'NAME' => 'name',
'FROM_COMPANY' => 'fromCompany',
'FROM_EMAIL' => 'fromEmail',
'FROM_NAME' => 'fromName',
'BODY_HTML_TEMPLATE' => 'bodyHtml',
'base_html' => 'baseHtml',
'BODY_PLAIN_TEMPLATE' => 'bodyText',
'GLOBAL_REPLACEMENTS' => 'replacements',
'ATTACHMENTS' => 'attachmentUrl',
'STARTDATE' => 'startdate',
'ENDDATE' => 'enddate',
];
}
public function __toString()
{
return json_encode($this);
}
}