1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EventEspresso\core\services\orm\tree_traversal; |
4
|
|
|
|
5
|
|
|
use EE_Base_Class; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class Visitor |
9
|
|
|
* |
10
|
|
|
* Stores info about an entity in a model relations tree |
11
|
|
|
* |
12
|
|
|
* @package Event Espresso |
13
|
|
|
* @author Mike Nelson |
14
|
|
|
* @since $VID:$ |
15
|
|
|
* |
16
|
|
|
*/ |
17
|
|
|
class EntityNode extends BaseNode |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var EE_Base_Class |
21
|
|
|
*/ |
22
|
|
|
protected $initialInstance; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var RelationNode[] |
26
|
|
|
*/ |
27
|
|
|
protected $relation_nodes; |
28
|
|
|
|
29
|
|
|
public function __construct( $instance) |
30
|
|
|
{ |
31
|
|
|
$this->initialInstance = $instance; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function discover(){ |
35
|
|
|
foreach($this->initialInstance->get_model()->relation_settings() as $relation){ |
36
|
|
|
if($relation->block_delete_if_related_models_exist()){ |
37
|
|
|
$this->relation_nodes[] = new RelationNode($this->initialInstance, $relation); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Whether this item has already been initialized |
45
|
|
|
*/ |
46
|
|
|
public function isDiscovered() |
47
|
|
|
{ |
48
|
|
|
// TODO: Implement isDiscovered() method. |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @since $VID:$ |
53
|
|
|
* @return boolean |
54
|
|
|
*/ |
55
|
|
|
public function isComplete() |
56
|
|
|
{ |
57
|
|
|
if($this->complete == null){ |
58
|
|
|
$this->complete = true; |
59
|
|
|
foreach($this->relation_nodes as $relation_node){ |
60
|
|
|
if(! $relation_node->isComplete()){ |
61
|
|
|
$this->complete = false; |
62
|
|
|
break; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
return $this->complete; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* |
71
|
|
|
* @since $VID:$ |
72
|
|
|
* @param $work_to_do |
73
|
|
|
* @return int units of work done |
74
|
|
|
*/ |
75
|
|
|
protected function work($work_to_do) |
76
|
|
|
{ |
77
|
|
|
$units_worked = 0; |
78
|
|
|
foreach($this->relation_nodes as $relation_node){ |
79
|
|
|
if(! $relation_node->isComplete()){ |
|
|
|
|
80
|
|
|
$units_worked += $relation_node->visit($work_to_do); |
81
|
|
|
} |
82
|
|
|
if($units_worked >= $work_to_do){ |
83
|
|
|
break; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
return $units_worked; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
// End of file Visitor.php |
90
|
|
|
// Location: EventEspresso\core\services\orm\tree_traversal/Visitor.php |
91
|
|
|
|
If an expression can have both
false
, andnull
as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.