<?php
namespace Tionvel\WorkflowBundle\Entity;
use App\Entity\User;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use Exception;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* Class WorkflowAttribute
* @package Tionvel\WorkflowBundle\Entity
* @ORM\Entity()
* @ORM\Table(name="workflow_attributes")
*/
class WorkflowAttribute
{
/**
* @var int
* @ORM\Id @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var WorkflowProcess
* @ORM\ManyToOne(
* targetEntity="Tionvel\WorkflowBundle\Entity\WorkflowProcess",
* inversedBy="attributes"
* )
* @ORM\JoinColumn(
* onDelete="CASCADE",
* nullable=true
* )
*/
private $process;
/**
* @var User
* @ORM\ManyToOne(targetEntity="App\Entity\User")
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
*/
private $createdBy;
/**
* @var DateTime
* @ORM\Column(type="datetime", options={"default": "CURRENT_TIMESTAMP"})
*/
private $createdAt;
/**
* @var string
* @ORM\Column(type="string")
*/
private $type;
/**
* @var string
* @ORM\Column(type="string")
*/
private $path;
/**
* @var string
* @ORM\Column(type="text", nullable=true, length=65535)
*/
private $value;
/**
* @var string
* @ORM\Column(type="string", nullable=true)
*/
private $rel;
/**
* @var boolean
* @ORM\Column(type="boolean")
*/
private $multiple = false;
/**
* @var int
* @ORM\Column(type="bigint")
*/
private $position = 0;
/**
* @var string
* @ORM\Column(type="string", nullable=true)
*/
public $key0;
/**
* @var string
* @ORM\Column(type="string", nullable=true)
*/
public $key1;
/**
* @var string
* @ORM\Column(type="string", nullable=true)
*/
public $key2;
/**
* @var string
* @ORM\Column(type="string", nullable=true)
*/
public $key3;
/**
* @var string
* @ORM\Column(type="string", nullable=true)
*/
public $key4;
/**
* @var string
* @ORM\Column(type="string", nullable=true)
*/
public $key5;
/**
* @var string
* @ORM\Column(type="string", nullable=true)
*/
public $key6;
/**
* @var string
* @ORM\Column(type="string", nullable=true)
*/
public $key7;
/**
* @var string
* @ORM\Column(type="string", nullable=true)
*/
public $key8;
/**
* @var string
* @ORM\Column(type="string", nullable=true)
*/
public $key9;
/**
* WorkflowAttribute constructor.
* @throws Exception
*/
public function __construct()
{
$this->position = time();
$this->createdAt = new DateTime;
}
/**
* @param WorkflowProcess $process
* @param $path
* @param $type
* @param $value
* @param string $rel
* @param null $createdBy
* @return WorkflowAttribute
* @throws Exception
*/
public static function create(WorkflowProcess $process, $path, $type, $value, $rel = null, $createdBy = null, $multiple = false)
{
$self = new self;
$self->setProcess($process);
$self->setPath($path);
$self->setType($type);
$self->setValue($value);
$self->setRel($rel);
$self->setCreatedBy($createdBy);
$self->setMultiple($multiple);
return $self;
}
/**
* @return string
*/
public function __toString()
{
return $this->value;
}
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @return mixed
*/
public function getPath()
{
return $this->position.'.'.$this->path;
}
/**
* @param mixed $path
*/
public function setPath($path)
{
$this->path = $path;
list (
$this->key0,
$this->key1,
$this->key2,
$this->key3,
$this->key4,
$this->key5,
$this->key6,
$this->key7,
$this->key8,
$this->key9,
) = array_pad(explode('.', $path), 11, null);
}
/**
* @return WorkflowProcess
*/
public function getProcess()
{
return $this->process;
}
/**
* @param WorkflowProcess $process
*/
public function setProcess($process)
{
$this->process = $process;
}
/**
* @return User
*/
public function getCreatedBy()
{
return $this->createdBy;
}
/**
* @param User $createdBy
*/
public function setCreatedBy($createdBy)
{
$this->createdBy = $createdBy;
}
/**
* @return DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* @return string|null
*/
public function getValue()
{
return $this->value;
}
public function setValue($value)
{
$this->value = $value;
}
public function getRel()
{
return $this->rel;
}
public function setRel($rel = null)
{
$this->rel = $rel;
}
public function getPosition()
{
return $this->position;
}
public function setPosition(int $position)
{
$this->position = $position;
}
public function getType()
{
return $this->type;
}
public function setType(string $type)
{
$this->type = $type;
}
public function isMultiple(): bool
{
return $this->multiple;
}
public function setMultiple(bool $multiple)
{
$this->multiple = $multiple;
}
/**
* @return array
*/
public function toArray()
{
return [
'path' => $this->path,
'value' => $this->value,
'type' => $this->type,
'rel' => $this->rel,
'pos' => $this->position,
'key0' => $this->key0,
'key1' => $this->key1,
'key2' => $this->key2,
'key3' => $this->key3,
'key4' => $this->key4,
'key5' => $this->key5,
'key6' => $this->key6,
'key7' => $this->key7,
'key8' => $this->key8,
'key9' => $this->key9,
'multiple' => $this->multiple,
'created_at' => $this->createdAt,
'created_by' => $this->createdBy,
];
}
}