PageRenderTime 31ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/concrete/src/Page/Stack/StackList.php

https://gitlab.com/koodersmiikka/operaatio-terveys
PHP | 111 lines | 93 code | 17 blank | 1 comment | 14 complexity | 50277b8032b476e575747621b67c33c0 MD5 | raw file
  1. <?php
  2. namespace Concrete\Core\Page\Stack;
  3. use Concrete\Core\Multilingual\Page\Section\Section;
  4. use Loader;
  5. use Concrete\Core\Legacy\PageList;
  6. use Page;
  7. use \Concrete\Core\Legacy\DatabaseItemList;
  8. class StackList extends PageList
  9. {
  10. public function __construct()
  11. {
  12. $this->ignoreAliases = true;
  13. $this->ignorePermissions = true;
  14. $this->filterByPageTypeHandle(STACKS_PAGE_TYPE);
  15. $this->addToQuery('inner join Stacks on Stacks.cID = p1.cID');
  16. $this->sortBy('p1.cDisplayOrder', 'asc');
  17. }
  18. public function filterByGlobalAreas()
  19. {
  20. $this->filter('stType', Stack::ST_TYPE_GLOBAL_AREA);
  21. }
  22. public function filterByUserAdded()
  23. {
  24. $this->filter('stType', Stack::ST_TYPE_USER_ADDED);
  25. }
  26. public function filterByStackCategory(StackCategory $category)
  27. {
  28. $this->filterByParentID($category->getPage()->getCollectionID());
  29. }
  30. public function filterByPageLanguage(\Concrete\Core\Page\Page $page)
  31. {
  32. $ms = Section::getBySectionOfSite($page);
  33. if (!is_object($ms)) {
  34. $ms = static::getPreferredSection();
  35. }
  36. if (is_object($ms)) {
  37. $this->filterByLanguageSection($ms);
  38. }
  39. }
  40. public function filterByLanguageSection(Section $ms)
  41. {
  42. $this->filter('stMultilingualSection', $ms->getCollectionID());
  43. }
  44. public static function export(\SimpleXMLElement $x)
  45. {
  46. $db = Loader::db();
  47. $r = $db->Execute('select stName, cID, stType from Stacks order by stName asc');
  48. if ($r->NumRows()) {
  49. $gas = $x->addChild('stacks');
  50. while ($row = $r->FetchRow()) {
  51. $stack = Stack::getByName($row['stName']);
  52. if (is_object($stack)) {
  53. $stack->export($gas);
  54. }
  55. }
  56. }
  57. }
  58. public function get($itemsToGet = 0, $offset = 0)
  59. {
  60. if ($this->getQuery() == '') {
  61. $this->setBaseQuery();
  62. }
  63. $stacks = array();
  64. $this->setItemsPerPage($itemsToGet);
  65. $r = DatabaseItemList::get($itemsToGet, $offset);
  66. foreach ($r as $row) {
  67. $s = Stack::getByID($row['cID'], 'RECENT');
  68. $stacks[] = $s;
  69. }
  70. return $stacks;
  71. }
  72. public static function rescanMultilingualStacks()
  73. {
  74. $sl = new static();
  75. $stacks = $sl->get();
  76. foreach($stacks as $stack) {
  77. $section = $stack->getMultilingualSection();
  78. if (!$section) {
  79. $section = false;
  80. $parent = \Page::getByID($stack->getCollectionParentID());
  81. if ($parent->getCollectionPath() == STACKS_PAGE_PATH) {
  82. // this is the default
  83. $section = Section::getDefaultSection();
  84. } else if ($parent->getPageTypeHandle() == STACK_CATEGORY_PAGE_TYPE) {
  85. $locale = $parent->getCollectionHandle();
  86. $section = Section::getByLocale($locale);
  87. }
  88. if ($section) {
  89. $stack->updateMultilingualSection($section);
  90. }
  91. }
  92. }
  93. }
  94. }