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-2013 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
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
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' ;
49 class DeployedSubpanelImplementation extends AbstractMetaDataImplementation implements MetaDataImplementationInterface
52 const HISTORYFILENAME = 'restored.php' ;
53 const HISTORYVARIABLENAME = 'layout_defs' ;
55 private $_subpanelName ;
56 private $_aSubPanelObject ; // an aSubPanel Object representing the current subpanel
61 * @param string subpanelName The name of this subpanel
62 * @param string moduleName The name of the module to which this subpanel belongs
64 function __construct ($subpanelName , $moduleName)
66 $GLOBALS [ 'log' ]->debug ( get_class ( $this ) . "->__construct($subpanelName , $moduleName)" ) ;
67 $this->_subpanelName = $subpanelName ;
68 $this->_moduleName = $moduleName ;
71 if (! isset ( $GLOBALS [ 'beanList' ] [ $moduleName ] ))
73 sugar_die ( get_class ( $this ) . ": Modulename $moduleName is not a Deployed Module" ) ;
77 $this->historyPathname = 'custom/history/modules/' . $moduleName . '/subpanels/' . $subpanelName . '/' . self::HISTORYFILENAME ;
78 $this->_history = new History ( $this->historyPathname ) ;
80 $module = get_module_info ( $moduleName ) ;
82 require_once ('include/SubPanel/SubPanelDefinitions.php') ;
83 // retrieve the definitions for all the available subpanels for this module from the subpanel
84 $spd = new SubPanelDefinitions ( $module ) ;
86 // Get the lists of fields already in the subpanel and those that can be added in
87 // Get the fields lists from an aSubPanel object describing this subpanel from the SubPanelDefinitions object
88 $this->_viewdefs = array ( ) ;
89 $this->_fielddefs = array ( ) ;
90 $this->_language = '' ;
91 if (! empty ( $spd->layout_defs ))
92 if (array_key_exists ( strtolower ( $subpanelName ), $spd->layout_defs [ 'subpanel_setup' ] ))
94 //First load the original defs from the module folder
95 $originalSubpanel = $spd->load_subpanel( $subpanelName , false, true);
96 $this->_fullFielddefs = $originalSubpanel->get_list_fields ();
97 $this->_mergeFielddefs ( $this->_fielddefs , $this->_fullFielddefs ) ;
99 $this->_aSubPanelObject = $spd->load_subpanel ( $subpanelName ) ;
100 // now check if there is a restored subpanel in the history area - if there is, then go ahead and use it
101 if (file_exists ( $this->historyPathname ))
103 // load in the subpanelDefOverride from the history file
104 $GLOBALS [ 'log' ]->debug ( get_class ( $this ) . ": loading from history" ) ;
105 require $this->historyPathname ;
106 $this->_viewdefs = $layout_defs;
109 $this->_viewdefs = $this->_aSubPanelObject->get_list_fields () ;
112 // don't attempt to access the template_instance property if our subpanel represents a collection, as it won't be there - the sub-sub-panels get this value instead
113 if ( ! $this->_aSubPanelObject->isCollection() )
114 $this->_language = $this->_aSubPanelObject->template_instance->module_dir ;
116 // Retrieve a copy of the bean for the parent module of this subpanel - so we can find additional fields for the layout
117 $subPanelParentModuleName = $this->_aSubPanelObject->get_module_name () ;
118 $beanListLower = array_change_key_case ( $GLOBALS [ 'beanList' ] ) ;
119 if (! empty ( $subPanelParentModuleName ) && isset ( $beanListLower [ strtolower ( $subPanelParentModuleName ) ] ))
121 $subPanelParentModule = get_module_info ( $subPanelParentModuleName ) ;
123 // Run through the preliminary list, keeping only those fields that are valid to include in a layout
124 foreach ( $subPanelParentModule->field_defs as $key => $def )
126 $key = strtolower ( $key ) ;
128 if (AbstractMetaDataParser::validField( $def ))
130 if ( ! isset ( $def [ 'label' ] ) )
131 $def [ 'label' ] = $def [ 'name' ] ;
132 $this->_fielddefs [ $key ] = $def ;
137 $this->_mergeFielddefs ( $this->_fielddefs , $this->_viewdefs ) ;
142 function getLanguage ()
144 return $this->_language ;
148 * Save a definition that will be used to display a subpanel for $this->_moduleName
149 * @param array defs Layout definition in the same format as received by the constructor
151 function deploy ($defs)
153 // first sort out the historical record...
154 write_array_to_file ( self::HISTORYVARIABLENAME, $this->_viewdefs, $this->historyPathname, 'w', '' ) ;
155 $this->_history->append ( $this->historyPathname ) ;
157 $this->_viewdefs = $defs ;
159 require_once 'include/SubPanel/SubPanel.php' ;
160 $subpanel = new SubPanel ( $this->_moduleName, 'fab4', $this->_subpanelName , $this->_aSubPanelObject ) ;
162 $subpanel->saveSubPanelDefOverride ( $this->_aSubPanelObject, 'list_fields', $defs ) ;
163 // now clear the cache so that the results are immediately visible
164 include_once ('include/TemplateHandler/TemplateHandler.php') ;
165 TemplateHandler::clearCache ( $this->_moduleName ) ;