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.
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/AbstractRelationship.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 OneToManyRelationship extends AbstractRelationship
74 * @param array $definition Parameters passed in as array defined in parent::$definitionKeys
75 * The lhs_module value is for the One side; the rhs_module value is for the Many
77 function __construct ($definition)
79 parent::__construct ( $definition ) ;
83 * BUILD methods called during the build
87 * Construct subpanel definitions
88 * The format is that of TO_MODULE => relationship, FROM_MODULE, FROM_MODULES_SUBPANEL, mimicking the format in the layoutdefs.php
89 * @return array An array of subpanel definitions, keyed by the module
91 function buildSubpanelDefinitions ()
93 if ($this->relationship_only)
97 if ($this->rhs_module == $this->lhs_module)
99 $source = $this->getJoinKeyLHS();
103 $this->lhs_module => $this->getSubpanelDefinition (
104 $this->relationship_name, $this->rhs_module, $this->rhs_subpanel , $this->getRightModuleSystemLabel() , $source
111 * @return array An array of field definitions, ready for the vardefs, keyed by module
113 function buildVardefs ( )
115 $vardefs = array ( ) ;
117 $vardefs [ $this->rhs_module ] [] = $this->getLinkFieldDefinition ( $this->lhs_module, $this->relationship_name, false,
118 'LBL_' . strtoupper ( $this->relationship_name . '_FROM_' . $this->getLeftModuleSystemLabel() ) . '_TITLE',
119 $this->relationship_only ? false : $this->getIDName( $this->lhs_module )
121 if ($this->rhs_module != $this->lhs_module )
123 $vardefs [ $this->lhs_module ] [] = $this->getLinkFieldDefinition ( $this->rhs_module, $this->relationship_name, true,
124 'LBL_' . strtoupper ( $this->relationship_name . '_FROM_' . $this->getRightModuleSystemLabel() ) . '_TITLE');
126 if (! $this->relationship_only)
128 $vardefs [ $this->rhs_module ] [] = $this->getRelateFieldDefinition ( $this->lhs_module, $this->relationship_name, $this->getLeftModuleSystemLabel() ) ;
129 $vardefs [ $this->rhs_module ] [] = $this->getLink2FieldDefinition ( $this->lhs_module, $this->relationship_name, true,
130 'LBL_' . strtoupper ( $this->relationship_name . '_FROM_' . $this->getRightModuleSystemLabel() ) . '_TITLE');
137 * Define what fields to add to which modules layouts
138 * @return array An array of module => fieldname
140 function buildFieldsToLayouts ()
142 if ($this->relationship_only)
145 return array( $this->rhs_module =>$this->getValidDBName($this->relationship_name . "_name")); // this must match the name of the relate field from buildVardefs
149 * @return array An array of relationship metadata definitions
151 function buildRelationshipMetaData ()
153 return array( $this->lhs_module => $this->getRelationshipMetaData ( MB_ONETOMANY ) ) ;