TYPO3 API  SVNRelease
class.tx_cms_backendlayout.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003  *  Copyright notice
00004  *
00005  *  (c) 2010-2011 GridView Team
00006  *  All rights reserved
00007  *
00008  *  This script is part of the TYPO3 project. The TYPO3 project is
00009  *  free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  The GNU General Public License can be found at
00015  *  http://www.gnu.org/copyleft/gpl.html.
00016  *  A copy is found in the textfile GPL.txt and important notices to the license
00017  *  from the author is found in LICENSE.txt distributed with these scripts.
00018  *
00019  *
00020  *  This script is distributed in the hope that it will be useful,
00021  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  *  GNU General Public License for more details.
00024  *
00025  *  This copyright notice MUST APPEAR in all copies of the script!
00026  ***************************************************************/
00027 
00028 class tx_cms_BackendLayout {
00029 
00030     /**
00031      * ItemProcFunc for colpos items
00032      *
00033      * @param  array $params
00034      * @return void
00035      */
00036     public function colPosListItemProcFunc(&$params) {
00037         if ($params['row']['pid'] > 0) {
00038             $params['items'] = $this->addColPosListLayoutItems($params['row']['pid'], $params['items']);
00039         } else {
00040             // negative uid_pid values indicate that the element has been inserted after an existing element
00041             // so there is no pid to get the backendLayout for and we have to get that first
00042             $existingElement = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('pid', 'tt_content', 'uid=' . -(intval($params['row']['pid'])));
00043             if ($existingElement['pid'] > 0) {
00044                 $params['items'] = $this->addColPosListLayoutItems($existingElement['pid'], $params['items']);
00045             }
00046         }
00047     }
00048 
00049     /**
00050      * Adds items to a colpos list
00051      *
00052      * @param  int  $pageId
00053      * @param  array  $items
00054      * @return array
00055      */
00056     protected function addColPosListLayoutItems($pageId, $items) {
00057         $layout = $this->getSelectedBackendLayout($pageId);
00058 
00059         if ($layout && $layout['__items']) {
00060             $items = $layout['__items'];
00061         }
00062 
00063         return $items;
00064     }
00065 
00066     /**
00067      * Gets the list of available columns for a given page id
00068      *
00069      * @param  int  $id
00070      * @return  array  $tcaItems
00071      */
00072     public function getColPosListItemsParsed($id) {
00073         $tsConfig  = t3lib_BEfunc::getModTSconfig($id, 'TCEFORM.tt_content.colPos');
00074         $tcaConfig = $GLOBALS['TCA']['tt_content']['columns']['colPos']['config'];
00075 
00076         $tceForms = t3lib_div::makeInstance('t3lib_TCEForms');
00077 
00078         $tcaItems = $tcaConfig['items'];
00079         $tcaItems = $tceForms->addItems($tcaItems, $tsConfig['properties']['addItems.']);
00080 
00081         if (isset($tcaConfig['itemsProcFunc']) && $tcaConfig['itemsProcFunc']) {
00082             $tcaItems = $this->addColPosListLayoutItems($id, $tcaItems);
00083         }
00084 
00085         foreach (t3lib_div::trimExplode(',', $tsConfig['properties']['removeItems'], 1) as $removeId) {
00086             foreach ($tcaItems as $key => $item) {
00087                 if ($item[1] == $removeId) {
00088                     unset($tcaItems[$key]);
00089                 }
00090             }
00091         }
00092 
00093         return $tcaItems;
00094     }
00095 
00096     /**
00097      * Gets the selected backend layout
00098      *
00099      * @param  int  $id
00100      * @return array|null  $backendLayout
00101      */
00102     public function getSelectedBackendLayout($id) {
00103         $rootline = t3lib_BEfunc::BEgetRootLine($id);
00104         $backendLayoutUid = NULL;
00105 
00106         for ($i = count($rootline); $i > 0; $i--) {
00107             $page = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
00108                 'uid, backend_layout, backend_layout_next_level',
00109                 'pages',
00110                 'uid=' . intval($rootline[$i]['uid'])
00111             );
00112             $selectedBackendLayout = intval($page['backend_layout']);
00113             $selectedBackendLayoutNextLevel = intval($page['backend_layout_next_level']);
00114             if ($selectedBackendLayout != 0 && $page['uid'] == $id) {
00115                 if ($selectedBackendLayout > 0) {
00116                         // Backend layout for current page is set
00117                     $backendLayoutUid = $selectedBackendLayout;
00118                 }
00119                 break;
00120             } else if ($selectedBackendLayoutNextLevel == -1 && $page['uid'] != $id) {
00121                     // Some previous page in our rootline sets layout_next to "None"
00122                 break;
00123             } else if ($selectedBackendLayoutNextLevel > 0 && $page['uid'] != $id) {
00124                     // Some previous page in our rootline sets some backend_layout, use it
00125                 $backendLayoutUid = $selectedBackendLayoutNextLevel;
00126                 break;
00127             }
00128         }
00129 
00130         $backendLayout = NULL;
00131         if ($backendLayoutUid) {
00132             $backendLayout = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
00133                 '*',
00134                 'backend_layout',
00135                 'uid=' . $backendLayoutUid
00136             );
00137 
00138             if ($backendLayout) {
00139                 $parser = t3lib_div::makeInstance('t3lib_TSparser');
00140                 $parser->parse($backendLayout['config']);
00141 
00142                 $backendLayout['__config']     = $parser->setup;
00143                 $backendLayout['__items']      = array();
00144                 $backendLayout['__colPosList'] = array();
00145 
00146                     // create items and colPosList
00147                 if ($backendLayout['__config']['backend_layout.'] && $backendLayout['__config']['backend_layout.']['rows.']) {
00148                     foreach ($backendLayout['__config']['backend_layout.']['rows.'] as $row) {
00149                         if (isset($row['columns.']) && is_array($row['columns.'])) {
00150                             foreach ($row['columns.'] as $column) {
00151                                 $backendLayout['__items'][] = array(
00152                                     $column['name'],
00153                                     $column['colPos'],
00154                                     NULL
00155                                 );
00156                                 $backendLayout['__colPosList'][] = $column['colPos'];
00157                             }
00158                         }
00159                     }
00160                 }
00161             }
00162         }
00163 
00164         return $backendLayout;
00165     }
00166 
00167 }
00168 
00169 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/classes/class.tx_cms_backendlayout.php']) {
00170     include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/classes/class.tx_cms_backendlayout.php']);
00171 }
00172 
00173 ?>