]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/parsers/views/UndeployedSubpanelImplementation.php
Release 6.5.0
[Github/sugarcrm.git] / modules / ModuleBuilder / parsers / views / UndeployedSubpanelImplementation.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  * Changes to AbstractSubpanelImplementation for DeployedSubpanels
40  * The main differences are in the load and save of the definitions
41  * For subpanels we must make use of the SubPanelDefinitions class to do this; this also means that the history mechanism,
42  * which tracks files, not objects, needs us to create an intermediate file representation of the definition that it can manage and restore
43  */
44
45 require_once 'modules/ModuleBuilder/parsers/views/MetaDataImplementationInterface.php' ;
46 require_once 'modules/ModuleBuilder/parsers/views/AbstractMetaDataImplementation.php' ;
47 require_once 'modules/ModuleBuilder/parsers/constants.php' ;
48
49 class UndeployedSubpanelImplementation extends AbstractMetaDataImplementation implements MetaDataImplementationInterface
50 {
51
52     const HISTORYFILENAME = 'restored.php' ;
53     const HISTORYVARIABLENAME = 'layout_defs' ;
54
55     /*
56      * Constructor
57      * @param string subpanelName   The name of this subpanel
58      * @param string moduleName     The name of the module to which this subpanel belongs
59      * @param string packageName    If not empty, the name of the package to which this subpanel belongs
60      */
61     function __construct ($subpanelName , $moduleName , $packageName)
62     {
63         $this->_subpanelName = $subpanelName ;
64         $this->_moduleName = $moduleName ;
65
66         // TODO: history
67         $this->historyPathname = 'custom/history/modulebuilder/packages/' . $packageName . '/modules/' . $moduleName . '/metadata/' . self::HISTORYFILENAME ;
68         $this->_history = new History ( $this->historyPathname ) ;
69
70         //get the bean from ModuleBuilder
71         $mb = new ModuleBuilder ( ) ;
72         $this->module = & $mb->getPackageModule ( $packageName, $moduleName ) ;
73         $this->module->mbvardefs->updateVardefs () ;
74         $this->_fielddefs = & $this->module->mbvardefs->vardefs [ 'fields' ] ;
75
76         $subpanel_layout = $this->module->getAvailibleSubpanelDef ( $this->_subpanelName ) ;
77         $this->_viewdefs = & $subpanel_layout [ 'list_fields' ] ;
78         $this->_mergeFielddefs($this->_fielddefs, $this->_viewdefs);
79         
80         // Set the global mod_strings directly as Sugar does not automatically load the language files for undeployed modules (how could it?)
81         $selected_lang = 'en_us';
82         if(isset($GLOBALS['current_language']) &&!empty($GLOBALS['current_language'])) {
83             $selected_lang = $GLOBALS['current_language'];
84         }
85         $GLOBALS [ 'mod_strings' ] = array_merge ( $GLOBALS [ 'mod_strings' ], $this->module->getModStrings ($selected_lang) ) ;
86     }
87
88     function getLanguage ()
89     {
90         return "" ; // '' is the signal to translate() to use the global mod_strings
91     }
92
93     /*
94      * Save a subpanel
95      * @param array defs    Layout definition in the same format as received by the constructor
96      * @param string type   The location for the file - for example, MB_BASEMETADATALOCATION for a location in the OOB metadata directory
97      */
98     function deploy ($defs)
99     {
100         $outputDefs = $this->module->getAvailibleSubpanelDef ( $this->_subpanelName ) ;
101         // first sort out the historical record...
102         // copy the definition to a temporary file then let the history object add it
103         write_array_to_file ( self::HISTORYVARIABLENAME, $outputDefs, $this->historyPathname, 'w', '' ) ;
104         $this->_history->append ( $this->historyPathname ) ;
105         // no need to unlink the temporary file as being handled by in history->append()
106         //unlink ( $this->historyPathname ) ;
107
108         $outputDefs [ 'list_fields' ] = $defs ;
109         $this->_viewdefs = $defs ;
110         $this->module->saveAvailibleSubpanelDef ( $this->_subpanelName, $outputDefs ) ;
111
112     }
113
114 }