<?php
namespace AdminBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Eventviva\ImageResize;
use Symfony\Component\HttpFoundation\File\UploadedFile;
/**
* Settings
*/
#[ORM\Table(name: '`settings`')]
#[ORM\UniqueConstraint(name: 'key_type', columns: ['key', 'type'])]
#[ORM\Entity(repositoryClass: \AdminBundle\Repository\SettingsRepository::class)]
#[ORM\HasLifecycleCallbacks]
class Settings extends BaseEntity
{
const CURRENCY_SYMBOL = [
'GBP' => '£',
'EUR' => '€',
'USD' => '$',
];
const TYPE_FINANCIAL = 1;
const TYPE_AREA = 2;
const TYPE_CAR = 3;
const TYPE_BOOKING = 4;
const TYPE_ACCOUNTS = 5;
const TYPE_API_DRIVER = 6;
const TYPE_API_CLIENT = 7;
const TYPE_GLOBAL = 9;
const TYPE_JOBS_PLAN = 10;
public static $typeList = [
self::TYPE_FINANCIAL => 'Financial',
self::TYPE_AREA => 'Area',
self::TYPE_BOOKING => 'Booking',
self::TYPE_ACCOUNTS => 'Accounts',
self::TYPE_API_DRIVER => 'API Driver',
self::TYPE_API_CLIENT => 'API Client',
self::TYPE_GLOBAL => 'Global',
self::TYPE_JOBS_PLAN => 'Jobs Plan',
];
public const KEY_BOOKING_DISTANCE_PERCENTAGE_CHARGE = 'booking_distance_percentage_charge';
public const KEY_BOOKING_TIME_EXTRA_CHARGE = 'automatic_extra_charge_min_time';
public const KEY_CLIENT_ACTIVE_EXTRA_CHARGE_EXTRA_DISTANCE = 'client_active_extra_charge_extra_distance';
public const KEY_CLIENT_ACTIVE_EXTRA_CHARGE_NOTIFICATION_AMOUNT = 'client_active_extra_charge_notification_amount';
const FILE_FOLDER = 'upload/settings/';
public const VALUE_CALCULATE_QUOTE_TYPE_OVER_ALL = 'over all';
public const VALUE_CALCULATE_QUOTE_TYPE_ADDED = 'added';
/**
* @var integer
*/
#[ORM\Column(name: 'id', type: 'integer', nullable: false)]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
protected $id;
/**
* @var string
*/
#[ORM\Column(name: '`key`', type: 'string', length: 255, nullable: false)]
private $key;
/**
* @var string
*/
#[ORM\Column(name: '`value`', type: 'text', nullable: true)]
private $value;
/**
* @var string
*/
#[ORM\Column(name: 'description', type: 'text', nullable: true)]
private $description;
/**
* @var integer
*/
#[ORM\Column(name: '`type`', type: 'smallint', length: 20, nullable: false)]
private $type;
/**
* @var integer
*/
#[ORM\Column(name: 'tags', type: 'string', length: 255, nullable: true)]
private $tags;
/**
* @var string
*/
#[ORM\Column(name: 'end_date', type: 'datetime', nullable: true)]
private $endDate;
/**
* @var string
*/
#[ORM\Column(name: 'start_date', type: 'datetime', nullable: true)]
private $startDate;
/**
* @var string
*/
#[ORM\Column(name: 'picture', type: 'string', length: 255, nullable: true)]
private $picture;
private $pictureFile;
public $symbol;
public function __construct($key = null, $value = null, $type = null)
{
if ($key) {
$this->setKey($key);
}
if ($value) {
$this->setValue($value);
}
if ($type) {
$this->setType($type);
}
}
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
*/
public function setId($id)
{
$this->id = $id;
}
/**
* @return string
*/
public function getKey()
{
return $this->key;
}
/**
* @param string $key
* @return Settings
*/
public function setKey(string $key): Settings
{
$this->key = $key;
return $this;
}
/**
* @return string
*/
public function getValue()
{
return $this->value;
}
/**
* @param string $value
* @return Settings
*/
public function setValue($value): Settings
{
$this->value = $value;
return $this;
}
/**
* @return int
*/
public function getType()
{
return $this->type;
}
/**
* @param int $type
* @return Settings
*/
public function setType(int $type): Settings
{
$this->type = $type;
return $this;
}
public function __toString()
{
return $this->getId() ? $this->getId() . '' : 'n\a';
}
/**
* @return string
*/
public function getStartDate()
{
return $this->startDate;
}
/**
* @param string $startDate
*/
public function setStartDate($startDate)
{
$this->startDate = $startDate;
}
/**
* @return string
*/
public function getEndDate()
{
return $this->endDate;
}
/**
* @param string $endDate
*/
public function setEndDate($endDate)
{
$this->endDate = $endDate;
}
/**
* Set picture
*
* @param string $picture
*
* @return Settings
*/
public function setPicture($picture)
{
$this->picture = $picture;
return $this;
}
public function getPicture()
{
return $this->picture;
}
/**
* @param UploadedFile $picture
*/
public function setPictureFile(UploadedFile $pictureFile = null)
{
$this->pictureFile = $pictureFile;
}
/**
* @return UploadedFile
*/
public function getPictureFile()
{
return $this->pictureFile;
}
public function getPicturePath()
{
if (!$this->picture) {
return;
}
return $this->getUploadFilePath() . $this->picture;
}
public function uploadPicture()
{
if (null === $this->getPictureFile()) {
return;
}
$this->removePictureFile();
$filename = sha1(uniqid(mt_rand(), true));
$this->picture = $filename . '.' . $this->getPictureFile()->guessExtension();
header("Content-type: image/jpeg");
$image = new ImageResize($this->getPictureFile());
$image->resizeToWidth(1980);
$image->save($this->getUploadFilePath() . '/' . $this->picture);
}
public function getUploadFilePath()
{
if (!is_dir(self::FILE_FOLDER)) {
mkdir(self::FILE_FOLDER, 0777, true);
}
return self::FILE_FOLDER;
}
public function removePictureFile()
{
if ($pictureFile = $this->getPicturePath()) {
@unlink($pictureFile);
}
}
public function getImageSizes()
{
if (!$this->picture) {
return;
}
$sizes = getimagesize($this->getUploadFilePath() . $this->picture);
$res = [];
if (!empty($sizes)) {
$res['width'] = $sizes[0];
$res['height'] = $sizes[1];
}
return $res;
}
#[ORM\PreUpdate]
#[ORM\PrePersist]
public function lifecycleFileUpload()
{
$this->uploadPicture();
}
#[ORM\PostRemove]
public function removeUpload()
{
$this->removePictureFile();
}
/**
* @return array
*/
public function getTags()
{
if (strpos($this->tags, ',') !== false) {
return explode(',', $this->tags);
} else {
return [$this->tags];
}
}
/**
* @param array $tags
*/
public function setTags($tags)
{
$this->tags = implode(',', $tags);
}
/**
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* @param string $description
*/
public function setDescription($description)
{
$this->description = $description;
}
}