2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Affero General Public License version 3 as published by the
8 * Free Software Foundation with the addition of the following permission added
9 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
18 * You should have received a copy of the GNU Affero General Public License along with
19 * this program; if not, see http://www.gnu.org/licenses or write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26 * The interactive user interfaces in modified source and object code versions
27 * of this program must display Appropriate Legal Notices, as required under
28 * Section 5 of the GNU Affero General Public License version 3.
30 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31 * these Appropriate Legal Notices must retain the display of the "Powered by
32 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33 * technical reasons, the Appropriate Legal Notices must display the words
34 * "Powered by SugarCRM".
35 ********************************************************************************/
37 require_once ('modules/ModuleBuilder/MB/AjaxCompose.php') ;
38 require_once ('modules/ModuleBuilder/MB/ModuleBuilder.php') ;
39 require_once ('modules/ModuleBuilder/views/view.relationship.php') ;
40 require_once ('modules/ModuleBuilder/Module/StudioModule.php') ;
41 require_once ('modules/ModuleBuilder/Module/StudioBrowser.php') ;
43 class ViewRelationships extends SugarView
46 * @see SugarView::_getModuleTitleParams()
48 protected function _getModuleTitleParams($browserTitle = false)
53 translate('LBL_MODULE_NAME','Administration'),
54 ModuleBuilderController::getModuleTitle(),
60 $moduleName = ! empty ( $_REQUEST [ 'view_module' ] ) ? $_REQUEST [ 'view_module' ] : $_REQUEST [ 'edit_module' ] ;
61 $smarty = new Sugar_Smarty ( ) ;
62 // set the mod_strings as we can be called after doing a Repair and the mod_strings are set to Administration
63 $GLOBALS['mod_strings'] = return_module_language($GLOBALS['current_language'], 'ModuleBuilder');
64 $smarty->assign ( 'mod_strings', $GLOBALS [ 'mod_strings' ] ) ;
65 $smarty->assign ( 'view_module', $moduleName ) ;
67 $ajax = new AjaxCompose ( ) ;
68 $json = getJSONobj () ;
69 $this->fromModuleBuilder = !empty ( $_REQUEST [ 'MB' ] ) || (!empty($_REQUEST['view_package']) && $_REQUEST['view_package'] != 'studio') ;
70 $smarty->assign('fromModuleBuilder', $this->fromModuleBuilder);
71 if (!$this->fromModuleBuilder)
73 $smarty->assign ( 'view_package', '' ) ;
75 $relationships = new DeployedRelationships ( $moduleName ) ;
76 $ajaxRelationships = $this->getAjaxRelationships( $relationships ) ;
77 $smarty->assign ( 'relationships', $json->encode ( $ajaxRelationships ) ) ;
78 $smarty->assign ( 'empty', (sizeof ( $ajaxRelationships ) == 0) ) ;
79 $smarty->assign ( 'studio', true ) ;
82 global $app_list_strings ;
83 $moduleNames = array_change_key_case ( $app_list_strings [ 'moduleList' ] ) ;
84 $translatedModule = $moduleNames [ strtolower ( $moduleName ) ] ;
85 $ajax->addCrumb ( translate('LBL_STUDIO'), 'ModuleBuilder.main("studio")' ) ;
86 $ajax->addCrumb ( $translatedModule, 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view_module=' . $moduleName . '")' ) ;
87 $ajax->addCrumb ( translate('LBL_RELATIONSHIPS'), '' ) ;
88 $ajax->addSection ( 'center', $moduleName . ' ' . translate('LBL_RELATIONSHIPS'), $this->fetchTemplate($smarty, 'modules/ModuleBuilder/tpls/studioRelationships.tpl'));
92 $smarty->assign ( 'view_package', $_REQUEST [ 'view_package' ] ) ;
94 $mb = new ModuleBuilder ( ) ;
95 $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ] ) ;
96 $package = $mb->packages [ $_REQUEST [ 'view_package' ] ] ;
97 $package->loadModuleTitles();
98 $relationships = new UndeployedRelationships ( $module->getModuleDir () ) ;
99 $ajaxRelationships = $this->getAjaxRelationships( $relationships ) ;
100 $smarty->assign ( 'relationships', $json->encode ( $ajaxRelationships ) ) ;
101 $smarty->assign ( 'empty', (sizeof ( $ajaxRelationships ) == 0) ) ;
103 $module->help [ 'default' ] = (empty ( $_REQUEST [ 'view_module' ] )) ? 'create' : 'modify' ;
104 $module->help [ 'group' ] = 'module' ;
106 $ajax->addCrumb ( translate('LBL_MODULEBUILDER'), 'ModuleBuilder.main("mb")' ) ;
107 $ajax->addCrumb ( $package->name, 'ModuleBuilder.getContent("module=ModuleBuilder&action=package&package=' . $package->name . '")' ) ;
108 $ajax->addCrumb ( $moduleName, 'ModuleBuilder.getContent("module=ModuleBuilder&action=module&view_package=' . $package->name . '&view_module=' . $moduleName . '")' ) ;
109 $ajax->addCrumb ( translate('LBL_RELATIONSHIPS'), '' ) ;
110 $ajax->addSection ( 'center', $moduleName . ' ' . translate('LBL_RELATIONSHIPS'), $this->fetchTemplate($smarty, 'modules/ModuleBuilder/tpls/studioRelationships.tpl'));
112 echo $ajax->getJavascript () ;
116 * Encode the relationships for this module for display in the Ext grid layout
118 function getAjaxRelationships ( $relationships )
120 $ajaxrels = array ( ) ;
121 foreach ( $relationships->getRelationshipList () as $relationshipName )
123 $rel = $relationships->get ( $relationshipName )->getDefinition () ;
124 $rel [ 'lhs_module' ] = translate( $rel [ 'lhs_module' ] ) ;
125 $rel [ 'rhs_module' ] = translate( $rel [ 'rhs_module' ] ) ;
127 //#28668 , translate the relationship type before render it .
128 switch($rel['relationship_type']){
130 $rel['relationship_type'] = translate ( 'LBL_ONETOONE' );
133 $rel['relationship_type'] = translate ( 'LBL_ONETOMANY' );
136 $rel['relationship_type'] = translate ( 'LBL_MANYTOONE' );
139 $rel['relationship_type'] = translate ( 'LBL_MANYTOMANY' );
141 default: $rel['relationship_type'] = '';
143 $rel [ 'name' ] = $relationshipName ;
144 if ($rel [ 'is_custom' ] && isset($rel [ 'from_studio' ]) && $rel [ 'from_studio' ]) {
145 $rel [ 'name' ] = $relationshipName . "*";
147 $ajaxrels [] = $rel ;
154 * This function overrides fetchTemplate from SugarView.
156 * @param FieldViewer $mixed the Sugar_Smarty instance
157 * @param string $template the file to fetch
158 * @return string contents from calling the fetch method on the Sugar_Smarty instance
160 protected function fetchTemplate($smarty, $template)
162 return $smarty->fetch($this->getCustomFilePathIfExists($template));