]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/parsers/views/AbstractMetaDataParser.php
Release 6.5.0
[Github/sugarcrm.git] / modules / ModuleBuilder / parsers / views / AbstractMetaDataParser.php
1 <?php
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.
6  * 
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.
13  * 
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
17  * details.
18  * 
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
22  * 02110-1301 USA.
23  * 
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.
26  * 
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.
30  * 
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  ********************************************************************************/
37
38
39 abstract class AbstractMetaDataParser
40 {
41
42         //Make these properties public for now until we can create some usefull accessors
43         public $_fielddefs ;
44         public $_viewdefs ;
45         protected $_moduleName ;
46     protected $implementation ; // the DeployedMetaDataImplementation or UndeployedMetaDataImplementation object to handle the reading and writing of files and field data
47
48     function getLayoutAsArray ()
49     {
50         $viewdefs = $this->_panels ;
51     }
52
53     function getLanguage ()
54     {
55         return $this->implementation->getLanguage () ;
56     }
57
58     function getHistory ()
59     {
60         return $this->implementation->getHistory () ;
61     }
62
63     public function getFieldDefs()
64     {
65         return $this->_fielddefs;
66     }
67     
68     function removeField ($fieldName)
69     {
70         return false;
71     }
72
73     /*
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
77      */
78     static function validField ( $def, $view = "")
79     {
80         //Studio invisible fields should always be hidden
81         if (isset ($def[ 'studio' ] ) )
82         {
83             if (is_array($def [ 'studio' ]))
84             {
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'];
89             } else {
90                 return ($def [ 'studio' ] != 'false' && $def [ 'studio' ] != 'hidden' && $def [ 'studio' ] !== false) ;
91                         }
92         }
93
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
95         return 
96                 ( 
97                   ( 
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
103           ||
104                   // exclude fields named *_name regardless of their type...just convention
105           (isset ( $def [ 'name' ] ) && substr ( $def [ 'name' ], -5 ) === '_name' ) ) ;
106     }
107
108         protected function _standardizeFieldLabels ( &$fielddefs )
109         {
110                 foreach ( $fielddefs as $key => $def )
111                 {
112                         if ( !isset ($def [ 'label' ] ) )
113                         {
114                                 $fielddefs [ $key ] [ 'label'] = ( isset ( $def [ 'vname' ] ) ) ? $def [ 'vname' ] : $key ;
115                         }
116                 }
117         }
118
119         abstract static function _trimFieldDefs ( $def ) ;
120         
121         public function getRequiredFields(){
122             $fieldDefs = $this->implementation->getFielddefs();
123             $newAry = array();
124             foreach($fieldDefs as $field){
125                 if(isset($field['required']) && $field['required'] && isset($field['name']) && empty( $field['readonly'])) {
126                     array_push($newAry , '"'.$field['name'].'"');
127             }
128         }
129         return $newAry;
130         }
131
132     /**
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'
135      * @static
136      * @param $val
137      * @return bool
138      */
139     protected static function isTrue($val)
140     {
141         if (is_string($val))
142         {
143             $str = strtolower($val);
144             return ($str != '0' && $str != 'false' && $str != "");
145         }
146         //For non-string types, juse use PHP's normal boolean conversion
147         else{
148             return ($val == true);
149         }
150
151         return true;
152     }
153
154 }
155 ?>