at the end of the day, it was inevitable

This commit is contained in:
Mo Elzubeir
2022-12-09 08:36:26 -06:00
commit 1218570914
1768 changed files with 887087 additions and 0 deletions
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,199 @@
<?php
namespace UserBundle\Entity\Notification;
use ApiBundle\Entity\NormalizableEntityInterface;
use ApiBundle\Serializer\Metadata\Metadata;
use ApiBundle\Serializer\Metadata\PropertyMetadata;
use AppBundle\Entity\BaseEntityTrait;
use AppBundle\Entity\EntityInterface;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use UserBundle\Entity\Notification\Schedule\AbstractNotificationSchedule;
/**
* Class NotificationSendHistory
*
* @ORM\Table(name="notifications_history")
* @ORM\Entity(repositoryClass="UserBundle\Repository\NotificationSendHistoryRepository")
*/
class NotificationSendHistory implements EntityInterface, NormalizableEntityInterface
{
use BaseEntityTrait;
/**
* @var Notification
*
* @ORM\ManyToOne(
* targetEntity="UserBundle\Entity\Notification\Notification",
* inversedBy="history"
* )
*/
private $notification;
/**
* Schedules which trigger notification sending.
*
* @var Collection
*
* @ORM\OneToMany(
* targetEntity="UserBundle\Entity\Notification\Schedule\AbstractNotificationSchedule",
* mappedBy="history",
* cascade={ "persist", "remove" }
* )
*/
private $schedules;
/**
* @var \DateTime
*
* @ORM\Column(type="datetime")
*/
private $date;
/**
* NotificationSendHistory constructor.
*
* @param Notification $notification A Notification entity
* instance.
* @param AbstractNotificationSchedule[]|array $schedule Array of schedules which
* trigger notification
* sending.
*/
public function __construct(Notification $notification, array $schedule)
{
$this->notification = $notification;
foreach ($schedule as $item) {
$this->addSchedule($item);
}
$this->date = $notification->getLastSentAt();
}
/**
* Set notification
*
* @param Notification $notification A Notification entity instance.
*
* @return NotificationSendHistory
*/
public function setNotification(Notification $notification = null)
{
$this->notification = $notification;
return $this;
}
/**
* Get notification
*
* @return Notification
*/
public function getNotification()
{
return $this->notification;
}
/**
* Add schedule
*
* @param AbstractNotificationSchedule $schedule A AbstractNotificationSchedule
* instance.
*
* @return NotificationSendHistory
*/
public function addSchedule(AbstractNotificationSchedule $schedule)
{
$this->schedules[] = $schedule;
$schedule->setHistory($this);
return $this;
}
/**
* Remove schedule
*
* @param AbstractNotificationSchedule $schedule A AbstractNotificationSchedule
* instance.
*
* @return NotificationSendHistory
*/
public function removeSchedule(AbstractNotificationSchedule $schedule)
{
$this->schedules->removeElement($schedule);
$schedule->setHistory(null);
return $this;
}
/**
* Get schedules
*
* @return Collection
*/
public function getSchedules()
{
return $this->schedules;
}
/**
* Set date
*
* @param \DateTime $date Sent date.
*
* @return NotificationSendHistory
*/
public function setDate(\DateTime $date)
{
$this->date = $date;
return $this;
}
/**
* Get date
*
* @return \DateTime
*/
public function getDate()
{
return $this->date;
}
/**
* Return metadata for current entity.
*
* @return \ApiBundle\Serializer\Metadata\Metadata
*/
public function getMetadata()
{
return new Metadata(static::class, [
PropertyMetadata::createInteger('notification', [ 'history' ])
->setField(function () {
return $this->notification->getId();
}),
PropertyMetadata::createString('name', [ 'history' ])
->setField(function () {
return $this->notification->getName();
}),
PropertyMetadata::createString('type', [ 'history' ])
->setField(function () {
return $this->notification->getNotificationType()->getValue();
}),
PropertyMetadata::createCollection('schedule', AbstractNotificationSchedule::class, [ 'history' ])
->setField('schedules'),
PropertyMetadata::createDate('date', [ 'history' ]),
]);
}
/**
* Return default normalization groups.
*
* @return array
*/
public function defaultGroups()
{
return [ 'id', 'history' ];
}
}
@@ -0,0 +1,211 @@
<?php
namespace UserBundle\Entity\Notification;
use ApiBundle\Entity\NormalizableEntityInterface;
use ApiBundle\Serializer\Metadata\Metadata;
use ApiBundle\Serializer\Metadata\PropertyMetadata;
use AppBundle\Entity\BaseEntityTrait;
use AppBundle\Entity\EntityInterface;
use Doctrine\ORM\Mapping as ORM;
/**
* NotificationTheme
*
* @ORM\Table(name="notification_themes")
* @ORM\Entity(repositoryClass="UserBundle\Repository\NotificationThemeRepository")
*/
class NotificationTheme implements EntityInterface, NormalizableEntityInterface
{
use BaseEntityTrait;
/**
* Theme name.
*
* @var string
*
* @ORM\Column
*/
private $name;
/**
* @var NotificationThemeOptions
*
* @ORM\Embedded(
* class="UserBundle\Entity\Notification\NotificationThemeOptions",
* columnPrefix="enhanced_"
* )
*/
private $enhanced;
/**
* @var NotificationThemeOptions
*
* @ORM\Embedded(
* class="UserBundle\Entity\Notification\NotificationThemeOptions",
* columnPrefix="plain_"
* )
*/
private $plain;
/**
* @var boolean
*
* @ORM\Column(type="boolean")
*/
private $published = false;
/**
* @var boolean
*
* @ORM\Column(type="boolean", name="`default`")
*/
private $default = false;
/**
* Set name
*
* @param string $name Theme name.
*
* @return NotificationTheme
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set enhanced
*
* @param NotificationThemeOptions $enhanced A NotificationThemeOptions instance.
*
* @return NotificationTheme
*/
public function setEnhanced(NotificationThemeOptions $enhanced)
{
$this->enhanced = $enhanced;
return $this;
}
/**
* Get enhanced
*
* @return NotificationThemeOptions
*/
public function getEnhanced()
{
return $this->enhanced;
}
/**
* Set plain
*
* @param NotificationThemeOptions $plain A NotificationThemeOptions instance.
*
* @return NotificationTheme
*/
public function setPlain(NotificationThemeOptions $plain)
{
$this->plain = $plain;
return $this;
}
/**
* Get plainOptions
*
* @return NotificationThemeOptions
*/
public function getPlain()
{
return $this->plain;
}
/**
* @param boolean $published Should this notification be published or not.
*
* @return NotificationTheme
*/
public function setPublished($published = true)
{
$this->published = $published;
return $this;
}
/**
* @return boolean
*/
public function isPublished()
{
return $this->published;
}
/**
* Set default
*
* @param boolean $default Set theme as default.
*
* @return NotificationTheme
*/
public function setDefault($default = true)
{
$this->default = $default;
return $this;
}
/**
* Get default
*
* @return boolean
*/
public function isDefault()
{
return $this->default;
}
/**
* Return metadata for current entity.
*
* @return \ApiBundle\Serializer\Metadata\Metadata
*/
public function getMetadata()
{
return new Metadata(static::class, [
PropertyMetadata::createInteger('id', [ 'id' ]),
PropertyMetadata::createString('name', [ 'notification_theme', 'notification_theme_list' ]),
PropertyMetadata::createBoolean('published', [ 'notification_theme' ]),
PropertyMetadata::createObject('enhanced', [ 'notification_theme' ])
->setField('enhanced')
->setActualType(NotificationThemeOptions::class),
PropertyMetadata::createObject('plain', [ 'notification_theme' ])
->setField('plain')
->setActualType(NotificationThemeOptions::class),
]);
}
/**
* Return default normalization groups.
*
* @return array
*/
public function defaultGroups()
{
return [ 'id', 'notification_theme' ];
}
}
@@ -0,0 +1,300 @@
<?php
namespace UserBundle\Entity\Notification;
use Doctrine\ORM\Mapping as ORM;
use UserBundle\Entity\Notification\ThemeOption\ThemeOptionColors;
use UserBundle\Entity\Notification\ThemeOption\ThemeOptionColorsBackground;
use UserBundle\Entity\Notification\ThemeOption\ThemeOptionColorsText;
use UserBundle\Entity\Notification\ThemeOption\ThemeOptionContent;
use UserBundle\Entity\Notification\ThemeOption\ThemeOptionFont;
use UserBundle\Entity\Notification\ThemeOption\ThemeOptionFonts;
use UserBundle\Entity\Notification\ThemeOption\ThemeOptionHeader;
use UserBundle\Entity\Notification\ThemeOption\ThemeOptionHighlightKeywords;
use UserBundle\Entity\Notification\ThemeOption\ThemeOptionShowInfo;
use UserBundle\Enum\FontFamilyEnum;
use UserBundle\Enum\ThemeOptionExtractEnum;
use UserBundle\Enum\ThemeOptionsTableOfContentsEnum;
use UserBundle\Enum\ThemeOptionsUserCommentsEnum;
/**
* NotificationThemeOptions
*
* @ORM\Embeddable
*/
class NotificationThemeOptions
{
const DEFAULT_HEADER_SIZE = 18;
const DEFAULT_TABLE_OF_CONTENTS_SIZE = 12;
const DEFAULT_FEED_TITLE_SIZE = 12;
const DEFAULT_ARTICLE_HEADLINE_SIZE = 16;
const DEFAULT_SOURCE_SIZE = 12;
const DEFAULT_AUTHOR_SIZE = 12;
const DEFAULT_DATE_SIZE = 12;
const DEFAULT_ARTICLE_CONTENT_SIZE = 12;
/**
* Text which locate just after header but before content.
* Contains HTML.
*
* @var string
*
* @ORM\Column(type="text")
*/
private $summary;
/**
* Text which locate before footer just after content.
* Contains HTML.
*
* @var string
*
* @ORM\Column(type="text")
*/
private $conclusion;
/**
* @var ThemeOptionHeader
*
* @ORM\Column(type="object")
*/
private $header;
/**
* @var ThemeOptionFonts
*
* @ORM\Column(type="object")
*/
private $fonts;
/**
* @var ThemeOptionContent
*
* @ORM\Column(type="object")
*/
private $content;
/**
* @var ThemeOptionColors
*
* @ORM\Column(type="object")
*/
private $colors;
/**
* NotificationThemeOptions constructor.
*
* @param string $summary Summary text.
* @param string $conclusion Conclusion text.
* @param ThemeOptionHeader $header A ThemeOptionHeader instance.
* @param ThemeOptionFonts $fonts A ThemeOptionFonts instance.
* @param ThemeOptionContent $content A ThemeOptionContent instance.
* @param ThemeOptionColors $colors A ThemeOptionColors instance.
*/
public function __construct(
$summary,
$conclusion,
ThemeOptionHeader $header,
ThemeOptionFonts $fonts,
ThemeOptionContent $content,
ThemeOptionColors $colors
) {
$this->summary = trim($summary);
$this->conclusion = trim($conclusion);
$this->header = $header;
$this->fonts = $fonts;
$this->content = $content;
$this->colors = $colors;
}
/**
* @return static
*/
public static function createDefault()
{
return new static(
'',
'',
new ThemeOptionHeader(
ThemeOptionHeader::DEFAULT_IMAGE,
'',
'Newsletter'
),
new ThemeOptionFonts(
new ThemeOptionFont(FontFamilyEnum::arial(), self::DEFAULT_HEADER_SIZE),
new ThemeOptionFont(FontFamilyEnum::arial(), self::DEFAULT_TABLE_OF_CONTENTS_SIZE),
new ThemeOptionFont(FontFamilyEnum::arial(), self::DEFAULT_FEED_TITLE_SIZE),
new ThemeOptionFont(FontFamilyEnum::arial(), self::DEFAULT_ARTICLE_HEADLINE_SIZE),
new ThemeOptionFont(FontFamilyEnum::arial(), self::DEFAULT_SOURCE_SIZE),
new ThemeOptionFont(FontFamilyEnum::arial(), self::DEFAULT_AUTHOR_SIZE),
new ThemeOptionFont(FontFamilyEnum::arial(), self::DEFAULT_DATE_SIZE),
new ThemeOptionFont(FontFamilyEnum::arial(), self::DEFAULT_ARTICLE_CONTENT_SIZE)
),
new ThemeOptionContent(
new ThemeOptionHighlightKeywords(),
new ThemeOptionShowInfo(
ThemeOptionsUserCommentsEnum::no(),
ThemeOptionsTableOfContentsEnum::simple()
),
'en',
ThemeOptionExtractEnum::context()
),
new ThemeOptionColors(
new ThemeOptionColorsBackground(),
new ThemeOptionColorsText()
)
);
}
/**
* @return string
*/
public function getSummary()
{
return $this->summary;
}
/**
* @return boolean
*/
public function hasSummary()
{
return $this->summary !== '';
}
/**
* @param string $summary Summary text.
*
* @return NotificationThemeOptions
*/
public function setSummary($summary)
{
$this->summary = $summary;
return $this;
}
/**
* @return string
*/
public function getConclusion()
{
return $this->conclusion;
}
/**
* @return boolean
*/
public function hasConclusion()
{
return $this->conclusion !== '';
}
/**
* @param string $conclusion Conclusion text.
*
* @return NotificationThemeOptions
*/
public function setConclusion($conclusion)
{
$this->conclusion = $conclusion;
return $this;
}
/**
* @return ThemeOptionHeader
*/
public function getHeader()
{
return $this->header;
}
/**
* @param ThemeOptionHeader $header A ThemeOptionHeader instance.
*
* @return NotificationThemeOptions
*/
public function setHeader(ThemeOptionHeader $header)
{
$this->header = $header;
return $this;
}
/**
* @return ThemeOptionFonts
*/
public function getFonts()
{
return $this->fonts;
}
/**
* @param ThemeOptionFonts $fonts A ThemeOptionFonts instance.
*
* @return NotificationThemeOptions
*/
public function setFonts(ThemeOptionFonts $fonts)
{
$this->fonts = $fonts;
return $this;
}
/**
* @return ThemeOptionContent
*/
public function getContent()
{
return $this->content;
}
/**
* @param ThemeOptionContent $content A ThemeOptionContent instance.
*
* @return NotificationThemeOptions
*/
public function setContent(ThemeOptionContent $content)
{
$this->content = $content;
return $this;
}
/**
* @return ThemeOptionColors
*/
public function getColors()
{
return $this->colors;
}
/**
* @param ThemeOptionColors $colors A ThemeOptionColors instace.
*
* @return NotificationThemeOptions
*/
public function setColors(ThemeOptionColors $colors)
{
$this->colors = $colors;
return $this;
}
/**
* @return array
*/
public function toArray()
{
return [
'summary' => $this->summary,
'conclusion' => $this->conclusion,
'header' => $this->header->toArray(),
'fonts' => $this->fonts->toArray(),
'content' => $this->content->toArray(),
'colors' => $this->colors->toArray(),
];
}
}
@@ -0,0 +1,140 @@
<?php
namespace UserBundle\Entity\Notification\Schedule;
use ApiBundle\Entity\NormalizableEntityInterface;
use AppBundle\Entity\BaseEntityTrait;
use AppBundle\Entity\EntityInterface;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use UserBundle\Entity\Notification\Notification;
use UserBundle\Entity\Notification\NotificationSendHistory;
/**
* Class AbstractNotificationSchedule
*
* @ORM\Table(name="notification_schedule")
* @ORM\Entity
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="type", type="string")
* @ORM\DiscriminatorMap({
* "daily"="DailyNotificationSchedule",
* "weekly"="WeeklyNotificationSchedule",
* "monthly"="MonthlyNotificationSchedule"
* })
*/
abstract class AbstractNotificationSchedule implements
EntityInterface,
NormalizableEntityInterface
{
use BaseEntityTrait;
/**
* @var Notification
*
* @ORM\ManyToOne(
* targetEntity="UserBundle\Entity\Notification\Notification",
* inversedBy="schedules"
* )
*/
private $notification;
/**
* @var NotificationSendHistory
*
* @ORM\ManyToOne(
* targetEntity="UserBundle\Entity\Notification\NotificationSendHistory",
* inversedBy="schedules"
* )
*/
private $history;
/**
* Set notification
*
* @param Notification $notification A Notification instance.
*
* @return static
*/
public function setNotification(Notification $notification = null)
{
$this->notification = $notification;
return $this;
}
/**
* Get notification
*
* @return Notification
*/
public function getNotification()
{
return $this->notification;
}
/**
* Set history
*
* @param NotificationSendHistory $history A NotificationSendHistory instance.
*
* @return AbstractNotificationSchedule
*/
public function setHistory(NotificationSendHistory $history = null)
{
$this->history = $history;
return $this;
}
/**
* Get history
*
* @return NotificationSendHistory
*/
public function getHistory()
{
return $this->history;
}
/**
* Compute all date's for this schedule in specified period.
*
* @param \DateTime $start Start of computing period.
* @param \DateTime $end End of computing period.
*
* @return \DateTime[]
*/
public function computeDates(\DateTime $start, \DateTime $end)
{
$modifiedStart = clone $start;
$modifiedEnd = clone $end;
$modifiedStart
->setTime($modifiedStart->format('H'), $modifiedStart->format('i'), 0);
// Add 1 seconds in order to catch end date if it should exists in result's.
$modifiedEnd
->setTime($modifiedEnd->format('H'), $modifiedEnd->format('i'), 1);
return $this->doComputeDates($modifiedStart, $modifiedEnd);
}
/**
* Return key identifier for current schedule.
*
* @return string
*/
abstract public function getKey();
/**
* Compute all date's for this schedule in specified period.
*
* @param \DateTime $start Start of computing period.
* @param \DateTime $end End of computing period.
*
* @return \DateTime[]
*/
abstract protected function doComputeDates(\DateTime $start, \DateTime $end);
}
@@ -0,0 +1,251 @@
<?php
namespace UserBundle\Entity\Notification\Schedule;
use ApiBundle\Serializer\Metadata\Metadata;
use ApiBundle\Serializer\Metadata\PropertyMetadata;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Class DailyNotificationSchedule
*
* @ORM\Entity
*/
class DailyNotificationSchedule extends AbstractNotificationSchedule
{
const TIME_15_M = '15m';
const TIME_30_M = '30m';
const TIME_1_H = '1h';
const TIME_2_H = '2h';
const TIME_3_H = '3h';
const TIME_4_H = '4h';
const TIME_6_H = '6h';
const TIME_12_H = '12h';
const TIME_ONCE = 'once';
const DAYS_ALL = 'all';
const DAYS_WEEKDAYS = 'weekdays';
const DAYS_WEEKENDS = 'weekends';
/**
* @var string
*
* @ORM\Column(length=5)
* @Assert\Choice(callback="getAvailableTime")
*/
private $time;
/**
* @var string
*
* @ORM\Column(length=9)
* @Assert\Choice(callback="getAvailableDays")
*/
private $days;
/**
* Map between available time values and crontab schedule string.
*
* @var string[]
*/
private static $timeMap = [
self::TIME_15_M => 'T15M',
self::TIME_30_M => 'T30M',
self::TIME_1_H => 'T1H',
self::TIME_2_H => 'T2H',
self::TIME_3_H => 'T3H',
self::TIME_4_H => 'T4H',
self::TIME_6_H => 'T6H',
self::TIME_12_H => 'T12H',
self::TIME_ONCE => '1D',
];
/**
* Get available time values.
*
* @return string[]
*/
public static function getAvailableTime()
{
return [
self::TIME_15_M,
self::TIME_30_M,
self::TIME_1_H,
self::TIME_2_H,
self::TIME_3_H,
self::TIME_4_H,
self::TIME_6_H,
self::TIME_12_H,
self::TIME_ONCE,
];
}
/**
* Get available days values.
*
* @return string[]
*/
public static function getAvailableDays()
{
return [
self::DAYS_ALL,
self::DAYS_WEEKDAYS,
self::DAYS_WEEKENDS,
];
}
/**
* Set time
*
* @param string $time One of TIME_ constant's.
*
* @return DailyNotificationSchedule
*/
public function setTime($time)
{
$this->time = $time;
return $this;
}
/**
* Get time
*
* @return string
*/
public function getTime()
{
return $this->time;
}
/**
* Set days
*
* @param string $days One of DAYS_ constant's.
*
* @return DailyNotificationSchedule
*/
public function setDays($days)
{
$this->days = $days;
return $this;
}
/**
* Get days
*
* @return string
*/
public function getDays()
{
return $this->days;
}
/**
* Get entity type
*
* @return string
*/
public function getEntityType()
{
return 'daily';
}
/**
* Return metadata for current entity.
*
* @return \ApiBundle\Serializer\Metadata\Metadata
*/
public function getMetadata()
{
return new Metadata(static::class, [
PropertyMetadata::createString('time', [ 'schedule' ]),
PropertyMetadata::createString('days', [ 'schedule' ]),
]);
}
/**
* Return default normalization groups.
*
* @return array
*/
public function defaultGroups()
{
return [ 'schedule' ];
}
/**
* @param array $data Normalized DailyNotificationSchedule.
*
* @return DailyNotificationSchedule
*/
public static function denormalize(array $data)
{
if (! isset($data['time'], $data['days'])) {
throw new \LogicException('Normalized DailyNotificationSchedule data must have \'time\' and \'days\' fields.');
}
return DailyNotificationSchedule::create()
->setTime($data['time'])
->setDays($data['days']);
}
/**
* Return key identifier for current schedule.
*
* @return string
*/
public function getKey()
{
return sprintf('daily_%s_%s', $this->time, $this->days);
}
/**
* Compute all date's for this schedule in specified period.
*
* @param \DateTime $start Start of computing period.
* @param \DateTime $end End of computing period.
*
* @return \DateTime[]
*/
protected function doComputeDates(\DateTime $start, \DateTime $end)
{
$period = new \DatePeriod(
$start,
new \DateInterval('P'. self::$timeMap[$this->time]),
$end,
\DatePeriod::EXCLUDE_START_DATE
);
$results = [];
switch ($this->days) {
case self::DAYS_ALL:
$results = iterator_to_array($period);
break;
case self::DAYS_WEEKDAYS:
/** @var \DateTime $date */
foreach ($period as $date) {
if ($date->format('N') <= 5) {
$results[] = $date;
}
}
break;
case self::DAYS_WEEKENDS:
/** @var \DateTime $date */
foreach ($period as $date) {
if ($date->format('N') > 5) {
$results[] = $date;
}
}
break;
}
return $results;
}
}
@@ -0,0 +1,235 @@
<?php
namespace UserBundle\Entity\Notification\Schedule;
use ApiBundle\Serializer\Metadata\Metadata;
use ApiBundle\Serializer\Metadata\PropertyMetadata;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Class MonthlyNotificationSchedule
*
* @ORM\Entity
*/
class MonthlyNotificationSchedule extends AbstractNotificationSchedule
{
const DAY_LAST = 'last';
/**
* @var string
*
* @ORM\Column(length=10)
* @Assert\Choice(callback="getAvailableDay")
*/
private $day;
/**
* @var integer
*
* @ORM\Column(type="smallint")
*/
private $hour;
/**
* @var integer
*
* @ORM\Column(type="smallint")
*/
private $minute;
/**
* Get available day's.
*
* @return string[]
*/
public static function getAvailableDay()
{
$days = range(1, 31);
$days[] = self::DAY_LAST;
return $days;
}
/**
* Set day
*
* @param string $day One of DAY_ const's.
*
* @return MonthlyNotificationSchedule
*/
public function setDay($day)
{
$this->day = $day;
return $this;
}
/**
* Get day
*
* @return string
*/
public function getDay()
{
return $this->day;
}
/**
* Set hour
*
* @param integer $hour Schedule hours.
*
* @return MonthlyNotificationSchedule
*/
public function setHour($hour)
{
$this->hour = $hour;
return $this;
}
/**
* Get hour
*
* @return integer
*/
public function getHour()
{
return $this->hour;
}
/**
* Set minutes
*
* @param integer $minute Schedule minutes.
*
* @return MonthlyNotificationSchedule
*/
public function setMinute($minute)
{
$this->minute = $minute;
return $this;
}
/**
* Get minute
*
* @return integer
*/
public function getMinute()
{
return $this->minute;
}
/**
* Get entity type
*
* @return string
*/
public function getEntityType()
{
return 'monthly';
}
/**
* Return metadata for current entity.
*
* @return \ApiBundle\Serializer\Metadata\Metadata
*/
public function getMetadata()
{
return new Metadata(static::class, [
PropertyMetadata::createString('day', [ 'schedule' ]),
PropertyMetadata::createString('hour', [ 'schedule' ]),
PropertyMetadata::createString('minute', [ 'schedule' ]),
]);
}
/**
* Return default normalization groups.
*
* @return array
*/
public function defaultGroups()
{
return [ 'schedule' ];
}
/**
* @param array $data Normalized MonthlyNotificationSchedule.
*
* @return MonthlyNotificationSchedule
*/
public static function denormalize(array $data)
{
if (! isset($data['day'], $data['hour'], $data['minute'])) {
throw new \LogicException('Normalized MonthlyNotificationSchedule data must have \'day\', \'hour\' and \'minute\' fields.');
}
return MonthlyNotificationSchedule::create()
->setDay($data['day'])
->setHour($data['hour'])
->setMinute($data['minute']);
}
/**
* Return key identifier for current schedule.
*
* @return string
*/
public function getKey()
{
return sprintf(
'monthly_%s_%s_%s',
$this->day,
$this->hour,
$this->minute
);
}
/**
* Compute all date's for this schedule in specified period.
*
* @param \DateTime $start Start of computing period.
* @param \DateTime $end End of computing period.
*
* @return \DateTime[]
*/
protected function doComputeDates(\DateTime $start, \DateTime $end)
{
$dates = [];
$date = clone $start;
if ($this->day === self::DAY_LAST) {
$date->modify('last day of this month');
while ($date <= $end) {
$tmp = clone $date;
$dates[] = $tmp->setTime($this->hour, $this->minute);
$date->modify('last day of next month');
}
} else {
$currentNum = $date->format('j');
if ($currentNum > $this->day) {
$date
->modify('first day of next month')
->modify(sprintf('%d day', $this->day - 1));
} elseif ($currentNum < $this->day) {
$date->modify(sprintf('%d day', $this->day - $currentNum));
}
while ($date <= $end) {
$tmp = clone $date;
$dates[] = $tmp->setTime($this->hour, $this->minute);
$date
->modify('first day of next month')
->modify(sprintf('%d day', $this->day - 1));
}
}
return $dates;
}
}
@@ -0,0 +1,331 @@
<?php
namespace UserBundle\Entity\Notification\Schedule;
use ApiBundle\Serializer\Metadata\Metadata;
use ApiBundle\Serializer\Metadata\PropertyMetadata;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Class WeeklyNotificationSchedule
*
* @ORM\Entity
*/
class WeeklyNotificationSchedule extends AbstractNotificationSchedule
{
const PERIOD_EVERY = 'every';
const PERIOD_FIRST = 'first';
const PERIOD_SECOND = 'second';
const PERIOD_THIRD = 'third';
const PERIOD_FOURTH = 'fourth';
const PERIOD_LAST = 'last';
const DAY_MONDAY = 'monday';
const DAY_TUESDAY = 'tuesday';
const DAY_WEDNESDAY = 'wednesday';
const DAY_THURSDAY = 'thursday';
const DAY_FRIDAY = 'friday';
const DAY_SATURDAY = 'saturday';
const DAY_SUNDAY = 'sunday';
/**
* @var string
*
* @ORM\Column(length=7)
* @Assert\Choice(callback="getAvailablePeriod")
*/
private $period;
/**
* @var string
*
* @ORM\Column(length=10)
* @Assert\Choice(callback="getAvailableDay")
*/
private $day;
/**
* @var integer
*
* @ORM\Column(type="smallint")
*/
private $hour;
/**
* @var integer
*
* @ORM\Column(type="smallint")
*/
private $minute;
/**
* Map between day and corntab schedule. Make sense only for PERIOD_EVERY.
*
* @var array[]
*/
private static $dayMap = [
self::DAY_MONDAY => 1,
self::DAY_TUESDAY => 2,
self::DAY_WEDNESDAY => 3,
self::DAY_TUESDAY => 4,
self::DAY_FRIDAY => 5,
self::DAY_SATURDAY => 6,
self::DAY_SUNDAY => 7,
];
/**
* Get available period's.
*
* @return string[]
*/
public static function getAvailablePeriod()
{
return [
self::PERIOD_EVERY,
self::PERIOD_FIRST,
self::PERIOD_SECOND,
self::PERIOD_THIRD,
self::PERIOD_FOURTH,
self::PERIOD_LAST,
];
}
/**
* Get available day's.
*
* @return string[]
*/
public static function getAvailableDay()
{
return [
self::DAY_MONDAY,
self::DAY_TUESDAY,
self::DAY_WEDNESDAY,
self::DAY_TUESDAY,
self::DAY_FRIDAY,
self::DAY_SATURDAY,
self::DAY_SUNDAY,
];
}
/**
* Set period
*
* @param string $period One of PERIOD_ const's.
*
* @return WeeklyNotificationSchedule
*/
public function setPeriod($period)
{
$this->period = $period;
return $this;
}
/**
* Get period
*
* @return string
*/
public function getPeriod()
{
return $this->period;
}
/**
* Set day
*
* @param string $day One of DAY_ const's.
*
* @return WeeklyNotificationSchedule
*/
public function setDay($day)
{
$this->day = $day;
return $this;
}
/**
* Get day
*
* @return string
*/
public function getDay()
{
return $this->day;
}
/**
* Set hour
*
* @param integer $hour Schedule hours.
*
* @return WeeklyNotificationSchedule
*/
public function setHour($hour)
{
$this->hour = $hour;
return $this;
}
/**
* Get hour
*
* @return integer
*/
public function getHour()
{
return $this->hour;
}
/**
* Set minute
*
* @param integer $minute Schedule minute.
*
* @return WeeklyNotificationSchedule
*/
public function setMinute($minute)
{
$this->minute = $minute;
return $this;
}
/**
* Get minute
*
* @return integer
*/
public function getMinute()
{
return $this->minute;
}
/**
* Get entity type
*
* @return string
*/
public function getEntityType()
{
return 'weekly';
}
/**
* Return metadata for current entity.
*
* @return \ApiBundle\Serializer\Metadata\Metadata
*/
public function getMetadata()
{
return new Metadata(static::class, [
PropertyMetadata::createString('period', [ 'schedule' ]),
PropertyMetadata::createString('day', [ 'schedule' ]),
PropertyMetadata::createString('hour', [ 'schedule' ]),
PropertyMetadata::createString('minute', [ 'schedule' ]),
]);
}
/**
* Return default normalization groups.
*
* @return array
*/
public function defaultGroups()
{
return [ 'schedule' ];
}
/**
* @param array $data Normalized WeeklyNotificationSchedule.
*
* @return WeeklyNotificationSchedule
*/
public static function denormalize(array $data)
{
if (! isset($data['period'], $data['day'], $data['hour'], $data['minute'])) {
throw new \LogicException('Normalized WeeklyNotificationSchedule data must have \'period\', \'day\', \'hour\' and \'minute\' fields.');
}
return WeeklyNotificationSchedule::create()
->setPeriod($data['period'])
->setDay($data['day'])
->setHour($data['hour'])
->setMinute($data['minute']);
}
/**
* Return key identifier for current schedule.
*
* @return string
*/
public function getKey()
{
return sprintf(
'weekly_%s_%s_%s_%s',
$this->period,
$this->day,
$this->hour,
$this->minute
);
}
/**
* Compute all date's for this schedule in specified period.
*
* @param \DateTime $start Start of computing period.
* @param \DateTime $end End of computing period.
*
* @return \DateTime[]
*/
protected function doComputeDates(\DateTime $start, \DateTime $end)
{
$dates = [];
$date = clone $start;
if ($this->period === self::PERIOD_EVERY) {
//
// Process every weekdays days.
//
if ($date->format('N') !== self::$dayMap[$this->day]) {
//
// If start date is not required weekday we should proceed to next
// required weekday.
//
$date->modify('next '. $this->day);
}
while ($date <= $end) {
$tmp = clone $date;
$dates[] = $tmp->setTime($this->hour, $this->minute);
$date->modify('next '. $this->day);
}
} else {
//
// Process specified weekday like second monday, third friday and etc.
//
$date->modify(sprintf(
'%s %s of this month',
$this->period,
$this->day
));
while ($date <= $end) {
$tmp = clone $date;
$dates[] = $tmp->setTime($this->hour, $this->minute);
$date->modify(sprintf(
'%s %s of next month',
$this->period,
$this->day
));
}
}
return $dates;
}
}
@@ -0,0 +1,117 @@
<?php
namespace UserBundle\Entity\Notification\ThemeOption;
/**
* Class ThemeOptionColors
* @package UserBundle\Entity\Notification\ThemeOption
*/
class ThemeOptionColors implements \Serializable
{
/**
* @var ThemeOptionColorsBackground
*/
private $background;
/**
* @var ThemeOptionColorsText
*/
private $text;
/**
* ThemeOptionColors constructor.
*
* @param ThemeOptionColorsBackground $background A ThemeOptionColorsBackground
* instance.
* @param ThemeOptionColorsText $text A ThemeOptionColorsText
* instance.
*/
public function __construct(
ThemeOptionColorsBackground $background,
ThemeOptionColorsText $text
) {
$this->background = $background;
$this->text = $text;
}
/**
* @return ThemeOptionColorsBackground
*/
public function getBackground()
{
return $this->background;
}
/**
* @param ThemeOptionColorsBackground $background A ThemeOptionColorsBackground
* instance.
*
* @return ThemeOptionColors
*/
public function setBackground(ThemeOptionColorsBackground $background)
{
$this->background = $background;
return $this;
}
/**
* @return ThemeOptionColorsText
*/
public function getText()
{
return $this->text;
}
/**
* @param ThemeOptionColorsText $text A ThemeOptionColorsText instance.
*
* @return ThemeOptionColors
*/
public function setText(ThemeOptionColorsText $text)
{
$this->text = $text;
return $this;
}
/**
* String representation of object.
*
* @return string the string representation of the object or null.
*/
public function serialize()
{
return serialize([
$this->background,
$this->text,
]);
}
/**
* Constructs the object
*
* @param string $serialized The string representation of the object.
*
* @return void
*/
public function unserialize($serialized)
{
$data = unserialize($serialized);
$this->background = $data[0];
$this->text = $data[1];
}
/**
* @return array
*/
public function toArray()
{
return [
'background' => $this->background->toArray(),
'text' => $this->text->toArray(),
];
}
}
@@ -0,0 +1,167 @@
<?php
namespace UserBundle\Entity\Notification\ThemeOption;
/**
* Class ThemeOptionColorsBackground
* @package UserBundle\Entity\Notification\ThemeOption
*/
class ThemeOptionColorsBackground implements \Serializable
{
const DEFAULT_HEADER = 'rgba(36, 37, 37, 1)';
const DEFAULT_EMAIL_BODY = 'rgba(244, 244, 245, 1)';
const DEFAULT_ACCENT = 'rgba(109, 110, 113, 1)';
/**
* CSS RGBA.
*
* ```
* rgba(125, 125, 125, 0.5);
* ```
*
* @var string
*/
private $header;
/**
* CSS RGBA.
*
* ```
* rgba(125, 125, 125, 0.5);
* ```
*
* @var string
*/
private $emailBody;
/**
* CSS RGBA.
*
* ```
* rgba(125, 125, 125, 0.5);
* ```
*
* @var string
*/
private $accent;
/**
* ThemeOptionColorsBackground constructor.
*
* @param string $header Header background color.
* @param string $emailBody Email body color.
* @param string $accent Accent color.
*/
public function __construct(
$header = self::DEFAULT_HEADER,
$emailBody = self::DEFAULT_EMAIL_BODY,
$accent = self::DEFAULT_ACCENT
) {
$this->header = trim($header);
$this->emailBody = trim($emailBody);
$this->accent = trim($accent);
}
/**
* @return string
*/
public function getHeader()
{
return $this->header;
}
/**
* @param string $header Header background color.
*
* @return ThemeOptionColorsBackground
*/
public function setHeader($header)
{
$this->header = $header;
return $this;
}
/**
* @return string
*/
public function getEmailBody()
{
return $this->emailBody;
}
/**
* @param string $emailBody Email body color.
*
* @return ThemeOptionColorsBackground
*/
public function setEmailBody($emailBody)
{
$this->emailBody = $emailBody;
return $this;
}
/**
* @return string
*/
public function getAccent()
{
return $this->accent;
}
/**
* @param string $accent Accent background color.
*
* @return ThemeOptionColorsBackground
*/
public function setAccent($accent)
{
$this->accent = $accent;
return $this;
}
/**
* String representation of object.
*
* @return string the string representation of the object or null.
*/
public function serialize()
{
return serialize([
$this->header,
$this->emailBody,
$this->accent,
]);
}
/**
* Constructs the object
*
* @param string $serialized The string representation of the object.
*
* @return void
*/
public function unserialize($serialized)
{
$data = unserialize($serialized);
$this->header = $data[0];
$this->emailBody = $data[1];
$this->accent = $data[2];
}
/**
* @return array
*/
public function toArray()
{
return [
'header' => $this->header,
'emailBody' => $this->emailBody,
'accent' => $this->accent,
];
}
}
@@ -0,0 +1,281 @@
<?php
namespace UserBundle\Entity\Notification\ThemeOption;
/**
* Class ThemeOptionColorsText
* @package UserBundle\Entity\Notification\ThemeOption
*/
class ThemeOptionColorsText implements \Serializable
{
const DEFAULT_HEADER = 'rgba(255, 255, 255, 1)';
const DEFAULT_ARTICLE_HEADLINE = 'rgba(0, 147, 176, 1)';
const DEFAULT_ARTICLE_CONTENT = 'rgba(102, 102, 102, 1)';
const DEFAULT_AUTHOR = 'rgba(143, 43, 140, 1)';
const DEFAULT_PUBLISH_DATE = 'rgba(109, 110, 113, 1)';
const DEFAULT_SOURCE = 'rgba(82, 83, 85, 1)';
/**
* CSS RGBA.
*
* ```
* rgba(125, 125, 125, 0.5);
* ```
*
* @var string
*/
private $header;
/**
* CSS RGBA.
*
* ```
* rgba(125, 125, 125, 0.5);
* ```
*
* @var string
*/
private $articleHeadline;
/**
* CSS RGBA.
*
* ```
* rgba(125, 125, 125, 0.5);
* ```
*
* @var string
*/
private $articleContent;
/**
* CSS RGBA.
*
* ```
* rgba(125, 125, 125, 0.5);
* ```
*
* @var string
*/
private $author;
/**
* CSS RGBA.
*
* ```
* rgba(125, 125, 125, 0.5);
* ```
*
* @var string
*/
private $publishDate;
/**
* CSS RGBA.
*
* ```
* rgba(125, 125, 125, 0.5);
* ```
*
* @var string
*/
private $source;
/**
* ThemeOptionColorsText constructor.
*
* @param string $header Header text color.
* @param string $articleHeadline Article headline text color.
* @param string $articleContent Article content text color.
* @param string $author Author text color.
* @param string $publishDate Publish date text color.
* @param string $source Source text color.
*/
public function __construct(
$header = self::DEFAULT_HEADER,
$articleHeadline = self::DEFAULT_ARTICLE_HEADLINE,
$articleContent = self::DEFAULT_ARTICLE_CONTENT,
$author = self::DEFAULT_AUTHOR,
$publishDate = self::DEFAULT_PUBLISH_DATE,
$source = self::DEFAULT_SOURCE
) {
$this->header = trim($header);
$this->articleHeadline = trim($articleHeadline);
$this->articleContent = trim($articleContent);
$this->author = trim($author);
$this->publishDate = trim($publishDate);
$this->source = trim($source);
}
/**
* @return string
*/
public function getHeader()
{
return $this->header;
}
/**
* @param string $header Header text color.
*
* @return ThemeOptionColorsText
*/
public function setHeader($header)
{
$this->header = $header;
return $this;
}
/**
* @return string
*/
public function getArticleHeadline()
{
return $this->articleHeadline;
}
/**
* @param string $articleHeadline Article headline text color.
*
* @return ThemeOptionColorsText
*/
public function setArticleHeadline($articleHeadline)
{
$this->articleHeadline = $articleHeadline;
return $this;
}
/**
* @return string
*/
public function getArticleContent()
{
return $this->articleContent;
}
/**
* @param string $articleContent Article content text color.
*
* @return ThemeOptionColorsText
*/
public function setArticleContent($articleContent)
{
$this->articleContent = $articleContent;
return $this;
}
/**
* @return string
*/
public function getAuthor()
{
return $this->author;
}
/**
* @param string $author Author text color.
*
* @return ThemeOptionColorsText
*/
public function setAuthor($author)
{
$this->author = $author;
return $this;
}
/**
* @return string
*/
public function getPublishDate()
{
return $this->publishDate;
}
/**
* @param string $publishDate Publish date text color.
*
* @return ThemeOptionColorsText
*/
public function setPublishDate($publishDate)
{
$this->publishDate = $publishDate;
return $this;
}
/**
* @return string
*/
public function getSource()
{
return $this->source;
}
/**
* @param string $source Source text color.
*
* @return ThemeOptionColorsText
*/
public function setSource($source)
{
$this->source = $source;
return $this;
}
/**
* String representation of object.
*
* @return string the string representation of the object or null.
*/
public function serialize()
{
return serialize([
$this->header,
$this->articleHeadline,
$this->articleContent,
$this->author,
$this->publishDate,
$this->source,
]);
}
/**
* Constructs the object
*
* @param string $serialized The string representation of the object.
*
* @return void
*/
public function unserialize($serialized)
{
$data = unserialize($serialized);
$this->header = $data[0];
$this->articleHeadline = $data[1];
$this->articleContent = $data[2];
$this->author = $data[3];
$this->publishDate = $data[4];
$this->source = $data[5];
}
/**
* @return array
*/
public function toArray()
{
return [
'header' => $this->header,
'articleHeadline' => $this->articleHeadline,
'articleContent' => $this->articleContent,
'author' => $this->author,
'publishDate' => $this->publishDate,
'source' => $this->source,
];
}
}
@@ -0,0 +1,184 @@
<?php
namespace UserBundle\Entity\Notification\ThemeOption;
use UserBundle\Enum\ThemeOptionExtractEnum;
/**
* Class ThemeOptionContent
* @package UserBundle\Entity\Notification\ThemeOption
*/
class ThemeOptionContent implements \Serializable
{
/**
* @var ThemeOptionHighlightKeywords
*/
private $highlightKeywords;
/**
* @var ThemeOptionShowInfo
*/
private $showInfo;
/**
* @var string
*/
private $language;
/**
* @var ThemeOptionExtractEnum
*/
private $extract;
/**
* ThemeOptionContent constructor.
*
* @param ThemeOptionHighlightKeywords $highlightKeywords A ThemeOptionHighlightKeywords
* instance.
* @param ThemeOptionShowInfo $showInfo A ThemeOptionShowInfo
* instance.
* @param string $language Selected notification
* language.
* @param ThemeOptionExtractEnum $extract A ThemeOptionExtractEnum
* instance.
*/
public function __construct(
ThemeOptionHighlightKeywords $highlightKeywords,
ThemeOptionShowInfo $showInfo,
$language,
ThemeOptionExtractEnum $extract
) {
$this->highlightKeywords = $highlightKeywords;
$this->showInfo = $showInfo;
$this->language = trim($language);
$this->extract = $extract;
}
/**
* @return ThemeOptionHighlightKeywords
*/
public function getHighlightKeywords()
{
return $this->highlightKeywords;
}
/**
* @param ThemeOptionHighlightKeywords $highlightKeywords A ThemeOptionHighlightKeywords
* instance.
*
* @return ThemeOptionContent
*/
public function setHighlightKeywords(ThemeOptionHighlightKeywords $highlightKeywords)
{
$this->highlightKeywords = $highlightKeywords;
return $this;
}
/**
* @return ThemeOptionShowInfo
*/
public function getShowInfo()
{
return $this->showInfo;
}
/**
* @param ThemeOptionShowInfo $showInfo A ThemeOptionShowInfo instance.
*
* @return ThemeOptionContent
*/
public function setShowInfo(ThemeOptionShowInfo $showInfo)
{
$this->showInfo = $showInfo;
return $this;
}
/**
* @return string
*/
public function getLanguage()
{
return $this->language;
}
/**
* @param string $language Selected theme language.
*
* @return ThemeOptionContent
*/
public function setLanguage($language)
{
$this->language = $language;
return $this;
}
/**
* @return ThemeOptionExtractEnum
*/
public function getExtract()
{
return $this->extract;
}
/**
* @param ThemeOptionExtractEnum $extract A ThemeOptionExtractEnum
* instance.
*
* @return ThemeOptionContent
*/
public function setExtract(ThemeOptionExtractEnum $extract)
{
$this->extract = $extract;
return $this;
}
/**
* String representation of object.
*
* @return string the string representation of the object or null.
*/
public function serialize()
{
return serialize([
$this->highlightKeywords,
$this->showInfo,
$this->language,
$this->extract,
]);
}
/**
* Constructs the object
*
* @param string $serialized The string representation of the object.
*
* @return void
*/
public function unserialize($serialized)
{
$data = unserialize($serialized);
$this->highlightKeywords = $data[0];
$this->showInfo = $data[1];
$this->language = $data[2];
$this->extract = $data[3];
}
/**
* @return array
*/
public function toArray()
{
return [
'highlightKeywords' => $this->highlightKeywords->toArray(),
'showInfo' => $this->showInfo->toArray(),
'language' => $this->language,
'extract' => $this->extract->getValue(),
];
}
}
@@ -0,0 +1,144 @@
<?php
namespace UserBundle\Entity\Notification\ThemeOption;
use UserBundle\Enum\FontFamilyEnum;
/**
* Class ThemeOptionFont
* @package UserBundle\Entity\Notification\ThemeOption
*/
class ThemeOptionFont implements \Serializable
{
/**
* @var FontFamilyEnum
*/
private $family;
/**
* @var integer
*/
private $size;
/**
* @var ThemeOptionFontStyle
*/
private $style;
/**
* ThemeOptionFont constructor.
*
* @param FontFamilyEnum $family Font family name.
* @param integer $size Font size.
* @param ThemeOptionFontStyle $style A ThemeOptionFontStyle instance.
*/
public function __construct(FontFamilyEnum $family, $size, ThemeOptionFontStyle $style = null)
{
$this->family = $family;
$this->size = (int) trim($size);
$this->style = $style === null ? new ThemeOptionFontStyle() : $style;
}
/**
* @return FontFamilyEnum
*/
public function getFamily()
{
return $this->family;
}
/**
* @param FontFamilyEnum $family Font family name.
*
* @return ThemeOptionFont
*/
public function setFamily(FontFamilyEnum $family)
{
$this->family = $family;
return $this;
}
/**
* @return integer
*/
public function getSize()
{
return $this->size;
}
/**
* @param integer $size Font size.
*
* @return ThemeOptionFont
*/
public function setSize($size)
{
$this->size = $size;
return $this;
}
/**
* @return ThemeOptionFontStyle
*/
public function getStyle()
{
return $this->style;
}
/**
* @param ThemeOptionFontStyle $style A ThemeOptionFontStyle instance.
*
* @return ThemeOptionFont
*/
public function setStyle(ThemeOptionFontStyle $style)
{
$this->style = $style;
return $this;
}
/**
* String representation of object.
*
* @return string the string representation of the object or null.
*/
public function serialize()
{
return serialize([
$this->family,
$this->size,
$this->style,
]);
}
/**
* Constructs the object
*
* @param string $serialized The string representation of the object.
*
* @return void
*/
public function unserialize($serialized)
{
$data = unserialize($serialized);
$this->family = $data[0];
$this->size = $data[1];
$this->style = $data[2];
}
/**
* @return array
*/
public function toArray()
{
return [
'family' => $this->family->getCss(),
'size' => $this->size,
'style' => $this->style->toArray(),
];
}
}
@@ -0,0 +1,142 @@
<?php
namespace UserBundle\Entity\Notification\ThemeOption;
/**
* Class ThemeOptionFontStyle
* @package UserBundle\Entity\Notification\ThemeOption
*/
class ThemeOptionFontStyle implements \Serializable
{
/**
* @var boolean
*/
private $bold;
/**
* @var boolean
*/
private $italic;
/**
* @var boolean
*/
private $underline;
/**
* ThemeOptionFontStyle constructor.
*
* @param boolean $bold Should be text bold or not.
* @param boolean $italic Should be text italic or not.
* @param boolean $underline Should be text underlined or not.
*/
public function __construct($bold = false, $italic = false, $underline = false)
{
$this->bold = (bool) $bold;
$this->italic = (bool) $italic;
$this->underline = (bool) $underline;
}
/**
* @return boolean
*/
public function isBold()
{
return $this->bold;
}
/**
* @param boolean $bold Should be text bold or not.
*
* @return static
*/
public function setBold($bold = true)
{
$this->bold = $bold;
return $this;
}
/**
* @return boolean
*/
public function isItalic()
{
return $this->italic;
}
/**
* @param boolean $italic Should be text italic or not.
*
* @return static
*/
public function setItalic($italic = true)
{
$this->italic = $italic;
return $this;
}
/**
* @return boolean
*/
public function isUnderline()
{
return $this->underline;
}
/**
* @param boolean $underline Should be text underlined or not.
*
* @return static
*/
public function setUnderline($underline = true)
{
$this->underline = $underline;
return $this;
}
/**
* String representation of object.
*
* @return string the string representation of the object or null.
*/
public function serialize()
{
return serialize([
$this->bold,
$this->italic,
$this->underline,
]);
}
/**
* Constructs the object
*
* @param string $serialized The string representation of the object.
*
* @return void
*/
public function unserialize($serialized)
{
$data = unserialize($serialized);
$this->bold = $data[0];
$this->italic = $data[1];
$this->underline = $data[2];
}
/**
* @return array
*/
public function toArray()
{
return [
'bold' => $this->bold,
'italic' => $this->italic,
'underline' => $this->underline,
];
}
}
@@ -0,0 +1,300 @@
<?php
namespace UserBundle\Entity\Notification\ThemeOption;
/**
* Class ThemeOptionFonts
* @package UserBundle\Entity\Notification\ThemeOption
*/
class ThemeOptionFonts implements \Serializable
{
/**
* @var ThemeOptionFont
*/
private $header;
/**
* @var ThemeOptionFont
*/
private $tableOfContents;
/**
* @var ThemeOptionFont
*/
private $feedTitle;
/**
* @var ThemeOptionFont
*/
private $articleHeadline;
/**
* @var ThemeOptionFont
*/
private $source;
/**
* @var ThemeOptionFont
*/
private $author;
/**
* @var ThemeOptionFont
*/
private $date;
/**
* @var ThemeOptionFont
*/
private $articleContent;
/**
* ThemeOptionFonts constructor.
*
* @param ThemeOptionFont $header A ThemeOptionFont instance.
* @param ThemeOptionFont $tableOfContents A ThemeOptionFont instance.
* @param ThemeOptionFont $feedTitle A ThemeOptionFont instance.
* @param ThemeOptionFont $articleHeadline A ThemeOptionFont instance.
* @param ThemeOptionFont $source A ThemeOptionFont instance.
* @param ThemeOptionFont $author A ThemeOptionFont instance.
* @param ThemeOptionFont $date A ThemeOptionFont instance.
* @param ThemeOptionFont $articleContent A ThemeOptionFont instance.
*/
public function __construct(
ThemeOptionFont $header,
ThemeOptionFont $tableOfContents,
ThemeOptionFont $feedTitle,
ThemeOptionFont $articleHeadline,
ThemeOptionFont $source,
ThemeOptionFont $author,
ThemeOptionFont $date,
ThemeOptionFont $articleContent
) {
$this->header = $header;
$this->tableOfContents = $tableOfContents;
$this->feedTitle = $feedTitle;
$this->articleHeadline = $articleHeadline;
$this->source = $source;
$this->author = $author;
$this->date = $date;
$this->articleContent = $articleContent;
}
/**
* @return ThemeOptionFont
*/
public function getHeader()
{
return $this->header;
}
/**
* @param ThemeOptionFont $header A ThemeOptionFont instance.
*
* @return ThemeOptionFonts
*/
public function setHeader(ThemeOptionFont $header)
{
$this->header = $header;
return $this;
}
/**
* @return ThemeOptionFont
*/
public function getTableOfContents()
{
return $this->tableOfContents;
}
/**
* @param ThemeOptionFont $tableOfContents A ThemeOptionFont instance.
*
* @return ThemeOptionFonts
*/
public function setTableOfContents(ThemeOptionFont $tableOfContents)
{
$this->tableOfContents = $tableOfContents;
return $this;
}
/**
* @return ThemeOptionFont
*/
public function getFeedTitle()
{
return $this->feedTitle;
}
/**
* @param ThemeOptionFont $feedTitle A ThemeOptionFont instance.
*
* @return ThemeOptionFonts
*/
public function setFeedTitle(ThemeOptionFont $feedTitle)
{
$this->feedTitle = $feedTitle;
return $this;
}
/**
* @return ThemeOptionFont
*/
public function getArticleHeadline()
{
return $this->articleHeadline;
}
/**
* @param ThemeOptionFont $articleHeadline A ThemeOptionFont instance.
*
* @return ThemeOptionFonts
*/
public function setArticleHeadline(ThemeOptionFont $articleHeadline)
{
$this->articleHeadline = $articleHeadline;
return $this;
}
/**
* @return ThemeOptionFont A ThemeOptionFont instance.
*/
public function getSource()
{
return $this->source;
}
/**
* @param ThemeOptionFont $source A ThemeOptionFont instance.
*
* @return ThemeOptionFonts
*/
public function setSource(ThemeOptionFont $source)
{
$this->source = $source;
return $this;
}
/**
* @return ThemeOptionFont
*/
public function getAuthor()
{
return $this->author;
}
/**
* @param ThemeOptionFont $author A ThemeOptionFont instance.
*
* @return ThemeOptionFonts
*/
public function setAuthor(ThemeOptionFont $author)
{
$this->author = $author;
return $this;
}
/**
* @return ThemeOptionFont
*/
public function getDate()
{
return $this->date;
}
/**
* @param ThemeOptionFont $date A ThemeOptionFont instance.
*
* @return ThemeOptionFonts
*/
public function setDate(ThemeOptionFont $date)
{
$this->date = $date;
return $this;
}
/**
* @return ThemeOptionFont
*/
public function getArticleContent()
{
return $this->articleContent;
}
/**
* @param ThemeOptionFont $articleContent A ThemeOptionFont instance.
*
* @return ThemeOptionFonts
*/
public function setArticleContent(ThemeOptionFont $articleContent)
{
$this->articleContent = $articleContent;
return $this;
}
/**
* String representation of object.
*
* @return string the string representation of the object or null.
*/
public function serialize()
{
return serialize([
$this->header,
$this->tableOfContents,
$this->feedTitle,
$this->articleHeadline,
$this->source,
$this->author,
$this->date,
$this->articleContent,
]);
}
/**
* Constructs the object
*
* @param string $serialized The string representation of the object.
*
* @return void
*/
public function unserialize($serialized)
{
$data = unserialize($serialized);
$this->header = $data[0];
$this->tableOfContents = $data[1];
$this->feedTitle = $data[2];
$this->articleHeadline = $data[3];
$this->source = $data[4];
$this->author = $data[5];
$this->date = $data[6];
$this->articleContent = $data[7];
}
/**
* @return array
*/
public function toArray()
{
return [
'header' => $this->header->toArray(),
'tableOfContents' => $this->tableOfContents->toArray(),
'feedTitle' => $this->feedTitle->toArray(),
'articleHeadline' => $this->articleHeadline->toArray(),
'source' => $this->source->toArray(),
'author' => $this->author->toArray(),
'date' => $this->date->toArray(),
'articleContent' => $this->articleContent->toArray(),
];
}
}
File diff suppressed because one or more lines are too long
@@ -0,0 +1,148 @@
<?php
namespace UserBundle\Entity\Notification\ThemeOption;
/**
* Class ThemeOptionHighlightKeywords
* @package UserBundle\Entity\Notification\ThemeOption
*/
class ThemeOptionHighlightKeywords implements \Serializable
{
/**
* @var boolean
*/
private $highlight;
/**
* @var boolean
*/
private $bold;
/**
* CSS RGBA.
*
* ```
* rgba(125, 125, 125, 0.5);
* ```
*
* @var string
*/
private $color;
/**
* ThemeOptionHighlightKeywords constructor.
*
* @param boolean $highlight Should system highlight keywords or not.
* @param boolean $bold Should highlight keyword be bold or not.
* @param string $color Highlight color.
*/
public function __construct($highlight = true, $bold = true, $color = 'rgba(255, 255, 0, 1)')
{
$this->highlight = (bool) $highlight;
$this->bold = (bool) $bold;
$this->color = trim($color);
}
/**
* @return boolean
*/
public function isHighlight()
{
return $this->highlight;
}
/**
* @param boolean $highlight Should system highlight keywords or not.
*
* @return ThemeOptionHighlightKeywords
*/
public function setHighlight($highlight = true)
{
$this->highlight = $highlight;
return $this;
}
/**
* @return boolean
*/
public function isBold()
{
return $this->bold;
}
/**
* @param boolean $bold Should highlight keyword be bold or not.
*
* @return ThemeOptionHighlightKeywords
*/
public function setBold($bold = true)
{
$this->bold = $bold;
return $this;
}
/**
* @return string
*/
public function getColor()
{
return $this->color;
}
/**
* @param string $color Highlight color.
*
* @return ThemeOptionHighlightKeywords
*/
public function setColor($color)
{
$this->color = $color;
return $this;
}
/**
* String representation of object.
*
* @return string the string representation of the object or null.
*/
public function serialize()
{
return serialize([
$this->highlight,
$this->bold,
$this->color,
]);
}
/**
* Constructs the object
*
* @param string $serialized The string representation of the object.
*
* @return void
*/
public function unserialize($serialized)
{
$data = unserialize($serialized);
$this->highlight = $data[0];
$this->bold = $data[1];
$this->color = $data[2];
}
/**
* @return array
*/
public function toArray()
{
return [
'highlight' => $this->highlight,
'bold' => $this->bold,
'color' => $this->color,
];
}
}
@@ -0,0 +1,313 @@
<?php
namespace UserBundle\Entity\Notification\ThemeOption;
use UserBundle\Enum\ThemeOptionsTableOfContentsEnum;
use UserBundle\Enum\ThemeOptionsUserCommentsEnum;
/**
* Class ThemeOptionShowInfo
* @package UserBundle\Entity\Notification\ThemeOption
*/
class ThemeOptionShowInfo implements \Serializable
{
/**
* @var boolean
*/
private $sourceCountry;
/**
* @var boolean
*/
private $articleSentiment;
/**
* @var boolean
*/
private $articleCount;
/**
* @var boolean
*/
private $images;
/**
* @var boolean
*/
private $sharingOptions;
/**
* @var boolean
*/
private $sectionDivider;
/**
* @var ThemeOptionsUserCommentsEnum
*/
private $userComments;
/**
* @var ThemeOptionsTableOfContentsEnum
*/
private $tableOfContents;
/**
* ThemeOptionShowInfo constructor.
*
* @param ThemeOptionsUserCommentsEnum|string $userComments A ThemeOptionsUserCommentsEnum
* instance.
* @param ThemeOptionsTableOfContentsEnum|string $tableOfContents A ThemeOptionsTableOfContentsEnum
* instance.
* @param boolean $sourceCountry Show or not source country.
* @param boolean $articleSentiment Show or not article sentiment.
* @param boolean $articleCount Show or not article count.
* @param boolean $images Show or not article images.
* @param boolean $sharingOptions Show or not sharing options.
* @param boolean $sectionDivider Show or not section divider.
*/
public function __construct(
$userComments,
$tableOfContents,
$sourceCountry = false,
$articleSentiment = true,
$articleCount = true,
$images = true,
$sharingOptions = true,
$sectionDivider = false
) {
$this->sourceCountry = (bool) $sourceCountry;
$this->articleSentiment = (bool) $articleSentiment;
$this->articleCount = (bool) $articleCount;
$this->images = (bool) $images;
$this->sharingOptions = (bool) $sharingOptions;
$this->sectionDivider = (bool) $sectionDivider;
$this->setUserComments($userComments);
$this->setTableOfContents($tableOfContents);
}
/**
* @return boolean
*/
public function isSourceCountry()
{
return $this->sourceCountry;
}
/**
* @param boolean $sourceCountry Show source country.
*
* @return ThemeOptionShowInfo
*/
public function setSourceCountry($sourceCountry = true)
{
$this->sourceCountry = $sourceCountry;
return $this;
}
/**
* @return boolean
*/
public function isArticleSentiment()
{
return $this->articleSentiment;
}
/**
* @param boolean $articleSentiment Show article sentiment.
*
* @return ThemeOptionShowInfo
*/
public function setArticleSentiment($articleSentiment = true)
{
$this->articleSentiment = $articleSentiment;
return $this;
}
/**
* @return boolean
*/
public function isArticleCount()
{
return $this->articleCount;
}
/**
* @param boolean $articleCount Show article count.
*
* @return ThemeOptionShowInfo
*/
public function setArticleCount($articleCount = true)
{
$this->articleCount = $articleCount;
return $this;
}
/**
* @return boolean
*/
public function isImages()
{
return $this->images;
}
/**
* @param boolean $images Show or not articles images.
*
* @return ThemeOptionShowInfo
*/
public function setImages($images = true)
{
$this->images = $images;
return $this;
}
/**
* @return boolean
*/
public function isSharingOptions()
{
return $this->sharingOptions;
}
/**
* @param boolean $sharingOptions Show or not sharing options.
*
* @return ThemeOptionShowInfo
*/
public function setSharingOptions($sharingOptions = true)
{
$this->sharingOptions = $sharingOptions;
return $this;
}
/**
* @return boolean
*/
public function isSectionDivider()
{
return $this->sectionDivider;
}
/**
* @param boolean $sectionDivider Show section divider or not.
*
* @return ThemeOptionShowInfo
*/
public function setSectionDivider($sectionDivider = true)
{
$this->sectionDivider = $sectionDivider;
return $this;
}
/**
* @return ThemeOptionsUserCommentsEnum
*/
public function getUserComments()
{
return $this->userComments;
}
/**
* @param ThemeOptionsUserCommentsEnum|string $userComments A ThemeOptionsUserCommentsEnum
* instance.
*
* @return ThemeOptionShowInfo
*/
public function setUserComments($userComments)
{
if (is_string($userComments)) {
$userComments = new ThemeOptionsUserCommentsEnum($userComments);
}
$this->userComments = $userComments;
return $this;
}
/**
* @return ThemeOptionsTableOfContentsEnum
*/
public function getTableOfContents()
{
return $this->tableOfContents;
}
/**
* @param ThemeOptionsTableOfContentsEnum|string $tableOfContents A ThemeOptionsTableOfContentsEnum
* instance.
*
* @return ThemeOptionShowInfo
*/
public function setTableOfContents($tableOfContents)
{
if (is_string($tableOfContents)) {
$tableOfContents = new ThemeOptionsTableOfContentsEnum($tableOfContents);
}
$this->tableOfContents = $tableOfContents;
return $this;
}
/**
* String representation of object.
*
* @return string the string representation of the object or null.
*/
public function serialize()
{
return serialize([
$this->sourceCountry,
$this->articleSentiment,
$this->articleCount,
$this->images,
$this->sharingOptions,
$this->sectionDivider,
$this->userComments,
$this->tableOfContents,
]);
}
/**
* Constructs the object
*
* @param string $serialized The string representation of the object.
*
* @return void
*/
public function unserialize($serialized)
{
$data = unserialize($serialized);
$this->sourceCountry = $data[0];
$this->articleSentiment = $data[1];
$this->articleCount = $data[2];
$this->images = $data[3];
$this->sharingOptions = $data[4];
$this->sectionDivider = $data[5];
$this->userComments = $data[6];
$this->tableOfContents = $data[7];
}
/**
* @return array
*/
public function toArray()
{
return [
'sourceCountry' => $this->sourceCountry,
'articleSentiment' => $this->articleSentiment,
'articleCount' => $this->articleCount,
'images' => $this->images,
'sharingOptions' => $this->sharingOptions,
'sectionDivider' => $this->sectionDivider,
'userComments' => $this->userComments->getValue(),
'tableOfContents' => $this->tableOfContents->getValue(),
];
}
}