File: D:/HostingSpaces/SBogers10/topswtwmobile.komma.pro/app/KommaApp/Shop/Tree/TreeService.php
<?php
namespace KommaApp\Shop\Tree;
abstract class TreeService
{
/**
* @param $id
* @return bool
*/
public function getNodeById($id)
{
$tree = $this->getTreeNodes();
if(isset($tree['index'][$id])) return $tree['index'][$id];
return false;
}
/**
* @return array
*/
public function getFirstLetters($sort = false)
{
$tree = $this->getTreeNodes(false);
$letters = [];
foreach($tree as $branch)
{
$firstLetter = substr($branch->name,0,1);
if( ! in_array($firstLetter,$letters)) $letters[] = $firstLetter;
}
if($sort){
sort($letters);
}
return $letters;
}
/**
* @param $node
* @return bool
*/
public function getRootNode($node)
{
while($parent = $this->checkParent($node))
{
$node = $parent;
}
return $node;
}
/**
* @param $node
* @return bool
*/
protected function checkParent($node)
{
if($node && $parent = $node->getParent())
{
return $parent;
}
return false;
}
}