<?php
namespace App\Entity;
use App\Entity\Person;
use Doctrine\ORM\Mapping as ORM;
use Menke\CommonsBundle\Entity\GenericEntity;
/**
* @ORM\Entity(repositoryClass="App\Repository\CustomerHistoryEntryRepository")
* @ORM\HasLifecycleCallbacks
*/
class CustomerHistoryEntry
{
const TYPE_SYSTEM_EVENT = 'system_event';
const TYPE_EMAIL = 'email';
const TYPE_NEWSLETTER_REGISTER = 'nl_register';
const TYPE_NEWSLETTER_DEREGISTER = 'nl_deregister';
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
protected $id;
/**
* @ORM\Column(type="string", length=255)
*/
protected $entry;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Person", inversedBy="history")
*/
protected $customer;
/**
* @ORM\Column(type="string", length=50)
*/
protected $systemAgent;
/**
* @ORM\Column(type="datetime")
*/
protected $date;
/**
* @ORM\Column(type="string", length=50)
*/
protected $type = self::TYPE_SYSTEM_EVENT;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\EmailHistoryEntry")
*/
protected $emailHistoryEntry;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $admin_id;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $set_by_admin;
/**
* @ORM\OneToOne(targetEntity=ManualNewsletter::class, cascade={"persist", "remove"})
*/
private $manual_newsletter;
/**
* @param string $entry
* @param Person $customer
* @param string $systemAgent
*/
public function __construct($entry = null, Person $customer = null, $systemAgent = null)
{
$this->entry = $entry;
$this->customer = $customer;
$this->systemAgent = $systemAgent;
$this->date = new \Datetime();
}
/**
* Create prefilled history entry for newsletter registration
*
* @param Person $customer
* @param string $systemAgent
* @return CustomerHistoryEntry
*/
public static function createForNewsletterRegister(Person $customer, $systemAgent)
{
$entry = new CustomerHistoryEntry('Newsletter abonniert', $customer, $systemAgent);
$entry->setType(CustomerHistoryEntry::TYPE_NEWSLETTER_REGISTER);
return $entry;
}
/**
* Create prefilled history entry for newsletter deregistration
*
* @param Person $customer
* @param string $systemAgent
* @return CustomerHistoryEntry
*/
public static function createForNewsletterDeregister(Person $customer, $systemAgent)
{
$entry = new CustomerHistoryEntry('Newsletter abbestellt', $customer, $systemAgent);
$entry->setType(CustomerHistoryEntry::TYPE_NEWSLETTER_DEREGISTER);
return $entry;
}
/**
* Create prefilled history entry for privacy policy acceptance registration
*
* @param Person $customer
* @param string $systemAgent
* @return CustomerHistoryEntry
*/
public static function createForPrivacyPolicyConfirm(Person $customer, $systemAgent)
{
$entry = new CustomerHistoryEntry('Datenschutz zugestimmt', $customer, $systemAgent);
return $entry;
}
/**
* Create prefilled history entry for privacy policy acceptance deregistration
*
* @param Person $customer
* @param string $systemAgent
* @return CustomerHistoryEntry
*/
public static function createForPrivacyPolicyDeconfirm(Person $customer, $systemAgent)
{
$entry = new CustomerHistoryEntry('Datenschutz Zustimmung zurückgezogen', $customer, $systemAgent);
return $entry;
}
/**
* @return int|null
*/
public function getId(): ?int
{
return $this->id;
}
/**
* @return null|string
*/
public function getEntry(): ?string
{
return $this->entry;
}
/**
* @param string $entry
* @return CustomerHistoryEntry
*/
public function setEntry(string $entry): self
{
$this->entry = $entry;
return $this;
}
/**
* @return Person|null
*/
public function getCustomer(): ?Person
{
return $this->customer;
}
/**
* @param Person|null $customer
* @return CustomerHistoryEntry
*/
public function setCustomer(?Person $customer): self
{
$this->customer = $customer;
return $this;
}
/**
* @return null|string
*/
public function getSystemAgent(): ?string
{
return $this->systemAgent;
}
/**
* @param string $systemAgent
* @return CustomerHistoryEntry
*/
public function setSystemAgent(string $systemAgent): self
{
$this->systemAgent = $systemAgent;
return $this;
}
/**
* @return \DateTimeInterface|null
*/
public function getDate(): ?\DateTimeInterface
{
return $this->date;
}
/**
* @param \DateTimeInterface $date
* @return CustomerHistoryEntry
*/
public function setDate(\DateTimeInterface $date): self
{
$this->date = $date;
return $this;
}
/**
* @return string|null
*/
public function getType(): ?string
{
return $this->type;
}
/**
* @param string $type
* @return self
*/
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
/**
* @return EmailHistoryEntry|null
*/
public function getEmailHistoryEntry(): ?EmailHistoryEntry
{
return $this->emailHistoryEntry;
}
/**
* @param EmailHistoryEntry|null $emailHistoryEntry
* @return self
*/
public function setEmailHistoryEntry(?EmailHistoryEntry $emailHistoryEntry): self
{
$this->emailHistoryEntry = $emailHistoryEntry;
return $this;
}
/**
* @return boolean
*/
public function isNewsletterRegister()
{
return $this->type == self::TYPE_NEWSLETTER_REGISTER;
}
/**
* @return boolean
*/
public function isNewsletterDeregister()
{
return $this->type == self::TYPE_NEWSLETTER_DEREGISTER;
}
/**
* @ORM\PostPersist
*/
public function onPostPersist()
{
$this->date = new \DateTime();
}
public function getAdminId(): ?int
{
return $this->admin_id;
}
public function setAdminId(?int $admin_id): self
{
$this->admin_id = $admin_id;
return $this;
}
public function getSetByAdmin(): ?bool
{
return $this->set_by_admin;
}
public function setSetByAdmin(?bool $set_by_admin): self
{
$this->set_by_admin = $set_by_admin;
return $this;
}
public function getManualNewsletter(): ?ManualNewsletter
{
return $this->manual_newsletter;
}
public function setManualNewsletter(?ManualNewsletter $manual_newsletter): self
{
$this->manual_newsletter = $manual_newsletter;
return $this;
}
}