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' ;
40 require_once 'modules/ModuleBuilder/parsers/relationships/OneToManyRelationship.php' ;
41 require_once 'modules/ModuleBuilder/parsers/constants.php' ;
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.
48 class ManyToOneRelationship extends AbstractRelationship
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
57 function __construct ($definition)
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,
76 $this->one_to_many = new OneToManyRelationship($onetomanyDef);
80 * BUILD methods called during the build
83 function buildLabels ()
85 return $this->one_to_many->buildLabels();
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
93 function buildSubpanelDefinitions ()
95 return $this->one_to_many->buildSubpanelDefinitions();
99 * @return array An array of field definitions, ready for the vardefs, keyed by module
101 function buildVardefs ( )
103 return $this->one_to_many->buildVardefs();
107 * Define what fields to add to which modules layouts
108 * @return array An array of module => fieldname
110 function buildFieldsToLayouts ()
112 if ($this->relationship_only)
115 return array( $this->lhs_module => $this->getValidDBName($this->relationship_name . "_name") ) ; // this must match the name of the relate field from buildVardefs
119 * @return array An array of relationship metadata definitions
121 function buildRelationshipMetaData ()
123 return $this->one_to_many->buildRelationshipMetaData();
126 public function setName ($relationshipName)
128 parent::setName($relationshipName);
129 $this->one_to_many->setname($relationshipName);
132 public function setReadonly ()
134 parent::setReadonly();
135 $this->one_to_many->setReadonly();
138 public function delete ()
141 $this->one_to_many->delete();
144 public function setRelationship_only ()
146 parent::setRelationship_only();
147 $this->one_to_many->setRelationship_only();