]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/views/view.relationships.php
Release 6.2.0
[Github/sugarcrm.git] / modules / ModuleBuilder / views / view.relationships.php
1  <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
5  * 
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.
12  * 
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
16  * details.
17  * 
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
21  * 02110-1301 USA.
22  * 
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.
25  * 
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.
29  * 
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  ********************************************************************************/
36
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') ;
42
43 class ViewRelationships extends SugarView
44 {
45     /**
46          * @see SugarView::_getModuleTitleParams()
47          */
48         protected function _getModuleTitleParams($browserTitle = false)
49         {
50             global $mod_strings;
51             
52         return array(
53            translate('LBL_MODULE_NAME','Administration'),
54            ModuleBuilderController::getModuleTitle(),
55            );
56     }
57
58     function display()
59     {
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 ) ;
66
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)
72         {
73             $smarty->assign ( 'view_package', '' ) ;
74
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 ) ;
80
81             //crumb
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'), $smarty->fetch ( 'modules/ModuleBuilder/tpls/studioRelationships.tpl' ) ) ;
89
90         } else
91         {
92             $smarty->assign ( 'view_package', $_REQUEST [ 'view_package' ] ) ;
93
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) ) ;
102
103             $module->help [ 'default' ] = (empty ( $_REQUEST [ 'view_module' ] )) ? 'create' : 'modify' ;
104             $module->help [ 'group' ] = 'module' ;
105
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'), //$smarty->fetch('modules/ModuleBuilder/tpls/MBRelationship/relationships.tpl'));
111             $smarty->fetch ( 'modules/ModuleBuilder/tpls/studioRelationships.tpl' ) ) ;
112         }
113         echo $ajax->getJavascript () ;
114     }
115
116     /*
117      * Encode the relationships for this module for display in the Ext grid layout
118      */
119     function getAjaxRelationships ( $relationships )
120     {
121         $ajaxrels = array ( ) ;
122         foreach ( $relationships->getRelationshipList () as $relationshipName )
123         {
124             $rel = $relationships->get ( $relationshipName )->getDefinition () ;
125             $rel [ 'lhs_module' ] = translate( $rel [ 'lhs_module' ] ) ;
126             $rel [ 'rhs_module' ] = translate( $rel [ 'rhs_module' ] ) ;
127             
128             //#28668  , translate the relationship type before render it .
129             switch($rel['relationship_type']){
130                 case 'one-to-one':
131                 $rel['relationship_type']  = translate ( 'LBL_ONETOONE' );
132                 break;
133                 case 'one-to-many':
134                 $rel['relationship_type']  = translate ( 'LBL_ONETOMANY' );
135                 break;
136                 case 'many-to-one':
137                 $rel['relationship_type']  = translate ( 'LBL_MANYTOONE' );
138                 break;
139                 case 'many-to-many':
140                 $rel['relationship_type']  = translate ( 'LBL_MANYTOMANY' );
141                 break;
142                 default: $rel['relationship_type']  = '';
143             }
144             $rel [ 'name' ] = $relationshipName ;
145             if ($rel [ 'is_custom' ] && isset($rel [ 'from_studio' ]) && $rel [ 'from_studio' ]) {
146                 $rel [ 'name' ] = $relationshipName . "*";
147             }
148             $ajaxrels [] = $rel ;
149         }
150         return $ajaxrels ;
151     }
152 }