Fixed bug #16445: Performance Tuning: Replace exec_SELECTgetRows with exec_SELECTgetS...
[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 * @mficzel
32 * @todo add items
33 * @param unknown_type $params
34 */
35 function colPosListItemProcFunc(&$params) {
36 $params['items'] = $this->addColPosListLayoutItems($params['row']['pid'], $params['items']);
37 }
38
39 function addColPosListLayoutItems($pageId, $items) {
40 $layout = $this->getSelectedBackendLayout($pageId);
41 if ($layout && $layout['__items']) {
42 $items = $layout['__items'];
43 }
44 return $items;
45 }
46
47 function getColPosListItemsParsed($id) {
48
49 $tsConfig = t3lib_BEfunc::getModTSconfig($id, 'TCEFORM.tt_content.colPos');
50 $tcaConfig = $GLOBALS['TCA']['tt_content']['columns']['colPos']['config'];
51
52 $TCEForms = t3lib_div::makeInstance('t3lib_TCEForms');
53 $tcaItems = $tcaConfig['items'];
54 $tcaItems = $TCEForms->addItems($tcaItems, $tsConfig['properties']['addItems.']);
55 if (isset($tcaConfig['itemsProcFunc']) && $tcaConfig['itemsProcFunc']) {
56 $tcaItems = $this->addColPosListLayoutItems($id, $tcaItems);
57 }
58 foreach (t3lib_div::trimExplode(',', $tsConfig['properties']['removeItems'], 1) as $removeId) {
59 unset($tcaItems[$removeId]);
60 }
61 return $tcaItems;
62 }
63
64 function getSelectedBackendLayout($id) {
65 $rootline = t3lib_BEfunc::BEgetRootLine($id);
66 $backendLayoutUid = null;
67 for ($i = count($rootline); $i > 0; $i--) {
68 $page = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('uid, be_layout, be_layout_next_level', 'pages', 'uid=' . intval($rootline[$i]['uid']));
69 if (intval($page['be_layout_next_level']) > 0 && $page['uid'] != $id) {
70 $backendLayoutUid = intval($page['be_layout_next_level']);
71 break;
72 } else {
73 if (intval($page['be_layout']) > 0) {
74 $backendLayoutUid = intval($page['be_layout']);
75 break;
76 }
77 }
78 }
79 $backendLayout = null;
80 if ($backendLayoutUid) {
81 $backendLayout = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', 'be_layouts', 'uid=' . $backendLayoutUid);
82 if ($backendLayout) {
83 $parser = t3lib_div::makeInstance('t3lib_TSparser');
84 $parser->parse($backendLayout['config']);
85 $backendLayout['__config'] = $parser->setup;
86 $backendLayout['__items'] = array();
87 $backendLayout['__colPosList'] = array();
88
89 // create items and colPosList
90 if ($backendLayout['__config']['be_layout.'] && $backendLayout['__config']['be_layout.']['rows.']) {
91 foreach ($backendLayout['__config']['be_layout.']['rows.'] as $row) {
92 foreach ($row['columns.'] as $column) {
93 $backendLayout['__items'][] = array(
94 $column['name'],
95 $column['colPos'],
96 NULL
97 );
98 $backendLayout['__colPosList'][] = $column['colPos'];
99 }
100 }
101 }
102
103 }
104 }
105 return $backendLayout;
106 }
107
108 }
109
110 ?>