parser.modifylayoutview.php
来自「SugarCRM5.1 开源PHP客户关系管理系统」· PHP 代码 · 共 517 行 · 第 1/2 页
PHP
517 行
<?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/ModuleBuilderParser.php');class ParserModifyLayoutView extends ModuleBuilderParser{ var $maxColumns; // number of columns in this layout var $usingWorkingFile = false; // if a working file exists (used by view.edit.php among others to determine the title for the layout edit panel) var $language_module; // set to module name for studio, passed to the smarty template and used by sugar_translate var $_sourceFile; // private - the source of the layout defn var $_customFile; // private var $_workingFile; // private var $_originalFile; //private var $_moduleVariable; // private - if set, contains the name of the variable containing the module name in the $viewdef file var $_module; // private var $_view; // private var $_viewdefs; // private var $_fieldDefs; // private /** * Constructor */ function init ($module, $view, $submittedLayout = false) { $this->_view = ucfirst($view); $this->_module = $module; $this->language_module = $module; $this->_baseDirectory = "modules/{$module}/metadata/"; $file = $this->_baseDirectory . strtolower($view) . "defs.php"; $this->_customFile = "custom/" . $file; $this->_workingFile = "custom/working/" . $file; $this->_sourceView = $this->_view; $this->_originalFile = $file ; $this->_sourceFile = $file; if (is_file($this->_workingFile)) { $this->_sourceFile = $this->_workingFile; $this->usingWorkingFile = true; } else if (is_file($this->_customFile)) { $this->_sourceFile = $this->_customFile; } else if (! is_file($this->_sourceFile)) { // if we don't have ANY defined metadata then improvise as best we can if (strtolower($this->_view) == 'quickcreate') { // special handling for quickcreates - base the quickcreate on the editview if no quickcreatedef exists $this->_sourceFile = $this->_baseDirectory."editviewdefs.php"; if (is_file("custom/" . $this->_sourceFile)) { $this->_sourceFile = "custom/" . $this->_sourceFile; } $this->_sourceView = 'EditView'; } else { $this->_fatalError('parser.modifylayout.php->init(): no metadata for '.$this->_module.' '.$this->_view); } } // get the fieldDefs from the bean $class = $GLOBALS ['beanList'] [$module]; require_once ($GLOBALS ['beanFiles'] [$class]); $bean = new $class(); $this->_fieldDefs = & $bean->field_defs; $this->loadModule($this->_module, $this->_sourceView); $this->_viewdefs ['panels'] = $this->_parseData($this->_viewdefs['panels']); // put into a canonical format $this->maxColumns = $this->_viewdefs ['templateMeta'] ['maxColumns']; if ($submittedLayout) { // replace the definitions with the new submitted layout $this->_loadLayoutFromRequest(); } else { $this->_padFields(); // destined for a View, so we want to add in (empty) fields }// $GLOBALS['log']->debug($this->_viewdefs['panels']); } function getAvailableFields () { // 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 $availableFields = $this->_getModelFields(); $GLOBALS['log']->debug( get_class($this)."->getAvailableFields(): _getModelFields returns: ".implode(",",array_keys($availableFields))); 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']]); $GLOBALS['log']->debug( get_class($this)."->getAvailableFields(): removing ".$fieldArray ['name'] ); } } } } } return $availableFields; } function getLayout () { return $this->_viewdefs ['panels']; } function writeWorkingFile () { $this->_writeToFile($this->_workingFile,$this->_view,$this->_module,$this->_viewdefs,$this->_variables); } function handleSave () { $this->_writeToFile($this->_customFile,$this->_view,$this->_module,$this->_viewdefs,$this->_variables); // now clear the cache so that the results are immediately visible include_once('include/TemplateHandler/TemplateHandler.php'); TemplateHandler::clearCache($this->_module,"{$this->_view}.tpl"); } function loadModule ($module, $view) { $this->_viewdefs = array(); $viewdefs = null; $loaded = $this->_loadFromFile($view,$this->_sourceFile,$module); $this->_viewdefs = $loaded['viewdefs'][$module][$view]; $this->_variables = $loaded['variables']; } /** * Load the canonical panel layout from the submitted form * */ function _loadLayoutFromRequest () { $i = 1; // set up the map of panel# (as provided in the _REQUEST) to panel ID (as used in $this->_viewdefs['panels']) foreach ($this->_viewdefs ['panels'] as $panelID => $panel) { $panelMap [$i ++] = $panelID; } // replace any old values with new panel labels from the request foreach ($_REQUEST as $key => $value) { $components = explode('-', $key); if ($components [0] == 'panel') { $panelMap [$components ['1']] = $value; } } $olddefs = $this->_viewdefs ['panels']; $origFieldDefs = $this->_getOrigFieldViewDefs();// $GLOBALS['log']->debug('origFieldDefs');// $GLOBALS['log']->debug($origFieldDefs); $this->_viewdefs ['panels'] = null; // because the new field properties should replace the old fields, not be merged if ($this->maxColumns < 1) { $this->_fatalError("EditDetailViewParser:invalid maxColumns=" . $this->maxColumns); } foreach ($_REQUEST as $slot => $value) { $slotComponents = explode('-', $slot); // [0] = 'slot', [1] = panel #, [2] = slot #, [3] = property name if ($slotComponents [0] == 'slot') { $slotNumber = $slotComponents ['2']; $panelID = $panelMap [$slotComponents ['1']]; $rowID = floor($slotNumber / $this->maxColumns); $colID = $slotNumber - ($rowID * $this->maxColumns); //If the original editview defined this field, copy that over. if ($slotComponents ['3'] == 'name' && isset($origFieldDefs [$value]) && is_array($origFieldDefs [$value])) { $this->_viewdefs ['panels'] [$panelID] [$rowID] [$colID] = $origFieldDefs [$value]; } else { $property = $slotComponents ['3']; if ($value == '(filler)') { $this->_viewdefs ['panels'] [$panelID] [$rowID] [$colID] = NULL; } else { $this->_viewdefs ['panels'] [$panelID] [$rowID] [$colID] [$property] = $value; } } } } // Now handle the (empty) fields - first non-(empty) field goes in at column 0; all other (empty)'s removed // Do this AFTER reading in all the $_REQUEST parameters as can't guarantee the order of those, and we need to operate on complete rows foreach ($this->_viewdefs ['panels'] as $panelID => $panel) { // remove all (empty)s foreach ($panel as $rowID => $row) { $startOfRow = true; $offset = 0; foreach ($row as $colID => $col) { if ($col ['name'] == '(empty)') { // if a leading (empty) then remove (by noting that remaining fields need to be shuffled along) if ($startOfRow) { $offset ++; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?