]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/parsers/views/AbstractMetaDataParser.php
Release 6.1.4
[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 is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2011 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     function removeField ($fieldName)
64     {
65         return false;
66     }
67
68     /*
69      * Is this field something we wish to show in Studio/ModuleBuilder layout editors?
70      * @param array $def    Field definition in the standard SugarBean field definition format - name, vname, type and so on
71      * @return boolean      True if ok to show, false otherwise
72      */
73     static function validField ( $def, $view = "")
74     {
75         //Studio invisible fields should always be hidden
76         if (isset ($def[ 'studio' ] ) )
77         {
78             if (is_array($def [ 'studio' ]))
79             {
80                 if (!empty($view) && isset($def [ 'studio' ][$view]))
81                    return $def [ 'studio' ][$view] !== false && $def [ 'studio' ][$view] !== 'false' && $def [ 'studio' ][$view] !== 'hidden';
82                 if (isset($def [ 'studio' ]['visible']))
83                    return $def [ 'studio' ]['visible'];
84             } else {
85                 return ($def [ 'studio' ] != 'false' && $def [ 'studio' ] != 'hidden' && $def [ 'studio' ] !== false) ;
86                         }
87         }
88
89         // 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
90         return 
91                 ( 
92                   ( 
93                     (empty ( $def [ 'source' ] ) || $def [ 'source' ] == 'db' || $def [ 'source' ] == 'custom_fields') 
94                         && isset($def [ 'type' ]) && $def [ 'type' ] != 'id' && $def [ 'type' ] != 'parent_type'
95                         && (empty ( $def [ 'dbType' ] ) || $def [ 'dbType' ] != 'id') 
96                         && ( isset ( $def [ 'name' ] ) && strcmp ( $def [ 'name' ] , 'deleted' ) != 0 ) 
97                   ) // db and custom fields that aren't ID fields
98           ||
99                   // exclude fields named *_name regardless of their type...just convention
100           (isset ( $def [ 'name' ] ) && substr ( $def [ 'name' ], -5 ) === '_name' ) ) ;
101     }
102
103         protected function _standardizeFieldLabels ( &$fielddefs )
104         {
105                 foreach ( $fielddefs as $key => $def )
106                 {
107                         if ( !isset ($def [ 'label' ] ) )
108                         {
109                                 $fielddefs [ $key ] [ 'label'] = ( isset ( $def [ 'vname' ] ) ) ? $def [ 'vname' ] : $key ;
110                         }
111                 }
112         }
113
114         abstract static function _trimFieldDefs ( $def ) ;
115         
116         public function getRequiredFields(){
117             $fieldDefs = $this->implementation->getFielddefs();
118             $newAry = array();
119             foreach($fieldDefs as $field){
120                 if(isset($field['required']) && $field['required'] && isset($field['name'])){
121                     array_push($newAry , '"'.$field['name'].'"');
122             }
123         }
124         return $newAry;
125         }
126
127 }
128 ?>