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-2012 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
39 require_once 'modules/ModuleBuilder/parsers/relationships/OneToManyRelationship.php' ;
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
47 * OOB modules implement One-To-Many relationships as:
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
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',
58 * 'id_name' => 'account_id',
59 * 'vname' => 'LBL_ACCOUNT_NAME',
60 * 'join_name'=>'accounts',
62 * 'link' => 'accounts',
63 * 'table' => 'accounts',
64 * 'module' => 'Accounts',
65 * 'source' => 'non-db'
66 * A link field which references the shared Relationship
69 class ActivitiesRelationship extends OneToManyRelationship
72 protected static $subpanelsAdded = array();
73 protected static $labelsAdded = array();
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
80 function __construct ($definition)
82 parent::__construct ( $definition ) ;
86 * BUILD methods called during the build
90 * Define the labels to be added to the module for the new relationships
91 * @return array An array of system value => display value
93 function buildLabels ()
95 $labelDefinitions = array ( ) ;
96 if (!$this->relationship_only )
98 if (!isset(ActivitiesRelationship::$labelsAdded[$this->lhs_module])) {
99 $labelDefinitions [] = array (
100 'module' => 'application' ,
101 'system_label' => 'parent_type_display',
102 'display_label' => array(
103 $this->lhs_module => $this->lhs_label ? $this->lhs_label : ucfirst($this->lhs_module)
107 $labelDefinitions [] = array (
108 'module' => 'application' ,
109 'system_label' => 'record_type_display',
110 'display_label' => array(
111 $this->lhs_module => $this->lhs_label ? $this->lhs_label : ucfirst($this->lhs_module)
115 $labelDefinitions [] = array (
116 'module' => 'application' ,
117 'system_label' => 'record_type_display_notes',
118 'display_label' => array(
119 $this->lhs_module => $this->lhs_label ? $this->lhs_label : ucfirst($this->lhs_module)
124 $labelDefinitions [] = array (
125 'module' => $this->lhs_module ,
126 'system_label' => 'LBL_' . strtoupper ( $this->relationship_name . '_FROM_' . $this->getRightModuleSystemLabel() ) . '_TITLE' ,
127 'display_label' => $this->lhs_label ? $this->lhs_label : ucfirst($this->lhs_module)
129 ActivitiesRelationship::$labelsAdded[$this->lhs_module] = true;
131 return $labelDefinitions ;
136 * @return array An array of field definitions, ready for the vardefs, keyed by module
138 function buildVardefs ( )
140 $vardefs = array ( ) ;
142 $vardefs [ $this->rhs_module ] [] = $this->getLinkFieldDefinition ( $this->lhs_module, $this->relationship_name ) ;
143 $vardefs [ $this->lhs_module ] [] = $this->getLinkFieldDefinition ( $this->rhs_module, $this->relationship_name ) ;
149 protected function getLinkFieldDefinition ($sourceModule , $relationshipName)
151 $vardef = array ( ) ;
152 $vardef [ 'name' ] = $relationshipName;
153 $vardef [ 'type' ] = 'link' ;
154 $vardef [ 'relationship' ] = $relationshipName ;
155 $vardef [ 'source' ] = 'non-db' ;
156 $vardef [ 'vname' ] = strtoupper("LBL_{$relationshipName}_FROM_{$sourceModule}_TITLE");
161 * Define what fields to add to which modules layouts
162 * @return array An array of module => fieldname
164 function buildFieldsToLayouts ()
166 if ($this->relationship_only)
169 return array( $this->rhs_module => $this->relationship_name . "_name" ) ; // this must match the name of the relate field from buildVardefs
172 function buildSubpanelDefinitions ()
174 if ($this->relationship_only || isset(ActivitiesRelationship::$subpanelsAdded[$this->lhs_module]))
177 ActivitiesRelationship::$subpanelsAdded[$this->lhs_module] = true;
178 $relationshipName = substr($this->relationship_name, 0, strrpos($this->relationship_name, '_'));
179 return array( $this->lhs_module => array (
180 'activities' => $this->buildActivitiesSubpanelDefinition ( $relationshipName ),
181 'history' => $this->buildHistorySubpanelDefinition ( $relationshipName ) ,
186 * @return array An array of relationship metadata definitions
188 function buildRelationshipMetaData ()
190 $relationshipName = $this->definition [ 'relationship_name' ];
191 $relMetadata = array ( ) ;
192 $relMetadata [ 'lhs_module' ] = $this->definition [ 'lhs_module' ] ;
193 $relMetadata [ 'lhs_table' ] = $this->getTablename($this->definition [ 'lhs_module' ]) ;
194 $relMetadata [ 'lhs_key' ] = 'id' ;
195 $relMetadata [ 'rhs_module' ] = $this->definition [ 'rhs_module' ] ;
196 $relMetadata [ 'rhs_table' ] = $this->getTablename($this->definition [ 'rhs_module' ]) ;
197 $relMetadata ['rhs_key'] = 'parent_id';
198 $relMetadata ['relationship_type'] = 'one-to-many';
199 $relMetadata ['relationship_role_column'] = 'parent_type';
200 $relMetadata ['relationship_role_column_value'] = $this->definition [ 'lhs_module' ] ;
202 return array( $this->lhs_module => array(
203 'relationships' => array ($relationshipName => $relMetadata),
204 'fields' => '', 'indices' => '', 'table' => '')
209 * Shortcut to construct an Activities collection subpanel
210 * @param AbstractRelationship $relationship Source relationship to Activities module
212 protected function buildActivitiesSubpanelDefinition ( $relationshipName )
216 'sort_order' => 'desc' ,
217 'sort_by' => 'date_start' ,
218 'title_key' => 'LBL_ACTIVITIES_SUBPANEL_TITLE' ,
219 'type' => 'collection' ,
220 'subpanel_name' => 'activities' , //this value is not associated with a physical file
221 'module' => 'Activities' ,
222 'top_buttons' => array (
223 array ( 'widget_class' => 'SubPanelTopCreateTaskButton' ) ,
224 array ( 'widget_class' => 'SubPanelTopScheduleMeetingButton' ) ,
225 array ( 'widget_class' => 'SubPanelTopScheduleCallButton' ) ,
226 array ( 'widget_class' => 'SubPanelTopComposeEmailButton' ) ) ,
227 'collection_list' => array (
228 'meetings' => array (
229 'module' => 'Meetings' ,
230 'subpanel_name' => 'ForActivities' ,
231 'get_subpanel_data' => $relationshipName. '_meetings' ) ,
233 'module' => 'Tasks' ,
234 'subpanel_name' => 'ForActivities' ,
235 'get_subpanel_data' => $relationshipName. '_tasks' ) ,
237 'module' => 'Calls' ,
238 'subpanel_name' => 'ForActivities' ,
239 'get_subpanel_data' => $relationshipName. '_calls' ) ) ) ;
243 * Shortcut to construct a History collection subpanel
244 * @param AbstractRelationship $relationship Source relationship to Activities module
246 protected function buildHistorySubpanelDefinition ( $relationshipName )
250 'sort_order' => 'desc' ,
251 'sort_by' => 'date_modified' ,
252 'title_key' => 'LBL_HISTORY' ,
253 'type' => 'collection' ,
254 'subpanel_name' => 'history' , //this values is not associated with a physical file.
255 'module' => 'History' ,
256 'top_buttons' => array (
257 array ( 'widget_class' => 'SubPanelTopCreateNoteButton' ) ,
258 array ( 'widget_class' => 'SubPanelTopArchiveEmailButton'),
259 array ( 'widget_class' => 'SubPanelTopSummaryButton' ) ) ,
260 'collection_list' => array (
261 'meetings' => array (
262 'module' => 'Meetings' ,
263 'subpanel_name' => 'ForHistory' ,
264 'get_subpanel_data' => $relationshipName. '_meetings' ) ,
266 'module' => 'Tasks' ,
267 'subpanel_name' => 'ForHistory' ,
268 'get_subpanel_data' => $relationshipName. '_tasks' ) ,
270 'module' => 'Calls' ,
271 'subpanel_name' => 'ForHistory' ,
272 'get_subpanel_data' => $relationshipName. '_calls' ) ,
274 'module' => 'Notes' ,
275 'subpanel_name' => 'ForHistory' ,
276 'get_subpanel_data' => $relationshipName. '_notes' ) ,
278 'module' => 'Emails' ,
279 'subpanel_name' => 'ForHistory' ,
280 'get_subpanel_data' => $relationshipName. '_emails' ) ) ) ;