]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/parsers/relationships/ManyToOneRelationship.php
Release 6.2.0
[Github/sugarcrm.git] / modules / ModuleBuilder / parsers / relationships / ManyToOneRelationship.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-2011 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 require_once 'modules/ModuleBuilder/parsers/relationships/OneToManyRelationship.php' ;
41 require_once 'modules/ModuleBuilder/parsers/constants.php' ;
42
43 /*
44  * Class to manage the metadata for a many-To-one Relationship
45  * Exactly the same as a one-to-many relationship except lhs and rhs modules have been reversed.
46  */
47
48 class ManyToOneRelationship extends AbstractRelationship
49 {
50         
51
52     /*
53      * Constructor
54      * @param array $definition Parameters passed in as array defined in parent::$definitionKeys
55      * The lhs_module value is for the One side; the rhs_module value is for the Many
56      */
57     function __construct ($definition) 
58     {
59         
60         parent::__construct ( $definition ) ;
61         $onetomanyDef = array_merge($definition, array(
62                 'rhs_label'    => isset($definition['lhs_label'])    ? $definition['lhs_label']    : null,
63                 'lhs_label'    => isset($definition['rhs_label'])    ? $definition['rhs_label']    : null,
64                 'lhs_subpanel' => isset($definition['rhs_subpanel']) ? $definition['rhs_subpanel'] : null,
65                 'rhs_subpanel' => isset($definition['lhs_subpanel']) ? $definition['lhs_subpanel'] : null,
66                 'lhs_module'   => isset($definition['rhs_module'])   ? $definition['rhs_module']   : null,
67                 'lhs_table'    => isset($definition['rhs_table'])    ? $definition['rhs_table']    : null,
68                 'lhs_key'      => isset($definition['rhs_key'])      ? $definition['rhs_key']      : null,
69                 'rhs_module'   => isset($definition['lhs_module'])   ? $definition['lhs_module']   : null,
70                 'rhs_table'    => isset($definition['lhs_table'])    ? $definition['lhs_table']    : null,
71                 'rhs_key'      => isset($definition['lhs_key'])      ? $definition['lhs_key']      : null,
72                 'join_key_lhs' => isset($definition['join_key_rhs']) ? $definition['join_key_rhs'] : null,
73                 'join_key_rhs' => isset($definition['join_key_lhs']) ? $definition['join_key_lhs'] : null,
74                 'relationship_type' => MB_ONETOMANY,
75         ));
76         $this->one_to_many = new OneToManyRelationship($onetomanyDef);
77     }
78
79     /*
80      * BUILD methods called during the build
81      */
82         
83         function buildLabels ()
84     {
85         return $this->one_to_many->buildLabels();
86     }
87     
88     /*
89      * Construct subpanel definitions
90      * The format is that of TO_MODULE => relationship, FROM_MODULE, FROM_MODULES_SUBPANEL, mimicking the format in the layoutdefs.php
91      * @return array    An array of subpanel definitions, keyed by the module
92      */
93     function buildSubpanelDefinitions ()
94     {        
95         return $this->one_to_many->buildSubpanelDefinitions();
96     }
97
98     /*
99      * @return array    An array of field definitions, ready for the vardefs, keyed by module
100      */
101     function buildVardefs ( )
102     {
103        return $this->one_to_many->buildVardefs();
104     }
105     
106     /*
107      * Define what fields to add to which modules layouts
108      * @return array    An array of module => fieldname
109      */
110     function buildFieldsToLayouts ()
111     {
112         if ($this->relationship_only)
113             return array () ;
114  
115         return array( $this->lhs_module => $this->getValidDBName($this->relationship_name . "_name") ) ; // this must match the name of the relate field from buildVardefs
116     }
117        
118     /*
119      * @return array    An array of relationship metadata definitions
120      */
121     function buildRelationshipMetaData ()
122     {
123         return $this->one_to_many->buildRelationshipMetaData();
124     }
125     
126     public function setName ($relationshipName)
127     {
128         parent::setName($relationshipName);
129         $this->one_to_many->setname($relationshipName);
130     }
131     
132     public function setReadonly ()
133     {
134         parent::setReadonly();
135         $this->one_to_many->setReadonly();
136     }
137     
138     public function delete ()
139     {
140         parent::delete();
141         $this->one_to_many->delete();
142     }
143     
144     public function setRelationship_only ()
145     {
146         parent::setRelationship_only();
147         $this->one_to_many->setRelationship_only();
148     }
149 }
150 ?>