TYPO3 CMS  TYPO3_7-6
SectionViewHelper.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
19 
49 {
51 
57  public function initializeArguments()
58  {
59  $this->registerArgument('as', 'string', 'Name of the template variable that will contain selected pages', true);
60  $this->registerArgument('column', 'string', 'Column numbers (colPos) from which to select content', false, '0');
61  $this->registerArgument('pageUid', 'integer', 'UID of page containing section-objects; defaults to current page', false, null);
62  $this->registerArgument('type', 'string', 'Search method when selecting indices from page', false, '');
63  }
64 
70  public function render()
71  {
72  $as = (string)$this->arguments['as'];
73  $pageUid = (int)$this->arguments['pageUid'];
74  $type = (string)$this->arguments['type'];
75 
76  if (empty($pageUid)) {
77  $pageUid = $this->getTypoScriptFrontendController()->id;
78  }
79 
80  if (!empty($type) && !in_array($type, ['all', 'header'], true)) {
81  return '';
82  }
83 
84  return $this->renderChildrenWithVariables([
85  $as => $this->findBySection($pageUid, $type, $this->arguments['column'])
86  ]);
87  }
88 
106  protected function findBySection($pageUid, $type = '', $column = '')
107  {
108  $constraints = [];
109  if (trim($column) !== '') {
110  $colPosList = implode(',', GeneralUtility::intExplode(',', $column, true));
111  $constraints[] = 'colPos IN(' . ($colPosList !== '' ? $colPosList : '0') . ')';
112  }
113 
114  switch ($type) {
115  case 'all':
116  break;
117  case 'header':
118  $constraints[] = 'sectionIndex = 1';
119  $constraints[] = 'header <> \'\'';
120  $constraints[] = 'header_layout <> 100';
121  break;
122  default:
123  $constraints[] = 'sectionIndex = 1';
124  }
125 
126  $whereStatement = implode(' AND ', $constraints);
127 
128  $contentElements = $this->getTypoScriptFrontendController()->cObj->getRecords('tt_content', [
129  'where' => $whereStatement,
130  'orderBy' => 'sorting',
131  'languageField' => 'sys_language_uid',
132  'pidInList' => (int)$pageUid
133  ]);
134 
135  return $contentElements;
136  }
137 }
static intExplode($delimiter, $string, $removeEmptyValues=false, $limit=0)
registerArgument($name, $type, $description, $required=false, $defaultValue=null)