gridlayoutmetadataparser.php
来自「SugarCRM5.1 开源PHP客户关系管理系统」· PHP 代码 · 共 510 行 · 第 1/2 页
PHP
510 行
$lastrow ++ ; $this->_viewdefs [ 'panels' ] [ $panelID ] [ $lastrow ] = array ( ) ; $column = 0 ; } $this->_viewdefs [ 'panels' ] [ $panelID ] [ $lastrow ] [ $column ] = $properties ; } return true ; } /* * Remove all instances of a field from the layout, and replace by (empty) * If the last row of a panel only consists of empty after removing the fields, then remove the row also. This undoes the standard addField() scenario; * if the fields had been moved around in the layout however then this will not completely undo any addField() * @param string $fieldName Name of the field to remove * @return boolean True if the field was removed; false otherwise */ function removeField ($fieldName) { $result = false ; foreach ( $this->_viewdefs [ 'panels' ] as $panelID => $panel ) { foreach ( $panel as $rowID => $row ) { foreach ( $row as $colID => $field ) if ($field [ 'name' ] == $fieldName) { $result = true ; $this->_viewdefs [ 'panels' ] [ $panelID ] [ $rowID ] [ $colID ] = self::$empty ; } $lastRowID = $rowID ; } // now remove the last row in this panel if it now consists only of (empty) $lastRow = $this->_viewdefs [ 'panels' ] [ $panelID ] [ $lastRowID ] ; $empty = true ; foreach ( $lastRow as $colID => $field ) $empty = $empty && ($field == self::$empty) ; if ($empty) unset ( $this->_viewdefs [ 'panels' ] [ $panelID ] [ $lastRowID ] ) ; } return $result ; } /* * Return an integer value for the next unused panel identifier, such that it and any larger numbers are guaranteed to be unused already in the layout * Necessary when adding new panels to a layout * @return integer First unique panel ID suffix */ function getFirstNewPanelId () { $firstNewPanelId = 0 ; foreach ( $this->_viewdefs [ 'panels' ] as $panelID => $panel ) { // strip out all but the numerics from the panelID - can't just use a cast as numbers may not be first in the string for ( $i = 0, $result = '' ; $i < strlen ( $panelID ) ; $i ++ ) { if (is_numeric ( $panelID [ $i ] )) { $result .= $panelID [ $i ] ; } } $firstNewPanelId = max ( ( int ) $result, $firstNewPanelId ) ; } return $firstNewPanelId + 1 ; } /* * Load the canonical panel layout from the submitted form and update the _viewdefs */ private function _populateFromRequest () { $GLOBALS['log']->setLevel('debug'); $GLOBALS [ 'log' ]->debug ( get_class ( $this ) . "->populateFromRequest()" ) ; $i = 1 ; // set up the map of panel# (as provided in the _REQUEST) to panel ID (as used in $this->_viewdefs['panels']) $i = 1 ; foreach ( $this->_viewdefs [ 'panels' ] as $panelID => $panel ) { $panelMap [ $i ++ ] = $panelID ; } foreach ( $_REQUEST as $key => $displayLabel ) { $components = explode ( '-', $key ) ; if ($components [ 0 ] == 'panel') { $panelMap [ $components [ '1' ] ] = $displayLabel ; } } $origFieldDefs = $this->_getFieldDefs ( $this->_viewdefs [ 'panels' ] ) ; $GLOBALS['log']->debug( print_r($origFieldDefs,true)); $this->_viewdefs [ 'panels' ] = array ( ) ; // because the new field properties should replace the old fields, not be merged 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->getMaxColumns () ) ; $colID = $slotNumber - ($rowID * $this->getMaxColumns ()) ; $property = $slotComponents [ '3' ] ; //If the original editview defined this field, copy that over, ignoring any (filler) values that might be in there if ($property == 'name' && $value != '(filler)' && isset ( $origFieldDefs [ $value ] ) && is_array ( $origFieldDefs [ $value ] )) { $this->_viewdefs [ 'panels' ] [ $panelID ] [ $rowID ] [ $colID ] = $origFieldDefs [ $value ] ; } else { if ($value == '(filler)') { $this->_viewdefs [ 'panels' ] [ $panelID ] [ $rowID ] [ $colID ] = NULL ; } else { $this->_viewdefs [ 'panels' ] [ $panelID ] [ $rowID ] [ $colID ] [ $property ] = $value ; } } } } $GLOBALS['log']->debug( print_r($this->_viewdefs [ 'panels' ],true)); $GLOBALS['log']->setLevel('fatal'); // 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 ++ ; } unset ( $row [ $colID ] ) ; } else { $startOfRow = false ; } } // reindex to remove leading (empty)s $newRow = array ( ) ; foreach ( $row as $colID => $col ) { $newRow [ $colID - $offset ] = $col ; } $this->_viewdefs [ 'panels' ] [ $panelID ] [ $rowID ] = $newRow ; } } } private function _standardizeLayout ($panels) { if (empty ( $panels )) return ; // Fix for a flexibility in the format of the panel sections - if only one panel, then we don't have a panel level defined, it goes straight into rows // See EditView2 for similar treatment if (! empty ( $panels ) && count ( $panels ) > 0) { $keys = array_keys ( $panels ) ; if (is_numeric ( $keys [ 0 ] )) { $defaultPanel = $panels ; unset ( $panels ) ; //blow away current value $panels [ 'default' ] = $defaultPanel ; } } $newPanels = array ( ) ; foreach ( $panels as $panelID => $panel ) { foreach ( $panel as $rowID => $row ) { foreach ( $row as $colID => $col ) { $properties = array ( ) ; if (! empty ( $col )) { if (is_string ( $col )) { $properties [ 'name' ] = $col ; } else if (! empty ( $col [ 'name' ] )) { $properties = $col ; } } else { $properties [ 'name' ] = '(filler)' ; // was translate ('LBL_FILLER') but studio2.js relies on (filler) regardless of language... $properties [ 'label' ] = translate ( 'LBL_FILLER' ) ; } if (! empty ( $properties [ 'name' ] )) { // get this field's label - if it has not been explicity provided, see if the fieldDefs has a label for this field, and if not fallback to the field name if (! isset ( $properties [ 'label' ] )) { if (! empty ( $this->_fielddefs [ $properties [ 'name' ] ] [ 'vname' ] )) { $properties [ 'label' ] = $this->_fielddefs [ $properties [ 'name' ] ] [ 'vname' ] ; } else { $properties [ 'label' ] = $properties [ 'name' ] ; } } $newPanels [ $panelID ] [ $rowID ] [ $colID ] = $properties ; } } } } return $newPanels ; } /* * Generate a list of field names with associated field definitions from the viewdefs * Used to ensure that we don't lose any field definition information supplied in the viewdefs that may not be in either the module field definitions, or in the _POST response * @param array $panelDefs Panel section of the viewdefs * @return array Field name => Field definition */ private function _getFieldDefs ($panelDefs) { $fieldDefs = array ( ) ; foreach ( $panelDefs as $pname => $paneldef ) { foreach ( $paneldef as $row ) { foreach ( $row as $fieldDef ) { $fieldDefs [ $fieldDef [ 'name' ] ] = $fieldDef ; } } } return $fieldDefs ; }}?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?