]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/MB/MBRelationship.php
Release 6.5.0
[Github/sugarcrm.git] / modules / ModuleBuilder / MB / MBRelationship.php
1 <?php
2
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/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' ;
43
44 /*
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
47  */
48
49 class MBRelationship
50 {
51     
52     public $relatableModules = array ( ) ; // required by MBModule
53     public $relationships = array ( ) ; // required by view.relationships.php; must be kept in sync with the implementation
54
55     
56     /*
57      * Constructor
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
61      */
62     function MBRelationship ($name , $path , $key_name)
63     {
64         $this->implementation = new UndeployedRelationships ( $path ) ;
65         $this->moduleName = $key_name ;
66         $this->path = $path ;
67         $this->updateRelationshipVariable();
68     }
69
70     function findRelatableModules ()
71     {
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 () ;
74     }
75
76     /*
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
80      */
81     function addFromPost ()
82     {
83         return $this->implementation->addFromPost () ;
84     }
85
86     /*
87      * New function to replace the old MBModule subpanel property - now we obtain the 'subpanels' (actually related modules) from the relationships object
88      */
89     function getRelationshipList ()
90     {
91         return $this->implementation->getRelationshipList () ;
92     }
93
94     function get ($relationshipName)
95     {
96         return $this->implementation->get ( $relationshipName ) ;
97     }
98
99     /*
100      * Deprecated
101      * Add a relationship to this set
102      * Original MBRelationships could only support one relationship between this module and any other
103      */
104     /*    
105     function addRelationship ($name , $relatedTo , $relatedSubpanel = 'default' , $mysubpanel = 'default' , $type)
106     {
107         $this->implementation->add ( new ManyToManyRelationship ( $name, $this->moduleName, $relatedTo, $mysubpanel, $relatedSubpanel ) ) ;
108         $this->updateRelationshipVariable () ;
109     }
110 */
111     
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)
115      */
116     function add ($rel)
117     {
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;
130     }
131
132     function delete ($name)
133     {
134         $this->implementation->delete ( $name ) ;
135         $this->updateRelationshipVariable () ;
136     }
137
138     function save ()
139     {
140         $this->implementation->save () ;
141     }
142
143     function build ($path)
144     {
145         $this->implementation->build () ;
146     }
147
148     function addInstallDefs (&$installDef)
149     {
150         $this->implementation->addInstallDefs ( $installDef ) ;
151     }
152
153     /*
154     function load ()
155     {
156         $this->implementation->load () ;
157         $this->updateRelationshipVariable () ;
158     }
159 */
160     /*
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...
163      */
164     
165     private function updateRelationshipVariable ()
166     {
167         foreach ( $this->implementation->getRelationshipList () as $relationshipName )
168         {
169             $rel = $this->implementation->getOldFormat ( $relationshipName ) ;
170             $this->relationships [ $relationshipName ] = $rel ;
171         }
172     }
173
174 }
175
176 ?>