src/Entity/Page.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. /**
  5. * Pages
  6. *
  7. * @ORM\Table(name="pages")
  8. * @ORM\Entity
  9. */
  10. class Page extends TranslatedEntity
  11. {
  12. protected $tranlatedEntity = 'PageDescription';
  13. /**
  14. * @var bool
  15. *
  16. * @ORM\Column(name="pages_id", type="integer", nullable=false)
  17. * @ORM\Id
  18. * @ORM\GeneratedValue(strategy="IDENTITY")
  19. */
  20. private $id;
  21. /**
  22. * @var string|null
  23. *
  24. * @ORM\Column(name="pages_image", type="string", length=64, nullable=true)
  25. */
  26. private $image;
  27. /**
  28. * @var \DateTime
  29. *
  30. * @ORM\Column(name="pages_date_added", type="datetime", nullable=true)
  31. */
  32. private $dateAdded;
  33. /**
  34. * @var \DateTime
  35. *
  36. * @ORM\Column(name="pages_date_modified", type="datetime", nullable=true)
  37. */
  38. private $dateModified;
  39. /**
  40. * @var string
  41. *
  42. * @ORM\Column(name="pages_author", type="string", length=255, nullable=true)
  43. */
  44. private $author;
  45. /**
  46. * @var bool
  47. *
  48. * @ORM\Column(name="pages_status", type="boolean", nullable=false, options={"default"="1"})
  49. */
  50. private $status = '1';
  51. /**
  52. * @var bool
  53. *
  54. * @ORM\Column(name="pages_sort_order", type="boolean", nullable=false)
  55. */
  56. private $sortOrder = '0';
  57. /**
  58. * @ORM\OneToMany(targetEntity="App\Entity\PageDescription", mappedBy="page")
  59. */
  60. private $descriptions = [];
  61. /**
  62. * @ORM\ManyToOne(targetEntity="App\Entity\PriceGroup")
  63. * @ORM\JoinColumn(name="price_group_id", referencedColumnName="id", nullable=true, onDelete="CASCADE")
  64. */
  65. private $context;
  66. public function getId(): ?int {
  67. return $this->id;
  68. }
  69. public function getImage(): ?string {
  70. return $this->image;
  71. }
  72. public function getDateAdded(): \DateTime {
  73. return $this->dateAdded;
  74. }
  75. public function getDateModified(): \DateTime {
  76. return $this->dateModified;
  77. }
  78. public function getAuthor() {
  79. return empty($this->author)?'':$this->author;
  80. }
  81. public function getStatus(): bool {
  82. return $this->status;
  83. }
  84. public function getSortOrder(): bool {
  85. return $this->sortOrder;
  86. }
  87. public function getTitle() {
  88. if(!empty($this->languageId)){
  89. $description = null;
  90. foreach($this->descriptions as $d){
  91. if($d->getLanguage()->getId()==$this->languageId){
  92. $description = $d;
  93. break;
  94. }
  95. }
  96. }
  97. if(empty($description) && count($this->descriptions)){
  98. $description = $this->descriptions[0];
  99. }
  100. return empty($description)?'':$description->getTitle();
  101. }
  102. public function getUrl() {
  103. if(!empty($this->languageId)){
  104. $description = null;
  105. foreach($this->descriptions as $d){
  106. if($d->getLanguage()->getId()==$this->languageId){
  107. $description = $d;
  108. break;
  109. }
  110. }
  111. }
  112. if(empty($description) && count($this->descriptions)){
  113. $description = $this->descriptions[0];
  114. }
  115. return empty($description)?'':$description->getUrl();
  116. }
  117. public function getDescriptions() {
  118. return $this->descriptions;
  119. }
  120. public function getPageDescription($lang='fr') : ?PageDescription {
  121. foreach($this->getDescriptions() as $desc){
  122. if($desc->getLanguage()->getCode() == $lang)
  123. return $desc;
  124. }
  125. return null;
  126. }
  127. public function getContext() {
  128. return $this->context;
  129. }
  130. public function setImage(?string $image): void {
  131. $this->image = $image;
  132. }
  133. public function setDateAdded(\DateTime $dateAdded): void {
  134. $this->dateAdded = $dateAdded;
  135. }
  136. public function setDateModified(\DateTime $dateModified): void {
  137. $this->dateModified = $dateModified;
  138. }
  139. public function setAuthor($author): void {
  140. $this->author = $author;
  141. }
  142. public function setStatus(bool $status): void {
  143. $this->status = $status;
  144. }
  145. public function setSortOrder(bool $sortOrder): void {
  146. $this->sortOrder = $sortOrder;
  147. }
  148. public function setDescriptions($descriptions): void {
  149. $this->descriptions = $descriptions;
  150. }
  151. public function setContext($context): void {
  152. $this->context = $context;
  153. }
  154. public function toArray() : array{
  155. $output = [
  156. 'id' => $this->getId(),
  157. 'title' => $this->getTitle(),
  158. 'author' => $this->getAuthor(),
  159. 'dateAdded' => $this->getDateAdded(),
  160. 'dateModified' => $this->getDateModified(),
  161. 'image' => $this->getImage(),
  162. 'status' => $this->getStatus(),
  163. 'sort' => $this->getSortOrder()
  164. ];
  165. return $output;
  166. }
  167. }