]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/VarDefHandler/VarDefHandler.php
Release 6.2.0
[Github/sugarcrm.git] / include / VarDefHandler / VarDefHandler.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
5  * 
6  * This program is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  * 
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
16  * details.
17  * 
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  * 
23  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
25  * 
26  * The interactive user interfaces in modified source and object code versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  * 
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the "Powered by
32  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33  * technical reasons, the Appropriate Legal Notices must display the words
34  * "Powered by SugarCRM".
35  ********************************************************************************/
36
37
38
39 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
40
41 //Vardef Handler Object
42 class VarDefHandler {
43
44         var $meta_array_name;
45         var $target_meta_array = false;
46         var $start_none = false;
47         var $extra_array = array();                                     //used to add custom items
48         var $options_array = array();
49         var $module_object;
50         var $start_none_lbl = null;
51         
52         function VarDefHandler(& $module, $meta_array_name=null){
53                 $this->module_object = $module;
54                 if($meta_array_name!=null){
55                         global $vardef_meta_array;
56                         include("include/VarDefHandler/vardef_meta_arrays.php");
57                         $this->target_meta_array = $vardef_meta_array[$meta_array_name];
58                 }
59                 
60         //end function setup
61         }
62
63         function get_vardef_array($use_singular=false, $remove_dups = false, $use_field_name = false, $use_field_label = false){
64                 global $dictionary;
65                 global $current_language;
66                 global $app_strings;
67                 global $app_list_strings;
68                 
69                 $temp_module_strings = return_module_language($current_language, $this->module_object->module_dir);
70                 
71                 $base_array = $this->module_object->field_defs;
72                 //$base_array = $dictionary[$this->module_object->object_name]['fields'];
73                 
74                 ///Inclue empty none set or not
75                 if($this->start_none==true){
76                         if(!empty($this->start_none_lbl)){
77                                 $this->options_array[''] = $this->start_none_lbl;
78                         } else {        
79                                 $this->options_array[''] = $app_strings['LBL_NONE'];
80                         }
81                 }
82                 
83         ///used for special one off items added to filter array  ex. would be href link for alert templates
84                 if(!empty($this->extra_array)){
85                 
86                         foreach($this->extra_array as $key => $value){
87                                 $this->options_array[$key] = $value;
88                         }
89                 }       
90         /////////end special one off//////////////////////////////////  
91                 
92         
93                 foreach($base_array as $key => $value_array){
94                         $compare_results = $this->compare_type($value_array);
95                         
96                         if($compare_results == true){
97                                  $label_name = '';
98                  if($value_array['type'] == 'link' && !$use_field_label){
99                         $this->module_object->load_relationship($value_array['name']);
100                     if(!empty($app_list_strings['moduleList'][$this->module_object->$value_array['name']->getRelatedModuleName()])){
101                         $label_name = $app_list_strings['moduleList'][$this->module_object->$value_array['name']->getRelatedModuleName()];
102                     }else{
103                         $label_name = $this->module_object->$value_array['name']->getRelatedModuleName();
104                     }
105                 }
106                                 else if(!empty($value_array['vname'])){
107                                         $label_name = $value_array['vname'];
108                                 } else {
109                                         $label_name = $value_array['name'];     
110                                 }       
111                                             
112                 
113                                 $label_name = get_label($label_name, $temp_module_strings);
114
115                                 if(!empty($value_array['table'])){      
116                                         //Custom Field
117                                         $column_table = $value_array['table'];
118                                 } else {
119                                         //Non-Custom Field
120                                         $column_table = $this->module_object->table_name;
121                                 }       
122
123                 if($value_array['type'] == 'link'){
124                         if($use_field_name){
125                                 $index = $value_array['name'];
126                                 
127                         }else{
128                                 $index = $this->module_object->$key->getRelatedModuleName();
129                         }
130                 }else{
131                                         $index = $key;
132                 }
133
134                                 $value = trim($label_name, ':');
135                                 if($remove_dups){
136                                         if(!in_array($value, $this->options_array))
137                                                 $this->options_array[$index] = $value;
138                                 }
139                                 else
140                                         $this->options_array[$index] = $value;
141                         
142                         //end if field is included
143                         }
144                                 
145                 //end foreach
146                 }
147                 if($use_singular == true){
148                         return convert_module_to_singular($this->options_array);
149                 } else {
150                         return $this->options_array;            
151                 }                       
152         
153         //end get_vardef_array
154         }       
155                 
156         
157         function compare_type($value_array){
158
159                 //Filter nothing?
160                 if(!is_array($this->target_meta_array)){
161                         return true;    
162                 }       
163
164                 ////////Use the $target_meta_array;
165                 if(isset($this->target_meta_array['inc_override'])){
166                         foreach($this->target_meta_array['inc_override'] as $attribute => $value){
167                                 
168                                         foreach($value as $actual_value){
169                                                 if(isset($value_array[$attribute]) && $value_array[$attribute] == $actual_value) return true;   
170                                         }       
171                                         if(isset($value_array[$attribute]) && $value_array[$attribute] == $value) return true;
172
173                         }
174                 }
175                 if(isset($this->target_meta_array['ex_override'])){
176                         foreach($this->target_meta_array['ex_override'] as $attribute => $value){
177                 
178                                 
179                                         foreach($value as $actual_value){
180                                         if(isset($value_array[$attribute]) && $value_array[$attribute] == $actual_value) return false;  
181
182                                                 if(isset($value_array[$attribute]) && $value_array[$attribute] == $value) return false;
183                                         }       
184
185                         //end foreach inclusion array
186                         }
187                 }               
188
189                 if(isset($this->target_meta_array['inclusion'])){
190                         foreach($this->target_meta_array['inclusion'] as $attribute => $value){
191                                 
192                                 if($attribute=="type"){
193                                         foreach($value as $actual_value){
194                                         if(isset($value_array[$attribute]) && $value_array[$attribute] != $actual_value) return false;  
195                                         }       
196                                 } else {                        
197                                         if(isset($value_array[$attribute]) && $value_array[$attribute] != $value) return false;
198                                 }
199                         //end foreach inclusion array
200                         }
201                 }
202
203                 if(isset($this->target_meta_array['exclusion'])){
204                         foreach($this->target_meta_array['exclusion'] as $attribute => $value){
205
206                                 foreach($value as $actual_value){
207                                     if ( $attribute == 'reportable' ) {
208                                         if ( $actual_value == 'true' ) $actual_value = 1;
209                                         if ( $actual_value == 'false' ) $actual_value = 0;
210                                     }
211                                         if(isset($value_array[$attribute]) && $value_array[$attribute] == $actual_value) return false;
212                                 }       
213         
214                         //end foreach inclusion array
215                         }
216                 }
217                 
218                 
219                 return true;
220
221         //end function compare_type
222         }               
223         
224 //end class VarDefHandler
225 }
226
227
228 ?>