src_legacy/Tionvel/WorkflowBundle/Entity/WorkflowAttribute.php line 17

Open in your IDE?
  1. <?php
  2. namespace Tionvel\WorkflowBundle\Entity;
  3. use App\Entity\User;
  4. use DateTime;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Exception;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. /**
  9. * Class WorkflowAttribute
  10. * @package Tionvel\WorkflowBundle\Entity
  11. * @ORM\Entity()
  12. * @ORM\Table(name="workflow_attributes")
  13. */
  14. class WorkflowAttribute
  15. {
  16. /**
  17. * @var int
  18. * @ORM\Id @ORM\Column(type="integer")
  19. * @ORM\GeneratedValue(strategy="AUTO")
  20. */
  21. private $id;
  22. /**
  23. * @var WorkflowProcess
  24. * @ORM\ManyToOne(
  25. * targetEntity="Tionvel\WorkflowBundle\Entity\WorkflowProcess",
  26. * inversedBy="attributes"
  27. * )
  28. * @ORM\JoinColumn(
  29. * onDelete="CASCADE",
  30. * nullable=true
  31. * )
  32. */
  33. private $process;
  34. /**
  35. * @var User
  36. * @ORM\ManyToOne(targetEntity="App\Entity\User")
  37. * @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
  38. */
  39. private $createdBy;
  40. /**
  41. * @var DateTime
  42. * @ORM\Column(type="datetime", options={"default": "CURRENT_TIMESTAMP"})
  43. */
  44. private $createdAt;
  45. /**
  46. * @var string
  47. * @ORM\Column(type="string")
  48. */
  49. private $type;
  50. /**
  51. * @var string
  52. * @ORM\Column(type="string")
  53. */
  54. private $path;
  55. /**
  56. * @var string
  57. * @ORM\Column(type="text", nullable=true, length=65535)
  58. */
  59. private $value;
  60. /**
  61. * @var string
  62. * @ORM\Column(type="string", nullable=true)
  63. */
  64. private $rel;
  65. /**
  66. * @var boolean
  67. * @ORM\Column(type="boolean")
  68. */
  69. private $multiple = false;
  70. /**
  71. * @var int
  72. * @ORM\Column(type="bigint")
  73. */
  74. private $position = 0;
  75. /**
  76. * @var string
  77. * @ORM\Column(type="string", nullable=true)
  78. */
  79. public $key0;
  80. /**
  81. * @var string
  82. * @ORM\Column(type="string", nullable=true)
  83. */
  84. public $key1;
  85. /**
  86. * @var string
  87. * @ORM\Column(type="string", nullable=true)
  88. */
  89. public $key2;
  90. /**
  91. * @var string
  92. * @ORM\Column(type="string", nullable=true)
  93. */
  94. public $key3;
  95. /**
  96. * @var string
  97. * @ORM\Column(type="string", nullable=true)
  98. */
  99. public $key4;
  100. /**
  101. * @var string
  102. * @ORM\Column(type="string", nullable=true)
  103. */
  104. public $key5;
  105. /**
  106. * @var string
  107. * @ORM\Column(type="string", nullable=true)
  108. */
  109. public $key6;
  110. /**
  111. * @var string
  112. * @ORM\Column(type="string", nullable=true)
  113. */
  114. public $key7;
  115. /**
  116. * @var string
  117. * @ORM\Column(type="string", nullable=true)
  118. */
  119. public $key8;
  120. /**
  121. * @var string
  122. * @ORM\Column(type="string", nullable=true)
  123. */
  124. public $key9;
  125. /**
  126. * WorkflowAttribute constructor.
  127. * @throws Exception
  128. */
  129. public function __construct()
  130. {
  131. $this->position = time();
  132. $this->createdAt = new DateTime;
  133. }
  134. /**
  135. * @param WorkflowProcess $process
  136. * @param $path
  137. * @param $type
  138. * @param $value
  139. * @param string $rel
  140. * @param null $createdBy
  141. * @return WorkflowAttribute
  142. * @throws Exception
  143. */
  144. public static function create(WorkflowProcess $process, $path, $type, $value, $rel = null, $createdBy = null, $multiple = false)
  145. {
  146. $self = new self;
  147. $self->setProcess($process);
  148. $self->setPath($path);
  149. $self->setType($type);
  150. $self->setValue($value);
  151. $self->setRel($rel);
  152. $self->setCreatedBy($createdBy);
  153. $self->setMultiple($multiple);
  154. return $self;
  155. }
  156. /**
  157. * @return string
  158. */
  159. public function __toString()
  160. {
  161. return $this->value;
  162. }
  163. /**
  164. * @return int
  165. */
  166. public function getId()
  167. {
  168. return $this->id;
  169. }
  170. /**
  171. * @return mixed
  172. */
  173. public function getPath()
  174. {
  175. return $this->position.'.'.$this->path;
  176. }
  177. /**
  178. * @param mixed $path
  179. */
  180. public function setPath($path)
  181. {
  182. $this->path = $path;
  183. list (
  184. $this->key0,
  185. $this->key1,
  186. $this->key2,
  187. $this->key3,
  188. $this->key4,
  189. $this->key5,
  190. $this->key6,
  191. $this->key7,
  192. $this->key8,
  193. $this->key9,
  194. ) = array_pad(explode('.', $path), 11, null);
  195. }
  196. /**
  197. * @return WorkflowProcess
  198. */
  199. public function getProcess()
  200. {
  201. return $this->process;
  202. }
  203. /**
  204. * @param WorkflowProcess $process
  205. */
  206. public function setProcess($process)
  207. {
  208. $this->process = $process;
  209. }
  210. /**
  211. * @return User
  212. */
  213. public function getCreatedBy()
  214. {
  215. return $this->createdBy;
  216. }
  217. /**
  218. * @param User $createdBy
  219. */
  220. public function setCreatedBy($createdBy)
  221. {
  222. $this->createdBy = $createdBy;
  223. }
  224. /**
  225. * @return DateTime
  226. */
  227. public function getCreatedAt()
  228. {
  229. return $this->createdAt;
  230. }
  231. /**
  232. * @return string|null
  233. */
  234. public function getValue()
  235. {
  236. return $this->value;
  237. }
  238. public function setValue($value)
  239. {
  240. $this->value = $value;
  241. }
  242. public function getRel()
  243. {
  244. return $this->rel;
  245. }
  246. public function setRel($rel = null)
  247. {
  248. $this->rel = $rel;
  249. }
  250. public function getPosition()
  251. {
  252. return $this->position;
  253. }
  254. public function setPosition(int $position)
  255. {
  256. $this->position = $position;
  257. }
  258. public function getType()
  259. {
  260. return $this->type;
  261. }
  262. public function setType(string $type)
  263. {
  264. $this->type = $type;
  265. }
  266. public function isMultiple(): bool
  267. {
  268. return $this->multiple;
  269. }
  270. public function setMultiple(bool $multiple)
  271. {
  272. $this->multiple = $multiple;
  273. }
  274. /**
  275. * @return array
  276. */
  277. public function toArray()
  278. {
  279. return [
  280. 'path' => $this->path,
  281. 'value' => $this->value,
  282. 'type' => $this->type,
  283. 'rel' => $this->rel,
  284. 'pos' => $this->position,
  285. 'key0' => $this->key0,
  286. 'key1' => $this->key1,
  287. 'key2' => $this->key2,
  288. 'key3' => $this->key3,
  289. 'key4' => $this->key4,
  290. 'key5' => $this->key5,
  291. 'key6' => $this->key6,
  292. 'key7' => $this->key7,
  293. 'key8' => $this->key8,
  294. 'key9' => $this->key9,
  295. 'multiple' => $this->multiple,
  296. 'created_at' => $this->createdAt,
  297. 'created_by' => $this->createdBy,
  298. ];
  299. }
  300. }