where('EventCode', $eventCode) ->where('EndDate IS NULL') ->where('Active', 1) ->groupStart() ->where('ScopeType', 'GLOBAL'); if ($testSiteID !== null) { $builder->orGroupStart() ->where('ScopeType', 'TESTSITE') ->where('TestSiteID', $testSiteID) ->groupEnd(); } $builder->groupEnd(); return $builder ->orderBy('Priority', 'ASC') ->orderBy('RuleID', 'ASC') ->findAll(); } }