/web/concrete/blocks/date_nav/controller.php

https://github.com/shin2/concrete5 · PHP · 135 lines · 103 code · 25 blank · 7 comment · 21 complexity · f6aafaae198a2e4740ea9d4ca60b26de MD5 · raw file

  1. <?php
  2. defined('C5_EXECUTE') or die("Access Denied.");
  3. class DateNavBlockController extends BlockController {
  4. protected $btTable = 'btDateNav';
  5. protected $btInterfaceWidth = "500";
  6. protected $btInterfaceHeight = "350";
  7. /**
  8. * Used for localization. If we want to localize the name/description we have to include this
  9. */
  10. public function getBlockTypeDescription() {
  11. return t("A collapsible date based navigation tree");
  12. }
  13. public function getBlockTypeName() {
  14. return t("Date Navigation");
  15. }
  16. public function getJavaScriptStrings() {
  17. return array(
  18. );
  19. }
  20. function getPages($query = null) {
  21. Loader::model('page_list');
  22. $db = Loader::db();
  23. $bID = $this->bID;
  24. if ($this->bID) {
  25. $q = "select * from btDateNav where bID = '$bID'";
  26. $r = $db->query($q);
  27. if ($r) {
  28. $row = $r->fetchRow();
  29. }
  30. } else {
  31. $row['num'] = $this->num;
  32. $row['cParentID'] = $this->cParentID;
  33. $row['cThis'] = $this->cThis;
  34. $row['orderBy'] = $this->orderBy;
  35. $row['ctID'] = $this->ctID;
  36. $row['rss'] = $this->rss;
  37. }
  38. $pl = new PageList();
  39. $pl->setNameSpace('b' . $this->bID);
  40. $cArray = array();
  41. //$pl->sortByPublicDate();
  42. $pl->sortByPublicDateDescending();
  43. $num = (int) $row['num'];
  44. if ($num > 0) {
  45. $pl->setItemsPerPage($num);
  46. }
  47. $c = $this->getCollectionObject();
  48. if (is_object($c)) {
  49. $this->cID = $c->getCollectionID();
  50. }
  51. $cParentID = ($row['cThis']) ? $this->cID : $row['cParentID'];
  52. if ($this->displayFeaturedOnly == 1) {
  53. Loader::model('attribute/categories/collection');
  54. $cak = CollectionAttributeKey::getByHandle('is_featured');
  55. if (is_object($cak)) {
  56. $pl->filterByIsFeatured(1);
  57. }
  58. }
  59. $pl->filter('cvName', '', '!=');
  60. if ($row['ctID']) {
  61. $pl->filterByCollectionTypeID($row['ctID']);
  62. }
  63. $pl->filterByAttribute('exclude_nav',false);
  64. if ($row['cParentID'] != 0) {
  65. $pl->filterByParentID($cParentID);
  66. }
  67. if ($num > 0) {
  68. $pages = $pl->getPage();
  69. } else {
  70. $pages = $pl->get();
  71. }
  72. $this->set('pl', $pl);
  73. return $pages;
  74. }
  75. public function edit() {
  76. $c = Page::getCurrentPage();
  77. if ($c->getCollectionID() != $this->cParentID && (!$this->cThis) && ($this->cParentID != 0)) {
  78. $isOtherPage = true;
  79. $this->set('isOtherPage', true);
  80. }
  81. }
  82. public function view() {
  83. $cArray = $this->getPages();
  84. $nh = Loader::helper('navigation');
  85. $this->set('nh', $nh);
  86. $this->set('cArray', $cArray);
  87. }
  88. function save($args) {
  89. // If we've gotten to the process() function for this class, we assume that we're in
  90. // the clear, as far as permissions are concerned (since we check permissions at several
  91. // points within the dispatcher)
  92. $db = Loader::db();
  93. $bID = $this->bID;
  94. $c = $this->getCollectionObject();
  95. if (is_object($c)) {
  96. $this->cID = $c->getCollectionID();
  97. }
  98. $args['num'] = ($args['num'] > 0) ? $args['num'] : 0;
  99. $args['cThis'] = ($args['cParentID'] == $this->cID) ? '1' : '0';
  100. $args['cParentID'] = ($args['cParentID'] == 'OTHER') ? $args['cParentIDValue'] : $args['cParentID'];
  101. $args['truncateSummaries'] = ($args['truncateSummaries']) ? '1' : '0';
  102. $args['truncateTitles'] = ($args['truncateTitles']) ? '1' : '0';
  103. $args['displayFeaturedOnly'] = ($args['displayFeaturedOnly']) ? '1' : '0';
  104. $args['truncateChars'] = intval($args['truncateChars']);
  105. $args['truncateTitleChars'] = intval($args['truncateTitleChars']);
  106. $args['showDescriptions'] = ($args['showDescriptions']) ? '1' : '0';
  107. parent::save($args);
  108. }
  109. }
  110. ?>