]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/parsers/relationships/ActivitiesRelationship.php
Release 6.5.13
[Github/sugarcrm.git] / modules / ModuleBuilder / parsers / relationships / ActivitiesRelationship.php
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  * 
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
38
39 require_once 'modules/ModuleBuilder/parsers/relationships/OneToManyRelationship.php' ;
40
41 /*
42  * Class to manage the metadata for a One-To-Many Relationship
43  * The One-To-Many relationships created by this class are a combination of a subpanel and a custom relate field
44  * The LHS (One) module will receive a new subpanel for the RHS module. The subpanel gets its data ('get_subpanel_data') from a link field that references a new Relationship
45  * The RHS (Many) module will receive a new relate field to point back to the LHS
46  *
47  * OOB modules implement One-To-Many relationships as:
48  *
49  * On the LHS (One) side:
50  * A Relationship of type one-to-many in the rhs modules vardefs.php
51  * A link field in the same vardefs.php with 'relationship'= the relationship name and 'source'='non-db'
52  * A subpanel which gets its data (get_subpanel_data) from the link field
53  *
54  * On the RHS (Many) side:
55  * A Relate field in the vardefs, formatted as in this example, which references a link field:
56  * 'name' => 'account_name',
57  * 'rname' => 'name',
58  * 'id_name' => 'account_id',
59  * 'vname' => 'LBL_ACCOUNT_NAME',
60  * 'join_name'=>'accounts',
61  * 'type' => 'relate',
62  * 'link' => 'accounts',
63  * 'table' => 'accounts',
64  * 'module' => 'Accounts',
65  * 'source' => 'non-db'
66  * A link field which references the shared Relationship
67  */
68
69 class ActivitiesRelationship extends OneToManyRelationship
70 {
71
72         protected static $subpanelsAdded = array();
73         protected static $labelsAdded = array();
74
75         /*
76      * Constructor
77      * @param array $definition Parameters passed in as array defined in parent::$definitionKeys
78      * The lhs_module value is for the One side; the rhs_module value is for the Many
79      */
80     function __construct ($definition)
81     {
82         parent::__construct ( $definition ) ;
83     }
84
85     /*
86      * BUILD methods called during the build
87      */
88
89         /*
90      * Define the labels to be added to the module for the new relationships
91      * @return array    An array of system value => display value
92      */
93     function buildLabels ()
94     {
95         $labelDefinitions = array ( ) ;
96         if (!$this->relationship_only )
97         {
98             if (!isset(ActivitiesRelationship::$labelsAdded[$this->lhs_module])) {
99                 foreach(getTypeDisplayList() as $typeDisplay)
100                 {
101                     $labelDefinitions [] = array (
102                         'module' => 'application',
103                         'system_label' => $typeDisplay,
104                         'display_label' => array(
105                             $this->lhs_module => $this->lhs_label ? $this->lhs_label : ucfirst($this->lhs_module)
106                         ),
107                     );
108                 }
109             }
110
111             $rhs_display_label = '';
112             if (!empty($this->rhs_label)) {
113                 $rhs_display_label .= $this->rhs_label . ':';
114             }
115             $rhs_display_label .= translate($this->rhs_module);
116
117             $lhs_display_label = '';
118             if (!empty($this->rhs_label)) {
119                 $lhs_display_label .= $this->rhs_label . ':';
120             }
121             $lhs_display_label .= translate($this->lhs_module);
122
123             $labelDefinitions[] = array (
124                 'module' => $this->lhs_module ,
125                 'system_label' => 'LBL_' . strtoupper($this->relationship_name . '_FROM_' . $this->getRightModuleSystemLabel()) . '_TITLE',
126                 'display_label' => $rhs_display_label
127             );
128             $labelDefinitions[] = array(
129                 'module' => $this->rhs_module,
130                 'system_label' => 'LBL_' . strtoupper($this->relationship_name . '_FROM_' . $this->getLeftModuleSystemLabel()) . '_TITLE',
131                 'display_label' => $lhs_display_label
132             );
133
134             ActivitiesRelationship::$labelsAdded[$this->lhs_module] = true;
135         }
136         return $labelDefinitions ;
137     }
138
139
140         /*
141      * @return array    An array of field definitions, ready for the vardefs, keyed by module
142      */
143     function buildVardefs ( )
144     {
145         $vardefs = array ( ) ;
146
147         $vardefs [ $this->rhs_module ] [] = $this->getLinkFieldDefinition ( $this->lhs_module, $this->relationship_name ) ;
148         $vardefs [ $this->lhs_module ] [] = $this->getLinkFieldDefinition ( $this->rhs_module, $this->relationship_name ) ;
149
150
151         return $vardefs ;
152     }
153
154         protected function getLinkFieldDefinition ($sourceModule , $relationshipName)
155     {
156         $vardef = array ( ) ;
157         $vardef [ 'name' ] = $relationshipName;
158         $vardef [ 'type' ] = 'link' ;
159         $vardef [ 'relationship' ] = $relationshipName ;
160         $vardef [ 'source' ] = 'non-db' ;
161         $vardef [ 'module' ] = $sourceModule ;
162         $vardef [ 'bean_name' ] = BeanFactory::getObjectName($sourceModule) ;
163         $vardef [ 'vname' ] = strtoupper("LBL_{$relationshipName}_FROM_{$sourceModule}_TITLE");
164         return $vardef ;
165     }
166
167     /*
168      * Define what fields to add to which modules layouts
169      * @return array    An array of module => fieldname
170      */
171     function buildFieldsToLayouts ()
172     {
173         if ($this->relationship_only)
174             return array () ;
175
176         return array( $this->rhs_module => $this->relationship_name . "_name" ) ; // this must match the name of the relate field from buildVardefs
177     }
178
179         function buildSubpanelDefinitions ()
180     {
181         if ($this->relationship_only || isset(ActivitiesRelationship::$subpanelsAdded[$this->lhs_module]))
182             return array () ;
183
184         ActivitiesRelationship::$subpanelsAdded[$this->lhs_module] = true;
185         $relationshipName = substr($this->relationship_name, 0, strrpos($this->relationship_name, '_'));
186         return array( $this->lhs_module => array (
187                                   'activities' => $this->buildActivitiesSubpanelDefinition ( $relationshipName ),
188                                   'history' => $this->buildHistorySubpanelDefinition ( $relationshipName ) ,
189                                 ));
190     }
191
192     /*
193      * @return array    An array of relationship metadata definitions
194      */
195     function buildRelationshipMetaData ()
196     {
197         $relationshipName = $this->definition [ 'relationship_name' ];
198         $relMetadata = array ( ) ;
199         $relMetadata [ 'lhs_module' ] = $this->definition [ 'lhs_module' ] ;
200         $relMetadata [ 'lhs_table' ] = $this->getTablename($this->definition [ 'lhs_module' ]) ;
201         $relMetadata [ 'lhs_key' ] = 'id' ;
202         $relMetadata [ 'rhs_module' ] = $this->definition [ 'rhs_module' ] ;
203         $relMetadata [ 'rhs_table' ] = $this->getTablename($this->definition [ 'rhs_module' ]) ;
204         $relMetadata ['rhs_key'] = 'parent_id';
205         $relMetadata ['relationship_type'] = 'one-to-many';
206         $relMetadata ['relationship_role_column'] = 'parent_type';
207         $relMetadata ['relationship_role_column_value'] = $this->definition [ 'lhs_module' ] ;
208
209         return array( $this->lhs_module => array(
210                 'relationships' => array ($relationshipName => $relMetadata),
211                 'fields' => '', 'indices' => '', 'table' => '')
212         ) ;
213     }
214
215 /*
216      * Shortcut to construct an Activities collection subpanel
217      * @param AbstractRelationship $relationship    Source relationship to Activities module
218      */
219     protected function buildActivitiesSubpanelDefinition ( $relationshipName )
220     {
221                 return array (
222             'order' => 10 ,
223             'sort_order' => 'desc' ,
224             'sort_by' => 'date_start' ,
225             'title_key' => 'LBL_ACTIVITIES_SUBPANEL_TITLE' ,
226             'type' => 'collection' ,
227             'subpanel_name' => 'activities' , //this value is not associated with a physical file
228             'module' => 'Activities' ,
229             'top_buttons' => array (
230                 array ( 'widget_class' => 'SubPanelTopCreateTaskButton' ) ,
231                 array ( 'widget_class' => 'SubPanelTopScheduleMeetingButton' ) ,
232                 array ( 'widget_class' => 'SubPanelTopScheduleCallButton' ) ,
233                 array ( 'widget_class' => 'SubPanelTopComposeEmailButton' ) ) ,
234                 'collection_list' => array (
235                     'meetings' => array (
236                         'module' => 'Meetings' ,
237                         'subpanel_name' => 'ForActivities' ,
238                         'get_subpanel_data' => $relationshipName. '_meetings' ) ,
239                     'tasks' => array (
240                         'module' => 'Tasks' ,
241                         'subpanel_name' => 'ForActivities' ,
242                         'get_subpanel_data' => $relationshipName. '_tasks' ) ,
243                     'calls' => array (
244                         'module' => 'Calls' ,
245                         'subpanel_name' => 'ForActivities' ,
246                         'get_subpanel_data' => $relationshipName. '_calls' ) ) ) ;
247     }
248
249     /*
250      * Shortcut to construct a History collection subpanel
251      * @param AbstractRelationship $relationship    Source relationship to Activities module
252      */
253     protected function buildHistorySubpanelDefinition ( $relationshipName )
254     {
255         return array (
256             'order' => 20 ,
257             'sort_order' => 'desc' ,
258             'sort_by' => 'date_modified' ,
259             'title_key' => 'LBL_HISTORY' ,
260             'type' => 'collection' ,
261             'subpanel_name' => 'history' , //this values is not associated with a physical file.
262             'module' => 'History' ,
263             'top_buttons' => array (
264                 array ( 'widget_class' => 'SubPanelTopCreateNoteButton' ) ,
265                                 array ( 'widget_class' => 'SubPanelTopArchiveEmailButton'),
266                 array ( 'widget_class' => 'SubPanelTopSummaryButton' ) ) ,
267                 'collection_list' => array (
268                     'meetings' => array (
269                         'module' => 'Meetings' ,
270                         'subpanel_name' => 'ForHistory' ,
271                         'get_subpanel_data' => $relationshipName. '_meetings' ) ,
272                     'tasks' => array (
273                         'module' => 'Tasks' ,
274                         'subpanel_name' => 'ForHistory' ,
275                         'get_subpanel_data' => $relationshipName. '_tasks' ) ,
276                     'calls' => array (
277                         'module' => 'Calls' ,
278                         'subpanel_name' => 'ForHistory' ,
279                         'get_subpanel_data' => $relationshipName. '_calls' ) ,
280                     'notes' => array (
281                         'module' => 'Notes' ,
282                         'subpanel_name' => 'ForHistory' ,
283                         'get_subpanel_data' => $relationshipName. '_notes' ) ,
284                     'emails' => array (
285                         'module' => 'Emails' ,
286                         'subpanel_name' => 'ForHistory' ,
287                         'get_subpanel_data' => $relationshipName. '_emails' ) ) )  ;
288     }
289 }