|
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-2013 SugarCRM Inc. |
|
6
|
|
|
|
|
7
|
|
|
* SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd. |
|
8
|
|
|
* Copyright (C) 2011 - 2014 Salesagility Ltd. |
|
9
|
|
|
* |
|
10
|
|
|
* This program is free software; you can redistribute it and/or modify it under |
|
11
|
|
|
* the terms of the GNU Affero General Public License version 3 as published by the |
|
12
|
|
|
* Free Software Foundation with the addition of the following permission added |
|
13
|
|
|
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK |
|
14
|
|
|
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY |
|
15
|
|
|
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. |
|
16
|
|
|
* |
|
17
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
18
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
19
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more |
|
20
|
|
|
* details. |
|
21
|
|
|
* |
|
22
|
|
|
* You should have received a copy of the GNU Affero General Public License along with |
|
23
|
|
|
* this program; if not, see http://www.gnu.org/licenses or write to the Free |
|
24
|
|
|
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
25
|
|
|
* 02110-1301 USA. |
|
26
|
|
|
* |
|
27
|
|
|
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road, |
|
28
|
|
|
* SW2-130, Cupertino, CA 95014, USA. or at email address [email protected]. |
|
29
|
|
|
* |
|
30
|
|
|
* The interactive user interfaces in modified source and object code versions |
|
31
|
|
|
* of this program must display Appropriate Legal Notices, as required under |
|
32
|
|
|
* Section 5 of the GNU Affero General Public License version 3. |
|
33
|
|
|
* |
|
34
|
|
|
* In accordance with Section 7(b) of the GNU Affero General Public License version 3, |
|
35
|
|
|
* these Appropriate Legal Notices must retain the display of the "Powered by |
|
36
|
|
|
* SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not |
|
37
|
|
|
* reasonably feasible for technical reasons, the Appropriate Legal Notices must |
|
38
|
|
|
* display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM". |
|
39
|
|
|
********************************************************************************/ |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
global $dictionary; |
|
43
|
|
|
//Load all relationship metadata |
|
44
|
|
|
include_once("modules/TableDictionary.php"); |
|
45
|
|
|
require_once("data/BeanFactory.php"); |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
define('REL_LHS','LHS'); |
|
49
|
|
|
define('REL_RHS','RHS'); |
|
50
|
|
|
define('REL_BOTH','BOTH_SIDES'); |
|
51
|
|
|
define('REL_MANY_MANY', 'many-to-many'); |
|
52
|
|
|
define('REL_ONE_MANY', 'one-to-many'); |
|
53
|
|
|
define('REL_ONE_ONE', 'one-to-one'); |
|
54
|
|
|
/** |
|
55
|
|
|
* A relationship is between two modules. |
|
56
|
|
|
* It contains at least two links. |
|
57
|
|
|
* Each link represents a connection from one record to the records linked in this relationship. |
|
58
|
|
|
* Links have a context(focus) bean while relationships do not. |
|
59
|
|
|
* @api |
|
60
|
|
|
*/ |
|
61
|
|
|
abstract class SugarRelationship |
|
62
|
|
|
{ |
|
63
|
|
|
protected $def; |
|
64
|
|
|
protected $lhsLink; |
|
65
|
|
|
protected $rhsLink; |
|
66
|
|
|
protected $ignore_role_filter = false; |
|
67
|
|
|
protected $self_referencing = false; //A relationship is self referencing when LHS module = RHS Module |
|
68
|
|
|
|
|
69
|
|
|
protected static $beansToResave = array(); |
|
70
|
|
|
|
|
71
|
|
|
public abstract function add($lhs, $rhs, $additionalFields = array()); |
|
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @abstract |
|
75
|
|
|
* @param $lhs SugarBean |
|
76
|
|
|
* @param $rhs SugarBean |
|
77
|
|
|
* @return boolean |
|
78
|
|
|
*/ |
|
79
|
|
|
public abstract function remove($lhs, $rhs); |
|
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @abstract |
|
83
|
|
|
* @param $link Link2 loads the rows for this relationship that match the given link |
|
84
|
|
|
* @return void |
|
85
|
|
|
*/ |
|
86
|
|
|
public abstract function load($link, $params = array()); |
|
|
|
|
|
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Gets the query to load a link. |
|
90
|
|
|
* This is currently public, but should prob be made protected later. |
|
91
|
|
|
* See Link2->getQuery |
|
92
|
|
|
* @abstract |
|
93
|
|
|
* @param $link Link Object to get query for. |
|
94
|
|
|
* @return string|array query used to load this relationship |
|
95
|
|
|
*/ |
|
96
|
|
|
public abstract function getQuery($link, $params = array()); |
|
|
|
|
|
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @abstract |
|
100
|
|
|
* @param Link2 $link |
|
101
|
|
|
* @return string|array the query to join against the related modules table for the given link. |
|
102
|
|
|
*/ |
|
103
|
|
|
public abstract function getJoin($link); |
|
|
|
|
|
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @abstract |
|
107
|
|
|
* @param SugarBean $lhs |
|
108
|
|
|
* @param SugarBean $rhs |
|
109
|
|
|
* @return bool |
|
110
|
|
|
*/ |
|
111
|
|
|
public abstract function relationship_exists($lhs, $rhs); |
|
|
|
|
|
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @abstract |
|
115
|
|
|
* @return string name of the table for this relationship |
|
116
|
|
|
*/ |
|
117
|
|
|
public abstract function getRelationshipTable(); |
|
|
|
|
|
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @param $link Link2 removes all the beans associated with this link from the relationship |
|
121
|
|
|
* @return boolean true if all beans were successfully removed or there |
|
122
|
|
|
* were not related beans, false otherwise |
|
123
|
|
|
*/ |
|
124
|
38 |
|
public function removeAll($link) |
|
125
|
|
|
{ |
|
126
|
38 |
|
$focus = $link->getFocus(); |
|
127
|
38 |
|
$related = $link->getBeans(); |
|
128
|
38 |
|
$result = true; |
|
129
|
38 |
|
foreach($related as $relBean) |
|
130
|
|
|
{ |
|
131
|
9 |
|
if (empty($relBean->id)) { |
|
132
|
|
|
continue; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
9 |
|
if ($link->getSide() == REL_LHS) |
|
136
|
|
|
{ |
|
137
|
5 |
|
$sub_result = $this->remove($focus, $relBean); |
|
138
|
|
|
} |
|
139
|
|
|
else |
|
140
|
|
|
{ |
|
141
|
4 |
|
$sub_result = $this->remove($relBean, $focus); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
9 |
|
$result = $result && $sub_result; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
38 |
|
return $result; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* @param $rowID id of SugarBean to remove from the relationship |
|
152
|
|
|
* @return void |
|
153
|
|
|
*/ |
|
154
|
|
|
public function removeById($rowID){ |
|
155
|
|
|
$this->removeRow(array("id" => $rowID)); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* @return string name of right hand side module. |
|
160
|
|
|
*/ |
|
161
|
124 |
|
public function getRHSModule() |
|
162
|
|
|
{ |
|
163
|
124 |
|
return $this->def['rhs_module']; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* @return string name of left hand side module. |
|
168
|
|
|
*/ |
|
169
|
82 |
|
public function getLHSModule() |
|
170
|
|
|
{ |
|
171
|
82 |
|
return $this->def['lhs_module']; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* @return String left link in relationship. |
|
176
|
|
|
*/ |
|
177
|
126 |
|
public function getLHSLink() |
|
178
|
|
|
{ |
|
179
|
126 |
|
return $this->lhsLink; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* @return String right link in relationship. |
|
184
|
|
|
*/ |
|
185
|
107 |
|
public function getRHSLink() |
|
186
|
|
|
{ |
|
187
|
107 |
|
return $this->rhsLink; |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* @return array names of fields stored on the relationship |
|
192
|
|
|
*/ |
|
193
|
|
|
public function getFields() |
|
194
|
|
|
{ |
|
195
|
|
|
return isset($this->def['fields']) ? $this->def['fields'] : array(); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* @param array $row values to be inserted into the relationship |
|
200
|
|
|
* @return bool|void null if new row was inserted and true if an existing row was updated |
|
201
|
|
|
*/ |
|
202
|
|
|
protected function addRow($row) |
|
203
|
|
|
{ |
|
204
|
|
|
$existing = $this->checkExisting($row); |
|
205
|
|
|
if (!empty($existing)) //Update the existing row, overriding the values with those passed in |
|
206
|
|
|
return $this->updateRow($existing['id'], array_merge($existing, $row)); |
|
207
|
|
|
|
|
208
|
|
|
$values = array(); |
|
209
|
|
|
foreach($this->getFields() as $def) |
|
210
|
|
|
{ |
|
211
|
|
|
$field = $def['name']; |
|
212
|
|
|
if (isset($row[$field])) |
|
213
|
|
|
{ |
|
214
|
|
|
$values[$field] = "'{$row[$field]}'"; |
|
215
|
|
|
} |
|
216
|
|
|
} |
|
217
|
|
|
$columns = implode(',', array_keys($values)); |
|
218
|
|
|
$values = implode(',', $values); |
|
219
|
|
|
if (!empty($values)) |
|
220
|
|
|
{ |
|
221
|
|
|
$query = "INSERT INTO {$this->getRelationshipTable()} ($columns) VALUES ($values)"; |
|
222
|
|
|
DBManagerFactory::getInstance()->query($query); |
|
223
|
|
|
} |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
/** |
|
227
|
|
|
* @param $id id of row to update |
|
228
|
|
|
* @param $values values to insert into row |
|
229
|
|
|
* @return resource result of update satatement |
|
230
|
|
|
*/ |
|
231
|
|
|
protected function updateRow($id, $values) |
|
232
|
|
|
{ |
|
233
|
|
|
$newVals = array(); |
|
234
|
|
|
//Unset the ID since we are using it to update the row |
|
235
|
|
|
if (isset($values['id'])) unset($values['id']); |
|
236
|
|
|
foreach($values as $field => $val) |
|
237
|
|
|
{ |
|
238
|
|
|
$newVals[] = "$field='$val'"; |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
$newVals = implode(",",$newVals); |
|
242
|
|
|
|
|
243
|
|
|
$query = "UPDATE {$this->getRelationshipTable()} set $newVals WHERE id='$id'"; |
|
244
|
|
|
|
|
245
|
|
|
return DBManagerFactory::getInstance()->query($query); |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
/** |
|
249
|
|
|
* Removes one or more rows from the relationship table |
|
250
|
|
|
* @param $where array of field=>value pairs to match |
|
251
|
|
|
* @return bool|resource |
|
252
|
|
|
*/ |
|
253
|
2 |
|
protected function removeRow($where) |
|
254
|
|
|
{ |
|
255
|
2 |
|
if (empty($where)) |
|
256
|
|
|
return false; |
|
257
|
|
|
|
|
258
|
2 |
|
$date_modified = TimeDate::getInstance()->getNow()->asDb(); |
|
259
|
2 |
|
$stringSets = array(); |
|
260
|
2 |
|
foreach ($where as $field => $val) |
|
261
|
|
|
{ |
|
262
|
2 |
|
$stringSets[] = "$field = '$val'"; |
|
263
|
|
|
} |
|
264
|
2 |
|
$whereString = "WHERE " . implode(" AND ", $stringSets); |
|
265
|
|
|
|
|
266
|
2 |
|
$query = "UPDATE {$this->getRelationshipTable()} set deleted=1 , date_modified = '$date_modified' $whereString"; |
|
267
|
|
|
|
|
268
|
2 |
|
return DBManagerFactory::getInstance()->query($query); |
|
269
|
|
|
|
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
|
|
/** |
|
273
|
|
|
* Checks for an existing row who's keys match the one passed in. |
|
274
|
|
|
* @param $row |
|
275
|
|
|
* @return array|bool returns false if now row is found, otherwise the row is returned |
|
276
|
|
|
*/ |
|
277
|
|
|
protected function checkExisting($row) |
|
278
|
|
|
{ |
|
279
|
|
|
$leftIDName = $this->def['join_key_lhs']; |
|
280
|
|
|
$rightIDName = $this->def['join_key_rhs']; |
|
281
|
|
|
if (empty($row[$leftIDName]) || empty($row[$rightIDName])) |
|
282
|
|
|
return false; |
|
283
|
|
|
|
|
284
|
|
|
$leftID = $row[$leftIDName]; |
|
285
|
|
|
$rightID = $row[$rightIDName]; |
|
286
|
|
|
//Check the relationship role as well |
|
287
|
|
|
$roleCheck = $this->getRoleWhere(); |
|
288
|
|
|
|
|
289
|
|
|
$query = "SELECT * FROM {$this->getRelationshipTable()} WHERE $leftIDName='$leftID' AND $rightIDName='$rightID' $roleCheck AND deleted=0"; |
|
290
|
|
|
|
|
291
|
|
|
$db = DBManagerFactory::getInstance(); |
|
292
|
|
|
$result = $db->query($query); |
|
293
|
|
|
$row = $db->fetchByAssoc($result); |
|
294
|
|
|
if (!empty($row)) |
|
295
|
|
|
{ |
|
296
|
|
|
return $row; |
|
297
|
|
|
} else{ |
|
298
|
|
|
return false; |
|
299
|
|
|
} |
|
300
|
|
|
} |
|
301
|
|
|
|
|
302
|
|
|
/** |
|
303
|
|
|
* Gets the relationship role column check for the where clause |
|
304
|
|
|
* @param string $table |
|
305
|
|
|
* @return string |
|
306
|
|
|
*/ |
|
307
|
61 |
|
protected function getRoleWhere($table = "", $ignore_role_filter = false) |
|
308
|
|
|
{ |
|
309
|
61 |
|
$ignore_role_filter = $ignore_role_filter || $this->ignore_role_filter; |
|
310
|
61 |
|
$roleCheck = ""; |
|
311
|
61 |
|
if (empty ($table)) |
|
312
|
35 |
|
$table = $this->getRelationshipTable(); |
|
313
|
61 |
|
if (!empty($this->def['relationship_role_column']) && !empty($this->def["relationship_role_column_value"]) && !$ignore_role_filter ) |
|
314
|
|
|
{ |
|
315
|
21 |
|
if (empty($table)) |
|
316
|
|
|
$roleCheck = " AND $this->relationship_role_column"; |
|
|
|
|
|
|
317
|
|
|
else |
|
318
|
21 |
|
$roleCheck = " AND $table.{$this->relationship_role_column}"; |
|
|
|
|
|
|
319
|
|
|
//role column value. |
|
320
|
21 |
|
if (empty($this->def['relationship_role_column_value'])) |
|
321
|
|
|
{ |
|
322
|
|
|
$roleCheck.=' IS NULL'; |
|
323
|
|
|
} else { |
|
324
|
21 |
|
$roleCheck.= " = '$this->relationship_role_column_value'"; |
|
|
|
|
|
|
325
|
|
|
} |
|
326
|
|
|
} |
|
327
|
61 |
|
return $roleCheck; |
|
328
|
|
|
} |
|
329
|
|
|
|
|
330
|
|
|
/** |
|
331
|
|
|
* @param SugarBean $focus base bean the hooks is triggered from |
|
332
|
|
|
* @param SugarBean $related bean being added/removed/updated from relationship |
|
333
|
|
|
* @param string $link_name name of link being triggerd |
|
334
|
|
|
* @return array base arguments to pass to relationship logic hooks |
|
335
|
|
|
*/ |
|
336
|
9 |
|
protected function getCustomLogicArguments($focus, $related, $link_name) |
|
337
|
|
|
{ |
|
338
|
9 |
|
$custom_logic_arguments = array(); |
|
339
|
9 |
|
$custom_logic_arguments['id'] = $focus->id; |
|
340
|
9 |
|
$custom_logic_arguments['related_id'] = $related->id; |
|
341
|
9 |
|
$custom_logic_arguments['module'] = $focus->module_dir; |
|
342
|
9 |
|
$custom_logic_arguments['related_module'] = $related->module_dir; |
|
343
|
9 |
|
$custom_logic_arguments['related_bean'] = $related; |
|
344
|
9 |
|
$custom_logic_arguments['link'] = $link_name; |
|
345
|
9 |
|
$custom_logic_arguments['relationship'] = $this->name; |
|
346
|
|
|
|
|
347
|
9 |
|
return $custom_logic_arguments; |
|
348
|
|
|
} |
|
349
|
|
|
|
|
350
|
|
|
/** |
|
351
|
|
|
* Call the before add logic hook for a given link |
|
352
|
|
|
* @param SugarBean $focus base bean the hooks is triggered from |
|
353
|
|
|
* @param SugarBean $related bean being added/removed/updated from relationship |
|
354
|
|
|
* @param string $link_name name of link being triggerd |
|
355
|
|
|
* @return void |
|
356
|
|
|
*/ |
|
357
|
|
|
protected function callBeforeAdd($focus, $related, $link_name="") |
|
358
|
|
|
{ |
|
359
|
|
|
$custom_logic_arguments = $this->getCustomLogicArguments($focus, $related, $link_name); |
|
360
|
|
|
$focus->call_custom_logic('before_relationship_add', $custom_logic_arguments); |
|
361
|
|
|
} |
|
362
|
|
|
|
|
363
|
|
|
/** |
|
364
|
|
|
* Call the after add logic hook for a given link |
|
365
|
|
|
* @param SugarBean $focus base bean the hooks is triggered from |
|
366
|
|
|
* @param SugarBean $related bean being added/removed/updated from relationship |
|
367
|
|
|
* @param string $link_name name of link being triggerd |
|
368
|
|
|
* @return void |
|
369
|
|
|
*/ |
|
370
|
|
|
protected function callAfterAdd($focus, $related, $link_name="") |
|
371
|
|
|
{ |
|
372
|
|
|
$custom_logic_arguments = $this->getCustomLogicArguments($focus, $related, $link_name); |
|
373
|
|
|
$focus->call_custom_logic('after_relationship_add', $custom_logic_arguments); |
|
374
|
|
|
} |
|
375
|
|
|
|
|
376
|
|
|
/** |
|
377
|
|
|
* @param SugarBean $focus |
|
378
|
|
|
* @param SugarBean $related |
|
379
|
|
|
* @param string $link_name |
|
380
|
|
|
* @return void |
|
381
|
|
|
*/ |
|
382
|
9 |
|
protected function callBeforeDelete($focus, $related, $link_name="") |
|
383
|
|
|
{ |
|
384
|
9 |
|
$custom_logic_arguments = $this->getCustomLogicArguments($focus, $related, $link_name); |
|
385
|
9 |
|
$focus->call_custom_logic('before_relationship_delete', $custom_logic_arguments); |
|
386
|
9 |
|
} |
|
387
|
|
|
|
|
388
|
|
|
/** |
|
389
|
|
|
* @param SugarBean $focus |
|
390
|
|
|
* @param SugarBean $related |
|
391
|
|
|
* @param string $link_name |
|
392
|
|
|
* @return void |
|
393
|
|
|
*/ |
|
394
|
9 |
|
protected function callAfterDelete($focus, $related, $link_name="") |
|
395
|
|
|
{ |
|
396
|
9 |
|
$custom_logic_arguments = $this->getCustomLogicArguments($focus, $related, $link_name); |
|
397
|
9 |
|
$focus->call_custom_logic('after_relationship_delete', $custom_logic_arguments); |
|
398
|
9 |
|
} |
|
399
|
|
|
|
|
400
|
|
|
/** |
|
401
|
|
|
* @param $optional_array clause to add to the where query when populating this relationship. It should be in the |
|
402
|
|
|
* @param string $add_and |
|
|
|
|
|
|
403
|
|
|
* @param string $prefix |
|
|
|
|
|
|
404
|
|
|
* @return string |
|
405
|
|
|
*/ |
|
406
|
|
|
protected function getOptionalWhereClause($optional_array) { |
|
407
|
|
|
//lhs_field, operator, and rhs_value must be set in optional_array |
|
408
|
|
|
foreach(array("lhs_field", "operator", "rhs_value") as $required){ |
|
409
|
|
|
if (empty($optional_array[$required])) |
|
410
|
|
|
return ""; |
|
411
|
|
|
} |
|
412
|
|
|
|
|
413
|
|
|
return $optional_array['lhs_field']."".$optional_array['operator']."'".$optional_array['rhs_value']."'"; |
|
414
|
|
|
} |
|
415
|
|
|
|
|
416
|
|
|
/** |
|
417
|
|
|
* Adds a realted Bean to the list to be resaved along with the current bean. |
|
418
|
|
|
* @static |
|
419
|
|
|
* @param SugarBean $bean |
|
420
|
|
|
* @return void |
|
421
|
|
|
*/ |
|
422
|
|
|
public static function addToResaveList($bean) |
|
423
|
|
|
{ |
|
424
|
|
|
if (!isset(self::$beansToResave[$bean->module_dir])) |
|
425
|
|
|
{ |
|
426
|
|
|
self::$beansToResave[$bean->module_dir] = array(); |
|
427
|
|
|
} |
|
428
|
|
|
self::$beansToResave[$bean->module_dir][$bean->id] = $bean; |
|
429
|
|
|
} |
|
430
|
|
|
|
|
431
|
|
|
/** |
|
432
|
|
|
* |
|
433
|
|
|
* @static |
|
434
|
|
|
* @return void |
|
435
|
|
|
*/ |
|
436
|
71 |
|
public static function resaveRelatedBeans() |
|
437
|
|
|
{ |
|
438
|
71 |
|
$GLOBALS['resavingRelatedBeans'] = true; |
|
439
|
|
|
|
|
440
|
|
|
//Resave any bean not currently in the middle of a save operation |
|
441
|
71 |
|
foreach(self::$beansToResave as $module => $beans) |
|
442
|
|
|
{ |
|
443
|
|
|
foreach ($beans as $bean) |
|
444
|
|
|
{ |
|
445
|
|
|
if (empty($bean->deleted) && empty($bean->in_save)) |
|
446
|
|
|
{ |
|
447
|
|
|
$bean->save(); |
|
448
|
|
|
} |
|
449
|
|
|
else |
|
450
|
|
|
{ |
|
451
|
|
|
// Bug 55942 save the in-save id which will be used to send workflow alert later |
|
452
|
|
|
if (isset($bean->id) && !empty($_SESSION['WORKFLOW_ALERTS'])) |
|
453
|
|
|
{ |
|
454
|
|
|
$_SESSION['WORKFLOW_ALERTS']['id'] = $bean->id; |
|
455
|
|
|
} |
|
456
|
|
|
} |
|
457
|
|
|
} |
|
458
|
|
|
} |
|
459
|
|
|
|
|
460
|
71 |
|
$GLOBALS['resavingRelatedBeans'] = false; |
|
461
|
|
|
|
|
462
|
|
|
//Reset the list of beans that will need to be resaved |
|
463
|
71 |
|
self::$beansToResave = array(); |
|
464
|
71 |
|
} |
|
465
|
|
|
|
|
466
|
|
|
/** |
|
467
|
|
|
* @return bool true if the relationship is a flex / parent relationship |
|
468
|
|
|
*/ |
|
469
|
|
|
public function isParentRelationship() |
|
470
|
|
|
{ |
|
471
|
|
|
//check role fields to see if this is a parent (flex relate) relationship |
|
472
|
|
|
if(!empty($this->def["relationship_role_column"]) && !empty($this->def["relationship_role_column_value"]) |
|
473
|
|
|
&& $this->def["relationship_role_column"] == "parent_type" && $this->def['rhs_key'] == "parent_id") |
|
474
|
|
|
{ |
|
475
|
|
|
return true; |
|
476
|
|
|
} |
|
477
|
|
|
return false; |
|
478
|
|
|
} |
|
479
|
|
|
|
|
480
|
22 |
|
public function __get($name) |
|
481
|
|
|
{ |
|
482
|
22 |
|
if (isset($this->def[$name])) |
|
483
|
21 |
|
return $this->def[$name]; |
|
484
|
|
|
|
|
485
|
|
|
switch($name) |
|
486
|
|
|
{ |
|
487
|
2 |
|
case "relationship_type": |
|
488
|
|
|
return $this->type; |
|
|
|
|
|
|
489
|
2 |
|
case 'relationship_name': |
|
490
|
|
|
return $this->name; |
|
491
|
2 |
|
case "lhs_module": |
|
492
|
|
|
return $this->getLHSModule(); |
|
493
|
2 |
|
case "rhs_module": |
|
494
|
|
|
return $this->getRHSModule(); |
|
495
|
2 |
|
case "lhs_table" : |
|
|
|
|
|
|
496
|
|
|
isset($this->def['lhs_table']) ? $this->def['lhs_table'] : ""; |
|
497
|
2 |
|
case "rhs_table" : |
|
|
|
|
|
|
498
|
|
|
isset($this->def['rhs_table']) ? $this->def['rhs_table'] : ""; |
|
499
|
2 |
|
case "list_fields": |
|
500
|
|
|
return array('lhs_table', 'lhs_key', 'rhs_module', 'rhs_table', 'rhs_key', 'relationship_type'); |
|
501
|
|
|
} |
|
502
|
|
|
|
|
503
|
2 |
|
if (isset($this->$name)) |
|
504
|
2 |
|
return $this->$name; |
|
505
|
|
|
|
|
506
|
|
|
return null; |
|
507
|
|
|
} |
|
508
|
|
|
} |
|
509
|
|
|
|