1 <?php
2 /**
3 * @package Joomla.Legacy
4 * @subpackage Base
5 *
6 * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE.txt
8 */
9
10 defined('JPATH_PLATFORM') or die;
11
12 /**
13 * Tree Node Class.
14 *
15 * @since 1.5
16 * @deprecated 3.0
17 */
18 class JNode extends JObject
19 {
20 /**
21 * Parent node
22 *
23 * @var JNode
24 * @since 1.5
25 * @deprecated 3.0
26 */
27 protected $_parent = null;
28
29 /**
30 * Array of Children
31 *
32 * @var JNode[]
33 * @since 1.5
34 * @deprecated 3.0
35 */
36 protected $_children = array();
37
38 /**
39 * Constructor
40 *
41 * @since 1.5
42 * @deprecated 3.0
43 */
44 public function __construct()
45 {
46 JLog::add('JNode::__construct() is deprecated.', JLog::WARNING, 'deprecated');
47
48 return true;
49 }
50
51 /**
52 * Add child to this node
53 *
54 * If the child already has a parent, the link is unset
55 *
56 * @param JNode &$child The child to be added
57 *
58 * @return void
59 *
60 * @since 1.5
61 * @deprecated 3.0
62 */
63 public function addChild(&$child)
64 {
65 JLog::add('JNode::addChild() is deprecated.', JLog::WARNING, 'deprecated');
66
67 if ($child instanceof Jnode)
68 {
69 $child->setParent($this);
70 }
71 }
72
73 /**
74 * Set the parent of a this node
75 *
76 * If the node already has a parent, the link is unset
77 *
78 * @param JNode|null &$parent The JNode for parent to be set or null
79 *
80 * @return void
81 *
82 * @since 1.5
83 * @deprecated 3.0
84 */
85 public function setParent(&$parent)
86 {
87 JLog::add('JNode::setParent() is deprecated.', JLog::WARNING, 'deprecated');
88
89 if ($parent instanceof JNode || is_null($parent))
90 {
91 $hash = spl_object_hash($this);
92
93 if (!is_null($this->_parent))
94 {
95 unset($this->_parent->children[$hash]);
96 }
97
98 if (!is_null($parent))
99 {
100 $parent->_children[$hash] = & $this;
101 }
102
103 $this->_parent = & $parent;
104 }
105 }
106
107 /**
108 * Get the children of this node
109 *
110 * @return JNode[] The children
111 *
112 * @since 1.5
113 * @deprecated 3.0
114 */
115 public function &getChildren()
116 {
117 JLog::add('JNode::getChildren() is deprecated.', JLog::WARNING, 'deprecated');
118
119 return $this->_children;
120 }
121
122 /**
123 * Get the parent of this node
124 *
125 * @return JNode|null JNode object with the parent or null for no parent
126 *
127 * @since 1.5
128 * @deprecated 3.0
129 */
130 public function &getParent()
131 {
132 JLog::add('JNode::getParent() is deprecated.', JLog::WARNING, 'deprecated');
133
134 return $this->_parent;
135 }
136
137 /**
138 * Test if this node has children
139 *
140 * @return boolean True if there are children
141 *
142 * @since 1.5
143 * @deprecated 3.0
144 */
145 public function hasChildren()
146 {
147 JLog::add('JNode::hasChildren() is deprecated.', JLog::WARNING, 'deprecated');
148
149 return (bool) count($this->_children);
150 }
151
152 /**
153 * Test if this node has a parent
154 *
155 * @return boolean True if there is a parent
156 *
157 * @since 1.6
158 * @deprecated 3.0
159 */
160 public function hasParent()
161 {
162 JLog::add('JNode::hasParent() is deprecated.', JLog::WARNING, 'deprecated');
163
164 return $this->getParent() != null;
165 }
166 }
167