]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/MB/MBVardefs.php
Release 6.5.0
[Github/sugarcrm.git] / modules / ModuleBuilder / MB / MBVardefs.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 class MBVardefs{
38         var $templates = array();
39         var $iTemplates = array();
40         var $vardefs = array();
41         var $vardef = array();
42         var $path = '';
43         var $name = '';
44         var $errors = array();
45
46         function MBVardefs($name, $path, $key_name){
47                 $this->path = $path;
48                 $this->name = $name;
49                 $this->key_name = $key_name;
50                 $this->load();
51         }
52
53         function loadTemplate($by_group, $template, $file){
54                 $module = $this->name;
55                 $table_name = $this->name;
56                 $object_name = $this->key_name;
57                 $_object_name = strtolower($this->key_name);
58
59                 // required by the vardef template for team security in SugarObjects
60                 $table_name = strtolower($module);
61
62                 if(file_exists($file)){
63                         include($file);
64             if (isset($vardefs))
65             {
66                 if($by_group){
67                     $this->vardefs['fields'] [$template]= $vardefs['fields'];
68                 }else{
69                     $this->vardefs['fields']= array_merge($this->vardefs['fields'], $vardefs['fields']);
70                     if(!empty($vardefs['relationships'])){
71                         $this->vardefs['relationships']= array_merge($this->vardefs['relationships'], $vardefs['relationships']);
72                     }
73                 }
74             }
75                 }
76         //Bug40450 - Extra 'Name' field in a File type module in module builder
77         if(array_key_exists('file', $this->templates))
78         {
79             unset($this->vardefs['fields']['name']);
80             unset($this->vardefs['fields']['file']['name']);
81         }
82
83         }
84
85         function mergeVardefs($by_group=false){
86                 $this->vardefs = array(
87                                         'fields'=>array(),
88                                         'relationships'=>array(),
89                 );
90 //              $object_name = $this->key_name;
91 //              $_object_name = strtolower($this->name);
92                 $module_name = $this->name;
93                 $this->loadTemplate($by_group,'basic',  MB_TEMPLATES . '/basic/vardefs.php');
94                 foreach($this->iTemplates as $template=>$val){
95                         $file = MB_IMPLEMENTS . '/' . $template . '/vardefs.php';
96                         $this->loadTemplate($by_group,$template, $file);
97                 }
98                 foreach($this->templates as $template=>$val){
99                         if($template == 'basic')continue;
100                         $file = MB_TEMPLATES . '/' . $template . '/vardefs.php';
101                         $this->loadTemplate($by_group,$template, $file);
102                 }
103
104                 if($by_group){
105                         $this->vardefs['fields'][$this->name] = $this->vardef['fields'];
106                 }else{
107                         $this->vardefs['fields'] = array_merge($this->vardefs['fields'], $this->vardef['fields']);
108                 }
109         }
110
111         function updateVardefs($by_group=false){
112                 $this->mergeVardefs($by_group);
113         }
114
115
116         function getVardefs(){
117                 return $this->vardefs;
118         }
119
120         function getVardef(){
121                 return $this->vardef;
122         }
123                 
124
125     function addFieldVardef($vardef)
126     {
127         if(!isset($vardef['default']) || strlen($vardef['default']) == 0)
128         {
129             unset($vardef['default']);
130         }
131         $this->vardef['fields'][$vardef['name']] = $vardef;
132     }
133
134         function deleteField($field){
135                 unset($this->vardef['fields'][$field->name]);
136         }
137
138         function save(){
139                 $header = file_get_contents('modules/ModuleBuilder/MB/header.php');
140                 write_array_to_file('vardefs', $this->vardef, $this->path . '/vardefs.php','w', $header);
141         }
142
143         function build($path){
144                 $header = file_get_contents('modules/ModuleBuilder/MB/header.php');
145                 write_array_to_file('dictionary["' . $this->name . '"]', $this->getVardefs(), $path . '/vardefs.php', 'w', $header);
146         }
147         function load(){
148                 $this->vardef = array('fields'=>array(), 'relationships'=>array());
149                 if(file_exists($this->path . '/vardefs.php')){
150                         include($this->path. '/vardefs.php');
151                         $this->vardef = $vardefs;
152                 }
153         }
154
155
156
157
158
159 }
160 ?>