src/Entity/App/Menu.php line 406

Open in your IDE?
  1. <?php
  2. namespace App\Entity\App;
  3. use App\Model\App\MenuItem;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9. * Menu
  10. *
  11. * @ORM\Table(name="menu")
  12. * @ORM\Entity(repositoryClass="App\Repository\App\MenuRepository")
  13. * @ORM\Cache(usage="READ_ONLY", region="public")
  14. */
  15. class Menu implements \Stringable
  16. {
  17. /**
  18. * @ORM\Column(name="id", type="integer")
  19. * @ORM\Id
  20. * @ORM\GeneratedValue(strategy="AUTO")
  21. */
  22. private int $id;
  23. // #[ORM\Column(name: 'slug', type: 'string', length: 30, nullable: true)]
  24. /**
  25. * @ORM\Column(name="slug", type="string", length=30, nullable=true)
  26. */
  27. private ?string $slug;
  28. // #[ORM\Column(name: 'attributes', type: Types::JSON, nullable: true, options: ['jsonb' => true])]
  29. /**
  30. * @ORM\Column(name="attributes", type="json", nullable=true, options={"jsonb": true})
  31. */
  32. private ?array $attributes;
  33. // #[ORM\Column(name: 'title', type: 'string', length: 50)]
  34. /**
  35. * @ORM\Column(name="title", type="string", length=50)
  36. */
  37. private ?string $title;
  38. // #[ORM\Column(name: 'locale', type: 'string', length: 2, nullable: true)]
  39. /**
  40. * @ORM\Column(name="locale", type="string", length=2, nullable=true)
  41. */
  42. private ?string $locale;
  43. // #[ORM\Column(name: 'url', type: 'string', length: 255, nullable: true)]
  44. /**
  45. * @ORM\Column(name="url", type="string", length=255, nullable=true)
  46. */
  47. private ?string $url;
  48. // #[ORM\Column(name: 'path', type: 'string', length: 50, nullable: true)]
  49. /**
  50. * @ORM\Column(name="path", type="string", length=50, nullable=true)
  51. */
  52. private ?string $path;
  53. // #[ORM\Column(name: 'parameters', type: Types::JSON, nullable: true, options: ['jsonb' => true])]
  54. /**
  55. * @ORM\Column(name="parameters", type="json", nullable=true, options={"jsonb": true})
  56. */
  57. private ?array $parameters;
  58. // #[ORM\Column(name: 'widget', type: 'string', length: 100, nullable: true)]
  59. /**
  60. * @ORM\Column(name="widget", type="string", nullable=true)
  61. */
  62. private ?string $widget;
  63. // #[ORM\Column(name: 'item_order', type: 'integer', nullable: true)]
  64. /**
  65. * @ORM\Column(name="item_order", type="integer", nullable=true)
  66. */
  67. private ?int $order = 0;
  68. // #[ORM\Column(name: 'has_right', type: 'boolean')]
  69. /**
  70. * @ORM\Column(name="has_right", type="boolean")
  71. */
  72. private bool $hasRight = true;
  73. // #[ORM\Column(name: 'user_right', type: 'string', nullable: true)]
  74. /**
  75. * @ORM\Column(name="user_right", type="string", nullable=true)
  76. */
  77. private ?string $right;
  78. // #[ORM\OneToMany(mappedBy: 'menu', targetEntity: Menu::class, cascade: ['persist'], fetch: 'EAGER')]
  79. // #[ORM\OrderBy(['order' => 'ASC'])]
  80. /**
  81. * @ORM\OneToMany(targetEntity="App\Entity\App\Menu", mappedBy="menu",cascade={"persist"}, fetch="EAGER")
  82. * @ORM\OrderBy({"order" = "ASC"})
  83. */
  84. private Collection $items;
  85. // #[ORM\ManyToOne(targetEntity: Menu::class, inversedBy: 'items')]
  86. // #[ORM\JoinColumn(name: 'menu', referencedColumnName: 'id', nullable: true)]
  87. /**
  88. * @ORM\ManyToOne(targetEntity="App\Entity\App\Menu", inversedBy="items")
  89. * @ORM\JoinColumn(name="menu", referencedColumnName="id", nullable=true)
  90. */
  91. private ?Menu $menu;
  92. public function __construct()
  93. {
  94. $this->items = new ArrayCollection();
  95. }
  96. public function __toString(): string
  97. {
  98. return (string) $this->getTitle();
  99. }
  100. /**
  101. * Get id
  102. *
  103. * @return int|null
  104. */
  105. public function getId()
  106. {
  107. return $this->id;
  108. }
  109. /**
  110. * Set slug
  111. *
  112. * @param string $slug
  113. */
  114. public function setSlug($slug): Menu
  115. {
  116. $this->slug = $slug;
  117. return $this;
  118. }
  119. /**
  120. * Get slug
  121. *
  122. * @return string
  123. */
  124. public function getSlug():? string
  125. {
  126. return (string) $this->slug;
  127. }
  128. /**
  129. * Set attributes
  130. *
  131. * @param array $attributes
  132. */
  133. public function setAttributes($attributes): Menu
  134. {
  135. $this->attributes = $attributes;
  136. return $this;
  137. }
  138. /**
  139. * Get attributes
  140. */
  141. public function getAttributes(): array
  142. {
  143. return $this->attributes ?? [];
  144. }
  145. /**
  146. * Set title
  147. *
  148. * @param string $title
  149. */
  150. public function setTitle($title): Menu
  151. {
  152. $this->title = $title;
  153. return $this;
  154. }
  155. /**
  156. * Get title
  157. *
  158. * @return string
  159. */
  160. public function getTitle():? string
  161. {
  162. return $this->title;
  163. }
  164. /**
  165. * Set locale
  166. *
  167. * @param string $locale
  168. */
  169. public function setLocale($locale): Menu
  170. {
  171. $this->locale = $locale;
  172. return $this;
  173. }
  174. /**
  175. * Get locale
  176. *
  177. * @return string
  178. */
  179. public function getLocale():? string
  180. {
  181. return $this->locale;
  182. }
  183. /**
  184. * Set url
  185. *
  186. * @param string $url
  187. */
  188. public function setUrl($url): Menu
  189. {
  190. $this->url = $url;
  191. return $this;
  192. }
  193. /**
  194. * Get url
  195. *
  196. * @return string
  197. */
  198. public function getUrl():? string
  199. {
  200. return $this->url;
  201. }
  202. /**
  203. * Set path
  204. *
  205. * @param string $path
  206. */
  207. public function setPath($path): Menu
  208. {
  209. $this->path = $path;
  210. return $this;
  211. }
  212. /**
  213. * Get path
  214. *
  215. * @return string
  216. */
  217. public function getPath():? string
  218. {
  219. return $this->path;
  220. }
  221. /**
  222. * Set parameters
  223. *
  224. * @param array $parameters
  225. */
  226. public function setParameters($parameters): Menu
  227. {
  228. $this->parameters = $parameters;
  229. return $this;
  230. }
  231. /**
  232. * Get parameters
  233. *
  234. * @return array
  235. */
  236. public function getParameters():? array
  237. {
  238. return $this->parameters;
  239. }
  240. /**
  241. * Get parameters
  242. */
  243. public function getParameterValue(): array
  244. {
  245. return (array) (\is_string($this->parameters) ? json_decode($this->parameters) : $this->parameters);
  246. }
  247. public function setParams(?string $params=null): Menu
  248. {
  249. $this->parameters = json_decode((string) $params);
  250. return $this;
  251. }
  252. /**
  253. * @return string
  254. */
  255. public function getParams()
  256. {
  257. return json_encode($this->parameters);
  258. }
  259. /**
  260. * Set order
  261. *
  262. * @param integer $order
  263. */
  264. public function setOrder($order): Menu
  265. {
  266. $this->order = $order;
  267. return $this;
  268. }
  269. /**
  270. * Get order
  271. *
  272. * @return integer
  273. */
  274. public function getOrder():? int
  275. {
  276. return $this->order;
  277. }
  278. /**
  279. * Set hasRight
  280. *
  281. * @param boolean $hasRight
  282. */
  283. public function setHasRight($hasRight): static
  284. {
  285. $this->hasRight = $hasRight;
  286. return $this;
  287. }
  288. /**
  289. * Get hasRight
  290. *
  291. * @return boolean
  292. */
  293. public function getHasRight()
  294. {
  295. return $this->hasRight;
  296. }
  297. /**
  298. * Set right
  299. *
  300. * @param string $right
  301. */
  302. public function setRight($right): Menu
  303. {
  304. $this->right = $right;
  305. return $this;
  306. }
  307. /**
  308. * Get right
  309. *
  310. * @return string
  311. */
  312. public function getRight()
  313. {
  314. return $this->right;
  315. }
  316. /**
  317. * Add item
  318. *
  319. *
  320. */
  321. public function addItem(Menu $item): Menu
  322. {
  323. $this->items[] = $item;
  324. $item->setLocale($this->locale);
  325. return $this;
  326. }
  327. /**
  328. * Remove item
  329. */
  330. public function removeItem(Menu $item): void
  331. {
  332. $this->items->removeElement($item);
  333. }
  334. /**
  335. * Get items
  336. */
  337. public function getItems(): Collection
  338. {
  339. return $this->items;
  340. }
  341. /**
  342. * Set menu
  343. *
  344. *
  345. */
  346. public function setMenu(Menu $menu = null): Menu
  347. {
  348. if (!$menu instanceof \App\Entity\App\Menu) {
  349. return $this;
  350. }
  351. $this->menu = $menu->addItem($this);
  352. return $this;
  353. }
  354. /**
  355. * Get menu
  356. *
  357. * @return Menu|null
  358. */
  359. public function getMenu()
  360. {
  361. return $this->menu;
  362. }
  363. /**
  364. * Set widget
  365. *
  366. * @param string $widget
  367. */
  368. public function setWidget($widget): Menu
  369. {
  370. $this->widget = $widget;
  371. return $this;
  372. }
  373. /**
  374. * Get widget
  375. *
  376. * @return string
  377. */
  378. public function getWidget():? string
  379. {
  380. return $this->widget;
  381. }
  382. }