1 | <?php |
||
2 | |||
3 | /** |
||
4 | * Page class |
||
5 | * |
||
6 | * @since 3.0 |
||
7 | */ |
||
8 | class ElggPage extends ElggObject { |
||
9 | |||
10 | /** |
||
11 | * {@inheritDoc} |
||
12 | */ |
||
13 | 6 | protected function initializeAttributes() { |
|
14 | 6 | parent::initializeAttributes(); |
|
15 | |||
16 | 6 | $this->attributes['subtype'] = 'page'; |
|
17 | |||
18 | // set default parent (this makes it a top page) |
||
19 | 6 | $this->parent_guid = 0; |
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
20 | 6 | } |
|
21 | |||
22 | /** |
||
23 | * Is this a top page in the tree |
||
24 | * |
||
25 | * @return bool |
||
26 | * |
||
27 | * @since 3.0 |
||
28 | */ |
||
29 | 1 | public function isTopPage() { |
|
30 | 1 | return empty($this->parent_guid); |
|
31 | } |
||
32 | |||
33 | /** |
||
34 | * Get the parent entity of this page |
||
35 | * |
||
36 | * @return false|ElggPage |
||
37 | * |
||
38 | * @since 3.0 |
||
39 | */ |
||
40 | 1 | public function getParentEntity() { |
|
41 | |||
42 | 1 | if (empty($this->parent_guid)) { |
|
43 | 1 | return false; |
|
44 | } |
||
45 | |||
46 | 1 | $parent = get_entity($this->parent_guid); |
|
47 | 1 | if ($parent instanceof ElggPage) { |
|
48 | 1 | return $parent; |
|
49 | } |
||
50 | |||
51 | 1 | return false; |
|
52 | } |
||
53 | |||
54 | /** |
||
55 | * Get the GUID of the parent entity |
||
56 | * |
||
57 | * @return int 0 if no parent |
||
58 | */ |
||
59 | 3 | public function getParentGUID() { |
|
60 | 3 | return (int) $this->parent_guid; |
|
61 | } |
||
62 | |||
63 | /** |
||
64 | * Set a new parent entity from a GUID |
||
65 | * |
||
66 | * @param int $guid the GUID of an ElggPage or 0 |
||
67 | * |
||
68 | * @return bool |
||
69 | * |
||
70 | * @since 3.0 |
||
71 | */ |
||
72 | 1 | public function setParentByGUID($guid) { |
|
73 | 1 | $guid = (int) $guid; |
|
74 | |||
75 | 1 | if (empty($guid)) { |
|
76 | 1 | $this->parent_guid = 0; |
|
0 ignored issues
–
show
|
|||
77 | 1 | return true; |
|
78 | } |
||
79 | |||
80 | 1 | $new_parent = get_entity($guid); |
|
81 | 1 | return $this->setParentEntity($new_parent); |
|
82 | } |
||
83 | |||
84 | /** |
||
85 | * Set the new parent entity |
||
86 | * |
||
87 | * @param ElggPage|null $entity the new parent entity. Eighter an ElggPage or null |
||
88 | * |
||
89 | * @return bool |
||
90 | * |
||
91 | * @since 3.0 |
||
92 | */ |
||
93 | 2 | public function setParentEntity($entity) { |
|
94 | |||
95 | 2 | if (empty($entity)) { |
|
96 | 1 | $this->parent_guid = 0; |
|
0 ignored issues
–
show
|
|||
97 | 1 | return true; |
|
98 | } |
||
99 | |||
100 | 2 | if (!$entity instanceof ElggPage || empty($entity->guid)) { |
|
101 | 2 | return false; |
|
102 | } |
||
103 | |||
104 | 2 | $this->parent_guid = $entity->guid; |
|
105 | 2 | return true; |
|
106 | } |
||
107 | } |
||
108 |