]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/parsers/views/UndeployedMetaDataImplementation.php
Release 6.5.0
[Github/sugarcrm.git] / modules / ModuleBuilder / parsers / views / UndeployedMetaDataImplementation.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 require_once 'modules/ModuleBuilder/MB/ModuleBuilder.php' ;
40 require_once 'modules/ModuleBuilder/parsers/views/AbstractMetaDataImplementation.php' ;
41 require_once 'modules/ModuleBuilder/parsers/views/MetaDataImplementationInterface.php' ;
42 require_once 'modules/ModuleBuilder/parsers/views/ListLayoutMetaDataParser.php' ;
43 require_once 'modules/ModuleBuilder/parsers/views/GridLayoutMetaDataParser.php' ;
44 require_once 'modules/ModuleBuilder/parsers/constants.php' ;
45
46 class UndeployedMetaDataImplementation extends AbstractMetaDataImplementation implements MetaDataImplementationInterface
47 {
48
49     private $_packageName ;
50
51    /*
52      * Constructor
53      * @param string $view
54      * @param string $moduleName
55      * @throws Exception Thrown if the provided view doesn't exist for this module
56      */
57
58     function __construct ($view , $moduleName , $packageName)
59     {
60
61         // BEGIN ASSERTIONS
62         if (! isset ( $this->_fileVariables [ $view ] ))
63         {
64             sugar_die ( get_class ( $this ) . ": View $view is not supported" ) ;
65         }
66         // END ASSERTIONS
67
68         $this->_view = strtolower ( $view ) ;
69         $this->_moduleName = $moduleName ;
70         $this->_packageName = $packageName ;
71
72         //get the bean from ModuleBuilder
73         $mb = new ModuleBuilder ( ) ;
74         $this->module = $module = & $mb->getPackageModule ( $packageName, $moduleName ) ;
75         $pak = $mb->getPackage($packageName);
76         $module->mbvardefs->updateVardefs () ;
77
78         // Set the list of fields associated with this module
79         $fielddefs = array_change_key_case ( $module->mbvardefs->vardefs [ 'fields' ] ) ;
80
81         // Set the global mod_strings directly as Sugar does not automatically load the language files for undeployed modules (how could it?)
82         $selected_lang = 'en_us';
83         if(isset($GLOBALS['current_language']) &&!empty($GLOBALS['current_language'])) {
84             $selected_lang = $GLOBALS['current_language'];
85         }
86         $GLOBALS [ 'mod_strings' ] = array_merge ( $GLOBALS [ 'mod_strings' ], $module->getModStrings ($selected_lang) ) ;
87
88         //Load relationshhip based fields and labels
89         $moduleRels = $pak->getRelationshipsForModule($moduleName);
90         foreach($moduleRels as $rName => $rel ) {
91             $varDefsSet = $rel->buildVardefs();
92         if (!empty($varDefsSet[$module->key_name])) {
93                 foreach ($varDefsSet[$module->key_name] as $def) {
94                     $fielddefs[$def['name']] = $def;
95                  }
96             }
97             $labels = $rel->buildLabels();
98             foreach ($labels as $def) {
99                 if ($def['module'] == $module->key_name) {
100                    $GLOBALS [ 'mod_strings' ][$def['system_label']] = $def['display_label'];
101
102                 }
103             }
104         }
105
106         $loaded = null ;
107         foreach ( array ( MB_WORKINGMETADATALOCATION , MB_HISTORYMETADATALOCATION ) as $type )
108         {
109                         $this->_sourceFilename = $this->getFileName ( $view, $moduleName, $packageName , $type ) ;
110                         if($view == MB_POPUPSEARCH || $view == MB_POPUPLIST){
111                                 $layout = $this->_loadFromPopupFile ( $this->_sourceFilename , null, $view);
112                         }else{
113                                 $layout = $this->_loadFromFile ( $this->_sourceFilename );
114                         }
115                         if ( null !== $layout  )
116                         {
117                                 // merge in the fielddefs from this layout
118                                 $this->_mergeFielddefs ( $fielddefs , $layout ) ;
119                                 $loaded = $layout ;
120                         }
121                 }
122
123         if ($loaded === null)
124         {
125             throw new Exception ( get_class ( $this ) . ": view definitions for View $this->_view and Module $this->_moduleName are missing" ) ;
126         }
127
128         $this->_viewdefs = $loaded ;
129         $sourceFilename = $this->getFileName ( $view, $moduleName, $packageName, MB_WORKINGMETADATALOCATION );
130         if($view == MB_POPUPSEARCH || $view == MB_POPUPLIST){
131                         $layout = $this->_loadFromPopupFile ( $sourceFilename , null, $view);
132                 }else{
133                         $layout = $this->_loadFromFile ($sourceFilename) ;
134                 }
135                 $this->_originalViewdefs = $layout ;
136                 $this->_fielddefs = $fielddefs ;
137         $this->_history = new History ( $this->getFileName ( $view, $moduleName, $packageName, MB_HISTORYMETADATALOCATION ) ) ;
138     }
139
140     function getLanguage ()
141     {
142         return $this->_packageName . $this->_moduleName ;
143     }
144
145     /*
146      * Deploy a layout
147      * @param array defs    Layout definition in the same format as received by the constructor
148      */
149     function deploy ($defs)
150     {
151         //If we are pulling from the History Location, that means we did a restore, and we need to save the history for the previous file.
152         if ($this->_sourceFilename == $this->getFileName ( $this->_view, $this->_moduleName, $this->_packageName, MB_HISTORYMETADATALOCATION )
153         && file_exists($this->getFileName ( $this->_view, $this->_moduleName, $this->_packageName, MB_WORKINGMETADATALOCATION ))) {
154                 $this->_history->append ( $this->getFileName ( $this->_view, $this->_moduleName, $this->_packageName, MB_WORKINGMETADATALOCATION )) ;
155         } else {
156                 $this->_history->append ( $this->_sourceFilename ) ;
157         }
158         $filename = $this->getFileName ( $this->_view, $this->_moduleName, $this->_packageName, MB_WORKINGMETADATALOCATION ) ;
159         $GLOBALS [ 'log' ]->debug ( get_class ( $this ) . "->deploy(): writing to " . $filename ) ;
160         $this->_saveToFile ( $filename, $defs ) ;
161     }
162
163     /*
164      * Construct a full pathname for the requested metadata
165      * @param string view           The view type, that is, EditView, DetailView etc
166      * @param string modulename     The name of the module that will use this layout
167      * @param string type
168      */
169     public static function getFileName ($view , $moduleName , $packageName , $type = MB_BASEMETADATALOCATION)
170     {
171
172         $type = strtolower ( $type ) ;
173
174         // BEGIN ASSERTIONS
175         if ($type != MB_BASEMETADATALOCATION && $type != MB_HISTORYMETADATALOCATION)
176         {
177             // just warn rather than die
178             $GLOBALS [ 'log' ]->warning ( "UndeployedMetaDataImplementation->getFileName(): view type $type is not recognized" ) ;
179         }
180         // END ASSERTIONS
181
182         $filenames = array (    MB_DASHLETSEARCH => 'dashletviewdefs',
183                                                         MB_DASHLET => 'dashletviewdefs',
184                                                         MB_LISTVIEW => 'listviewdefs' ,
185                                                         MB_BASICSEARCH => 'searchdefs' ,
186                                                         MB_ADVANCEDSEARCH => 'searchdefs' ,
187                                                         MB_EDITVIEW => 'editviewdefs' ,
188                                                         MB_DETAILVIEW => 'detailviewdefs' ,
189                                                         MB_QUICKCREATE => 'quickcreatedefs',
190                                                         MB_POPUPSEARCH => 'popupdefs',
191                                                         MB_POPUPLIST => 'popupdefs',
192                                                         ) ;
193
194         switch ( $type)
195         {
196             case MB_HISTORYMETADATALOCATION :
197                 return 'custom/history/modulebuilder/packages/' . $packageName . '/modules/' . $moduleName . '/metadata/' . $filenames [ $view ] . '.php' ;
198             default :
199                 // get the module again, all so we can call this method statically without relying on the module stored in the class variables
200                 $mb = new ModuleBuilder ( ) ;
201                 $module = & $mb->getPackageModule ( $packageName, $moduleName ) ;
202                 return $module->getModuleDir () . '/metadata/' . $filenames [ $view ] . '.php' ;
203         }
204
205     }
206     
207     public function getModuleDir(){
208                 return $this->module->key_name;
209         }
210 }
211 ?>