PageRenderTime 24ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/jacknicole/sugarcrm_dev
PHP | 211 lines | 124 code | 25 blank | 62 comment | 27 complexity | 87c39c5818423ac119f20c9f44b11de8 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-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. require_once 'modules/ModuleBuilder/MB/ModuleBuilder.php' ;
  38. require_once 'modules/ModuleBuilder/parsers/views/AbstractMetaDataImplementation.php' ;
  39. require_once 'modules/ModuleBuilder/parsers/views/MetaDataImplementationInterface.php' ;
  40. require_once 'modules/ModuleBuilder/parsers/views/ListLayoutMetaDataParser.php' ;
  41. require_once 'modules/ModuleBuilder/parsers/views/GridLayoutMetaDataParser.php' ;
  42. require_once 'modules/ModuleBuilder/parsers/constants.php' ;
  43. class UndeployedMetaDataImplementation extends AbstractMetaDataImplementation implements MetaDataImplementationInterface
  44. {
  45. private $_packageName ;
  46. /*
  47. * Constructor
  48. * @param string $view
  49. * @param string $moduleName
  50. * @throws Exception Thrown if the provided view doesn't exist for this module
  51. */
  52. function __construct ($view , $moduleName , $packageName)
  53. {
  54. // BEGIN ASSERTIONS
  55. if (! isset ( $this->_fileVariables [ $view ] ))
  56. {
  57. sugar_die ( get_class ( $this ) . ": View $view is not supported" ) ;
  58. }
  59. // END ASSERTIONS
  60. $this->_view = strtolower ( $view ) ;
  61. $this->_moduleName = $moduleName ;
  62. $this->_packageName = $packageName ;
  63. //get the bean from ModuleBuilder
  64. $mb = new ModuleBuilder ( ) ;
  65. $this->module = $module = & $mb->getPackageModule ( $packageName, $moduleName ) ;
  66. $pak = $mb->getPackage($packageName);
  67. $module->mbvardefs->updateVardefs () ;
  68. // Set the list of fields associated with this module
  69. $fielddefs = array_change_key_case ( $module->mbvardefs->vardefs [ 'fields' ] ) ;
  70. // Set the global mod_strings directly as Sugar does not automatically load the language files for undeployed modules (how could it?)
  71. $selected_lang = 'en_us';
  72. if(isset($GLOBALS['current_language']) &&!empty($GLOBALS['current_language'])) {
  73. $selected_lang = $GLOBALS['current_language'];
  74. }
  75. $GLOBALS [ 'mod_strings' ] = array_merge ( $GLOBALS [ 'mod_strings' ], $module->getModStrings ($selected_lang) ) ;
  76. //Load relationshhip based fields and labels
  77. $moduleRels = $pak->getRelationshipsForModule($moduleName);
  78. foreach($moduleRels as $rName => $rel ) {
  79. $varDefsSet = $rel->buildVardefs();
  80. if (!empty($varDefsSet[$module->key_name])) {
  81. foreach ($varDefsSet[$module->key_name] as $def) {
  82. $fielddefs[$def['name']] = $def;
  83. }
  84. }
  85. $labels = $rel->buildLabels();
  86. foreach ($labels as $def) {
  87. if ($def['module'] == $module->key_name) {
  88. $GLOBALS [ 'mod_strings' ][$def['system_label']] = $def['display_label'];
  89. }
  90. }
  91. }
  92. $loaded = null ;
  93. foreach ( array ( MB_WORKINGMETADATALOCATION , MB_HISTORYMETADATALOCATION ) as $type )
  94. {
  95. $this->_sourceFilename = $this->getFileName ( $view, $moduleName, $packageName , $type ) ;
  96. if($view == MB_POPUPSEARCH || $view == MB_POPUPLIST){
  97. $layout = $this->_loadFromPopupFile ( $this->_sourceFilename , null, $view);
  98. }else{
  99. $layout = $this->_loadFromFile ( $this->_sourceFilename );
  100. }
  101. if ( null !== $layout )
  102. {
  103. // merge in the fielddefs from this layout
  104. $this->_mergeFielddefs ( $fielddefs , $layout ) ;
  105. $loaded = $layout ;
  106. }
  107. }
  108. if ($loaded === null)
  109. {
  110. throw new Exception ( get_class ( $this ) . ": view definitions for View $this->_view and Module $this->_moduleName are missing" ) ;
  111. }
  112. $this->_viewdefs = $loaded ;
  113. $sourceFilename = $this->getFileName ( $view, $moduleName, $packageName, MB_WORKINGMETADATALOCATION );
  114. if($view == MB_POPUPSEARCH || $view == MB_POPUPLIST){
  115. $layout = $this->_loadFromPopupFile ( $sourceFilename , null, $view);
  116. }else{
  117. $layout = $this->_loadFromFile ($sourceFilename) ;
  118. }
  119. $this->_originalViewdefs = $layout ;
  120. $this->_fielddefs = $fielddefs ;
  121. $this->_history = new History ( $this->getFileName ( $view, $moduleName, $packageName, MB_HISTORYMETADATALOCATION ) ) ;
  122. }
  123. function getLanguage ()
  124. {
  125. return $this->_packageName . $this->_moduleName ;
  126. }
  127. /*
  128. * Deploy a layout
  129. * @param array defs Layout definition in the same format as received by the constructor
  130. */
  131. function deploy ($defs)
  132. {
  133. //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.
  134. if ($this->_sourceFilename == $this->getFileName ( $this->_view, $this->_moduleName, $this->_packageName, MB_HISTORYMETADATALOCATION )
  135. && file_exists($this->getFileName ( $this->_view, $this->_moduleName, $this->_packageName, MB_WORKINGMETADATALOCATION ))) {
  136. $this->_history->append ( $this->getFileName ( $this->_view, $this->_moduleName, $this->_packageName, MB_WORKINGMETADATALOCATION )) ;
  137. } else {
  138. $this->_history->append ( $this->_sourceFilename ) ;
  139. }
  140. $filename = $this->getFileName ( $this->_view, $this->_moduleName, $this->_packageName, MB_WORKINGMETADATALOCATION ) ;
  141. $GLOBALS [ 'log' ]->debug ( get_class ( $this ) . "->deploy(): writing to " . $filename ) ;
  142. $this->_saveToFile ( $filename, $defs ) ;
  143. }
  144. /*
  145. * Construct a full pathname for the requested metadata
  146. * @param string view The view type, that is, EditView, DetailView etc
  147. * @param string modulename The name of the module that will use this layout
  148. * @param string type
  149. */
  150. public static function getFileName ($view , $moduleName , $packageName , $type = MB_BASEMETADATALOCATION)
  151. {
  152. $type = strtolower ( $type ) ;
  153. // BEGIN ASSERTIONS
  154. if ($type != MB_BASEMETADATALOCATION && $type != MB_HISTORYMETADATALOCATION)
  155. {
  156. // just warn rather than die
  157. $GLOBALS [ 'log' ]->warning ( "UndeployedMetaDataImplementation->getFileName(): view type $type is not recognized" ) ;
  158. }
  159. // END ASSERTIONS
  160. $filenames = array ( MB_DASHLETSEARCH => 'dashletviewdefs',
  161. MB_DASHLET => 'dashletviewdefs',
  162. MB_LISTVIEW => 'listviewdefs' ,
  163. MB_BASICSEARCH => 'searchdefs' ,
  164. MB_ADVANCEDSEARCH => 'searchdefs' ,
  165. MB_EDITVIEW => 'editviewdefs' ,
  166. MB_DETAILVIEW => 'detailviewdefs' ,
  167. MB_QUICKCREATE => 'quickcreatedefs',
  168. MB_POPUPSEARCH => 'popupdefs',
  169. MB_POPUPLIST => 'popupdefs',
  170. ) ;
  171. switch ( $type)
  172. {
  173. case MB_HISTORYMETADATALOCATION :
  174. return 'custom/history/modulebuilder/packages/' . $packageName . '/modules/' . $moduleName . '/metadata/' . $filenames [ $view ] . '.php' ;
  175. default :
  176. // get the module again, all so we can call this method statically without relying on the module stored in the class variables
  177. $mb = new ModuleBuilder ( ) ;
  178. $module = & $mb->getPackageModule ( $packageName, $moduleName ) ;
  179. return $module->getModuleDir () . '/metadata/' . $filenames [ $view ] . '.php' ;
  180. }
  181. }
  182. public function getModuleDir(){
  183. return $this->module->key_name;
  184. }
  185. }
  186. ?>