2 if (! defined ( 'sugarEntry' ) || ! sugarEntry)
3 die ( 'Not A Valid Entry Point' ) ;
4 /*********************************************************************************
5 * SugarCRM Community Edition is a customer relationship management program developed by
6 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU Affero General Public License version 3 as published by the
10 * Free Software Foundation with the addition of the following permission added
11 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
12 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
13 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
20 * You should have received a copy of the GNU Affero General Public License along with
21 * this program; if not, see http://www.gnu.org/licenses or write to the Free
22 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
26 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
28 * The interactive user interfaces in modified source and object code versions
29 * of this program must display Appropriate Legal Notices, as required under
30 * Section 5 of the GNU Affero General Public License version 3.
32 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
33 * these Appropriate Legal Notices must retain the display of the "Powered by
34 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
35 * technical reasons, the Appropriate Legal Notices must display the words
36 * "Powered by SugarCRM".
37 ********************************************************************************/
40 require_once 'modules/ModuleBuilder/parsers/views/AbstractMetaDataParser.php' ;
41 require_once 'modules/ModuleBuilder/parsers/views/MetaDataParserInterface.php' ;
42 require_once 'modules/ModuleBuilder/parsers/constants.php' ;
44 class GridLayoutMetaDataParser extends AbstractMetaDataParser implements MetaDataParserInterface
47 static $variableMap = array (
48 MB_EDITVIEW => 'EditView' ,
49 MB_DETAILVIEW => 'DetailView' ,
50 MB_QUICKCREATE => 'QuickCreate',
57 * @param string view The view type, that is, editview, searchview etc
58 * @param string moduleName The name of the module to which this view belongs
59 * @param string packageName If not empty, the name of the package to which this view belongs
61 function __construct ($view , $moduleName , $packageName = '')
63 $GLOBALS [ 'log' ]->debug ( get_class ( $this ) . "->__construct( {$view} , {$moduleName} , {$packageName} )" ) ;
65 $view = strtolower ( $view ) ;
67 $this->FILLER = array ( 'name' => MBConstants::$FILLER['name'] , 'label' => translate ( MBConstants::$FILLER['label'] ) ) ;
69 $this->_moduleName = $moduleName ;
70 $this->_view = $view ;
72 if (empty ( $packageName ))
74 require_once 'modules/ModuleBuilder/parsers/views/DeployedMetaDataImplementation.php' ;
75 $this->implementation = new DeployedMetaDataImplementation ( $view, $moduleName, self::$variableMap ) ;
78 require_once 'modules/ModuleBuilder/parsers/views/UndeployedMetaDataImplementation.php' ;
79 $this->implementation = new UndeployedMetaDataImplementation ( $view, $moduleName, $packageName ) ;
82 $viewdefs = $this->implementation->getViewdefs () ;
83 if (!isset(self::$variableMap [ $view ]))
84 self::$variableMap [ $view ] = $view;
86 if (!isset($viewdefs [ self::$variableMap [ $view ]])){
87 sugar_die ( get_class ( $this ) . ": incorrect view variable for $view" ) ;
90 $viewdefs = $viewdefs [ self::$variableMap [ $view ] ] ;
91 if (! isset ( $viewdefs [ 'templateMeta' ] ))
92 sugar_die ( get_class ( $this ) . ": missing templateMeta section in layout definition (case sensitive)" ) ;
94 if (! isset ( $viewdefs [ 'panels' ] ))
95 sugar_die ( get_class ( $this ) . ": missing panels section in layout definition (case sensitive)" ) ;
97 $this->_viewdefs = $viewdefs ;
98 if ($this->getMaxColumns () < 1)
99 sugar_die ( get_class ( $this ) . ": maxColumns=" . $this->getMaxColumns () . " - must be greater than 0!" ) ;
101 $this->_fielddefs = $this->implementation->getFielddefs() ;
102 $this->_standardizeFieldLabels( $this->_fielddefs );
103 $this->_viewdefs [ 'panels' ] = $this->_convertFromCanonicalForm ( $this->_viewdefs [ 'panels' ] , $this->_fielddefs ) ; // put into our internal format
104 $this->_originalViewDef = $this->getFieldsFromLayout($this->implementation->getOriginalViewdefs ());
108 * Save a draft layout
110 function writeWorkingFile ($populate = true)
113 $this->_populateFromRequest ( $this->_fielddefs ) ;
115 $viewdefs = $this->_viewdefs ;
116 $viewdefs [ 'panels' ] = $this->_convertToCanonicalForm ( $this->_viewdefs [ 'panels' ] , $this->_fielddefs ) ;
117 $this->implementation->save ( array ( self::$variableMap [ $this->_view ] => $viewdefs ) ) ;
122 * @param boolean $populate If true (default), then update the layout first with new layout information from the $_REQUEST array
124 function handleSave ($populate = true)
126 $GLOBALS [ 'log' ]->info ( get_class ( $this ) . "->handleSave()" ) ;
129 $this->_populateFromRequest ( $this->_fielddefs ) ;
131 $viewdefs = $this->_viewdefs ;
132 $viewdefs [ 'panels' ] = $this->_convertToCanonicalForm ( $this->_viewdefs [ 'panels' ] , $this->_fielddefs ) ;
133 $this->implementation->deploy ( array ( self::$variableMap [ $this->_view ] => $viewdefs ) ) ;
137 * Return the layout, padded out with (empty) and (filler) fields ready for display
139 function getLayout ()
141 $viewdefs = array () ;
142 $fielddefs = $this->_fielddefs;
143 $fielddefs [ $this->FILLER [ 'name' ] ] = $this->FILLER ;
144 $fielddefs [ MBConstants::$EMPTY [ 'name' ] ] = MBConstants::$EMPTY ;
146 foreach ( $this->_viewdefs [ 'panels' ] as $panelID => $panel )
148 foreach ( $panel as $rowID => $row )
150 foreach ( $row as $colID => $fieldname )
152 if (isset ($this->_fielddefs [ $fieldname ]))
154 $viewdefs [ $panelID ] [ $rowID ] [ $colID ] = self::_trimFieldDefs( $this->_fielddefs [ $fieldname ] ) ;
156 else if (isset($this->_originalViewDef [ $fieldname ]) && is_array($this->_originalViewDef [ $fieldname ]))
158 $viewdefs [ $panelID ] [ $rowID ] [ $colID ] = self::_trimFieldDefs( $this->_originalViewDef [ $fieldname ] ) ;
162 $viewdefs [ $panelID ] [ $rowID ] [ $colID ] = array("name" => $fieldname, "label" => $fieldname);
170 function getMaxColumns ()
172 if (!empty( $this->_viewdefs) && isset($this->_viewdefs [ 'templateMeta' ] [ 'maxColumns' ]))
174 return $this->_viewdefs [ 'templateMeta' ] [ 'maxColumns' ] ;
181 function getAvailableFields ()
184 // Obtain the full list of valid fields in this module
185 $availableFields = array () ;
186 foreach ( $this->_fielddefs as $key => $def )
188 if ( GridLayoutMetaDataParser::validField ( $def, $this->_view ) || isset($this->_originalViewDef[$key]) )
190 //If the field original label existing, we should use the original label instead the label in its fielddefs.
191 if(isset($this->_originalViewDef[$key]) && is_array($this->_originalViewDef[$key]) && isset($this->_originalViewDef[$key]['label'])){
192 $availableFields [ $key ] = array ( 'name' => $key , 'label' => $this->_originalViewDef[$key]['label']) ;
194 $availableFields [ $key ] = array ( 'name' => $key , 'label' => isset($def [ 'label' ]) ? $def [ 'label' ] : $def['vname'] ) ; // layouts use 'label' not 'vname' for the label entry
197 $availableFields[$key]['translatedLabel'] = translate( isset($def [ 'label' ]) ? $def [ 'label' ] : $def['vname'], $this->_moduleName);
202 // Available fields are those that are in the Model and the original layout definition, but not already shown in the View
203 // 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
204 if (! empty ( $this->_viewdefs ))
206 foreach ( $this->_viewdefs [ 'panels' ] as $panel )
208 foreach ( $panel as $row )
210 foreach ( $row as $field )
212 unset ( $availableFields [ $field ] ) ;
218 //eggsurplus: Bug 10329 - sort on intuitive display labels
219 //sort by translatedLabel
220 function cmpLabel($a, $b)
222 return strcmp($a["translatedLabel"], $b["translatedLabel"]);
224 usort($availableFields , 'cmpLabel');
226 return $availableFields ;
229 function getPanelDependency ( $panelID )
231 if ( ! isset ( $this->_viewdefs [ 'templateMeta' ][ 'dependency' ] ) && ! isset ( $this->_viewdefs [ 'templateMeta' ][ 'dependency' ] [ $panelID ] ) )
234 return $this->_viewdefs [ 'templateMeta' ][ 'dependency' ] [ $panelID ] ;
238 * Add a new field to the layout
239 * If $panelID is passed in, attempt to add to that panel, otherwise add to the first panel
240 * 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
241 * and the field added to the start of it.
242 * @param array $def Set of properties for the field, in same format as in the viewdefs
243 * @param string $panelID Identifier of the panel to add the field to; empty or false if we should use the first panel
245 function addField ( $def , $panelID = FALSE)
248 if (count ( $this->_viewdefs [ 'panels' ] ) == 0)
250 $GLOBALS [ 'log' ]->error ( get_class ( $this ) . "->addField(): _viewdefs empty for module {$this->_moduleName} and view {$this->_view}" ) ;
253 // if a panelID was not provided, use the first available panel in the list
256 $panels = array_keys ( $this->_viewdefs [ 'panels' ] ) ;
257 list ( $dummy, $panelID ) = each ( $panels ) ;
260 if (isset ( $this->_viewdefs [ 'panels' ] [ $panelID ] ))
263 $panel = $this->_viewdefs [ 'panels' ] [ $panelID ] ;
264 $lastrow = count ( $panel ) - 1 ; // index starts at 0
265 $maxColumns = $this->getMaxColumns () ;
266 $lastRowDef = $this->_viewdefs [ 'panels' ] [ $panelID ] [ $lastrow ];
267 for ( $column = 0 ; $column < $maxColumns ; $column ++ )
269 if (! isset ( $lastRowDef [ $column ] )
270 || (is_array( $lastRowDef [ $column ]) && $lastRowDef [ $column ][ 'name' ] == '(empty)')
271 || (is_string( $lastRowDef [ $column ]) && $lastRowDef [ $column ] == '(empty)')
277 // if we're on the last column of the last row, start a new row
278 if ($column >= $maxColumns)
281 $this->_viewdefs [ 'panels' ] [ $panelID ] [ $lastrow ] = array ( ) ;
285 $this->_viewdefs [ 'panels' ] [ $panelID ] [ $lastrow ] [ $column ] = $def [ 'name' ] ;
286 // now update the fielddefs
287 if (isset($this->_fielddefs [ $def [ 'name' ] ]))
289 $this->_fielddefs [ $def [ 'name' ] ] = array_merge ( $this->_fielddefs [ $def [ 'name' ] ] , $def ) ;
292 $this->_fielddefs [ $def [ 'name' ] ] = $def;
299 * Remove all instances of a field from the layout, and replace by (filler)
300 * Filler because we attempt to preserve the customized layout as much as possible - replacing by (empty) would mean that the positions or sizes of adjacent fields may change
301 * If the last row of a panel only consists of (filler) after removing the fields, then remove the row also. This undoes the standard addField() scenario;
302 * If the fields had been moved around in the layout however then this will not completely undo any addField()
303 * @param string $fieldName Name of the field to remove
304 * @return boolean True if the field was removed; false otherwise
306 function removeField ($fieldName)
308 $GLOBALS [ 'log' ]->info ( get_class ( $this ) . "->removeField($fieldName)" ) ;
311 reset ( $this->_viewdefs ) ;
312 $firstPanel = each ( $this->_viewdefs [ 'panels' ] ) ;
313 $firstPanelID = $firstPanel [ 'key' ] ;
315 foreach ( $this->_viewdefs [ 'panels' ] as $panelID => $panel )
317 $lastRowTouched = false ;
318 $lastRowID = count ( $this->_viewdefs [ 'panels' ] [ $panelID ] ) - 1 ; // zero offset
320 foreach ( $panel as $rowID => $row )
323 foreach ( $row as $colID => $field )
324 if ($field == $fieldName)
326 $lastRowTouched = $rowID ;
327 $this->_viewdefs [ 'panels' ] [ $panelID ] [ $rowID ] [ $colID ] = $this->FILLER [ 'name' ];
332 // if we removed a field from the last row of this panel, tidy up if the last row now consists only of (empty) or (filler)
334 if ( $lastRowTouched == $lastRowID )
336 $lastRow = $this->_viewdefs [ 'panels' ] [ $panelID ] [ $lastRowID ] ; // can't use 'end' for this as we need the key as well as the value...
340 foreach ( $lastRow as $colID => $field )
341 $empty &= $field == MBConstants::$EMPTY ['name' ] || $field == $this->FILLER [ 'name' ] ;
345 unset ( $this->_viewdefs [ 'panels' ] [ $panelID ] [ $lastRowID ] ) ;
346 // if the row was the only one in the panel, and the panel is not the first (default) panel, then remove the panel also
347 if ( count ( $this->_viewdefs [ 'panels' ] [ $panelID ] ) == 0 && $panelID != $firstPanelID )
348 unset ( $this->_viewdefs [ 'panels' ] [ $panelID ] ) ;
353 $result |= ($lastRowTouched !== false ); // explicitly compare to false as row 0 will otherwise evaluate as false
360 function setPanelDependency ( $panelID , $dependency )
362 // only accept dependencies for pre-existing panels
363 if ( ! isset ( $this->_viewdefs [ 'panels' ] [ $panelID ] ) )
366 $this->_viewdefs [ 'templateMeta' ] [ 'dependency' ] [ $panelID ] = $dependency ;
371 * 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
372 * Necessary when adding new panels to a layout
373 * @return integer First unique panel ID suffix
375 function getFirstNewPanelId ()
377 $firstNewPanelId = 0 ;
378 foreach ( $this->_viewdefs [ 'panels' ] as $panelID => $panel )
380 // strip out all but the numerics from the panelID - can't just use a cast as numbers may not be first in the string
381 for ( $i = 0, $result = '' ; $i < strlen ( $panelID ) ; $i ++ )
383 if (is_numeric ( $panelID [ $i ] ))
385 $result .= $panelID [ $i ] ;
389 $firstNewPanelId = max ( ( int ) $result, $firstNewPanelId ) ;
391 return $firstNewPanelId + 1 ;
395 * Load the panel layout from the submitted form and update the _viewdefs
397 protected function _populateFromRequest ( &$fielddefs )
399 $GLOBALS [ 'log' ]->debug ( get_class ( $this ) . "->populateFromRequest()" ) ;
402 // set up the map of panel# (as provided in the _REQUEST) to panel ID (as used in $this->_viewdefs['panels'])
404 foreach ( $this->_viewdefs [ 'panels' ] as $panelID => $panel )
406 $panelMap [ $i ++ ] = $panelID ;
409 foreach ( $_REQUEST as $key => $displayLabel )
411 $components = explode ( '-', $key ) ;
412 if ($components [ 0 ] == 'panel' && $components [ 2 ] == 'label')
414 $panelMap [ $components [ '1' ] ] = $displayLabel ;
418 $this->_viewdefs [ 'panels' ] = array () ; // because the new field properties should replace the old fields, not be merged
420 // run through the $_REQUEST twice - first to obtain the fieldnames, the second to update the field properties
421 for ( $pass=1 ; $pass<=2 ; $pass++ )
423 foreach ( $_REQUEST as $slot => $value )
425 $slotComponents = explode ( '-', $slot ) ; // [0] = 'slot', [1] = panel #, [2] = slot #, [3] = property name
427 if ($slotComponents [ 0 ] == 'slot')
429 $slotNumber = $slotComponents [ '2' ] ;
430 $panelID = $panelMap [ $slotComponents [ '1' ] ] ;
431 $rowID = floor ( $slotNumber / $this->getMaxColumns () ) ;
432 $colID = $slotNumber - ($rowID * $this->getMaxColumns ()) ;
433 $property = $slotComponents [ '3' ] ;
435 //If this field has a custom definition, copy that over
438 if ( $property == 'name' )
439 $this->_viewdefs [ 'panels' ] [ $panelID ] [ $rowID ] [ $colID ] = $value ;
442 // update fielddefs for this property in the provided position
443 if ( isset ( $this->_viewdefs [ 'panels' ] [ $panelID ] [ $rowID ] [ $colID ] ) )
445 $fieldname = $this->_viewdefs [ 'panels' ] [ $panelID ] [ $rowID ] [ $colID ] ;
446 $fielddefs [ $fieldname ] [ $property ] = $value ;
454 //Set the tabs setting
455 if (isset($_REQUEST['panels_as_tabs']))
457 if ($_REQUEST['panels_as_tabs'] == false || $_REQUEST['panels_as_tabs'] == "false")
458 $this->setUseTabs( false );
460 $this->setUseTabs( true );
463 //bug: 38232 - Set the sync detail and editview settings
464 if (isset($_REQUEST['sync_detail_and_edit']))
466 if ($_REQUEST['sync_detail_and_edit'] === false || $_REQUEST['sync_detail_and_edit'] === "false")
468 $this->setSyncDetailEditViews( false );
470 elseif(!empty($_REQUEST['sync_detail_and_edit']))
472 $this->setSyncDetailEditViews( true );
476 $GLOBALS [ 'log' ]->debug ( print_r ( $this->_viewdefs [ 'panels' ], true ) ) ;
480 /* Convert our internal format back to the standard Canonical MetaData layout
481 * First non-(empty) field goes in at column 0; all other (empty)'s removed
482 * Studio required fields are also added to the layout.
483 * 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
485 protected function _convertToCanonicalForm ( $panels , $fielddefs )
487 $previousViewDef = $this->getFieldsFromLayout($this->implementation->getViewdefs ());
488 $oldDefs = $this->implementation->getViewdefs ();
489 $currentFields = $this->getFieldsFromLayout($this->_viewdefs);
490 foreach($fielddefs as $field => $def)
492 if (self::fieldIsRequired($def) && !isset($currentFields[$field]))
494 //Use the previous viewdef if this field was on it.
495 if (isset($previousViewDef[$field]))
497 $def = $previousViewDef[$field];
499 //next see if the field was on the original layout.
500 else if (isset ($this->_originalViewDef [ $field ]))
502 $def = $this->_originalViewDef [ $field ] ;
504 //Otherwise make up a viewdef for it from field_defs
507 $def = self::_trimFieldDefs( $def ) ;
509 $this->addField($def);
513 foreach ( $panels as $panelID => $panel )
515 // remove all (empty)s
516 foreach ( $panel as $rowID => $row )
520 foreach ( $row as $colID => $fieldname )
522 if ($fieldname == MBConstants::$EMPTY[ 'name' ])
524 // if a leading (empty) then remove (by noting that remaining fields need to be shuffled along)
529 unset ( $row [ $colID ] ) ;
532 $startOfRow = false ;
536 // reindex to remove leading (empty)s and replace fieldnames by full definition from fielddefs
537 $newRow = array ( ) ;
538 foreach ( $row as $colID => $fieldname )
540 if ($fieldname == null || !isset($fielddefs[$fieldname]))
543 //Backwards compatibility and a safeguard against multiple calls to _convertToCanonicalForm
544 if(is_array($fieldname))
546 $newRow [ $colID - $offset ] = $fieldname;
550 //Replace (filler) with the empty string
551 if ($fieldname == $this->FILLER[ 'name' ]) {
552 $newRow [ $colID - $offset ] = '' ;
554 //Use the previous viewdef if this field was on it.
555 else if (isset($previousViewDef[$fieldname]))
557 $newRow[$colID - $offset] = $this->getNewRowItem($previousViewDef[$fieldname], $fielddefs[$fieldname]);
559 //next see if the field was on the original layout.
560 else if (isset ($this->_originalViewDef [ $fieldname ]))
562 $newRow[$colID - $offset] = $this->getNewRowItem($this->_originalViewDef[$fieldname], $fielddefs[$fieldname]);
564 //Otherwise make up a viewdef for it from field_defs
565 else if (isset ($fielddefs [ $fieldname ]))
567 $newRow [ $colID - $offset ] = self::_trimFieldDefs( $fielddefs [ $fieldname ] ) ;
570 //No additional info on this field can be found, jsut use the name;
573 $newRow [ $colID - $offset ] = $fieldname;
576 $panels [ $panelID ] [ $rowID ] = $newRow ;
584 * fixing bug #44428: Studio | Tab Order causes layout errors
585 * @param string|array $source it can be a string which contain just a name of field
586 * or an array with field attributes including name
587 * @param array $fielddef stores field defs from request
588 * @return string|array definition of new row item
590 function getNewRowItem($source, $fielddef)
592 //We should copy over the tabindex if it is set.
594 if (isset ($fielddef) && !empty($fielddef['tabindex']))
596 if (is_array($source))
602 $newRow['name'] = $source;
604 $newRow['tabindex'] = $fielddef['tabindex'];
614 * Convert from the standard MetaData format to our internal format
615 * Replace NULL with (filler) and missing entries with (empty)
617 protected function _convertFromCanonicalForm ( $panels , $fielddefs )
619 if (empty ( $panels ))
622 // Fix for a flexibility in the format of the panel sections - if only one panel, then we don't have a panel level defined,
623 // it goes straight into rows
624 // See EditView2 for similar treatment
625 if (! empty ( $panels ) && count ( $panels ) > 0)
627 $keys = array_keys ( $panels ) ;
628 if (is_numeric ( $keys [ 0 ] ))
630 $defaultPanel = $panels ;
631 unset ( $panels ) ; //blow away current value
632 $panels [ 'default' ] = $defaultPanel ;
636 $newPanels = array ( ) ;
638 // replace '' with (filler)
639 foreach ( $panels as $panelID => $panel )
641 foreach ( $panel as $rowID => $row )
644 foreach ( $row as $colID => $col )
646 if ( ! empty ( $col ) )
648 if ( is_string ( $col ))
651 } else if (! empty ( $col [ 'name' ] ))
653 $fieldname = $col [ 'name' ] ;
657 $fieldname = $this->FILLER['name'] ;
660 $newPanels [ $panelID ] [ $rowID ] [ $cols ] = $fieldname ;
666 // replace missing fields with (empty)
667 foreach ( $newPanels as $panelID => $panel )
670 foreach ( $panel as $rowID => $row )
672 // pad between fields on a row
673 foreach ( $row as $colID => $col )
675 for ( $i = $column + 1 ; $i < $colID ; $i ++ )
677 $row [ $i ] = MBConstants::$EMPTY ['name'];
681 // now pad out to the end of the row
682 if (($column + 1) < $this->getMaxColumns ())
683 { // last column is maxColumns-1
684 for ( $i = $column + 1 ; $i < $this->getMaxColumns () ; $i ++ )
686 $row [ $i ] = MBConstants::$EMPTY ['name'] ;
690 $newPanels [ $panelID ] [ $rowID ] = $row ;
697 protected function getFieldsFromLayout($viewdef) {
698 if (isset($viewdef['panels']))
700 $panels = $viewdef['panels'];
702 $panels = $viewdef[self::$variableMap [ $this->_view ] ]['panels'];
706 if (is_array($panels))
708 foreach ( $panels as $rows) {
709 foreach ($rows as $fields) {
710 //wireless layouts have one less level of depth
711 if (is_array($fields) && isset($fields['name'])) {
712 $ret[$fields['name']] = $fields;
715 if (!is_array($fields)) {
716 $ret[$fields] = $fields;
719 foreach ($fields as $field) {
720 if (is_array($field) && !empty($field['name']))
722 $ret[$field['name']] = $field;
724 else if(!is_array($field)){
725 $ret[$field] = $field;
734 protected function fieldIsRequired($def)
736 if (isset($def['studio']))
738 if (is_array($def['studio']))
740 if (!empty($def['studio'][$this->_view]) && $def['studio'][$this->_view] == "required")
744 else if (!empty($def['studio']['required']) && $def['studio']['required'] == true)
749 else if ($def['studio'] == "required" ){
756 static function _trimFieldDefs ( $def )
758 $ret = array_intersect_key ( $def ,
759 array ( 'studio' => true , 'name' => true , 'label' => true , 'displayParams' => true , 'comment' => true ,
760 'customCode' => true , 'customLabel' => true , 'tabindex' => true , 'hideLabel' => true) ) ;
761 if (!empty($def['vname']) && empty($def['label']))
762 $ret['label'] = $def['vname'];
766 public function getUseTabs(){
767 if (isset($this->_viewdefs [ 'templateMeta' ]['useTabs']))
768 return $this->_viewdefs [ 'templateMeta' ]['useTabs'];
773 public function setUseTabs($useTabs){
774 $this->_viewdefs [ 'templateMeta' ]['useTabs'] = $useTabs;
778 * Return whether the Detail & EditView should be in sync.
780 public function getSyncDetailEditViews(){
781 if (isset($this->_viewdefs [ 'templateMeta' ]['syncDetailEditViews']))
782 return $this->_viewdefs [ 'templateMeta' ]['syncDetailEditViews'];
788 * Sync DetailView & EditView. This should only be set on the EditView
789 * @param bool $syncViews
791 public function setSyncDetailEditViews($syncDetailEditViews){
792 $this->_viewdefs [ 'templateMeta' ]['syncDetailEditViews'] = $syncDetailEditViews;
796 * Getter function to get the implementation method which is a private variable
797 * @return DeployedMetaDataImplementation
799 public function getImplementation(){
800 return $this->implementation;
804 * Public access to _convertFromCanonicalForm
809 public function convertFromCanonicalForm ( $panels , $fielddefs )
811 return $this->_convertFromCanonicalForm ( $panels , $fielddefs );
815 * Public access to _convertToCanonicalForm
820 public function convertToCanonicalForm ( $panels , $fielddefs )
822 return $this->_convertToCanonicalForm ( $panels , $fielddefs );
827 * @return Array list of fields in this module that have the calculated property
829 public function getCalculatedFields() {
831 foreach ($this->_fielddefs as $field => $def)
833 if(!empty($def['calculated']) && !empty($def['formula']))
843 * @return Array fields in the given panel
845 public function getFieldsInPanel($targetPanel) {
846 return iterator_to_array(new RecursiveIteratorIterator(new RecursiveArrayIterator($this->_viewdefs['panels'][$targetPanel])));