]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/parsers/relationships/OneToManyRelationship.php
Release 6.5.0
[Github/sugarcrm.git] / modules / ModuleBuilder / parsers / relationships / OneToManyRelationship.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-2012 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/AbstractRelationship.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 OneToManyRelationship extends AbstractRelationship
70 {
71
72     /*
73      * Constructor
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
76      */
77     function __construct ($definition)
78     {
79         parent::__construct ( $definition ) ;
80     }
81
82     /*
83      * BUILD methods called during the build
84      */
85     
86     /*
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
90      */
91     function buildSubpanelDefinitions ()
92     {        
93         if ($this->relationship_only)
94             return array () ;
95         
96         $source = "";
97         if ($this->rhs_module == $this->lhs_module)
98         {
99                 $source = $this->getJoinKeyLHS();
100         }
101  
102         return array( 
103                 $this->lhs_module => $this->getSubpanelDefinition ( 
104                         $this->relationship_name, $this->rhs_module, $this->rhs_subpanel , $this->getRightModuleSystemLabel() , $source
105                 ) 
106         );
107     }
108
109
110     /*
111      * @return array    An array of field definitions, ready for the vardefs, keyed by module
112      */
113         function buildVardefs ( )
114     {
115         $vardefs = array ( ) ;
116         
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 )
120         ) ;
121         if ($this->rhs_module != $this->lhs_module )
122         {
123                 $vardefs [ $this->lhs_module ] [] = $this->getLinkFieldDefinition ( $this->rhs_module, $this->relationship_name, true,
124                 'LBL_' . strtoupper ( $this->relationship_name . '_FROM_' . $this->getRightModuleSystemLabel()  ) . '_TITLE');
125         }
126         if (! $this->relationship_only)
127         {
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');
131         }
132         
133         return $vardefs ;
134     }
135     
136     /*
137      * Define what fields to add to which modules layouts
138      * @return array    An array of module => fieldname
139      */
140     function buildFieldsToLayouts ()
141     {
142         if ($this->relationship_only)
143             return array () ;
144  
145         return array( $this->rhs_module =>$this->getValidDBName($this->relationship_name . "_name")); // this must match the name of the relate field from buildVardefs
146     }
147        
148     /*
149      * @return array    An array of relationship metadata definitions
150      */
151     function buildRelationshipMetaData ()
152     {
153         return array( $this->lhs_module => $this->getRelationshipMetaData ( MB_ONETOMANY ) ) ;
154     }
155
156 }
157 ?>