ContentSection.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /**
  3. *
  4. * PHP Pro Bid $Id$ XZ5Ny3tFt1+kV4xJCoPYhkGeMygzsAUGNn6ts3nHYOg=
  5. *
  6. * @link http://www.phpprobid.com
  7. * @copyright Copyright (c) 2014 Online Ventures Software LTD & CodeCube SRL
  8. * @license http://www.phpprobid.com/license Commercial License
  9. *
  10. * @version 7.0
  11. */
  12. /**
  13. * content section page class - used by location navigation container
  14. */
  15. namespace Ppb\Navigation\Page;
  16. use Cube\Navigation\Page\AbstractPage,
  17. Cube\Controller\Front;
  18. class ContentSection extends AbstractPage
  19. {
  20. /**
  21. *
  22. * active section id
  23. *
  24. * @var int
  25. */
  26. protected $_sectionId;
  27. /**
  28. *
  29. * sluggable value
  30. *
  31. * @var string
  32. */
  33. protected $_slug;
  34. /**
  35. *
  36. * set active section id
  37. *
  38. * @param int $sectionId
  39. *
  40. * @return $this
  41. */
  42. public function setSectionId($sectionId)
  43. {
  44. $this->_sectionId = $sectionId;
  45. return $this;
  46. }
  47. /**
  48. *
  49. * get active section id
  50. *
  51. * @return int
  52. */
  53. public function getSectionId()
  54. {
  55. if (!$this->_sectionId) {
  56. $this->setSectionId(
  57. Front::getInstance()->getRequest()->getParam('id'));
  58. }
  59. return $this->_sectionId;
  60. }
  61. /**
  62. *
  63. * set slug
  64. *
  65. * @param string $slug
  66. *
  67. * @return $this
  68. */
  69. public function setSlug($slug)
  70. {
  71. $this->_slug = $slug;
  72. return $this;
  73. }
  74. /**
  75. *
  76. * get slug
  77. *
  78. * @return string
  79. */
  80. public function getSlug()
  81. {
  82. return $this->_slug;
  83. }
  84. /**
  85. *
  86. * override get method to use the slug if available for the url
  87. *
  88. * @param string $name
  89. * @return mixed|null|string
  90. */
  91. public function get($name)
  92. {
  93. if ($name == 'params' && !empty($this->_slug)) {
  94. return $this->getSlug();
  95. }
  96. return parent::get($name);
  97. }
  98. /**
  99. *
  100. * check if a section is active
  101. *
  102. * @param bool $recursive check in sub-sections as well, and if a sub-section is active, return the current page as active
  103. *
  104. * @return bool returns active status
  105. */
  106. public function isActive($recursive = false)
  107. {
  108. if (!$this->_active) {
  109. if ($this->getSectionId() == $this->_id) {
  110. $this->_active = true;
  111. return true;
  112. }
  113. }
  114. return parent::isActive($recursive);
  115. }
  116. }