]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/VarDefHandler/VarDefHandler.php
Release 6.5.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-2012 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 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
39
40 /**
41  * Vardef Handler Object
42  * @api
43  */
44 class VarDefHandler {
45
46         var $meta_array_name;
47         var $target_meta_array = false;
48         var $start_none = false;
49         var $extra_array = array();                                     //used to add custom items
50         var $options_array = array();
51         var $module_object;
52         var $start_none_lbl = null;
53
54
55     function VarDefHandler($module, $meta_array_name=null)
56     {
57         $this->meta_array_name = $meta_array_name;
58                 $this->module_object = $module;
59                 if($meta_array_name!=null){
60                         global $vardef_meta_array;
61                         include("include/VarDefHandler/vardef_meta_arrays.php");
62                         $this->target_meta_array = $vardef_meta_array[$meta_array_name];
63                 }
64
65         //end function setup
66         }
67
68         function get_vardef_array($use_singular=false, $remove_dups = false, $use_field_name = false, $use_field_label = false){
69                 global $dictionary;
70                 global $current_language;
71                 global $app_strings;
72                 global $app_list_strings;
73
74                 $temp_module_strings = return_module_language($current_language, $this->module_object->module_dir);
75
76                 $base_array = $this->module_object->field_defs;
77                 //$base_array = $dictionary[$this->module_object->object_name]['fields'];
78
79                 ///Inclue empty none set or not
80                 if($this->start_none==true){
81                         if(!empty($this->start_none_lbl)){
82                                 $this->options_array[''] = $this->start_none_lbl;
83                         } else {
84                                 $this->options_array[''] = $app_strings['LBL_NONE'];
85                         }
86                 }
87
88         ///used for special one off items added to filter array  ex. would be href link for alert templates
89                 if(!empty($this->extra_array)){
90
91                         foreach($this->extra_array as $key => $value){
92                                 $this->options_array[$key] = $value;
93                         }
94                 }
95         /////////end special one off//////////////////////////////////
96
97
98                 foreach($base_array as $key => $value_array){
99                         $compare_results = $this->compare_type($value_array);
100
101                         if($compare_results == true){
102                                  $label_name = '';
103                  if($value_array['type'] == 'link' && !$use_field_label){
104                         $this->module_object->load_relationship($value_array['name']);
105                     if(!empty($app_list_strings['moduleList'][$this->module_object->$value_array['name']->getRelatedModuleName()])){
106                         $label_name = $app_list_strings['moduleList'][$this->module_object->$value_array['name']->getRelatedModuleName()];
107                     }else{
108                         $label_name = $this->module_object->$value_array['name']->getRelatedModuleName();
109                     }
110                 }
111                                 else if(!empty($value_array['vname'])){
112                                         $label_name = $value_array['vname'];
113                                 } else {
114                                         $label_name = $value_array['name'];
115                                 }
116
117
118                                 $label_name = get_label($label_name, $temp_module_strings);
119
120                                 if(!empty($value_array['table'])){
121                                         //Custom Field
122                                         $column_table = $value_array['table'];
123                                 } else {
124                                         //Non-Custom Field
125                                         $column_table = $this->module_object->table_name;
126                                 }
127
128                 if($value_array['type'] == 'link'){
129                         if($use_field_name){
130                                 $index = $value_array['name'];
131
132                         }else{
133                                 $index = $this->module_object->$key->getRelatedModuleName();
134                         }
135                 }else{
136                                         $index = $key;
137                 }
138
139                                 $value = trim($label_name, ':');
140                                 if($remove_dups){
141                                         if(!in_array($value, $this->options_array))
142                                                 $this->options_array[$index] = $value;
143                                 }
144                                 else
145                                         $this->options_array[$index] = $value;
146
147                         //end if field is included
148                         }
149
150                 //end foreach
151                 }
152                 if($use_singular == true){
153                         return convert_module_to_singular($this->options_array);
154                 } else {
155                         return $this->options_array;
156                 }
157
158         //end get_vardef_array
159         }
160
161
162         function compare_type($value_array){
163
164                 //Filter nothing?
165                 if(!is_array($this->target_meta_array)){
166                         return true;
167                 }
168
169                 ////////Use the $target_meta_array;
170                 if(isset($this->target_meta_array['inc_override'])){
171                         foreach($this->target_meta_array['inc_override'] as $attribute => $value){
172
173                                         foreach($value as $actual_value){
174                                                 if(isset($value_array[$attribute]) && $value_array[$attribute] == $actual_value) return true;
175                                         }
176                                         if(isset($value_array[$attribute]) && $value_array[$attribute] == $value) return true;
177
178                         }
179                 }
180                 if(isset($this->target_meta_array['ex_override'])){
181                         foreach($this->target_meta_array['ex_override'] as $attribute => $value){
182
183
184                                         foreach($value as $actual_value){
185                                         if(isset($value_array[$attribute]) && $value_array[$attribute] == $actual_value) return false;
186
187                                                 if(isset($value_array[$attribute]) && $value_array[$attribute] == $value) return false;
188                                         }
189
190                         //end foreach inclusion array
191                         }
192                 }
193
194                 if(isset($this->target_meta_array['inclusion'])){
195                         foreach($this->target_meta_array['inclusion'] as $attribute => $value){
196
197                                 if($attribute=="type"){
198                                         foreach($value as $actual_value){
199                                         if(isset($value_array[$attribute]) && $value_array[$attribute] != $actual_value) return false;
200                                         }
201                                 } else {
202                                         if(isset($value_array[$attribute]) && $value_array[$attribute] != $value) return false;
203                                 }
204                         //end foreach inclusion array
205                         }
206                 }
207
208                 if(isset($this->target_meta_array['exclusion'])){
209                         foreach($this->target_meta_array['exclusion'] as $attribute => $value){
210
211                                 foreach($value as $actual_value){
212                                     if ( $attribute == 'reportable' ) {
213                                         if ( $actual_value == 'true' ) $actual_value = 1;
214                                         if ( $actual_value == 'false' ) $actual_value = 0;
215                                     }
216                                         if(isset($value_array[$attribute]) && $value_array[$attribute] == $actual_value) return false;
217                                 }
218
219                         //end foreach inclusion array
220                         }
221                 }
222
223
224                 return true;
225
226         //end function compare_type
227         }
228
229 //end class VarDefHandler
230 }
231
232
233 ?>