vendor/perfectneeds/content-multi-lang-bundle/Entity/DynamicContentAttribute.php line 14

Open in your IDE?
  1. <?php
  2. namespace PN\ContentBundle\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Symfony\Component\Validator\Constraints as Assert;
  5. use PN\LocaleBundle\Model\Translatable;
  6. use PN\LocaleBundle\Model\LocaleTrait;
  7. /**
  8. * @ORM\Table(name="dynamic_content_attribute")
  9. * @ORM\Entity()
  10. */
  11. class DynamicContentAttribute implements Translatable
  12. {
  13. use LocaleTrait;
  14. const TYPE_TEXT = 1;
  15. const TYPE_LONGTEXT = 2;
  16. const TYPE_LINK = 3;
  17. const TYPE_IMAGE = 4;
  18. const TYPE_DOCUMENT = 5;
  19. const TYPE_HTML = 6;
  20. const TYPE_NUMBER = 7;
  21. public static $types = [
  22. "Text (100 character)" => self::TYPE_TEXT,
  23. "Long text" => self::TYPE_LONGTEXT,
  24. "Link" => self::TYPE_LINK,
  25. "Image" => self::TYPE_IMAGE,
  26. "Document" => self::TYPE_DOCUMENT,
  27. "Number" => self::TYPE_NUMBER,
  28. "HTML Tags" => self::TYPE_HTML,
  29. ];
  30. /**
  31. * @var int
  32. *
  33. * @ORM\Column(name="id", type="integer")
  34. * @ORM\Id
  35. * @ORM\GeneratedValue(strategy="AUTO")
  36. */
  37. private $id;
  38. /**
  39. * @ORM\ManyToOne(targetEntity="DynamicContent", inversedBy="dynamicContentAttributes")
  40. */
  41. protected $dynamicContent;
  42. /**
  43. * @ORM\ManyToMany(targetEntity="\PN\MediaBundle\Entity\Image", cascade={"persist", "remove" })
  44. */
  45. protected $image;
  46. /**
  47. * @ORM\ManyToMany(targetEntity="\PN\MediaBundle\Entity\Document" ,cascade={"persist", "remove"})
  48. */
  49. protected $document;
  50. /**
  51. * @var string
  52. * @Assert\NotNull()
  53. * @ORM\Column(name="title", type="string", length=50)
  54. */
  55. protected $title;
  56. /**
  57. * @var string
  58. * @ORM\Column(name="value", type="text", nullable=true)
  59. */
  60. protected $value;
  61. /**
  62. * @var string
  63. * @Assert\NotNull()
  64. * @ORM\Column(name="type", type="smallint")
  65. */
  66. protected $type;
  67. /**
  68. * @var string
  69. * @ORM\Column(name="hint", type="string", nullable=true)
  70. */
  71. protected $hint;
  72. /**
  73. * @ORM\Column(name="image_width", type="float", nullable=true)
  74. */
  75. protected $imageWidth;
  76. /**
  77. * @ORM\Column(name="image_height", type="float", nullable=true)
  78. */
  79. protected $imageHeight;
  80. /**
  81. * @ORM\OneToMany(targetEntity="PN\ContentBundle\Entity\Translation\DynamicContentAttributeTranslation", mappedBy="translatable", cascade={"ALL"}, orphanRemoval=true)
  82. */
  83. protected $translations;
  84. /**
  85. * Constructor
  86. */
  87. public function __construct()
  88. {
  89. $this->image = new \Doctrine\Common\Collections\ArrayCollection();
  90. $this->translations = new \Doctrine\Common\Collections\ArrayCollection();
  91. }
  92. public function __toString()
  93. {
  94. return (string)$this->getValue();
  95. }
  96. public function getTypeName()
  97. {
  98. return array_search($this->getType(), self::$types);
  99. }
  100. /**
  101. * Get id
  102. *
  103. * @return integer
  104. */
  105. public function getId()
  106. {
  107. return $this->id;
  108. }
  109. /**
  110. * Set title
  111. *
  112. * @param string $title
  113. *
  114. * @return DynamicContentAttribute
  115. */
  116. public function setTitle($title)
  117. {
  118. $this->title = $title;
  119. return $this;
  120. }
  121. /**
  122. * Get title
  123. *
  124. * @return string
  125. */
  126. public function getTitle()
  127. {
  128. return $this->title;
  129. }
  130. /**
  131. * Set type
  132. *
  133. * @param integer $type
  134. *
  135. * @return DynamicContentAttribute
  136. */
  137. public function setType($type)
  138. {
  139. $this->type = $type;
  140. return $this;
  141. }
  142. /**
  143. * Get type
  144. *
  145. * @return integer
  146. */
  147. public function getType()
  148. {
  149. return $this->type;
  150. }
  151. /**
  152. * Set hint
  153. *
  154. * @param string $hint
  155. *
  156. * @return DynamicContentAttribute
  157. */
  158. public function setHint($hint)
  159. {
  160. $this->hint = $hint;
  161. return $this;
  162. }
  163. /**
  164. * Get hint
  165. *
  166. * @return string
  167. */
  168. public function getHint()
  169. {
  170. return $this->hint;
  171. }
  172. /**
  173. * Set dynamicContent
  174. *
  175. * @param \PN\ContentBundle\Entity\DynamicContent $dynamicContent
  176. *
  177. * @return DynamicContentAttribute
  178. */
  179. public function setDynamicContent(\PN\ContentBundle\Entity\DynamicContent $dynamicContent = null)
  180. {
  181. $this->dynamicContent = $dynamicContent;
  182. return $this;
  183. }
  184. /**
  185. * Get dynamicContent
  186. *
  187. * @return \PN\ContentBundle\Entity\DynamicContent
  188. */
  189. public function getDynamicContent()
  190. {
  191. return $this->dynamicContent;
  192. }
  193. /**
  194. * Add image
  195. *
  196. * @param \PN\MediaBundle\Entity\Image $image
  197. *
  198. * @return DynamicContentAttribute
  199. */
  200. public function addImage(\PN\MediaBundle\Entity\Image $image)
  201. {
  202. $this->image[] = $image;
  203. return $this;
  204. }
  205. /**
  206. * Remove image
  207. *
  208. * @param \PN\MediaBundle\Entity\Image $image
  209. */
  210. public function removeImage(\PN\MediaBundle\Entity\Image $image)
  211. {
  212. $this->image->removeElement($image);
  213. }
  214. /**
  215. * Get image
  216. *
  217. * @return \Doctrine\Common\Collections\Collection
  218. */
  219. public function getImage()
  220. {
  221. return $this->image->first();
  222. }
  223. /**
  224. * Add document
  225. *
  226. * @param \PN\MediaBundle\Entity\Document $document
  227. *
  228. * @return DynamicContentAttribute
  229. */
  230. public function addDocument(\PN\MediaBundle\Entity\Document $document)
  231. {
  232. $this->document[] = $document;
  233. return $this;
  234. }
  235. /**
  236. * Remove document
  237. *
  238. * @param \PN\MediaBundle\Entity\Document $document
  239. */
  240. public function removeDocument(\PN\MediaBundle\Entity\Document $document)
  241. {
  242. $this->document->removeElement($document);
  243. }
  244. /**
  245. * Get document
  246. *
  247. * @return \Doctrine\Common\Collections\Collection
  248. */
  249. public function getDocument()
  250. {
  251. return $this->document->first();
  252. }
  253. /**
  254. * Set value
  255. *
  256. * @param string $value
  257. *
  258. * @return DynamicContentAttribute
  259. */
  260. public function setValue($value)
  261. {
  262. $this->value = $value;
  263. return $this;
  264. }
  265. /**
  266. * Get value
  267. *
  268. * @return string
  269. */
  270. public function getValue()
  271. {
  272. return !$this->currentTranslation ? $this->value : $this->currentTranslation->getValue();
  273. }
  274. /**
  275. * Set imageWidth
  276. *
  277. * @param float $imageWidth
  278. * @return DynamicContentAttribute
  279. */
  280. public function setImageWidth($imageWidth)
  281. {
  282. $this->imageWidth = $imageWidth;
  283. return $this;
  284. }
  285. /**
  286. * Get imageWidth
  287. *
  288. * @return float
  289. */
  290. public function getImageWidth()
  291. {
  292. return $this->imageWidth;
  293. }
  294. /**
  295. * Set imageHeight
  296. *
  297. * @param float $imageHeight
  298. * @return DynamicContentAttribute
  299. */
  300. public function setImageHeight($imageHeight)
  301. {
  302. $this->imageHeight = $imageHeight;
  303. return $this;
  304. }
  305. /**
  306. * Get imageHeight
  307. *
  308. * @return float
  309. */
  310. public function getImageHeight()
  311. {
  312. return $this->imageHeight;
  313. }
  314. }