examples/AdManager/v201811/CustomTargetingService/GetPredefinedCustomTargetingKeysAndValues.php
private static function getPredefinedCustomTargetingKeyIds(
        ServiceFactory $serviceFactory,
        AdManagerSession $session
    ) {
        $customTargetingKeyIds = [];

        $customTargetingService = $serviceFactory->createCustomTargetingService(
            $session
        );

        // Create a statement to get all custom targeting keys.
        $pageSize = StatementBuilder::SUGGESTED_PAGE_LIMIT;
        $statementBuilder = (new StatementBuilder())->where('type = :type')
            ->orderBy('id ASC')
            ->limit($pageSize)
            ->withBindVariableValue('type', CustomTargetingKeyType::PREDEFINED);

        // Retrieve a small amount of custom targeting keys at a time, paging
        // through until all custom targeting keys have been retrieved.
        $totalResultSetSize = 0;
        do {
            $page = $customTargetingService->getCustomTargetingKeysByStatement(
                $statementBuilder->toStatement()
            );

            if ($page->getResults() !== null) {
                $totalResultSetSize = $page->getTotalResultSetSize();
                $i = $page->getStartIndex();
                foreach ($page->getResults() as $customTargetingKey) {
                    printf(
                        "%d) Custom targeting key with ID %d, name '%s', and"
                        . " display name '%s' was found.%s",
                        $i++,
                        $customTargetingKey->getId(),
                        $customTargetingKey->getName(),
                        $customTargetingKey->getDisplayName(),
                        PHP_EOL
                    );
                    $customTargetingKeyIds[] = $customTargetingKey->getId();
                }
            }

            $statementBuilder->increaseOffsetBy($pageSize);
        } while ($statementBuilder->getOffset() < $totalResultSetSize);

        printf(
            "Number of keys found: %d%s%s",
            $totalResultSetSize,
            PHP_EOL,
            PHP_EOL
        );

        return $customTargetingKeyIds;
    }
private static function getPredefinedCustomTargetingKeyIds(
        ServiceFactory $serviceFactory,
        AdManagerSession $session
    ) {
        $customTargetingKeyIds = [];

        $customTargetingService = $serviceFactory->createCustomTargetingService(
            $session
        );

        // Create a statement to get all custom targeting keys.
        $pageSize = StatementBuilder::SUGGESTED_PAGE_LIMIT;
        $statementBuilder = (new StatementBuilder())->where('type = :type')
            ->orderBy('id ASC')
            ->limit($pageSize)
            ->withBindVariableValue('type', CustomTargetingKeyType::PREDEFINED);

        // Retrieve a small amount of custom targeting keys at a time, paging
        // through until all custom targeting keys have been retrieved.
        $totalResultSetSize = 0;
        do {
            $page = $customTargetingService->getCustomTargetingKeysByStatement(
                $statementBuilder->toStatement()
            );

            if ($page->getResults() !== null) {
                $totalResultSetSize = $page->getTotalResultSetSize();
                $i = $page->getStartIndex();
                foreach ($page->getResults() as $customTargetingKey) {
                    printf(
                        "%d) Custom targeting key with ID %d, name '%s', and"
                        . " display name '%s' was found.%s",
                        $i++,
                        $customTargetingKey->getId(),
                        $customTargetingKey->getName(),
                        $customTargetingKey->getDisplayName(),
                        PHP_EOL
                    );
                    $customTargetingKeyIds[] = $customTargetingKey->getId();
                }
            }

            $statementBuilder->increaseOffsetBy($pageSize);
        } while ($statementBuilder->getOffset() < $totalResultSetSize);

        printf(
            "Number of keys found: %d%s%s",
            $totalResultSetSize,
            PHP_EOL,
            PHP_EOL
        );

        return $customTargetingKeyIds;
    }
private static function getPredefinedCustomTargetingKeyIds ( ServiceFactory $ serviceFactory , AdManagerSession $ session ) { $ customTargetingKeyIds = [ ] ; $ customTargetingService = $ serviceFactory -> createCustomTargetingService ( $ session ) ; // Create a statement to get all custom targeting keys. $ pageSize = StatementBuilder :: SUGGESTED_PAGE_LIMIT ; $ statementBuilder = ( new StatementBuilder ( ) ) -> where ( 'type = :type' ) -> orderBy ( 'id ASC' ) -> limit ( $ pageSize ) -> withBindVariableValue ( 'type' , CustomTargetingKeyType :: PREDEFINED ) ; // Retrieve a small amount of custom targeting keys at a time, paging // through until all custom targeting keys have been retrieved. $ totalResultSetSize = 0 ; do { $ page = $ customTargetingService -> getCustomTargetingKeysByStatement ( $ statementBuilder -> toStatement ( ) ) ; if ( $ page -> getResults ( ) !== null ) { $ totalResultSetSize = $ page -> getTotalResultSetSize ( ) ; $ i = $ page -> getStartIndex ( ) ; foreach ( $ page -> getResults ( ) as $ customTargetingKey ) { printf ( "%d) Custom targeting key with ID %d, name '%s', and" . " display name '%s' was found.%s" , $ i ++ , $ customTargetingKey -> getId ( ) , $ customTargetingKey -> getName ( ) , $ customTargetingKey -> getDisplayName ( ) , PHP_EOL ) ; $ customTargetingKeyIds [ ] = $ customTargetingKey -> getId ( ) ; } } $ statementBuilder -> increaseOffsetBy ( $ pageSize ) ; } while ( $ statementBuilder -> getOffset ( ) < $ totalResultSetSize ) ; printf ( "Number of keys found: %d%s%s" , $ totalResultSetSize , PHP_EOL , PHP_EOL ) ; return $ customTargetingKeyIds ; }
Gets predefined custom targeting key IDs.
Gets predefined custom targeting key IDs .