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.
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 require_once ('modules/ModuleBuilder/parsers/views/ListLayoutMetaDataParser.php') ;
40 require_once ('modules/ModuleBuilder/parsers/views/SearchViewMetaDataParser.php') ;
41 require_once 'modules/ModuleBuilder/parsers/constants.php' ;
43 class DashletMetaDataParser extends ListLayoutMetaDataParser
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_AVAILABLE' => 'getAdditionalFields' , 'LBL_HIDDEN' => 'getAvailableFields' ) ;
52 * $this->columns Array of 'Column LBL'=>function_to_retrieve_fields_for_this_column() - expected by the view
54 * @param string moduleName The name of the module to which this listview belongs
55 * @param string packageName If not empty, the name of the package to which this listview belongs
57 function __construct ($view, $moduleName , $packageName = '')
60 $this->search = ($view == MB_DASHLETSEARCH) ? true : false;
61 $this->_moduleName = $moduleName;
62 $this->_packageName = $packageName;
63 $this->_view = $view ;
66 $this->columns = array ( 'LBL_DEFAULT' => 'getAdditionalFields' , 'LBL_HIDDEN' => 'getAvailableFields' ) ;
67 parent::__construct ( MB_DASHLETSEARCH, $moduleName, $packageName ) ;
70 parent::__construct ( MB_DASHLET, $moduleName, $packageName ) ;
72 $this->_viewdefs = $this->mergeFieldDefinitions($this->_viewdefs, $this->_fielddefs);
76 * Dashlets contain both a searchview and list view definition, therefore we need to merge only the relevant info
78 function mergeFieldDefinitions ( $viewdefs, $fielddefs ) {
79 if ($this->_view == MB_DASHLETSEARCH && isset($viewdefs['searchfields']))
81 //Remove any relate fields from the possible defs as they will break the homepage
82 foreach($fielddefs as $id=>$def) {
83 if (isset($def['type']) && $def['type'] == 'relate') {
84 if( isset($fielddefs[$id]['id_name'])){
85 $fielddefs[$fielddefs[$id]['id_name']] = $def;
86 unset($fielddefs[$id]);
90 $viewdefs = array_change_key_case($viewdefs['searchfields']);
91 $viewdefs = $this->_viewdefs = $this->convertSearchToListDefs($viewdefs);
93 else if ($this->_view == MB_DASHLET && isset($viewdefs['columns']))
95 $viewdefs = $this->_viewdefs = array_change_key_case($viewdefs['columns']);
96 $viewdefs = $this->_viewdefs = $this->convertSearchToListDefs($viewdefs);
102 function convertSearchToListDefs($defs) {
104 foreach($defs as $key=>$value) {
105 $temp[$key] = $value;
106 if (!isset ($temp[$key]['name'])) {
107 $temp[$key]['name'] = $key;
113 private function ConvertSearchToDashletDefs($defs) {
115 foreach($defs as $key=>$value) {
116 if($value['default']) {
117 //$temp[$key] = $value;
118 $temp[$key] = array('default' => '');
120 $temp[$key] = $value;
126 function handleSave ($populate = true)
128 if (empty ( $this->_packageName ))
130 foreach(array(MB_CUSTOMMETADATALOCATION , MB_BASEMETADATALOCATION) as $value){
131 $file = $this->implementation->getFileName(MB_DASHLET, $this->_moduleName, $value);
132 if(file_exists($file)){
136 $writeTodashletName = $dashletName = $this->implementation->getLanguage().'Dashlet';
137 if(!file_exists($file)){
138 $file = "modules/{$this->_moduleName}/Dashlets/My{$this->_moduleName}Dashlet/My{$this->_moduleName}Dashlet.data.php";
139 $dashletName = 'My'.$this->implementation->getLanguage().'Dashlet';
141 $writeFile = $this->implementation->getFileName(MB_DASHLET, $this->_moduleName);
142 if(!file_exists($writeFile)){
143 mkdir_recursive ( dirname ( $writeFile ) ) ;
147 $writeFile = $file = $this->implementation->getFileName(MB_DASHLET, $this->_moduleName, $this->_packageName);
148 $writeTodashletName = $dashletName =$this->implementation->module->key_name . 'Dashlet';
151 $this->implementation->_history->append ( $file ) ;
153 $this->_populateFromRequest() ;
157 if (!isset($dashletData[$dashletName])) {
158 sugar_die ("unable to load Module Dashlet Definition");
160 if ($fh = sugar_fopen ( $writeFile, 'w' ))
162 if ($this->_view == MB_DASHLETSEARCH)
164 $dashletData[$dashletName]['searchFields'] = $this->ConvertSearchToDashletDefs($this->_viewdefs);
167 $dashletData[$dashletName]['columns'] = $this->_viewdefs;
169 $out .= "\$dashletData['$writeTodashletName']['searchFields'] = " . var_export_helper ($dashletData[$dashletName]['searchFields']) . ";\n";
170 $out .= "\$dashletData['$writeTodashletName']['columns'] = " . var_export_helper ($dashletData[$dashletName]['columns']) . ";\n";