TYPO3 CMS  TYPO3_6-2
CategoryMenuUtility.php
Go to the documentation of this file.
1 <?php
3 
18 
30  protected static $sortingField;
31 
40  public function collectPages($selectedCategories, $configuration, $parentObject) {
41  $selectedPages = array();
42  $categoriesPerPage = array();
43  // Determine the name of the relation field
44  $relationField = '';
45  if (isset($configuration['relation.'])) {
46  $relationField = $parentObject->parent_cObj->stdWrap(
47  $configuration['relation'],
48  $configuration['relation.']
49  );
50  } elseif (isset($configuration['relation'])) {
51  $relationField = $configuration['relation'];
52  }
53  // Get the pages for each selected category
54  $selectedCategories = GeneralUtility::intExplode(',', $selectedCategories, TRUE);
55  foreach ($selectedCategories as $aCategory) {
57  $aCategory,
58  TRUE,
59  'pages',
60  $relationField
61  );
62  $categoryUid = $collection->getUid();
63  // Loop on the results, overlay each page record found
64  foreach ($collection as $pageItem) {
65  $parentObject->getSysPage()->versionOL('pages', $pageItem, TRUE);
66  if (is_array($pageItem)) {
67  $selectedPages[$pageItem['uid']] = $parentObject->getSysPage()->getPageOverlay($pageItem);
68  // Keep a list of the categories each page belongs to
69  if (!isset($categoriesPerPage[$pageItem['uid']])) {
70  $categoriesPerPage[$pageItem['uid']] = array();
71  }
72  $categoriesPerPage[$pageItem['uid']][] = $categoryUid;
73  }
74  }
75  }
76  // Loop on the selected pages to add the categories they belong to, as comma-separated list of category uid's)
77  // (this makes them available for rendering, if needed)
78  foreach ($selectedPages as $uid => $pageRecord) {
79  $selectedPages[$uid]['_categories'] = implode(',', $categoriesPerPage[$uid]);
80  }
81 
82  // Sort the pages according to the sorting property
83  self::$sortingField = isset($configuration['sorting.']) ? $parentObject->getParentContentObject()->stdWrap($configuration['sorting'], $configuration['sorting.']) : $configuration['sorting'];
84  $order = isset($configuration['order.']) ? $parentObject->getParentContentObject()->stdWrap($configuration['order'], $configuration['order.']) : $configuration['order'];
85  $selectedPages = $this->sortPages($selectedPages, $order);
86 
87  return $selectedPages;
88  }
89 
100  protected function sortPages($pages, $order) {
101  // Perform the sorting only if a criterion was actually defined
102  if (!empty(self::$sortingField)) {
103  // Check that the sorting field exists (checking the first record is enough)
104  $firstPage = current($pages);
105  if (isset($firstPage[self::$sortingField])) {
106  // Make sure the order property is either "asc" or "desc" (default is "asc")
107  if (!empty($order)) {
108  $order = strtolower($order);
109  if ($order != 'desc') {
110  $order = 'asc';
111  }
112  }
113  uasort(
114  $pages,
115  array(
116  '\TYPO3\CMS\Frontend\ContentObject\Menu\CategoryMenuUtility',
117  'sortPagesUtility'
118  )
119  );
120  // If the sort order is descending, reverse the sorted array
121  if ($order == 'desc') {
122  $pages = array_reverse($pages, TRUE);
123  }
124  }
125  }
126  return $pages;
127  }
128 
136  static public function sortPagesUtility($pageA, $pageB) {
137  return strnatcasecmp($pageA[self::$sortingField], $pageB[self::$sortingField]);
138  }
139 }
static intExplode($delimiter, $string, $removeEmptyValues=FALSE, $limit=0)
$uid
Definition: server.php:36
static load($id, $fillItems=FALSE, $tableName='', $fieldName='')
collectPages($selectedCategories, $configuration, $parentObject)