gridlayoutmetadataparser.php

来自「SugarCRM5.1 开源PHP客户关系管理系统」· PHP 代码 · 共 510 行 · 第 1/2 页

PHP
510
字号
<?phpif(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');/********************************************************************************* * SugarCRM is a customer relationship management program developed by * SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc. *  * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the * Free Software Foundation with the addition of the following permission added * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. *  * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more * details. *  * You should have received a copy of the GNU General Public License along with * this program; if not, see http://www.gnu.org/licenses or write to the Free * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301 USA. *  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road, * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com. *  * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. *  * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by * SugarCRM" logo. If the display of the logo is not reasonably feasible for * technical reasons, the Appropriate Legal Notices must display the words * "Powered by SugarCRM". *********************************************************************************/require_once 'modules/ModuleBuilder/parsers/views/AbstractMetaDataParser.php' ;require_once 'modules/ModuleBuilder/parsers/views/MetaDataParserInterface.php' ;require_once 'modules/ModuleBuilder/parsers/constants.php' ;class GridLayoutMetaDataParser extends AbstractMetaDataParser implements MetaDataParserInterface{        static $variableMap = array ( MB_EDITVIEW => 'EditView' , MB_DETAILVIEW => 'DetailView' , MB_QUICKCREATE => 'QuickCreate' ) ;    private static $empty = array ( 'name' => '(empty)' , 'label' => '(empty)' ) ;    /*     * Constructor     * @param string view           The view type, that is, editview, searchview etc     * @param string moduleName     The name of the module to which this view belongs     * @param string packageName    If not empty, the name of the package to which this view belongs     */    function __construct ($view , $moduleName , $packageName = '')    {        $GLOBALS [ 'log' ]->debug ( get_class ( $this ) . "->__construct( {$view} , {$moduleName} , {$packageName} )" ) ;        $view = strtolower ( $view ) ;                // BEGIN ASSERTIONS        if ($view != MB_EDITVIEW && $view != MB_DETAILVIEW && $view != MB_QUICKCREATE)        {            sugar_die ( get_class ( $this ) . ": View $view is not supported" ) ;        }        // END ASSERTIONS                $this->_moduleName = $moduleName ;        $this->_view = $view ;                if (empty ( $packageName ))        {            require_once 'modules/ModuleBuilder/parsers/views/DeployedMetaDataImplementation.php' ;            $this->implementation = new DeployedMetaDataImplementation ( $view, $moduleName, self::$variableMap ) ;        } else        {            require_once 'modules/ModuleBuilder/parsers/views/UndeployedMetaDataImplementation.php' ;            $this->implementation = new UndeployedMetaDataImplementation ( $view, $moduleName, $packageName ) ;        }                $viewdefs = $this->implementation->getViewdefs () ;                if (! isset ( $viewdefs [ self::$variableMap [ $view ] ] ))        {            sugar_die ( get_class ( $this ) . ": missing variable " . self::$variableMap [ $view ] . " in layout definition" ) ;        }        $viewdefs = $viewdefs [ self::$variableMap [ $view ] ] ;        if (! isset ( $viewdefs [ 'templateMeta' ] ))        {            sugar_die ( get_class ( $this ) . ": missing templateMeta section in layout definition (case sensitive)" ) ;        }        if (! isset ( $viewdefs [ 'panels' ] ))        {            sugar_die ( get_class ( $this ) . ": missing panels section in layout definition (case sensitive)" ) ;        }                $this->_fielddefs = $this->implementation->getModuleFielddefs () ;        $this->_viewdefs = $viewdefs ;                if ($this->getMaxColumns () < 1)        {            sugar_die ( get_class ( $this ) . ": maxColumns=" . $this->getMaxColumns () . " - must be greater than 0!" ) ;        }        $this->_viewdefs [ 'panels' ] = $this->_standardizeLayout ( $this->_viewdefs [ 'panels' ] ) ; // put into a canonical format    }    /*     * Save a draft layout     */    function writeWorkingFile ()    {        $this->_populateFromRequest () ;        $this->implementation->save ( array ( self::$variableMap [ $this->_view ] => $this->_viewdefs ) ) ;    }    /*     * Deploy the layout     * @param boolean $populate If true (default), then update the layout first with new layout information from the $_REQUEST array     */    function handleSave ($populate = true)    {        $GLOBALS [ 'log' ]->debug ( get_class ( $this ) . "->handleSave( " . (($populate) ? "true" : "false") . " )" ) ;        if ($populate)        {            $this->_populateFromRequest () ;        } else        {            // strip (filler) fields and replace by NULLs to be compatible with the standard file format            foreach ( $this->_viewdefs [ 'panels' ] as $panelID => $panel )            {                foreach ( $panel as $rowID => $row )                {                    foreach ( $row as $colID => $col )                    {                        if ($col [ 'name' ] == '(filler)')                        {                            $this->_viewdefs [ 'panels' ] [ $panelID ] [ $rowID ] [ $colID ] = NULL ;                        }                    }                }            }        }                $this->implementation->deploy ( array ( self::$variableMap [ $this->_view ] => $this->_viewdefs ) ) ;    }    /*     * Return the layout, all padded out with (empty) fields ready to be displayed     */    function getLayout ()    {        if (! empty ( $this->_viewdefs ))        {            foreach ( $this->_viewdefs [ 'panels' ] as $panelID => $panel )            {                $column = 0 ;                foreach ( $panel as $rowID => $row )                {                    // pad between fields on a row                    foreach ( $row as $colID => $col )                    {                        for ( $i = $column + 1 ; $i < $colID ; $i ++ )                        {                            $row [ $i ] = self::$empty ;                        }                        $column = $colID ;                    }                    // now pad out to the end of the row                    if (($column + 1) < $this->getMaxColumns ())                    { // last column is maxColumns-1                        for ( $i = $column + 1 ; $i < $this->getMaxColumns () ; $i ++ )                        {                            $row [ $i ] = self::$empty ;                        }                    }                    ksort ( $row ) ;                    $this->_viewdefs [ 'panels' ] [ $panelID ] [ $rowID ] = $row ;                }            }        }                return $this->_viewdefs [ 'panels' ] ;    }    function getMaxColumns ()    {        return $this->_viewdefs [ 'templateMeta' ] [ 'maxColumns' ] ;    }    function getAvailableFields ()    {                $availableFields = array ( ) ;        foreach ( $this->_fielddefs as $field => $def )        {            $label = isset ( $def [ 'vname' ] ) ? $def [ 'vname' ] : $def [ 'name' ] ;            $availableFields [ $field ] = array ( 'name' => $field , 'label' => $label ) ;        }        // Available fields are those that are in the Model and the original layout definition, but not already shown in the View        // So, because the formats of the two are different we brute force loop through View and unset the fields we find in a copy of Model        if (! empty ( $this->_viewdefs ))        {            foreach ( $this->_viewdefs [ 'panels' ] as $panel )            {                foreach ( $panel as $row )                {                    foreach ( $row as $fieldArray )                    { // fieldArray is an array('name'=>name,'label'=>label)                        if (isset ( $fieldArray [ 'name' ] ))                        {                            unset ( $availableFields [ $fieldArray [ 'name' ] ] ) ;                        }                    }                }            }        }        return $availableFields ;    }    /*     * Add a new field to the layout     * If $panelID is passed in, attempt to add to that panel, otherwise add to the first panel     * The field is added in place of the first empty (not filler) slot after the last field in the panel; if that row is full, then a new row will be added to the end of the panel     * and the field added to the start of it.      * @param array $properties Set of properties for the field, in same format as in the viewdefs     * @param string $panelID Identifier of the panel to add the field to; empty or false if we should use the first panel     */    function addField ($properties , $panelID = FALSE)    {                if (count ( $this->_viewdefs [ 'panels' ] ) == 0)        {            $GLOBALS [ 'log' ]->error ( get_class ( $this ) . "->addField(): _viewdefs empty for module {$this->_moduleName} and view {$this->_view}" ) ;        }        // if a panelID was not provided, use the first available panel in the list        if (! $panelID)        {            $panels = array_keys ( $this->_viewdefs [ 'panels' ] ) ;            list ( $dummy, $panelID ) = each ( $panels ) ;        }                if (isset ( $this->_viewdefs [ 'panels' ] [ $panelID ] ))        {                        $panel = $this->_viewdefs [ 'panels' ] [ $panelID ] ;            $lastrow = count ( $panel ) - 1 ; // index starts at 0            $maxColumns = $this->getMaxColumns () ;            for ( $column = 0 ; $column < $maxColumns ; $column ++ )            {                if (! isset ( $this->_viewdefs [ 'panels' ] [ $panelID ] [ $lastrow ] [ $column ] ) || ($this->_viewdefs [ 'panels' ] [ $panelID ] [ $lastrow ] [ $column ] [ 'name' ] == '(empty)'))                    break ;            }                        // if we're on the last column of the last row, start a new row            if ($column >= $maxColumns)            {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?