<?php
function fn_inside_a($aql)
{
	$list = $aql->Consume(1);
	
	$ids = $list[0]->value;	
	
	global $db;
	$rel = 2;	
	$existing = array();
	
	$mt = microtime(true);
		
	$extra = "";
	if (count($existing) > 0) 
	{
		$extra = " AND childasset IN (".implode(",",$existing).')';
	}
	
	if (count($ids) == 0)
	{
		$a = new AQLStackElement();
		$a->typename = "assetlist";
		$a->islist = true;
		$a->value = array();
		array_push($aql->stack,$a);
	}
		
	$query = $db->query("SELECT childasset FROM assetrelclosures WHERE relationship=".$rel." AND parentasset IN (".implode(',',$ids).")".$extra);
	
	$apool = array();
	
	while($row = $query->fetch(PDO::FETCH_ASSOC)) 
	{
		$apool[] = $row['childasset'];
	}
	
	$a = new AQLStackElement();
	$a->typename = "assetlist";
	$a->islist = true;
	$a->value = $apool;
	array_push($aql->stack,$a);

}
?>