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

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