<?php

/**
 * Created by PhpStorm.
 * User: Eric
 * Date: 31/08/2018
 * Time: 17:03
 */

namespace Combodo\iTop\Test\UnitTest\Core;

use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
use DBObjectSearch;
use DBSearch;
use OQLException;
use OqlInterpreter;
use OQLParserException;
use UnknownClassOqlException;
use UserRights;

class OQLParserTest extends ItopDataTestCase
{
	/**
	 * @group iTopChangeMgt
	 * @group itopConfigMgmt
	 * @group itopRequestMgmt
	 * @group specificOrgInSampleData
	 * @dataProvider NestedQueryProvider
	 *
	 * @param $sQuery
	 *
	 * @throws \OQLException
	 */
	public function testGoodNestedQueryQueryParser($sQuery)
	{
		$this->debug($sQuery);
		$oDbObjectSearch = DBObjectSearch::FromOQL($sQuery);
		$sOql = $oDbObjectSearch->ToOQL();
		$this->debug($sOql);
		self::assertEquals($sQuery, $sOql);
	}

	public function testUnknownClassOqlException()
	{
		$oOrgId = $this->GivenObjectInDB('Organization', ['name' => 'TestOrg']);
		$sLogin = $this->GivenUserRestrictedToAnOrganizationInDB($oOrgId, self::$aURP_Profiles['Portal user']);
		UserRights::Login($sLogin);

		try {
			DBSearch::FromOQL('SELECT UnknownClass');
			$this->fail('An UnknownClassOqlException should have been thrown');
		} catch (UnknownClassOqlException $e) {
			$this->assertNotContains('DBProperty', $e->GetSuggestions(), 'user should not be recommanded to perform queries on classes his not allowed to see');
		}
	}

	public function NestedQueryProvider()
	{
		return [
			["SELECT `U` FROM User AS `U` JOIN Person AS `P` ON `U`.contactid = `P`.id WHERE ((`U`.`status` = 'enabled') AND (`U`.`id` NOT IN (SELECT `U` FROM User AS `U` JOIN Person AS `P` ON `U`.contactid = `P`.id JOIN URP_UserOrg AS `L` ON `L`.userid = `U`.id WHERE ((`U`.`status` = 'enabled') AND (`L`.`allowed_org_id` = `P`.`org_id`)) UNION SELECT `U` FROM User AS `U` WHERE ((`U`.`status` = 'enabled') AND (`U`.`id` NOT IN (SELECT `U` FROM User AS `U` JOIN URP_UserOrg AS `L` ON `L`.userid = `U`.id WHERE (`U`.`status` = 'enabled')))))))"],
			["SELECT `Ur` FROM UserRequest AS `Ur` WHERE (`Ur`.`id` NOT IN (SELECT `Ur` FROM UserRequest AS `Ur` JOIN lnkFunctionalCIToTicket AS `lnk` ON `lnk`.ticket_id = `Ur`.id WHERE 1))"],
			["SELECT `T` FROM Ticket AS `T` WHERE ((`T`.`finalclass` IN ('userrequest', 'change')) AND (`T`.`id` NOT IN (SELECT `Ur` FROM UserRequest AS `Ur` JOIN lnkFunctionalCIToTicket AS `lnk` ON `lnk`.ticket_id = `Ur`.id WHERE 1 UNION SELECT `C` FROM Change AS `C` JOIN lnkFunctionalCIToTicket AS `lnk` ON `lnk`.ticket_id = `C`.id WHERE 1)))"],
			["SELECT `PhysicalDevice` FROM PhysicalDevice AS `PhysicalDevice` WHERE ((`PhysicalDevice`.`status` = 'production') AND (`PhysicalDevice`.`id` NOT IN (SELECT `p` FROM PhysicalDevice AS `p` JOIN lnkFunctionalCIToProviderContract AS `l` ON `l`.functionalci_id = `p`.id WHERE 1)))"],
			['SELECT `UserRequest` FROM UserRequest AS `UserRequest` JOIN Person AS `P` ON `UserRequest`.agent_id = `P`.id JOIN Organization AS `Organization` ON `P`.org_id = `Organization`.id WHERE (`UserRequest`.`org_id` IN (SELECT `Organization` FROM Organization AS `Organization` WHERE (`Organization`.`id` = `UserRequest`.`org_id`)))'],
			['SELECT `UserRequest` FROM UserRequest AS `UserRequest` WHERE (`UserRequest`.`org_id` IN (SELECT `Organization` FROM Organization AS `Organization` WHERE (`Organization`.`id` = `UserRequest`.`org_id`)))'],
			['SELECT `UserRequest` FROM UserRequest AS `UserRequest` WHERE (`UserRequest`.`org_id` IN (SELECT `Organization` FROM Organization AS `Organization` WHERE 1))'],
			['SELECT `UserRequest` FROM UserRequest AS `UserRequest` WHERE (`UserRequest`.`org_id` NOT IN (SELECT `Organization` FROM Organization AS `Organization` WHERE 1))'],
			['SELECT `UserRequest` FROM UserRequest AS `UserRequest` WHERE (`UserRequest`.`org_id` IN (SELECT `Organization` FROM Organization AS `Organization` JOIN Organization AS `Organization1` ON `Organization`.parent_id BELOW `Organization1`.id WHERE (`Organization1`.`id` = \'3\')))'],
			['SELECT `UserRequest` FROM UserRequest AS `UserRequest` WHERE (`UserRequest`.`org_id` IN (SELECT `Organization` FROM Organization AS `Organization` WHERE (`Organization`.`id` = \'3\')))'],
			["SELECT `L`, `P` FROM Location AS `L` JOIN Person AS `P` ON `P`.location_id = `L`.id WHERE 1"],
			["SELECT `UserRequest` FROM UserRequest AS `UserRequest` WHERE ((`UserRequest`.`agent_id` = :current_contact_id) AND (`UserRequest`.`status` NOT IN ('closed', 'resolved')))"],
			["SELECT `L` FROM Person AS `P` JOIN Location AS `L` ON `P`.location_id = `L`.id WHERE 1"],
		];
	}

	/**
	 * Bug N°4052 OQL parser limit for huge request
	 * @throws \OQLException
	 */
	public function testOQLParserStackSize()
	{
		// OQL Parser stack size is 1000
		$sQuery = "SELECT Organization WHERE 1";
		$sQuery .= str_repeat(" UNION SELECT Organization WHERE 1", 497);
		//$sExpression = "SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `lnk1` ON `lnk1`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`lnk1`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s1` ON `GARE`.service_id = `s1`.id JOIN lnkServiceToTeam AS `lnk2` ON `lnk2`.service_id = `s1`.id JOIN Team AS `t3` ON `lnk2`.team_id = `t3`.id JOIN Organization AS `Node3` ON `t3`.org_id = `Node3`.id JOIN Organization AS `Root3` ON `Node3`.parent_id BELOW `Root3`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root3`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s2` ON `GARE`.service_id = `s2`.id JOIN lnkServiceToTeam AS `lnk3` ON `lnk3`.service_id = `s2`.id JOIN Team AS `t4` ON `lnk3`.team_id = `t4`.id JOIN Organization AS `Node4` ON `t4`.org_id = `Node4`.id JOIN Organization AS `Root4` ON `Node4`.parent_id BELOW `Root4`.id JOIN lnkOrganizationToPerson AS `lnk5` ON `lnk5`.organization_id = `Root4`.id JOIN lnkPersonToTeam AS `lnk4` ON `lnk4`.team_id = `t4`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`lnk5`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s3` ON `GARE`.service_id = `s3`.id JOIN lnkOrganizationToService AS `lnk6` ON `lnk6`.service_id = `s3`.id JOIN Team AS `t5` ON `lnk6`.team_id = `t5`.id JOIN Organization AS `Node5` ON `t5`.org_id = `Node5`.id JOIN Organization AS `Root5` ON `Node5`.parent_id BELOW `Root5`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root5`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s4` ON `GARE`.service_id = `s4`.id JOIN lnkOrganizationToService AS `lnk7` ON `lnk7`.service_id = `s4`.id JOIN Team AS `t6` ON `lnk7`.team_id = `t6`.id JOIN Organization AS `Node6` ON `t6`.org_id = `Node6`.id JOIN Organization AS `Root6` ON `Node6`.parent_id BELOW `Root6`.id JOIN lnkOrganizationToPerson AS `lnk9` ON `lnk9`.organization_id = `Root6`.id JOIN lnkPersonToTeam AS `lnk8` ON `lnk8`.team_id = `t6`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`lnk9`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `lnk1` ON `lnk1`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`lnk1`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `lnk1` ON `lnk1`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`lnk1`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`lnk1`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `lnk1` ON `lnk1`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s1` ON `GARE`.service_id = `s1`.id JOIN lnkServiceToTeam AS `lnk2` ON `lnk2`.service_id = `s1`.id JOIN Team AS `t3` ON `lnk2`.team_id = `t3`.id JOIN Organization AS `Node3` ON `t3`.org_id = `Node3`.id JOIN Organization AS `Root3` ON `Node3`.parent_id BELOW `Root3`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`lnk1`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root3`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `lnk1` ON `lnk1`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s2` ON `GARE`.service_id = `s2`.id JOIN lnkServiceToTeam AS `lnk3` ON `lnk3`.service_id = `s2`.id JOIN Team AS `t4` ON `lnk3`.team_id = `t4`.id JOIN Organization AS `Node4` ON `t4`.org_id = `Node4`.id JOIN Organization AS `Root4` ON `Node4`.parent_id BELOW `Root4`.id JOIN lnkOrganizationToPerson AS `lnk5` ON `lnk5`.organization_id = `Root4`.id JOIN lnkPersonToTeam AS `lnk4` ON `lnk4`.team_id = `t4`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`lnk1`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`lnk5`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `lnk1` ON `lnk1`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s3` ON `GARE`.service_id = `s3`.id JOIN lnkOrganizationToService AS `lnk6` ON `lnk6`.service_id = `s3`.id JOIN Team AS `t5` ON `lnk6`.team_id = `t5`.id JOIN Organization AS `Node5` ON `t5`.org_id = `Node5`.id JOIN Organization AS `Root5` ON `Node5`.parent_id BELOW `Root5`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`lnk1`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root5`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `lnk1` ON `lnk1`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s4` ON `GARE`.service_id = `s4`.id JOIN lnkOrganizationToService AS `lnk7` ON `lnk7`.service_id = `s4`.id JOIN Team AS `t6` ON `lnk7`.team_id = `t6`.id JOIN Organization AS `Node6` ON `t6`.org_id = `Node6`.id JOIN Organization AS `Root6` ON `Node6`.parent_id BELOW `Root6`.id JOIN lnkOrganizationToPerson AS `lnk9` ON `lnk9`.organization_id = `Root6`.id JOIN lnkPersonToTeam AS `lnk8` ON `lnk8`.team_id = `t6`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`lnk1`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`lnk9`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s1` ON `GARE`.service_id = `s1`.id JOIN lnkServiceToTeam AS `lnk2` ON `lnk2`.service_id = `s1`.id JOIN Team AS `t3` ON `lnk2`.team_id = `t3`.id JOIN Organization AS `Node3` ON `t3`.org_id = `Node3`.id JOIN Organization AS `Root3` ON `Node3`.parent_id BELOW `Root3`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root3`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `lnk1` ON `lnk1`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s1` ON `GARE`.service_id = `s1`.id JOIN lnkServiceToTeam AS `lnk2` ON `lnk2`.service_id = `s1`.id JOIN Team AS `t3` ON `lnk2`.team_id = `t3`.id JOIN Organization AS `Node3` ON `t3`.org_id = `Node3`.id JOIN Organization AS `Root3` ON `Node3`.parent_id BELOW `Root3`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root3`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`lnk1`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s1` ON `GARE`.service_id = `s1`.id JOIN lnkServiceToTeam AS `lnk2` ON `lnk2`.service_id = `s1`.id JOIN Team AS `t3` ON `lnk2`.team_id = `t3`.id JOIN Organization AS `Node3` ON `t3`.org_id = `Node3`.id JOIN Organization AS `Root3` ON `Node3`.parent_id BELOW `Root3`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root3`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root3`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s1` ON `GARE`.service_id = `s1`.id JOIN lnkServiceToTeam AS `lnk2` ON `lnk2`.service_id = `s1`.id JOIN Team AS `t3` ON `lnk2`.team_id = `t3`.id JOIN Organization AS `Node3` ON `t3`.org_id = `Node3`.id JOIN Organization AS `Root3` ON `Node3`.parent_id BELOW `Root3`.id JOIN lnkOrganizationToPerson AS `lnk5` ON `lnk5`.organization_id = `Root3`.id JOIN lnkPersonToTeam AS `lnk4` ON `lnk4`.team_id = `t3`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root3`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`lnk5`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s1` ON `GARE`.service_id = `s1`.id JOIN lnkServiceToTeam AS `lnk2` ON `lnk2`.service_id = `s1`.id JOIN Team AS `t3` ON `lnk2`.team_id = `t3`.id JOIN Organization AS `Node3` ON `t3`.org_id = `Node3`.id JOIN Organization AS `Root3` ON `Node3`.parent_id BELOW `Root3`.id JOIN lnkOrganizationToService AS `lnk6` ON `lnk6`.service_id = `s1`.id JOIN Team AS `t5` ON `lnk6`.team_id = `t5`.id JOIN Organization AS `Node5` ON `t5`.org_id = `Node5`.id JOIN Organization AS `Root5` ON `Node5`.parent_id BELOW `Root5`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root3`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root5`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s1` ON `GARE`.service_id = `s1`.id JOIN lnkServiceToTeam AS `lnk2` ON `lnk2`.service_id = `s1`.id JOIN Team AS `t3` ON `lnk2`.team_id = `t3`.id JOIN Organization AS `Node3` ON `t3`.org_id = `Node3`.id JOIN Organization AS `Root3` ON `Node3`.parent_id BELOW `Root3`.id JOIN lnkOrganizationToService AS `lnk7` ON `lnk7`.service_id = `s1`.id JOIN Team AS `t6` ON `lnk7`.team_id = `t6`.id JOIN Organization AS `Node6` ON `t6`.org_id = `Node6`.id JOIN Organization AS `Root6` ON `Node6`.parent_id BELOW `Root6`.id JOIN lnkOrganizationToPerson AS `lnk9` ON `lnk9`.organization_id = `Root6`.id JOIN lnkPersonToTeam AS `lnk8` ON `lnk8`.team_id = `t6`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root3`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`lnk9`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s2` ON `GARE`.service_id = `s2`.id JOIN lnkServiceToTeam AS `lnk3` ON `lnk3`.service_id = `s2`.id JOIN Team AS `t4` ON `lnk3`.team_id = `t4`.id JOIN Organization AS `Node4` ON `t4`.org_id = `Node4`.id JOIN Organization AS `Root4` ON `Node4`.parent_id BELOW `Root4`.id JOIN lnkOrganizationToPerson AS `lnk5` ON `lnk5`.organization_id = `Root4`.id JOIN lnkPersonToTeam AS `lnk4` ON `lnk4`.team_id = `t4`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`lnk5`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `lnk1` ON `lnk1`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s2` ON `GARE`.service_id = `s2`.id JOIN lnkServiceToTeam AS `lnk3` ON `lnk3`.service_id = `s2`.id JOIN Team AS `t4` ON `lnk3`.team_id = `t4`.id JOIN Organization AS `Node4` ON `t4`.org_id = `Node4`.id JOIN Organization AS `Root4` ON `Node4`.parent_id BELOW `Root4`.id JOIN lnkOrganizationToPerson AS `lnk5` ON `lnk5`.organization_id = `Root4`.id JOIN lnkPersonToTeam AS `lnk4` ON `lnk4`.team_id = `t4`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`lnk5`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`lnk1`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s2` ON `GARE`.service_id = `s2`.id JOIN lnkServiceToTeam AS `lnk3` ON `lnk3`.service_id = `s2`.id JOIN Team AS `t4` ON `lnk3`.team_id = `t4`.id JOIN Organization AS `Node4` ON `t4`.org_id = `Node4`.id JOIN Organization AS `Root4` ON `Node4`.parent_id BELOW `Root4`.id JOIN lnkOrganizationToPerson AS `lnk5` ON `lnk5`.organization_id = `Root4`.id JOIN lnkPersonToTeam AS `lnk4` ON `lnk4`.team_id = `t4`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`lnk5`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root4`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s2` ON `GARE`.service_id = `s2`.id JOIN lnkServiceToTeam AS `lnk3` ON `lnk3`.service_id = `s2`.id JOIN Team AS `t4` ON `lnk3`.team_id = `t4`.id JOIN Organization AS `Node4` ON `t4`.org_id = `Node4`.id JOIN Organization AS `Root4` ON `Node4`.parent_id BELOW `Root4`.id JOIN lnkOrganizationToPerson AS `lnk5` ON `lnk5`.organization_id = `Root4`.id JOIN lnkPersonToTeam AS `lnk4` ON `lnk4`.team_id = `t4`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`lnk5`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`lnk5`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s2` ON `GARE`.service_id = `s2`.id JOIN lnkServiceToTeam AS `lnk3` ON `lnk3`.service_id = `s2`.id JOIN Team AS `t4` ON `lnk3`.team_id = `t4`.id JOIN Organization AS `Node4` ON `t4`.org_id = `Node4`.id JOIN Organization AS `Root4` ON `Node4`.parent_id BELOW `Root4`.id JOIN lnkOrganizationToPerson AS `lnk5` ON `lnk5`.organization_id = `Root4`.id JOIN lnkPersonToTeam AS `lnk4` ON `lnk4`.team_id = `t4`.id JOIN lnkOrganizationToService AS `lnk6` ON `lnk6`.service_id = `s2`.id JOIN Team AS `t5` ON `lnk6`.team_id = `t5`.id JOIN Organization AS `Node5` ON `t5`.org_id = `Node5`.id JOIN Organization AS `Root5` ON `Node5`.parent_id BELOW `Root5`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`lnk5`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root5`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s2` ON `GARE`.service_id = `s2`.id JOIN lnkServiceToTeam AS `lnk3` ON `lnk3`.service_id = `s2`.id JOIN Team AS `t4` ON `lnk3`.team_id = `t4`.id JOIN Organization AS `Node4` ON `t4`.org_id = `Node4`.id JOIN Organization AS `Root4` ON `Node4`.parent_id BELOW `Root4`.id JOIN lnkOrganizationToPerson AS `lnk5` ON `lnk5`.organization_id = `Root4`.id JOIN lnkPersonToTeam AS `lnk4` ON `lnk4`.team_id = `t4`.id JOIN lnkOrganizationToService AS `lnk7` ON `lnk7`.service_id = `s2`.id JOIN Team AS `t6` ON `lnk7`.team_id = `t6`.id JOIN Organization AS `Node6` ON `t6`.org_id = `Node6`.id JOIN Organization AS `Root6` ON `Node6`.parent_id BELOW `Root6`.id JOIN lnkOrganizationToPerson AS `lnk9` ON `lnk9`.organization_id = `Root6`.id JOIN lnkPersonToTeam AS `lnk8` ON `lnk8`.team_id = `t6`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`lnk5`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`lnk9`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s3` ON `GARE`.service_id = `s3`.id JOIN lnkOrganizationToService AS `lnk6` ON `lnk6`.service_id = `s3`.id JOIN Team AS `t5` ON `lnk6`.team_id = `t5`.id JOIN Organization AS `Node5` ON `t5`.org_id = `Node5`.id JOIN Organization AS `Root5` ON `Node5`.parent_id BELOW `Root5`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root5`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `lnk1` ON `lnk1`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s3` ON `GARE`.service_id = `s3`.id JOIN lnkOrganizationToService AS `lnk6` ON `lnk6`.service_id = `s3`.id JOIN Team AS `t5` ON `lnk6`.team_id = `t5`.id JOIN Organization AS `Node5` ON `t5`.org_id = `Node5`.id JOIN Organization AS `Root5` ON `Node5`.parent_id BELOW `Root5`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root5`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`lnk1`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s3` ON `GARE`.service_id = `s3`.id JOIN lnkOrganizationToService AS `lnk6` ON `lnk6`.service_id = `s3`.id JOIN Team AS `t5` ON `lnk6`.team_id = `t5`.id JOIN Organization AS `Node5` ON `t5`.org_id = `Node5`.id JOIN Organization AS `Root5` ON `Node5`.parent_id BELOW `Root5`.id JOIN lnkServiceToTeam AS `lnk2` ON `lnk2`.service_id = `s3`.id JOIN Team AS `t3` ON `lnk2`.team_id = `t3`.id JOIN Organization AS `Node3` ON `t3`.org_id = `Node3`.id JOIN Organization AS `Root3` ON `Node3`.parent_id BELOW `Root3`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root5`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root3`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s3` ON `GARE`.service_id = `s3`.id JOIN lnkOrganizationToService AS `lnk6` ON `lnk6`.service_id = `s3`.id JOIN Team AS `t5` ON `lnk6`.team_id = `t5`.id JOIN Organization AS `Node5` ON `t5`.org_id = `Node5`.id JOIN Organization AS `Root5` ON `Node5`.parent_id BELOW `Root5`.id JOIN lnkServiceToTeam AS `lnk3` ON `lnk3`.service_id = `s3`.id JOIN Team AS `t4` ON `lnk3`.team_id = `t4`.id JOIN Organization AS `Node4` ON `t4`.org_id = `Node4`.id JOIN Organization AS `Root4` ON `Node4`.parent_id BELOW `Root4`.id JOIN lnkOrganizationToPerson AS `lnk5` ON `lnk5`.organization_id = `Root4`.id JOIN lnkPersonToTeam AS `lnk4` ON `lnk4`.team_id = `t4`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root5`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`lnk5`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s3` ON `GARE`.service_id = `s3`.id JOIN lnkOrganizationToService AS `lnk6` ON `lnk6`.service_id = `s3`.id JOIN Team AS `t5` ON `lnk6`.team_id = `t5`.id JOIN Organization AS `Node5` ON `t5`.org_id = `Node5`.id JOIN Organization AS `Root5` ON `Node5`.parent_id BELOW `Root5`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root5`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root5`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s3` ON `GARE`.service_id = `s3`.id JOIN lnkOrganizationToService AS `lnk6` ON `lnk6`.service_id = `s3`.id JOIN Team AS `t5` ON `lnk6`.team_id = `t5`.id JOIN Organization AS `Node5` ON `t5`.org_id = `Node5`.id JOIN Organization AS `Root5` ON `Node5`.parent_id BELOW `Root5`.id JOIN lnkOrganizationToPerson AS `lnk9` ON `lnk9`.organization_id = `Root5`.id JOIN lnkPersonToTeam AS `lnk8` ON `lnk8`.team_id = `t5`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root5`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`lnk9`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s4` ON `GARE`.service_id = `s4`.id JOIN lnkOrganizationToService AS `lnk7` ON `lnk7`.service_id = `s4`.id JOIN Team AS `t6` ON `lnk7`.team_id = `t6`.id JOIN Organization AS `Node6` ON `t6`.org_id = `Node6`.id JOIN Organization AS `Root6` ON `Node6`.parent_id BELOW `Root6`.id JOIN lnkOrganizationToPerson AS `lnk9` ON `lnk9`.organization_id = `Root6`.id JOIN lnkPersonToTeam AS `lnk8` ON `lnk8`.team_id = `t6`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`lnk9`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `lnk1` ON `lnk1`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s4` ON `GARE`.service_id = `s4`.id JOIN lnkOrganizationToService AS `lnk7` ON `lnk7`.service_id = `s4`.id JOIN Team AS `t6` ON `lnk7`.team_id = `t6`.id JOIN Organization AS `Node6` ON `t6`.org_id = `Node6`.id JOIN Organization AS `Root6` ON `Node6`.parent_id BELOW `Root6`.id JOIN lnkOrganizationToPerson AS `lnk9` ON `lnk9`.organization_id = `Root6`.id JOIN lnkPersonToTeam AS `lnk8` ON `lnk8`.team_id = `t6`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`lnk9`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`lnk1`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s4` ON `GARE`.service_id = `s4`.id JOIN lnkOrganizationToService AS `lnk7` ON `lnk7`.service_id = `s4`.id JOIN Team AS `t6` ON `lnk7`.team_id = `t6`.id JOIN Organization AS `Node6` ON `t6`.org_id = `Node6`.id JOIN Organization AS `Root6` ON `Node6`.parent_id BELOW `Root6`.id JOIN lnkOrganizationToPerson AS `lnk9` ON `lnk9`.organization_id = `Root6`.id JOIN lnkPersonToTeam AS `lnk8` ON `lnk8`.team_id = `t6`.id JOIN lnkServiceToTeam AS `lnk2` ON `lnk2`.service_id = `s4`.id JOIN Team AS `t3` ON `lnk2`.team_id = `t3`.id JOIN Organization AS `Node3` ON `t3`.org_id = `Node3`.id JOIN Organization AS `Root3` ON `Node3`.parent_id BELOW `Root3`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`lnk9`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root3`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s4` ON `GARE`.service_id = `s4`.id JOIN lnkOrganizationToService AS `lnk7` ON `lnk7`.service_id = `s4`.id JOIN Team AS `t6` ON `lnk7`.team_id = `t6`.id JOIN Organization AS `Node6` ON `t6`.org_id = `Node6`.id JOIN Organization AS `Root6` ON `Node6`.parent_id BELOW `Root6`.id JOIN lnkOrganizationToPerson AS `lnk9` ON `lnk9`.organization_id = `Root6`.id JOIN lnkPersonToTeam AS `lnk8` ON `lnk8`.team_id = `t6`.id JOIN lnkServiceToTeam AS `lnk3` ON `lnk3`.service_id = `s4`.id JOIN Team AS `t4` ON `lnk3`.team_id = `t4`.id JOIN Organization AS `Node4` ON `t4`.org_id = `Node4`.id JOIN Organization AS `Root4` ON `Node4`.parent_id BELOW `Root4`.id JOIN lnkOrganizationToPerson AS `lnk5` ON `lnk5`.organization_id = `Root4`.id JOIN lnkPersonToTeam AS `lnk4` ON `lnk4`.team_id = `t4`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`lnk9`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`lnk5`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s4` ON `GARE`.service_id = `s4`.id JOIN lnkOrganizationToService AS `lnk7` ON `lnk7`.service_id = `s4`.id JOIN Team AS `t6` ON `lnk7`.team_id = `t6`.id JOIN Organization AS `Node6` ON `t6`.org_id = `Node6`.id JOIN Organization AS `Root6` ON `Node6`.parent_id BELOW `Root6`.id JOIN lnkOrganizationToPerson AS `lnk9` ON `lnk9`.organization_id = `Root6`.id JOIN lnkPersonToTeam AS `lnk8` ON `lnk8`.team_id = `t6`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`lnk9`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root6`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s4` ON `GARE`.service_id = `s4`.id JOIN lnkOrganizationToService AS `lnk7` ON `lnk7`.service_id = `s4`.id JOIN Team AS `t6` ON `lnk7`.team_id = `t6`.id JOIN Organization AS `Node6` ON `t6`.org_id = `Node6`.id JOIN Organization AS `Root6` ON `Node6`.parent_id BELOW `Root6`.id JOIN lnkOrganizationToPerson AS `lnk9` ON `lnk9`.organization_id = `Root6`.id JOIN lnkPersonToTeam AS `lnk8` ON `lnk8`.team_id = `t6`.id WHERE (((((`Root`.`id` = :current_contact->org_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`lnk9`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`lnk9`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`l2`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s1` ON `GARE`.service_id = `s1`.id JOIN lnkServiceToTeam AS `lnk2` ON `lnk2`.service_id = `s1`.id JOIN Team AS `t3` ON `lnk2`.team_id = `t3`.id JOIN Organization AS `Node3` ON `t3`.org_id = `Node3`.id JOIN Organization AS `Root3` ON `Node3`.parent_id BELOW `Root3`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root3`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s2` ON `GARE`.service_id = `s2`.id JOIN lnkServiceToTeam AS `lnk3` ON `lnk3`.service_id = `s2`.id JOIN Team AS `t4` ON `lnk3`.team_id = `t4`.id JOIN Organization AS `Node4` ON `t4`.org_id = `Node4`.id JOIN Organization AS `Root4` ON `Node4`.parent_id BELOW `Root4`.id JOIN lnkOrganizationToPerson AS `lnk5` ON `lnk5`.organization_id = `Root4`.id JOIN lnkPersonToTeam AS `lnk4` ON `lnk4`.team_id = `t4`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`lnk5`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s3` ON `GARE`.service_id = `s3`.id JOIN lnkOrganizationToService AS `lnk6` ON `lnk6`.service_id = `s3`.id JOIN Team AS `t5` ON `lnk6`.team_id = `t5`.id JOIN Organization AS `Node5` ON `t5`.org_id = `Node5`.id JOIN Organization AS `Root5` ON `Node5`.parent_id BELOW `Root5`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root5`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s4` ON `GARE`.service_id = `s4`.id JOIN lnkOrganizationToService AS `lnk7` ON `lnk7`.service_id = `s4`.id JOIN Team AS `t6` ON `lnk7`.team_id = `t6`.id JOIN Organization AS `Node6` ON `t6`.org_id = `Node6`.id JOIN Organization AS `Root6` ON `Node6`.parent_id BELOW `Root6`.id JOIN lnkOrganizationToPerson AS `lnk9` ON `lnk9`.organization_id = `Root6`.id JOIN lnkPersonToTeam AS `lnk8` ON `lnk8`.team_id = `t6`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`lnk9`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`l2`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`l2`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`l2`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s1` ON `GARE`.service_id = `s1`.id JOIN lnkServiceToTeam AS `lnk2` ON `lnk2`.service_id = `s1`.id JOIN Team AS `t3` ON `lnk2`.team_id = `t3`.id JOIN Organization AS `Node3` ON `t3`.org_id = `Node3`.id JOIN Organization AS `Root3` ON `Node3`.parent_id BELOW `Root3`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`l2`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root3`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s2` ON `GARE`.service_id = `s2`.id JOIN lnkServiceToTeam AS `lnk3` ON `lnk3`.service_id = `s2`.id JOIN Team AS `t4` ON `lnk3`.team_id = `t4`.id JOIN Organization AS `Node4` ON `t4`.org_id = `Node4`.id JOIN Organization AS `Root4` ON `Node4`.parent_id BELOW `Root4`.id JOIN lnkOrganizationToPerson AS `lnk5` ON `lnk5`.organization_id = `Root4`.id JOIN lnkPersonToTeam AS `lnk4` ON `lnk4`.team_id = `t4`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`l2`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`lnk5`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s3` ON `GARE`.service_id = `s3`.id JOIN lnkOrganizationToService AS `lnk6` ON `lnk6`.service_id = `s3`.id JOIN Team AS `t5` ON `lnk6`.team_id = `t5`.id JOIN Organization AS `Node5` ON `t5`.org_id = `Node5`.id JOIN Organization AS `Root5` ON `Node5`.parent_id BELOW `Root5`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`l2`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root5`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s4` ON `GARE`.service_id = `s4`.id JOIN lnkOrganizationToService AS `lnk7` ON `lnk7`.service_id = `s4`.id JOIN Team AS `t6` ON `lnk7`.team_id = `t6`.id JOIN Organization AS `Node6` ON `t6`.org_id = `Node6`.id JOIN Organization AS `Root6` ON `Node6`.parent_id BELOW `Root6`.id JOIN lnkOrganizationToPerson AS `lnk9` ON `lnk9`.organization_id = `Root6`.id JOIN lnkPersonToTeam AS `lnk8` ON `lnk8`.team_id = `t6`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`l2`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`lnk9`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s1` ON `GARE`.service_id = `s1`.id JOIN lnkServiceToTeam AS `lnk2` ON `lnk2`.service_id = `s1`.id JOIN Team AS `t3` ON `lnk2`.team_id = `t3`.id JOIN Organization AS `Node3` ON `t3`.org_id = `Node3`.id JOIN Organization AS `Root3` ON `Node3`.parent_id BELOW `Root3`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root3`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s1` ON `GARE`.service_id = `s1`.id JOIN lnkServiceToTeam AS `lnk2` ON `lnk2`.service_id = `s1`.id JOIN Team AS `t3` ON `lnk2`.team_id = `t3`.id JOIN Organization AS `Node3` ON `t3`.org_id = `Node3`.id JOIN Organization AS `Root3` ON `Node3`.parent_id BELOW `Root3`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root3`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`l2`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s1` ON `GARE`.service_id = `s1`.id JOIN lnkServiceToTeam AS `lnk2` ON `lnk2`.service_id = `s1`.id JOIN Team AS `t3` ON `lnk2`.team_id = `t3`.id JOIN Organization AS `Node3` ON `t3`.org_id = `Node3`.id JOIN Organization AS `Root3` ON `Node3`.parent_id BELOW `Root3`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root3`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root3`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s1` ON `GARE`.service_id = `s1`.id JOIN lnkServiceToTeam AS `lnk2` ON `lnk2`.service_id = `s1`.id JOIN Team AS `t3` ON `lnk2`.team_id = `t3`.id JOIN Organization AS `Node3` ON `t3`.org_id = `Node3`.id JOIN Organization AS `Root3` ON `Node3`.parent_id BELOW `Root3`.id JOIN lnkOrganizationToPerson AS `lnk5` ON `lnk5`.organization_id = `Root3`.id JOIN lnkPersonToTeam AS `lnk4` ON `lnk4`.team_id = `t3`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root3`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`lnk5`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s1` ON `GARE`.service_id = `s1`.id JOIN lnkServiceToTeam AS `lnk2` ON `lnk2`.service_id = `s1`.id JOIN Team AS `t3` ON `lnk2`.team_id = `t3`.id JOIN Organization AS `Node3` ON `t3`.org_id = `Node3`.id JOIN Organization AS `Root3` ON `Node3`.parent_id BELOW `Root3`.id JOIN lnkOrganizationToService AS `lnk6` ON `lnk6`.service_id = `s1`.id JOIN Team AS `t5` ON `lnk6`.team_id = `t5`.id JOIN Organization AS `Node5` ON `t5`.org_id = `Node5`.id JOIN Organization AS `Root5` ON `Node5`.parent_id BELOW `Root5`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root3`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root5`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s1` ON `GARE`.service_id = `s1`.id JOIN lnkServiceToTeam AS `lnk2` ON `lnk2`.service_id = `s1`.id JOIN Team AS `t3` ON `lnk2`.team_id = `t3`.id JOIN Organization AS `Node3` ON `t3`.org_id = `Node3`.id JOIN Organization AS `Root3` ON `Node3`.parent_id BELOW `Root3`.id JOIN lnkOrganizationToService AS `lnk7` ON `lnk7`.service_id = `s1`.id JOIN Team AS `t6` ON `lnk7`.team_id = `t6`.id JOIN Organization AS `Node6` ON `t6`.org_id = `Node6`.id JOIN Organization AS `Root6` ON `Node6`.parent_id BELOW `Root6`.id JOIN lnkOrganizationToPerson AS `lnk9` ON `lnk9`.organization_id = `Root6`.id JOIN lnkPersonToTeam AS `lnk8` ON `lnk8`.team_id = `t6`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root3`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`lnk9`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s2` ON `GARE`.service_id = `s2`.id JOIN lnkServiceToTeam AS `lnk3` ON `lnk3`.service_id = `s2`.id JOIN Team AS `t4` ON `lnk3`.team_id = `t4`.id JOIN Organization AS `Node4` ON `t4`.org_id = `Node4`.id JOIN Organization AS `Root4` ON `Node4`.parent_id BELOW `Root4`.id JOIN lnkOrganizationToPerson AS `lnk5` ON `lnk5`.organization_id = `Root4`.id JOIN lnkPersonToTeam AS `lnk4` ON `lnk4`.team_id = `t4`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`lnk5`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s2` ON `GARE`.service_id = `s2`.id JOIN lnkServiceToTeam AS `lnk3` ON `lnk3`.service_id = `s2`.id JOIN Team AS `t4` ON `lnk3`.team_id = `t4`.id JOIN Organization AS `Node4` ON `t4`.org_id = `Node4`.id JOIN Organization AS `Root4` ON `Node4`.parent_id BELOW `Root4`.id JOIN lnkOrganizationToPerson AS `lnk5` ON `lnk5`.organization_id = `Root4`.id JOIN lnkPersonToTeam AS `lnk4` ON `lnk4`.team_id = `t4`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`lnk5`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`l2`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s2` ON `GARE`.service_id = `s2`.id JOIN lnkServiceToTeam AS `lnk3` ON `lnk3`.service_id = `s2`.id JOIN Team AS `t4` ON `lnk3`.team_id = `t4`.id JOIN Organization AS `Node4` ON `t4`.org_id = `Node4`.id JOIN Organization AS `Root4` ON `Node4`.parent_id BELOW `Root4`.id JOIN lnkOrganizationToPerson AS `lnk5` ON `lnk5`.organization_id = `Root4`.id JOIN lnkPersonToTeam AS `lnk4` ON `lnk4`.team_id = `t4`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`lnk5`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root4`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s2` ON `GARE`.service_id = `s2`.id JOIN lnkServiceToTeam AS `lnk3` ON `lnk3`.service_id = `s2`.id JOIN Team AS `t4` ON `lnk3`.team_id = `t4`.id JOIN Organization AS `Node4` ON `t4`.org_id = `Node4`.id JOIN Organization AS `Root4` ON `Node4`.parent_id BELOW `Root4`.id JOIN lnkOrganizationToPerson AS `lnk5` ON `lnk5`.organization_id = `Root4`.id JOIN lnkPersonToTeam AS `lnk4` ON `lnk4`.team_id = `t4`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`lnk5`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`lnk5`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s2` ON `GARE`.service_id = `s2`.id JOIN lnkServiceToTeam AS `lnk3` ON `lnk3`.service_id = `s2`.id JOIN Team AS `t4` ON `lnk3`.team_id = `t4`.id JOIN Organization AS `Node4` ON `t4`.org_id = `Node4`.id JOIN Organization AS `Root4` ON `Node4`.parent_id BELOW `Root4`.id JOIN lnkOrganizationToPerson AS `lnk5` ON `lnk5`.organization_id = `Root4`.id JOIN lnkPersonToTeam AS `lnk4` ON `lnk4`.team_id = `t4`.id JOIN lnkOrganizationToService AS `lnk6` ON `lnk6`.service_id = `s2`.id JOIN Team AS `t5` ON `lnk6`.team_id = `t5`.id JOIN Organization AS `Node5` ON `t5`.org_id = `Node5`.id JOIN Organization AS `Root5` ON `Node5`.parent_id BELOW `Root5`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`lnk5`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root5`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s2` ON `GARE`.service_id = `s2`.id JOIN lnkServiceToTeam AS `lnk3` ON `lnk3`.service_id = `s2`.id JOIN Team AS `t4` ON `lnk3`.team_id = `t4`.id JOIN Organization AS `Node4` ON `t4`.org_id = `Node4`.id JOIN Organization AS `Root4` ON `Node4`.parent_id BELOW `Root4`.id JOIN lnkOrganizationToPerson AS `lnk5` ON `lnk5`.organization_id = `Root4`.id JOIN lnkPersonToTeam AS `lnk4` ON `lnk4`.team_id = `t4`.id JOIN lnkOrganizationToService AS `lnk7` ON `lnk7`.service_id = `s2`.id JOIN Team AS `t6` ON `lnk7`.team_id = `t6`.id JOIN Organization AS `Node6` ON `t6`.org_id = `Node6`.id JOIN Organization AS `Root6` ON `Node6`.parent_id BELOW `Root6`.id JOIN lnkOrganizationToPerson AS `lnk9` ON `lnk9`.organization_id = `Root6`.id JOIN lnkPersonToTeam AS `lnk8` ON `lnk8`.team_id = `t6`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`lnk5`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`lnk9`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s3` ON `GARE`.service_id = `s3`.id JOIN lnkOrganizationToService AS `lnk6` ON `lnk6`.service_id = `s3`.id JOIN Team AS `t5` ON `lnk6`.team_id = `t5`.id JOIN Organization AS `Node5` ON `t5`.org_id = `Node5`.id JOIN Organization AS `Root5` ON `Node5`.parent_id BELOW `Root5`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root5`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s3` ON `GARE`.service_id = `s3`.id JOIN lnkOrganizationToService AS `lnk6` ON `lnk6`.service_id = `s3`.id JOIN Team AS `t5` ON `lnk6`.team_id = `t5`.id JOIN Organization AS `Node5` ON `t5`.org_id = `Node5`.id JOIN Organization AS `Root5` ON `Node5`.parent_id BELOW `Root5`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root5`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`l2`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s3` ON `GARE`.service_id = `s3`.id JOIN lnkOrganizationToService AS `lnk6` ON `lnk6`.service_id = `s3`.id JOIN Team AS `t5` ON `lnk6`.team_id = `t5`.id JOIN Organization AS `Node5` ON `t5`.org_id = `Node5`.id JOIN Organization AS `Root5` ON `Node5`.parent_id BELOW `Root5`.id JOIN lnkServiceToTeam AS `lnk2` ON `lnk2`.service_id = `s3`.id JOIN Team AS `t3` ON `lnk2`.team_id = `t3`.id JOIN Organization AS `Node3` ON `t3`.org_id = `Node3`.id JOIN Organization AS `Root3` ON `Node3`.parent_id BELOW `Root3`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root5`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root3`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s3` ON `GARE`.service_id = `s3`.id JOIN lnkOrganizationToService AS `lnk6` ON `lnk6`.service_id = `s3`.id JOIN Team AS `t5` ON `lnk6`.team_id = `t5`.id JOIN Organization AS `Node5` ON `t5`.org_id = `Node5`.id JOIN Organization AS `Root5` ON `Node5`.parent_id BELOW `Root5`.id JOIN lnkServiceToTeam AS `lnk3` ON `lnk3`.service_id = `s3`.id JOIN Team AS `t4` ON `lnk3`.team_id = `t4`.id JOIN Organization AS `Node4` ON `t4`.org_id = `Node4`.id JOIN Organization AS `Root4` ON `Node4`.parent_id BELOW `Root4`.id JOIN lnkOrganizationToPerson AS `lnk5` ON `lnk5`.organization_id = `Root4`.id JOIN lnkPersonToTeam AS `lnk4` ON `lnk4`.team_id = `t4`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root5`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`lnk5`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s3` ON `GARE`.service_id = `s3`.id JOIN lnkOrganizationToService AS `lnk6` ON `lnk6`.service_id = `s3`.id JOIN Team AS `t5` ON `lnk6`.team_id = `t5`.id JOIN Organization AS `Node5` ON `t5`.org_id = `Node5`.id JOIN Organization AS `Root5` ON `Node5`.parent_id BELOW `Root5`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root5`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root5`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s3` ON `GARE`.service_id = `s3`.id JOIN lnkOrganizationToService AS `lnk6` ON `lnk6`.service_id = `s3`.id JOIN Team AS `t5` ON `lnk6`.team_id = `t5`.id JOIN Organization AS `Node5` ON `t5`.org_id = `Node5`.id JOIN Organization AS `Root5` ON `Node5`.parent_id BELOW `Root5`.id JOIN lnkOrganizationToPerson AS `lnk9` ON `lnk9`.organization_id = `Root5`.id JOIN lnkPersonToTeam AS `lnk8` ON `lnk8`.team_id = `t5`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`Root5`.`id` = :current_contact->org_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`lnk9`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s4` ON `GARE`.service_id = `s4`.id JOIN lnkOrganizationToService AS `lnk7` ON `lnk7`.service_id = `s4`.id JOIN Team AS `t6` ON `lnk7`.team_id = `t6`.id JOIN Organization AS `Node6` ON `t6`.org_id = `Node6`.id JOIN Organization AS `Root6` ON `Node6`.parent_id BELOW `Root6`.id JOIN lnkOrganizationToPerson AS `lnk9` ON `lnk9`.organization_id = `Root6`.id JOIN lnkPersonToTeam AS `lnk8` ON `lnk8`.team_id = `t6`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`lnk9`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s4` ON `GARE`.service_id = `s4`.id JOIN lnkOrganizationToService AS `lnk7` ON `lnk7`.service_id = `s4`.id JOIN Team AS `t6` ON `lnk7`.team_id = `t6`.id JOIN Organization AS `Node6` ON `t6`.org_id = `Node6`.id JOIN Organization AS `Root6` ON `Node6`.parent_id BELOW `Root6`.id JOIN lnkOrganizationToPerson AS `lnk9` ON `lnk9`.organization_id = `Root6`.id JOIN lnkPersonToTeam AS `lnk8` ON `lnk8`.team_id = `t6`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`lnk9`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`l2`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s4` ON `GARE`.service_id = `s4`.id JOIN lnkOrganizationToService AS `lnk7` ON `lnk7`.service_id = `s4`.id JOIN Team AS `t6` ON `lnk7`.team_id = `t6`.id JOIN Organization AS `Node6` ON `t6`.org_id = `Node6`.id JOIN Organization AS `Root6` ON `Node6`.parent_id BELOW `Root6`.id JOIN lnkOrganizationToPerson AS `lnk9` ON `lnk9`.organization_id = `Root6`.id JOIN lnkPersonToTeam AS `lnk8` ON `lnk8`.team_id = `t6`.id JOIN lnkServiceToTeam AS `lnk2` ON `lnk2`.service_id = `s4`.id JOIN Team AS `t3` ON `lnk2`.team_id = `t3`.id JOIN Organization AS `Node3` ON `t3`.org_id = `Node3`.id JOIN Organization AS `Root3` ON `Node3`.parent_id BELOW `Root3`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`lnk9`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root3`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s4` ON `GARE`.service_id = `s4`.id JOIN lnkOrganizationToService AS `lnk7` ON `lnk7`.service_id = `s4`.id JOIN Team AS `t6` ON `lnk7`.team_id = `t6`.id JOIN Organization AS `Node6` ON `t6`.org_id = `Node6`.id JOIN Organization AS `Root6` ON `Node6`.parent_id BELOW `Root6`.id JOIN lnkOrganizationToPerson AS `lnk9` ON `lnk9`.organization_id = `Root6`.id JOIN lnkPersonToTeam AS `lnk8` ON `lnk8`.team_id = `t6`.id JOIN lnkServiceToTeam AS `lnk3` ON `lnk3`.service_id = `s4`.id JOIN Team AS `t4` ON `lnk3`.team_id = `t4`.id JOIN Organization AS `Node4` ON `t4`.org_id = `Node4`.id JOIN Organization AS `Root4` ON `Node4`.parent_id BELOW `Root4`.id JOIN lnkOrganizationToPerson AS `lnk5` ON `lnk5`.organization_id = `Root4`.id JOIN lnkPersonToTeam AS `lnk4` ON `lnk4`.team_id = `t4`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`lnk9`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`lnk5`.`person_id` = :current_contact_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s4` ON `GARE`.service_id = `s4`.id JOIN lnkOrganizationToService AS `lnk7` ON `lnk7`.service_id = `s4`.id JOIN Team AS `t6` ON `lnk7`.team_id = `t6`.id JOIN Organization AS `Node6` ON `t6`.org_id = `Node6`.id JOIN Organization AS `Root6` ON `Node6`.parent_id BELOW `Root6`.id JOIN lnkOrganizationToPerson AS `lnk9` ON `lnk9`.organization_id = `Root6`.id JOIN lnkPersonToTeam AS `lnk8` ON `lnk8`.team_id = `t6`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`lnk9`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`Root6`.`id` = :current_contact->org_id)) UNION SELECT `GARE` FROM UserRequest AS `GARE` JOIN Team AS `t` ON `GARE`.team_id = `t`.id JOIN Organization AS `Node` ON `t`.org_id = `Node`.id JOIN Organization AS `Root` ON `Node`.parent_id BELOW `Root`.id JOIN lnkOrganizationToPerson AS `l2` ON `l2`.organization_id = `Root`.id JOIN lnkPersonToTeam AS `l` ON `l`.team_id = `t`.id JOIN Service AS `s4` ON `GARE`.service_id = `s4`.id JOIN lnkOrganizationToService AS `lnk7` ON `lnk7`.service_id = `s4`.id JOIN Team AS `t6` ON `lnk7`.team_id = `t6`.id JOIN Organization AS `Node6` ON `t6`.org_id = `Node6`.id JOIN Organization AS `Root6` ON `Node6`.parent_id BELOW `Root6`.id JOIN lnkOrganizationToPerson AS `lnk9` ON `lnk9`.organization_id = `Root6`.id JOIN lnkPersonToTeam AS `lnk8` ON `lnk8`.team_id = `t6`.id WHERE (((((`l2`.`person_id` = :current_contact_id) AND ((`GARE`.`agent_id` != '') AND (`GARE`.`operational_status` NOT IN ('closed', 'resolved')))) AND (`lnk9`.`person_id` = :current_contact_id)) AND (`GARE`.`finalclass` = 'UserRequest')) AND (`lnk9`.`person_id` = :current_contact_id))";
		try {
			$oOql = new OqlInterpreter($sQuery);
			$oOql->ParseQuery();
		} catch (OQLParserException $e) {
			self::fail("OQL Parser stack overflow");
		} catch (OQLException $e) {
			self::fail("OQL Parser stack overflow");
		}
		self::assertTrue(true);
	}

}
