Follow-up to #16396: cleanup code, added phpDoc and XCLASS definition
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / class.tx_cms_be_layout.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010 GridView Team
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 class tx_cms_be_layout {
29
30 /**
31 * ItemProcFunc for colpos items
32 *
33 * @param array $params
34 * @return void
35 */
36 public function colPosListItemProcFunc(&$params) {
37 $params['items'] = $this->addColPosListLayoutItems($params['row']['pid'], $params['items']);
38 }
39
40 /**
41 * Adds items to a colpos list
42 *
43 * @param int $pageId
44 * @param array $items
45 * @return array
46 */
47 protected function addColPosListLayoutItems($pageId, $items) {
48 $layout = $this->getSelectedBackendLayout($pageId);
49 if ($layout && $layout['__items']) {
50 $items = $layout['__items'];
51 }
52 return $items;
53 }
54
55 /**
56 * Gets the list of available columns for a given page id
57 *
58 * @param int $id
59 * @return array $tcaItems
60 */
61 public function getColPosListItemsParsed($id) {
62
63 $tsConfig = t3lib_BEfunc::getModTSconfig($id, 'TCEFORM.tt_content.colPos');
64 $tcaConfig = $GLOBALS['TCA']['tt_content']['columns']['colPos']['config'];
65
66 /** @var $tceForms t3lib_TCEForms */
67 $tceForms = t3lib_div::makeInstance('t3lib_TCEForms');
68 $tcaItems = $tcaConfig['items'];
69 $tcaItems = $tceForms->addItems($tcaItems, $tsConfig['properties']['addItems.']);
70 if (isset($tcaConfig['itemsProcFunc']) && $tcaConfig['itemsProcFunc']) {
71 $tcaItems = $this->addColPosListLayoutItems($id, $tcaItems);
72 }
73 foreach (t3lib_div::trimExplode(',', $tsConfig['properties']['removeItems'], 1) as $removeId) {
74 unset($tcaItems[$removeId]);
75 }
76
77 return $tcaItems;
78 }
79
80 /**
81 * Gets the selected backend layout
82 *
83 * @param int $id
84 * @return array|null $backendLayout
85 */
86 public function getSelectedBackendLayout($id) {
87 $rootline = t3lib_BEfunc::BEgetRootLine($id);
88 $backendLayoutUid = null;
89 for ($i = count($rootline); $i > 0; $i--) {
90 $page = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
91 'uid, be_layout, be_layout_next_level',
92 'pages',
93 'uid=' . intval($rootline[$i]['uid'])
94 );
95 if (intval($page['be_layout_next_level']) > 0 && $page['uid'] != $id) {
96 $backendLayoutUid = intval($page['be_layout_next_level']);
97 break;
98 } else {
99 if (intval($page['be_layout']) > 0) {
100 $backendLayoutUid = intval($page['be_layout']);
101 break;
102 }
103 }
104 }
105 $backendLayout = NULL;
106 if ($backendLayoutUid) {
107 $backendLayout = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', 'be_layouts', 'uid=' . $backendLayoutUid);
108 if ($backendLayout) {
109 /** @var $parser t3lib_TSparser */
110 $parser = t3lib_div::makeInstance('t3lib_TSparser');
111 $parser->parse($backendLayout['config']);
112 $backendLayout['__config'] = $parser->setup;
113 $backendLayout['__items'] = array();
114 $backendLayout['__colPosList'] = array();
115
116 // create items and colPosList
117 if ($backendLayout['__config']['be_layout.'] && $backendLayout['__config']['be_layout.']['rows.']) {
118 foreach ($backendLayout['__config']['be_layout.']['rows.'] as $row) {
119 if (isset($row['columns.']) && is_array($row['columns.'])) {
120 foreach ($row['columns.'] as $column) {
121 $backendLayout['__items'][] = array(
122 $column['name'],
123 $column['colPos'],
124 NULL
125 );
126 $backendLayout['__colPosList'][] = $column['colPos'];
127 }
128 }
129 }
130 }
131
132 }
133 }
134 return $backendLayout;
135 }
136
137 }
138
139 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/class.tx_cms_be_layout.php']) {
140 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/class.tx_cms_be_layout.php']);
141 }
142
143 ?>