Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.19 KB | None | 0 0
  1. /**
  2. * @ORMEntity(repositoryClass="AppRepositoryMenuRepository")
  3. */
  4. class Menu
  5. {
  6. /**
  7. * @Groups({"menu"})
  8. * @ORMId
  9. * @ORMColumn(type="integer")
  10. * @ORMGeneratedValue(strategy="AUTO")
  11. */
  12. private $id;
  13.  
  14. // ...
  15.  
  16. /**
  17. * References translated menus.
  18. * @Groups({"localized_menus"})
  19. *
  20. * @ORMOneToMany(
  21. * targetEntity="LocalizedMenu"
  22. * ,mappedBy="parentMenu"
  23. * ,indexBy="locale"
  24. * ,cascade={"persist", "remove"}
  25. * )
  26. * @ORMOrderBy({"locale" = "ASC"})
  27. */
  28. private $localizedMenus;
  29.  
  30. // ...
  31.  
  32. public function getLocalizedMenu($locale) {
  33. if (!isset($this->localizedMenus[$locale])) {
  34. return new LocalizedMenu($locale, $this);
  35. }
  36. return $this->localizedMenus[$locale];
  37. }
  38.  
  39. public function addLocalizedMenu($localizedMenu): self
  40. {
  41. $this->localizedMenus[$localizedMenu->getLocale()] = $localizedMenu;
  42.  
  43. return $this;
  44. }
  45. }
  46.  
  47. /**
  48. * @ORMEntity(repositoryClass="AppRepositoryLocalizedMenuRepository")
  49. */
  50. class LocalizedMenu
  51. {
  52. public function __construct($locale, $menu) {
  53. $this->locale = $locale;
  54. $this->parentMenu = $menu;
  55. $this->parentMenu->addLocalizedMenu($this);
  56. }
  57.  
  58. // region FIELDS
  59. /**
  60. * @Groups({"localized_menu", "localized_menus"})
  61. * @ORMId
  62. * @ORMColumn(type="integer")
  63. * @ORMGeneratedValue(strategy="AUTO")
  64. */
  65. private $id;
  66. /**
  67. * @Groups({"localized_menu", "localized_menus"})
  68. * @var $locale string
  69. * @ORMColumn(
  70. * type = "string"
  71. * ,unique = true
  72. * )
  73. */
  74. private $locale = "";
  75. /**
  76. * @Groups({"localized_menu", "localized_menus"})
  77. * @ORMColumn(
  78. * type = "string",
  79. * length = 75
  80. * )
  81. */
  82. private $title = "";
  83. /**
  84. * @Groups({"localized_menu", "localized_menus"})
  85. * @var $description string Extra description for this menu item
  86. * @ORMColumn(
  87. * type = "text",
  88. * name = "description"
  89. * )
  90. */
  91. private $description = "";
  92. /**
  93. * @Groups({"localized_menu", "localized_menus"})
  94. * @ORMColumn(
  95. * type = "datetime",
  96. * name = "creation_date"
  97. * )
  98. * @AssertDateTime()
  99. */
  100. private $creationDate;
  101. /**
  102. * @Groups({"localized_menu", "localized_menus"})
  103. * @ORMColumn(
  104. * type = "datetime",
  105. * name = "edit_date"
  106. * )
  107. * @AssertDateTime()
  108. */
  109. private $editDate;
  110.  
  111. /**
  112. * @Groups({"localized_menu", "localized_menus"})
  113. * @ORMColumn(type="text")
  114. * @AssertNotBlank(
  115. * message = "Een menu item is een pagina die inhoud nodig heeft, vergeet dit niet"
  116. * )
  117. */
  118. private $content = "";
  119.  
  120. /**
  121. * @var $parentMenu Menu Parent menu for this localized menu
  122. *
  123. * @Groups({"localized_menu", "localized_parent_menu"})
  124. * @ORMManyToOne(
  125. * targetEntity="Menu",
  126. * inversedBy="localizedMenus"
  127. * )
  128. */
  129. private $parentMenu;
  130. }
  131.  
  132. $builder
  133. ->add('localizedMenus', CollectionType::class, array(
  134. 'entry_type' => LocalizedMenuType::class,
  135. "entry_options" => [
  136. "choice_locale" => $options["choice_locale"]
  137. ],
  138. 'allow_add' => true,
  139. 'allow_delete' => true,
  140. 'required' => false
  141. ))
  142.  
  143. $builder
  144. ->add('title', TextType::class, array(
  145. 'label' => 'Titel',
  146. 'trim' => true
  147. ))
  148. ->add('description', TextareaType::class, array(
  149. 'label' => 'Omschrijving',
  150. 'trim' => true
  151. ))
  152. ->add('content', TextareaType::class, array(
  153. 'label' => 'Inhoud',
  154. 'trim' => true,
  155. 'attr' => array('class' => 'tinymce'),
  156. 'data' => " "
  157. ))
  158. ->add('locale', LocaleType::class, array(
  159. "choice_translation_locale" => $options["choice_locale"]
  160. ))
  161. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement