bundle/w3des/AdminBundle/src/Model/ValueTrait.php line 206

Open in your IDE?
  1. <?php
  2. namespace w3des\AdminBundle\Model;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use w3des\AdminBundle\Entity\File;
  5. use w3des\AdminBundle\Entity\Node;
  6. use VertigoLabs\DoctrineFullTextPostgres\ORM\Mapping\TsVector;
  7. trait ValueTrait
  8. {
  9. /**
  10. * @ORM\Column(type="string")
  11. */
  12. private $name;
  13. /**
  14. * @ORM\Column(type="string", length=2)
  15. */
  16. private $locale;
  17. /**
  18. * @ORM\Column(type="integer")
  19. */
  20. private $pos = 0;
  21. /**
  22. * @ORM\Column(type="string")
  23. */
  24. private $type;
  25. /**
  26. * @ORM\Column(type="string", nullable=true)
  27. */
  28. private $stringValue;
  29. /**
  30. * @ORM\Column(type="integer", nullable=true)
  31. */
  32. private $intValue;
  33. /**
  34. * @ORM\Column(type="float", nullable=true)
  35. */
  36. private $floatValue;
  37. /**
  38. * @ORM\Column(type="text", nullable=true)
  39. */
  40. private $textValue;
  41. /**
  42. * @ORM\Column(type="datetime", nullable=true)
  43. */
  44. private $dateTimeValue;
  45. /**
  46. * @ORM\ManyToOne(targetEntity="w3des\AdminBundle\Entity\File", fetch="EAGER", cascade={"persist", "merge", "detach", "refresh"})
  47. * @ORM\JoinColumn(name="file_value", referencedColumnName="id")
  48. */
  49. private $fileValue;
  50. private $newPos;
  51. /**
  52. * @var TsVector
  53. * @TsVector(name="string_value_fts", fields={"stringValue", "textValue"}, language="english")
  54. */
  55. private $fts;
  56. public $uploadedFile;
  57. /**
  58. * @ORM\ManyToOne(targetEntity="Node", cascade={"persist"}, fetch="EAGER")
  59. * @ORM\JoinColumn(name="node_value", referencedColumnName="id")
  60. */
  61. private $nodeValue;
  62. public function getPos()
  63. {
  64. return $this->pos;
  65. }
  66. public function setPos($pos)
  67. {
  68. $this->pos = $pos;
  69. return $this;
  70. }
  71. public function getType()
  72. {
  73. return $this->type;
  74. }
  75. public function setType($type)
  76. {
  77. $this->type = $type;
  78. return $this;
  79. }
  80. public function cleanValues()
  81. {
  82. $this->intValue = null;
  83. $this->stringValue = null;
  84. $this->textValue = null;
  85. $this->floatValue = null;
  86. $this->dateTimeValue = null;
  87. $this->fileValue = null;
  88. $this->nodeValue = null;
  89. }
  90. public function getStringValue()
  91. {
  92. return $this->stringValue;
  93. }
  94. public function setStringValue($stringValue)
  95. {
  96. $this->cleanValues();
  97. $this->stringValue = $stringValue;
  98. return $this;
  99. }
  100. public function getIntValue()
  101. {
  102. return $this->intValue;
  103. }
  104. public function setIntValue($intValue)
  105. {
  106. $this->cleanValues();
  107. $this->intValue = $intValue;
  108. return $this;
  109. }
  110. public function getFloatValue()
  111. {
  112. return $this->floatValue;
  113. }
  114. public function setFloatValue($floatValue)
  115. {
  116. $this->cleanValues();
  117. $this->floatValue = $floatValue;
  118. return $this;
  119. }
  120. public function getTextValue()
  121. {
  122. return $this->textValue;
  123. }
  124. public function setTextValue($textValue)
  125. {
  126. $this->cleanValues();
  127. $this->textValue = $textValue;
  128. return $this;
  129. }
  130. public function getName()
  131. {
  132. return $this->name;
  133. }
  134. public function setName($name)
  135. {
  136. $this->name = $name;
  137. return $this;
  138. }
  139. public function getLocale()
  140. {
  141. return $this->locale;
  142. }
  143. public function setLocale(string $locale)
  144. {
  145. $this->locale = $locale;
  146. return $this;
  147. }
  148. public function getDateTimeValue()
  149. {
  150. return $this->dateTimeValue;
  151. }
  152. public function setDateTimeValue($dateTimeValue)
  153. {
  154. $this->dateTimeValue = $dateTimeValue;
  155. return $this;
  156. }
  157. /**
  158. * @return File
  159. */
  160. public function getFileValue()
  161. {
  162. return $this->fileValue;
  163. }
  164. public function setFileValue(File $file = null)
  165. {
  166. $this->fileValue = $file;
  167. }
  168. public function setNodeValue(Node $nodeValue = null)
  169. {
  170. $this->cleanValues();
  171. $this->nodeValue = $nodeValue;
  172. return $this;
  173. }
  174. public function getNodeValue()
  175. {
  176. return $this->nodeValue;
  177. }
  178. public function getValue()
  179. {
  180. switch ($this->getType()) {
  181. /** @var \w3des\AdminBundle\Entity\Setting $sett */
  182. case 'string':
  183. return $this->getStringValue();
  184. case 'text':
  185. return $this->getTextValue();
  186. case 'datetime':
  187. case 'date':
  188. return $this->getDateTimeValue();
  189. case 'bool':
  190. case 'boolean':
  191. return (bool) $this->getIntValue();
  192. case 'integer':
  193. return $this->getIntValue();
  194. case 'float':
  195. return $this->getFloatValue();
  196. case 'file':
  197. return $this->getFileValue();
  198. case 'node':
  199. return $this->getNodeValue();
  200. }
  201. }
  202. public function setValue($value)
  203. {
  204. switch ($this->getType()) {
  205. /** @var \w3des\AdminBundle\Entity\Setting $sett */
  206. case 'string':
  207. $this->setStringValue($value);
  208. break;
  209. case 'text':
  210. $this->setTextValue($value);
  211. break;
  212. case 'date':
  213. if ($value instanceof \DateTime) {
  214. $value->setTime(0, 0,0);
  215. }
  216. case 'datetime':
  217. $this->setDateTimeValue($value);
  218. break;
  219. case 'bool':
  220. case 'boolean':
  221. $this->setIntValue($value ? 1 : 0);
  222. break;
  223. case 'integer':
  224. $this->setIntValue($value);
  225. break;
  226. case 'float':
  227. $this->setFloatValue($value);
  228. break;
  229. case 'file':
  230. $this->setFileValue($value);
  231. break;
  232. case 'node':
  233. $this->setNodeValue($value);
  234. break;
  235. default:
  236. throw new \InvalidArgumentException('Unknown type:' . $this->getType());
  237. }
  238. }
  239. public static function getFieldName($storeType)
  240. {
  241. switch ($storeType) {
  242. /** @var \w3des\AdminBundle\Entity\Setting $sett */
  243. case 'string':
  244. return 'stringValue';
  245. case 'text':
  246. return 'textValue';
  247. case 'datetime':
  248. case 'date':
  249. return 'dateTimeValue';
  250. case 'bool':
  251. case 'boolean':
  252. return 'intValue';
  253. case 'integer':
  254. return 'intValue';
  255. case 'float':
  256. return 'floatValue';
  257. case 'file':
  258. return 'fileValue';
  259. case 'node':
  260. return 'nodeValue';
  261. }
  262. }
  263. /**
  264. * @return $newPos
  265. */
  266. public function getNewPos()
  267. {
  268. return $this->newPos;
  269. }
  270. /**
  271. * @param mixed $newPos
  272. */
  273. public function setNewPos($newPos)
  274. {
  275. $this->newPos = $newPos;
  276. }
  277. }