]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/parsers/relationships/OneToOneRelationship.php
Release 6.5.0
[Github/sugarcrm.git] / modules / ModuleBuilder / parsers / relationships / OneToOneRelationship.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-One Relationship
43  * The LHS module will receive a new relate field to point back to the RHS
44  * The RHS module will receive a new relate field to point back to the LHS
45  * 
46  * OOB modules implement One-To-One relationships as:
47  * A Relationship of type one-to-one in one modules vardefs.php
48  * A single link field in the same vardefs.php with 'relationship'= the relationship name, and 'link-type'='one', 'Module'=other side, and 'source'='non-db'
49  * These are not common - examples are in InboundEmail and Schedulers, both pre-5.0 modules
50  * InboundEmail:
51  *      'created_by_link' => array (
52             'name' => 'created_by_link',
53             'type' => 'link',
54             'relationship' => 'inbound_email_created_by',
55             'vname' => 'LBL_CREATED_BY_USER',
56             'link_type' => 'one',
57             'module' => 'Users',
58             'bean_name' => 'User',
59             'source' => 'non-db',
60         ),
61
62  */
63
64 class OneToOneRelationship extends AbstractRelationship
65 {
66
67     /*
68      * Constructor
69      * @param array $definition Parameters passed in as array with keys defined in parent::keys
70      */
71     function __construct ($definition)
72     {
73         parent::__construct ( $definition ) ;
74     }
75     
76     /*
77      * BUILD methods called during the build
78      */
79     
80     /*
81      * @return array    An array of relationship metadata definitions
82      */
83     function buildRelationshipMetaData ()
84     {
85         return array( $this->lhs_module => $this->getRelationshipMetaData ( MB_ONETOONE ) ) ;
86     }
87
88     /* Build a set of Link Field definitions for this relationship
89      * @return array    An array of field definitions, ready for the vardefs, keyed by module
90      */
91     function buildVardefs ( )
92     {
93         $vardefs = array ( ) ;
94         $vardefs [ $this->rhs_module ] [] = $this->getLinkFieldDefinition ( $this->lhs_module, $this->relationship_name , false, 
95             'LBL_' . strtoupper ( $this->relationship_name . '_FROM_' . $this->getLeftModuleSystemLabel() ) . '_TITLE' ,
96             $this->relationship_only ? false : $this->getIDName( $this->lhs_module )
97         ) ;
98         $vardefs [ $this->lhs_module ] [] = $this->getLinkFieldDefinition ( $this->rhs_module, $this->relationship_name, false, 
99             'LBL_' . strtoupper ( $this->relationship_name . '_FROM_' . $this->getRightModuleSystemLabel()   ) . '_TITLE'  ,
100             $this->relationship_only ? false : $this->getIDName( $this->rhs_module )
101         ) ;
102         
103         if (!$this->relationship_only)
104         {
105             $vardefs [ $this->lhs_module ] [] = $this->getRelateFieldDefinition ( $this->rhs_module, $this->relationship_name, $this->getRightModuleSystemLabel() ) ;
106             $vardefs [ $this->rhs_module ] [] = $this->getRelateFieldDefinition ( $this->lhs_module, $this->relationship_name, $this->getLeftModuleSystemLabel() ) ;
107             $vardefs [ $this->lhs_module ] [] = $this->getLink2FieldDefinition ( $this->rhs_module, $this->relationship_name , false, 
108             'LBL_' . strtoupper ( $this->relationship_name . '_FROM_' . $this->getRightModuleSystemLabel()   ) . '_TITLE' ) ;
109             $vardefs [ $this->rhs_module ] [] = $this->getLink2FieldDefinition ( $this->lhs_module, $this->relationship_name , false, 
110             'LBL_' . strtoupper ( $this->relationship_name . '_FROM_' . $this->getLeftModuleSystemLabel() ) . '_TITLE' ) ;
111         }
112         
113         return $vardefs ;
114     }
115
116     /*
117      * Define what fields to add to which modules layouts
118      * @return array    An array of module => fieldname
119      */
120     function buildFieldsToLayouts ()
121     {
122         if ($this->relationship_only)
123             return array () ;
124  
125         if ($this->lhs_module == $this->rhs_module) // don't add in two fields on recursive relationships
126             return array ( $this->lhs_module => $this->getValidDBName($this->relationship_name . "_name") );
127         else
128             return array (
129                 $this->lhs_module => $this->getValidDBName($this->relationship_name . "_name") ,
130                 $this->rhs_module => $this->getValidDBName($this->relationship_name . "_name")
131             ) ;
132     }
133
134 }
135
136 ?>