Breadcrumb.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\Core\UI\Helpers;
  3. /**
  4. * Breadcrumb
  5. *
  6. * @author Sławomir Miśkowicz <slawomir@modulesgarden.com>
  7. */
  8. class Breadcrumb
  9. {
  10. use \ModulesGarden\ProxmoxAddon\Core\UI\Traits\Title;
  11. use \ModulesGarden\ProxmoxAddon\Core\Traits\Lang;
  12. use \ModulesGarden\ProxmoxAddon\Core\Traits\IsAdmin;
  13. protected $url = null;
  14. protected $order = 100;
  15. public function __construct($url = null, $title = null, $order = null, $rawTitle = null)
  16. {
  17. $this->setUrl($url);
  18. $this->setTitle($title);
  19. $this->setOrder($order);
  20. $this->setRawTitle($rawTitle);
  21. }
  22. public function setOrder($order = null)
  23. {
  24. if (is_int($order) && $order >= 0)
  25. {
  26. $this->order = $order;
  27. }
  28. return $this;
  29. }
  30. public function getOrder()
  31. {
  32. return $this->order;
  33. }
  34. public function setUrl($url = null)
  35. {
  36. if (is_string($url) && $url !== '')
  37. {
  38. $this->url = $url;
  39. }
  40. return $this;
  41. }
  42. public function getUrl()
  43. {
  44. return $this->url;
  45. }
  46. public function getBreadcrumb()
  47. {
  48. return ['url' => $this->url, 'title' => $this->buildTitle()];
  49. }
  50. public function buildTitle()
  51. {
  52. if ($this->getRawTitle())
  53. {
  54. return $this->getRawTitle();
  55. }
  56. $this->loadLang();
  57. return $this->lang->absoluteTranslate('addon' . ($this->isAdmin() ? 'AA' : 'CA'), 'breadcrumbs', $this->title);
  58. }
  59. }