TYPO3 CMS  TYPO3_6-2
TreeNode.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\Tree;
3 
18 
26 
32  protected $id = '';
33 
39  protected $parentNode = NULL;
40 
46  protected $childNodes = NULL;
47 
56  public function __construct(array $data = array()) {
57  if (count($data)) {
58  $this->dataFromArray($data);
59  }
60  }
61 
68  public function setChildNodes(\TYPO3\CMS\Backend\Tree\TreeNodeCollection $childNodes) {
69  $this->childNodes = $childNodes;
70  }
71 
77  public function removeChildNodes() {
78  if ($this->childNodes !== NULL) {
79  unset($this->childNodes);
80  $this->childNodes = NULL;
81  }
82  }
83 
89  public function getChildNodes() {
90  return $this->childNodes;
91  }
92 
98  public function hasChildNodes() {
99  if ($this->childNodes !== NULL) {
100  return TRUE;
101  }
102  return FALSE;
103  }
104 
111  public function setId($id) {
112  $this->id = $id;
113  }
114 
120  public function getId() {
121  return $this->id;
122  }
123 
130  public function setParentNode(\TYPO3\CMS\Backend\Tree\TreeNode $parentNode = NULL) {
131  $this->parentNode = $parentNode;
132  }
133 
139  public function getParentNode() {
140  return $this->parentNode;
141  }
142 
149  public function equals(\TYPO3\CMS\Backend\Tree\TreeNode $other) {
150  return $this->id == $other->getId();
151  }
152 
164  public function compareTo($other) {
165  if ($this->equals($other)) {
166  return 0;
167  }
168  return $this->id > $other->getId() ? 1 : -1;
169  }
170 
177  public function toArray($addChildNodes = TRUE) {
178  $arrayRepresentation = array(
179  'serializeClassName' => get_class($this),
180  'id' => $this->id
181  );
182  if ($this->parentNode !== NULL) {
183  $arrayRepresentation['parentNode'] = $this->parentNode->toArray(FALSE);
184  } else {
185  $arrayRepresentation['parentNode'] = '';
186  }
187  if ($this->hasChildNodes() && $addChildNodes) {
188  $arrayRepresentation['childNodes'] = $this->childNodes->toArray();
189  } else {
190  $arrayRepresentation['childNodes'] = '';
191  }
192  return $arrayRepresentation;
193  }
194 
201  public function dataFromArray($data) {
202  $this->setId($data['id']);
203  if (isset($data['parentNode']) && $data['parentNode'] !== '') {
204  $this->setParentNode(GeneralUtility::makeInstance($data['parentNode']['serializeClassName'], $data['parentNode']));
205  }
206  if (isset($data['childNodes']) && $data['childNodes'] !== '') {
207  $this->setChildNodes(GeneralUtility::makeInstance($data['childNodes']['serializeClassName'], $data['childNodes']));
208  }
209  }
210 
216  public function serialize() {
217  return serialize($this->toArray());
218  }
219 
227  public function unserialize($serializedString) {
228  $arrayRepresentation = unserialize($serializedString);
229  if ($arrayRepresentation['serializeClassName'] !== get_class($this)) {
230  throw new \TYPO3\CMS\Core\Exception('Deserialized object type is not identical!', 1294586646);
231  }
232  $this->dataFromArray($arrayRepresentation);
233  }
234 
235 }
toArray($addChildNodes=TRUE)
Definition: TreeNode.php:177
setParentNode(\TYPO3\CMS\Backend\Tree\TreeNode $parentNode=NULL)
Definition: TreeNode.php:130
equals(\TYPO3\CMS\Backend\Tree\TreeNode $other)
Definition: TreeNode.php:149
unserialize($serializedString)
Definition: TreeNode.php:227
setChildNodes(\TYPO3\CMS\Backend\Tree\TreeNodeCollection $childNodes)
Definition: TreeNode.php:68
__construct(array $data=array())
Definition: TreeNode.php:56