2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM Community Edition is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero General Public License version 3 as published by the
9 * Free Software Foundation with the addition of the following permission added
10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19 * You should have received a copy of the GNU Affero General Public License along with
20 * this program; if not, see http://www.gnu.org/licenses or write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27 * The interactive user interfaces in modified source and object code versions
28 * of this program must display Appropriate Legal Notices, as required under
29 * Section 5 of the GNU Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32 * these Appropriate Legal Notices must retain the display of the "Powered by
33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34 * technical reasons, the Appropriate Legal Notices must display the words
35 * "Powered by SugarCRM".
36 ********************************************************************************/
39 abstract class AbstractMetaDataParser
42 //Make these properties public for now until we can create some usefull accessors
45 protected $_moduleName ;
46 protected $implementation ; // the DeployedMetaDataImplementation or UndeployedMetaDataImplementation object to handle the reading and writing of files and field data
48 function getLayoutAsArray ()
50 $viewdefs = $this->_panels ;
53 function getLanguage ()
55 return $this->implementation->getLanguage () ;
58 function getHistory ()
60 return $this->implementation->getHistory () ;
63 public function getFieldDefs()
65 return $this->_fielddefs;
68 function removeField ($fieldName)
74 * Is this field something we wish to show in Studio/ModuleBuilder layout editors?
75 * @param array $def Field definition in the standard SugarBean field definition format - name, vname, type and so on
76 * @return boolean True if ok to show, false otherwise
78 static function validField ( $def, $view = "")
80 //Studio invisible fields should always be hidden
81 if (isset ($def[ 'studio' ] ) )
83 if (is_array($def [ 'studio' ]))
85 if (!empty($view) && isset($def [ 'studio' ][$view]))
86 return $def [ 'studio' ][$view] !== false && $def [ 'studio' ][$view] !== 'false' && $def [ 'studio' ][$view] !== 'hidden';
87 if (isset($def [ 'studio' ]['visible']))
88 return $def [ 'studio' ]['visible'];
90 return ($def [ 'studio' ] != 'false' && $def [ 'studio' ] != 'hidden' && $def [ 'studio' ] !== false) ;
94 // bug 19656: this test changed after 5.0.0b - we now remove all ID type fields - whether set as type, or dbtype, from the fielddefs
98 (empty ( $def [ 'source' ] ) || $def [ 'source' ] == 'db' || $def [ 'source' ] == 'custom_fields')
99 && isset($def [ 'type' ]) && $def [ 'type' ] != 'id' && $def [ 'type' ] != 'parent_type'
100 && (empty ( $def [ 'dbType' ] ) || $def [ 'dbType' ] != 'id')
101 && ( isset ( $def [ 'name' ] ) && strcmp ( $def [ 'name' ] , 'deleted' ) != 0 )
102 ) // db and custom fields that aren't ID fields
104 // exclude fields named *_name regardless of their type...just convention
105 (isset ( $def [ 'name' ] ) && substr ( $def [ 'name' ], -5 ) === '_name' ) ) ;
108 protected function _standardizeFieldLabels ( &$fielddefs )
110 foreach ( $fielddefs as $key => $def )
112 if ( !isset ($def [ 'label' ] ) )
114 $fielddefs [ $key ] [ 'label'] = ( isset ( $def [ 'vname' ] ) ) ? $def [ 'vname' ] : $key ;
119 abstract static function _trimFieldDefs ( $def ) ;
121 public function getRequiredFields(){
122 $fieldDefs = $this->implementation->getFielddefs();
124 foreach($fieldDefs as $field){
125 if(isset($field['required']) && $field['required'] && isset($field['name']) && empty( $field['readonly'])) {
126 array_push($newAry , '"'.$field['name'].'"');
133 * Used to determine if a field property is true or false given that it could be
134 * the boolean value or a string value such use 'false' or '0'
139 protected static function isTrue($val)
143 $str = strtolower($val);
144 return ($str != '0' && $str != 'false' && $str != "");
146 //For non-string types, juse use PHP's normal boolean conversion
148 return ($val == true);