]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/views/view.relationships.php
Release 6.5.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-2012 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'), $this->fetchTemplate($smarty, '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'), $this->fetchTemplate($smarty, 'modules/ModuleBuilder/tpls/studioRelationships.tpl'));
111         }
112         echo $ajax->getJavascript () ;
113     }
114
115     /*
116      * Encode the relationships for this module for display in the Ext grid layout
117      */
118     function getAjaxRelationships ( $relationships )
119     {
120         $ajaxrels = array ( ) ;
121         foreach ( $relationships->getRelationshipList () as $relationshipName )
122         {
123             $rel = $relationships->get ( $relationshipName )->getDefinition () ;
124             $rel [ 'lhs_module' ] = translate( $rel [ 'lhs_module' ] ) ;
125             $rel [ 'rhs_module' ] = translate( $rel [ 'rhs_module' ] ) ;
126             
127             //#28668  , translate the relationship type before render it .
128             switch($rel['relationship_type']){
129                 case 'one-to-one':
130                 $rel['relationship_type']  = translate ( 'LBL_ONETOONE' );
131                 break;
132                 case 'one-to-many':
133                 $rel['relationship_type']  = translate ( 'LBL_ONETOMANY' );
134                 break;
135                 case 'many-to-one':
136                 $rel['relationship_type']  = translate ( 'LBL_MANYTOONE' );
137                 break;
138                 case 'many-to-many':
139                 $rel['relationship_type']  = translate ( 'LBL_MANYTOMANY' );
140                 break;
141                 default: $rel['relationship_type']  = '';
142             }
143             $rel [ 'name' ] = $relationshipName ;
144             if ($rel [ 'is_custom' ] && isset($rel [ 'from_studio' ]) && $rel [ 'from_studio' ]) {
145                 $rel [ 'name' ] = $relationshipName . "*";
146             }
147             $ajaxrels [] = $rel ;
148         }
149         return $ajaxrels ;
150     }
151
152     /**
153      * fetchTemplate
154      * This function overrides fetchTemplate from SugarView.
155      *
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
159      */
160     protected function fetchTemplate($smarty, $template)
161     {
162         return $smarty->fetch($this->getCustomFilePathIfExists($template));
163     }
164 }