PageRenderTime 38ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/ModuleBuilder/parsers/views/UndeployedMetaDataImplementation.php

https://gitlab.com/tjaafar/SuiteCRM
PHP | 214 lines | 124 code | 25 blank | 65 comment | 27 complexity | 0899dae7cf854c2a03e35ac0b0e3e1d4 MD5 | raw file
  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-2013 SugarCRM Inc.
  6. * SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd.
  7. * Copyright (C) 2011 - 2014 Salesagility Ltd.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it under
  10. * the terms of the GNU Affero General Public License version 3 as published by the
  11. * Free Software Foundation with the addition of the following permission added
  12. * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  13. * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
  14. * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  15. *
  16. * This program is distributed in the hope that it will be useful, but WITHOUT
  17. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  18. * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  19. * details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License along with
  22. * this program; if not, see http://www.gnu.org/licenses or write to the Free
  23. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  24. * 02110-1301 USA.
  25. *
  26. * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
  27. * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
  28. *
  29. * The interactive user interfaces in modified source and object code versions
  30. * of this program must display Appropriate Legal Notices, as required under
  31. * Section 5 of the GNU Affero General Public License version 3.
  32. *
  33. * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
  34. * these Appropriate Legal Notices must retain the display of the "Powered by
  35. * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
  36. * reasonably feasible for technical reasons, the Appropriate Legal Notices must
  37. * display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM".
  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. class UndeployedMetaDataImplementation extends AbstractMetaDataImplementation implements MetaDataImplementationInterface
  46. {
  47. private $_packageName ;
  48. /*
  49. * Constructor
  50. * @param string $view
  51. * @param string $moduleName
  52. * @throws Exception Thrown if the provided view doesn't exist for this module
  53. */
  54. function __construct ($view , $moduleName , $packageName)
  55. {
  56. // BEGIN ASSERTIONS
  57. if (! isset ( $this->_fileVariables [ $view ] ))
  58. {
  59. sugar_die ( get_class ( $this ) . ": View $view is not supported" ) ;
  60. }
  61. // END ASSERTIONS
  62. $this->_view = strtolower ( $view ) ;
  63. $this->_moduleName = $moduleName ;
  64. $this->_packageName = $packageName ;
  65. //get the bean from ModuleBuilder
  66. $mb = new ModuleBuilder ( ) ;
  67. $this->module = $module = & $mb->getPackageModule ( $packageName, $moduleName ) ;
  68. $pak = $mb->getPackage($packageName);
  69. $module->mbvardefs->updateVardefs () ;
  70. // Set the list of fields associated with this module
  71. $fielddefs = array_change_key_case ( $module->mbvardefs->vardefs [ 'fields' ] ) ;
  72. // Set the global mod_strings directly as Sugar does not automatically load the language files for undeployed modules (how could it?)
  73. $selected_lang = 'en_us';
  74. if(isset($GLOBALS['current_language']) &&!empty($GLOBALS['current_language'])) {
  75. $selected_lang = $GLOBALS['current_language'];
  76. }
  77. $GLOBALS [ 'mod_strings' ] = array_merge ( $GLOBALS [ 'mod_strings' ], $module->getModStrings ($selected_lang) ) ;
  78. //Load relationshhip based fields and labels
  79. $moduleRels = $pak->getRelationshipsForModule($moduleName);
  80. foreach($moduleRels as $rName => $rel ) {
  81. $varDefsSet = $rel->buildVardefs();
  82. if (!empty($varDefsSet[$module->key_name])) {
  83. foreach ($varDefsSet[$module->key_name] as $def) {
  84. $fielddefs[$def['name']] = $def;
  85. }
  86. }
  87. $labels = $rel->buildLabels();
  88. foreach ($labels as $def) {
  89. if ($def['module'] == $module->key_name) {
  90. $GLOBALS [ 'mod_strings' ][$def['system_label']] = $def['display_label'];
  91. }
  92. }
  93. }
  94. $loaded = null ;
  95. foreach ( array ( MB_BASEMETADATALOCATION , MB_HISTORYMETADATALOCATION ) as $type )
  96. {
  97. $this->_sourceFilename = $this->getFileName ( $view, $moduleName, $packageName , $type ) ;
  98. if($view == MB_POPUPSEARCH || $view == MB_POPUPLIST){
  99. $layout = $this->_loadFromPopupFile ( $this->_sourceFilename , null, $view);
  100. }else{
  101. $layout = $this->_loadFromFile ( $this->_sourceFilename );
  102. }
  103. if ( null !== $layout )
  104. {
  105. // merge in the fielddefs from this layout
  106. $this->_mergeFielddefs ( $fielddefs , $layout ) ;
  107. $loaded = $layout ;
  108. }
  109. }
  110. if ($loaded === null)
  111. {
  112. throw new Exception ( get_class ( $this ) . ": view definitions for View $this->_view and Module $this->_moduleName are missing" ) ;
  113. }
  114. $this->_viewdefs = $loaded ;
  115. $sourceFilename = $this->getFileName ( $view, $moduleName, $packageName, MB_BASEMETADATALOCATION );
  116. if($view == MB_POPUPSEARCH || $view == MB_POPUPLIST){
  117. $layout = $this->_loadFromPopupFile ( $sourceFilename , null, $view);
  118. }else{
  119. $layout = $this->_loadFromFile ($sourceFilename) ;
  120. }
  121. $this->_originalViewdefs = $layout ;
  122. $this->_fielddefs = $fielddefs ;
  123. $this->_history = new History ( $this->getFileName ( $view, $moduleName, $packageName, MB_HISTORYMETADATALOCATION ) ) ;
  124. }
  125. function getLanguage ()
  126. {
  127. return $this->_packageName . $this->_moduleName ;
  128. }
  129. /*
  130. * Deploy a layout
  131. * @param array defs Layout definition in the same format as received by the constructor
  132. */
  133. function deploy ($defs)
  134. {
  135. //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.
  136. if ($this->_sourceFilename == $this->getFileName ( $this->_view, $this->_moduleName, $this->_packageName, MB_HISTORYMETADATALOCATION )
  137. && file_exists($this->getFileName ( $this->_view, $this->_moduleName, $this->_packageName, MB_BASEMETADATALOCATION ))) {
  138. $this->_history->append ( $this->getFileName ( $this->_view, $this->_moduleName, $this->_packageName, MB_BASEMETADATALOCATION )) ;
  139. } else {
  140. $this->_history->append ( $this->_sourceFilename ) ;
  141. }
  142. $filename = $this->getFileName ( $this->_view, $this->_moduleName, $this->_packageName, MB_BASEMETADATALOCATION ) ;
  143. $GLOBALS [ 'log' ]->debug ( get_class ( $this ) . "->deploy(): writing to " . $filename ) ;
  144. $this->_saveToFile ( $filename, $defs ) ;
  145. }
  146. /*
  147. * Construct a full pathname for the requested metadata
  148. * @param string view The view type, that is, EditView, DetailView etc
  149. * @param string modulename The name of the module that will use this layout
  150. * @param string type
  151. */
  152. public static function getFileName ($view , $moduleName , $packageName , $type = MB_BASEMETADATALOCATION)
  153. {
  154. $type = strtolower ( $type ) ;
  155. // BEGIN ASSERTIONS
  156. if ($type != MB_BASEMETADATALOCATION && $type != MB_HISTORYMETADATALOCATION)
  157. {
  158. // just warn rather than die
  159. $GLOBALS [ 'log' ]->warning ( "UndeployedMetaDataImplementation->getFileName(): view type $type is not recognized" ) ;
  160. }
  161. // END ASSERTIONS
  162. $filenames = array ( MB_DASHLETSEARCH => 'dashletviewdefs',
  163. MB_DASHLET => 'dashletviewdefs',
  164. MB_LISTVIEW => 'listviewdefs' ,
  165. MB_BASICSEARCH => 'searchdefs' ,
  166. MB_ADVANCEDSEARCH => 'searchdefs' ,
  167. MB_EDITVIEW => 'editviewdefs' ,
  168. MB_DETAILVIEW => 'detailviewdefs' ,
  169. MB_QUICKCREATE => 'quickcreatedefs',
  170. MB_POPUPSEARCH => 'popupdefs',
  171. MB_POPUPLIST => 'popupdefs',
  172. ) ;
  173. switch ( $type)
  174. {
  175. case MB_HISTORYMETADATALOCATION :
  176. return 'custom/history/modulebuilder/packages/' . $packageName . '/modules/' . $moduleName . '/metadata/' . $filenames [ $view ] . '.php' ;
  177. default :
  178. // get the module again, all so we can call this method statically without relying on the module stored in the class variables
  179. $mb = new ModuleBuilder ( ) ;
  180. $module = & $mb->getPackageModule ( $packageName, $moduleName ) ;
  181. return $module->getModuleDir () . '/metadata/' . $filenames [ $view ] . '.php' ;
  182. }
  183. }
  184. public function getModuleDir(){
  185. return $this->module->key_name;
  186. }
  187. }
  188. ?>