2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2011 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-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
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
51 * 'created_by_link' => array (
52 'name' => 'created_by_link',
54 'relationship' => 'inbound_email_created_by',
55 'vname' => 'LBL_CREATED_BY_USER',
58 'bean_name' => 'User',
64 class OneToOneRelationship extends AbstractRelationship
69 * @param array $definition Parameters passed in as array with keys defined in parent::keys
71 function __construct ($definition)
73 parent::__construct ( $definition ) ;
77 * BUILD methods called during the build
81 * @return array An array of relationship metadata definitions
83 function buildRelationshipMetaData ()
85 return array( $this->lhs_module => $this->getRelationshipMetaData ( MB_ONETOONE ) ) ;
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
91 function buildVardefs ( )
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 $vardefs [ $this->lhs_module ] [] = $this->getLinkFieldDefinition ( $this->rhs_module, $this->relationship_name, false,
97 'LBL_' . strtoupper ( $this->relationship_name . '_FROM_' . $this->getRightModuleSystemLabel() ) . '_TITLE' ) ;
99 if (!$this->relationship_only)
101 $vardefs [ $this->lhs_module ] [] = $this->getRelateFieldDefinition ( $this->rhs_module, $this->relationship_name, $this->getRightModuleSystemLabel() ) ;
102 $vardefs [ $this->rhs_module ] [] = $this->getRelateFieldDefinition ( $this->lhs_module, $this->relationship_name, $this->getLeftModuleSystemLabel() ) ;
103 $vardefs [ $this->lhs_module ] [] = $this->getLink2FieldDefinition ( $this->rhs_module, $this->relationship_name , false,
104 'LBL_' . strtoupper ( $this->relationship_name . '_FROM_' . $this->getRightModuleSystemLabel() ) . '_TITLE' ) ;
105 $vardefs [ $this->rhs_module ] [] = $this->getLink2FieldDefinition ( $this->lhs_module, $this->relationship_name , false,
106 'LBL_' . strtoupper ( $this->relationship_name . '_FROM_' . $this->getLeftModuleSystemLabel() ) . '_TITLE' ) ;
113 * Define what fields to add to which modules layouts
114 * @return array An array of module => fieldname
116 function buildFieldsToLayouts ()
118 if ($this->relationship_only)
121 if ($this->lhs_module == $this->rhs_module) // don't add in two fields on recursive relationships
122 return array ( $this->lhs_module => $this->getValidDBName($this->relationship_name . "_name") );
125 $this->lhs_module => $this->getValidDBName($this->relationship_name . "_name") ,
126 $this->rhs_module => $this->getValidDBName($this->relationship_name . "_name")