]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/parsers/views/SubpanelMetaDataParser.php
Release 6.2.0
[Github/sugarcrm.git] / modules / ModuleBuilder / parsers / views / SubpanelMetaDataParser.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-2011 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
40 require_once ('modules/ModuleBuilder/parsers/views/ListLayoutMetaDataParser.php') ;
41 require_once 'modules/ModuleBuilder/parsers/constants.php' ;
42
43 class SubpanelMetaDataParser extends ListLayoutMetaDataParser
44 {
45
46     // Columns is used by the view to construct the listview - each column is built by calling the named function
47     public $columns = array ( 'LBL_DEFAULT' => 'getDefaultFields' , 'LBL_HIDDEN' => 'getAvailableFields' ) ;
48     protected $labelIdentifier = 'vname' ; // labels in the subpanel defs are tagged 'vname' =>
49
50     /*
51      * Constructor
52      * Must set:
53      * $this->columns   Array of 'Column LBL'=>function_to_retrieve_fields_for_this_column() - expected by the view
54      *
55      * @param string subpanelName   The name of this subpanel
56      * @param string moduleName     The name of the module to which this subpanel belongs
57      * @param string packageName    If not empty, the name of the package to which this subpanel belongs
58      */
59     function __construct ($subpanelName , $moduleName , $packageName = '')
60     {
61         $GLOBALS [ 'log' ]->debug ( get_class ( $this ) . ": __construct()" ) ;
62
63         // TODO: check the implementations
64         if (empty ( $packageName ))
65         {
66             require_once 'modules/ModuleBuilder/parsers/views/DeployedSubpanelImplementation.php' ;
67             $this->implementation = new DeployedSubpanelImplementation ( $subpanelName, $moduleName ) ;
68             //$this->originalViewDef = $this->implementation->getOriginalDefs ();
69         } else
70         {
71             require_once 'modules/ModuleBuilder/parsers/views/UndeployedSubpanelImplementation.php' ;
72             $this->implementation = new UndeployedSubpanelImplementation ( $subpanelName, $moduleName, $packageName ) ;
73         }
74
75         $this->_viewdefs = array_change_key_case ( $this->implementation->getViewdefs () ) ; // force to lower case so don't have problems with case mismatches later
76         $this->_fielddefs =  $this->implementation->getFielddefs ();
77         $this->_standardizeFieldLabels( $this->_fielddefs );
78         $GLOBALS['log']->debug ( get_class($this)."->__construct(): viewdefs = ".print_r($this->_viewdefs,true));
79         $GLOBALS['log']->debug ( get_class($this)."->__construct(): viewdefs = ".print_r($this->_viewdefs,true));
80         $this->_invisibleFields = $this->findInvisibleFields( $this->_viewdefs ) ;
81
82         $GLOBALS['log']->debug ( get_class($this)."->__construct(): invisibleFields = ".print_r($this->_invisibleFields,true));
83     }
84
85     /*
86      * Save the layout
87      */
88     function handleSave ($populate = true)
89     {
90         if ($populate)
91         {
92             $this->_populateFromRequest() ;
93             if (isset ($_REQUEST['subpanel_title']) && isset($_REQUEST['subpanel_title_key'])) {
94                     $selected_lang = (!empty($_REQUEST['selected_lang'])? $_REQUEST['selected_lang']:$_SESSION['authenticated_user_language']);
95                         if(empty($selected_lang)){
96                             $selected_lang = $GLOBALS['sugar_config']['default_language'];
97                         }
98                         require_once 'modules/ModuleBuilder/parsers/parser.label.php' ;
99                 $labelParser = new ParserLabel ( $_REQUEST['view_module'] , isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
100                 $labelParser->addLabels($selected_lang, array($_REQUEST['subpanel_title_key'] =>  $_REQUEST['subpanel_title']), $_REQUEST['view_module']);
101             }
102         }
103
104         $this->implementation->deploy ( $this->restoreInvisibleFields ( $this->_invisibleFields , $this->_viewdefs ) ) ; // unlike our parent, do not force the field names back to upper case
105     }
106
107     /**
108      * Return a list of the default fields for a subpanel
109      * TODO: have this return just a list of fields, without definitions
110      * @return array    List of default fields as an array, where key = value = <field name>
111      */
112     function getDefaultFields ()
113     {
114         $defaultFields = array ( ) ;
115         foreach ( $this->_viewdefs as $key => $def )
116         {
117             if (empty ( $def [ 'usage' ] ) || strcmp ( $def [ 'usage' ], 'query_only' ) == 1)
118             {
119                 $defaultFields [ strtolower ( $key ) ] = $this->_viewdefs [ $key ] ;
120             }
121         }
122
123         return $defaultFields ;
124     }
125
126     /*
127      * Find the query_only fields in the viewdefs
128      * Query_only fields are used by the MVC to generate the subpanel but are not editable - they must be maintained in the layout
129      * @param viewdefs The viewdefs to be searched for invisible fields
130      * @return Array of invisible fields, ready to be provided to $this->restoreInvisibleFields
131      */
132     function findInvisibleFields( $viewdefs )
133     {
134         $invisibleFields = array () ;
135         foreach ( $viewdefs as $name => $def )
136             if ( isset($def [ 'usage' ] ) && ($def [ 'usage'] == 'query_only') )
137                 $invisibleFields [ $name ] = $def ;
138         return $invisibleFields ;
139     }
140
141     function restoreInvisibleFields ( $invisibleFields , $viewdefs )
142     {
143         foreach ( $invisibleFields as $name => $def )
144         {
145             $viewdefs [ $name ] = $def ;
146         }
147         return $viewdefs ;
148     }
149     
150     static function _trimFieldDefs ( $def )
151     {
152         $listDef = parent::_trimFieldDefs($def); 
153         if (isset($listDef ['label']))
154         {
155             $listDef ['vname'] = $listDef ['label'];
156             unset($listDef ['label']);
157         }
158         return $listDef;
159     }
160
161 }
162 ?>