3 /*********************************************************************************
4 * SugarCRM Community Edition is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2012 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/UndeployedRelationships.php' ;
40 require_once 'modules/ModuleBuilder/parsers/relationships/AbstractRelationships.php' ;
41 require_once 'modules/ModuleBuilder/parsers/relationships/AbstractRelationship.php' ;
42 require_once 'modules/ModuleBuilder/parsers/relationships/ManyToManyRelationship.php' ;
45 * This is an Adapter for the new UndeployedRelationships Class to allow ModuleBuilder to use the new class without change
46 * As ModuleBuilder is updated, references to this MBRelationship class should be replaced by direct references to UndeployedRelationships
52 public $relatableModules = array ( ) ; // required by MBModule
53 public $relationships = array ( ) ; // required by view.relationships.php; must be kept in sync with the implementation
58 * @param string $name The name of this module (not used)
59 * @param string $path The base path of the module directory within the ModuleBuilder package directory
60 * @param string $key_name The Fully Qualified Name for this module - that is, $packageName_$name
62 function MBRelationship ($name , $path , $key_name)
64 $this->implementation = new UndeployedRelationships ( $path ) ;
65 $this->moduleName = $key_name ;
67 $this->updateRelationshipVariable();
70 function findRelatableModules ()
72 // do not call findRelatableModules in the constructor as it leads to an infinite loop if the implementation calls getPackage() which loads the packages which loads the module which findsRelatableModules which...
73 $this->relatableModules = $this->implementation->findRelatableModules () ;
77 * Originally in 5.0 this method expected $_POST variables keyed in the "old" format - lhs_module, relate, msub, rsub etc
78 * At 5.1 this has been changed to the "new" format of lhs_module, rhs_module, lhs_subpanel, rhs_subpanel, label
79 * @return AbstractRelationship
81 function addFromPost ()
83 return $this->implementation->addFromPost () ;
87 * New function to replace the old MBModule subpanel property - now we obtain the 'subpanels' (actually related modules) from the relationships object
89 function getRelationshipList ()
91 return $this->implementation->getRelationshipList () ;
94 function get ($relationshipName)
96 return $this->implementation->get ( $relationshipName ) ;
101 * Add a relationship to this set
102 * Original MBRelationships could only support one relationship between this module and any other
105 function addRelationship ($name , $relatedTo , $relatedSubpanel = 'default' , $mysubpanel = 'default' , $type)
107 $this->implementation->add ( new ManyToManyRelationship ( $name, $this->moduleName, $relatedTo, $mysubpanel, $relatedSubpanel ) ) ;
108 $this->updateRelationshipVariable () ;
112 /* Add a relationship to this set
113 * Original MBRelationships could only support one relationship between this module and any other
114 * @param array $rel Relationship definition in the old format (defined by self::oldFormatKeys)
118 // convert old format definition to new format
119 if (! isset ( $rel [ 'lhs_module' ] ))
120 $rel [ 'lhs_module' ] = $this->moduleName ;
121 $definition = AbstractRelationships::convertFromOldFormat ( $rel ) ;
122 if (! isset ( $definition ['relationship_type']))
123 $definition ['relationship_type'] = 'many-to-many';
124 // get relationship object from RelationshipFactory
125 $relationship = RelationshipFactory::newRelationship ( $definition ) ;
126 // add relationship to the set of relationships
127 $this->implementation->add ( $relationship ) ;
128 $this->updateRelationshipVariable () ;
129 return $relationship;
132 function delete ($name)
134 $this->implementation->delete ( $name ) ;
135 $this->updateRelationshipVariable () ;
140 $this->implementation->save () ;
143 function build ($path)
145 $this->implementation->build () ;
148 function addInstallDefs (&$installDef)
150 $this->implementation->addInstallDefs ( $installDef ) ;
156 $this->implementation->load () ;
157 $this->updateRelationshipVariable () ;
161 * Transitional function to keep the public relationship variable in sync with the implementation master copy
162 * We have to do this as various things refer directly to MBRelationship->relationships...
165 private function updateRelationshipVariable ()
167 foreach ( $this->implementation->getRelationshipList () as $relationshipName )
169 $rel = $this->implementation->getOldFormat ( $relationshipName ) ;
170 $this->relationships [ $relationshipName ] = $rel ;