Root Node Function


(Nic Hubbard) #1

Is there a function somewhere that can be used to restrict to a root node? Meaning, if an asset ID is passed, it is checked to see if it is found under the set root node, if it is, it returns true, if it is not under that root node, it returns false?


(Nic Hubbard) #2

Ok, I made a quick function that returns true if a certain asset is found under a set root node.

    		function checkRoot($id)
    	{
    		$root = $GLOBALS['SQ_SYSTEM']->am->getChildren($this->attr('root_node'));
    		foreach($root as $key => $val) {
    			if ($key == $id) {
    				return TRUE;
    			}
    		}// End foreach
    	
    	}// End checkRoot


Not entirely sure this is the fastest method though...

(Greg Sherwood) #3

It's probably faster to do a getParents() on the child asset and check to see if the root_node is in the parent list. You should get fewer results from getParents() than getChildren().


I don't remember the return format of getParents(), but you might be able to do something like (pseudocode):

$parents = getParents($id);

return isset($parents[$root_node]);



You may not even need a function to do that if there is no other logic in there.


(Nic Hubbard) #4

[quote]I don't remember the return format of getParents(), but you might be able to do something like (pseudocode):
$parents = getParents($id);

return isset($parents[$root_node]);[/quote]



Nice one Greg! Thank you, this one worked perfectly and does seem to be a much quicker and simpler solution.



I appreciate the help!