Attribute.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?php
  2. /*
  3. * This file is part of the Sylius package.
  4. *
  5. * (c) Paweł Jędrzejewski
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Sylius\Component\Attribute\Model;
  11. use Sylius\Component\Translation\Model\AbstractTranslatable;
  12. /**
  13. * Model for object attributes.
  14. *
  15. * @author Paweł Jędrzejewski <pawel@sylius.org>
  16. * @author Gonzalo Vilaseca <gvilaseca@reiss.co.uk>
  17. */
  18. class Attribute extends AbstractTranslatable implements AttributeInterface
  19. {
  20. /**
  21. * Attribute id.
  22. *
  23. * @var mixed
  24. */
  25. protected $id;
  26. /**
  27. * Type.
  28. *
  29. * @var string
  30. */
  31. protected $type = AttributeTypes::TEXT;
  32. /**
  33. * Internal name.
  34. *
  35. * @var string
  36. */
  37. protected $name;
  38. /**
  39. * Attribute configuration.
  40. *
  41. * @var array
  42. */
  43. protected $configuration = array();
  44. /**
  45. * Creation time.
  46. *
  47. * @var \DateTime
  48. */
  49. protected $createdAt;
  50. /**
  51. * Last update time.
  52. *
  53. * @var \DateTime
  54. */
  55. protected $updatedAt;
  56. public function __construct()
  57. {
  58. parent::__construct();
  59. $this->createdAt = new \DateTime();
  60. }
  61. /**
  62. * {@inheritdoc}
  63. */
  64. public function __toString()
  65. {
  66. return $this->name;
  67. }
  68. /**
  69. * {@inheritdoc}
  70. */
  71. public function getId()
  72. {
  73. return $this->id;
  74. }
  75. /**
  76. * {@inheritdoc}
  77. */
  78. public function getName()
  79. {
  80. return $this->name;
  81. }
  82. /**
  83. * {@inheritdoc}
  84. */
  85. public function setName($name)
  86. {
  87. $this->name = $name;
  88. return $this;
  89. }
  90. /**
  91. * {@inheritdoc}
  92. */
  93. public function getPresentation()
  94. {
  95. return $this->translate()->getPresentation();
  96. }
  97. /**
  98. * {@inheritdoc}
  99. */
  100. public function setPresentation($presentation)
  101. {
  102. $this->translate()->setPresentation($presentation);
  103. return $this;
  104. }
  105. /**
  106. * {@inheritdoc}
  107. */
  108. public function getType()
  109. {
  110. return $this->type;
  111. }
  112. /**
  113. * {@inheritdoc}
  114. */
  115. public function setType($type)
  116. {
  117. $this->type = $type;
  118. return $this;
  119. }
  120. /**
  121. * {@inheritdoc}
  122. */
  123. public function getConfiguration()
  124. {
  125. return $this->configuration;
  126. }
  127. /**
  128. * {@inheritdoc}
  129. */
  130. public function setConfiguration(array $configuration)
  131. {
  132. $this->configuration = $configuration;
  133. return $this;
  134. }
  135. /**
  136. * {@inheritdoc}
  137. */
  138. public function getCreatedAt()
  139. {
  140. return $this->createdAt;
  141. }
  142. /**
  143. * {@inheritdoc}
  144. */
  145. public function setCreatedAt(\DateTime $createdAt)
  146. {
  147. $this->createdAt = $createdAt;
  148. return $this;
  149. }
  150. /**
  151. * {@inheritdoc}
  152. */
  153. public function getUpdatedAt()
  154. {
  155. return $this->updatedAt;
  156. }
  157. /**
  158. * {@inheritdoc}
  159. */
  160. public function setUpdatedAt(\DateTime $updatedAt)
  161. {
  162. $this->updatedAt = $updatedAt;
  163. return $this;
  164. }
  165. /**
  166. * {@inheritdoc}
  167. */
  168. protected function getTranslationEntityClass()
  169. {
  170. return get_class().'Translation';
  171. }
  172. }