examples/AdWords/v201809/Migration/MigrateToExtensionSettings.php
private static function getSitelinksFromFeed(
        AdWordsServices $adWordsServices,
        AdWordsSession $session,
        $feedId
    ) {
        printf("Processing feed ID %d...\n", $feedId);
        $sitelinks = [];

        // Retrieve all the feed items from the feed.
        $feedItems = self::getFeedItems($adWordsServices, $session, $feedId);

        if ($feedItems !== null) {
            // Retrieve the feed's attribute mapping.
            $attributeFieldMappings = self::getAttributeFieldMappings(
                $adWordsServices,
                $session,
                $feedId,
                self::PLACEHOLDER_TYPE_SITELINKS
            );

            foreach ($feedItems as $feedItem) {
                $sitelinkFromFeed = new SitelinkFromFeed(
                    $feedItem->getFeedId(),
                    $feedItem->getFeedItemId()
                );

                foreach ($feedItem->getAttributeValues() as $attributeValue) {
                    // This attribute hasn't been mapped to a field.
                    if (array_key_exists(
                        $attributeValue->getFeedAttributeId(),
                        $attributeFieldMappings
                    ) === false) {
                        continue;
                    }
                    // Get the list of all the fields to which this attribute has been
                    // mapped.
                    foreach ($attributeFieldMappings[$attributeValue->getFeedAttributeId()] as $fieldId) {
                        // Read the appropriate value depending on the ID of the mapped
                        // field.
                        switch ($fieldId) {
                            case self::PLACEHOLDER_FIELD_TEXT:
                                $sitelinkFromFeed->setText($attributeValue->getStringValue());
                                break;
                            case self::PLACEHOLDER_FIELD_URL:
                                $sitelinkFromFeed->setUrl($attributeValue->getStringValue());
                                break;
                            case self::PLACEHOLDER_FIELD_FINAL_URLS:
                                $sitelinkFromFeed->setFinalUrls(
                                    $attributeValue->getStringValues()
                                );
                                break;
                            case self::PLACEHOLDER_FIELD_FINAL_MOBILE_URLS:
                                $sitelinkFromFeed->setFinalMobileUrls(
                                    $attributeValue->getStringValues()
                                );
                                break;
                            case self::PLACEHOLDER_FIELD_TRACKING_URL_TEMPLATE:
                                $sitelinkFromFeed->setTrackingUrlTemplate(
                                    $attributeValue->getStringValue()
                                );
                                break;
                            case self::PLACEHOLDER_FIELD_LINE2:
                                $sitelinkFromFeed->setLine2($attributeValue->getStringValue());
                                break;
                            case self::PLACEHOLDER_FIELD_LINE3:
                                $sitelinkFromFeed->setLine3($attributeValue->getStringValue());
                                break;
                        }
                    }
                }
                $sitelinks[$feedItem->getFeedItemId()] = $sitelinkFromFeed;
            }
        }

        return $sitelinks;
    }
private static function getSitelinksFromFeed(
        AdWordsServices $adWordsServices,
        AdWordsSession $session,
        $feedId
    ) {
        printf("Processing feed ID %d...\n", $feedId);
        $sitelinks = [];

        // Retrieve all the feed items from the feed.
        $feedItems = self::getFeedItems($adWordsServices, $session, $feedId);

        if ($feedItems !== null) {
            // Retrieve the feed's attribute mapping.
            $attributeFieldMappings = self::getAttributeFieldMappings(
                $adWordsServices,
                $session,
                $feedId,
                self::PLACEHOLDER_TYPE_SITELINKS
            );

            foreach ($feedItems as $feedItem) {
                $sitelinkFromFeed = new SitelinkFromFeed(
                    $feedItem->getFeedId(),
                    $feedItem->getFeedItemId()
                );

                foreach ($feedItem->getAttributeValues() as $attributeValue) {
                    // This attribute hasn't been mapped to a field.
                    if (array_key_exists(
                        $attributeValue->getFeedAttributeId(),
                        $attributeFieldMappings
                    ) === false) {
                        continue;
                    }
                    // Get the list of all the fields to which this attribute has been
                    // mapped.
                    foreach ($attributeFieldMappings[$attributeValue->getFeedAttributeId()] as $fieldId) {
                        // Read the appropriate value depending on the ID of the mapped
                        // field.
                        switch ($fieldId) {
                            case self::PLACEHOLDER_FIELD_TEXT:
                                $sitelinkFromFeed->setText($attributeValue->getStringValue());
                                break;
                            case self::PLACEHOLDER_FIELD_URL:
                                $sitelinkFromFeed->setUrl($attributeValue->getStringValue());
                                break;
                            case self::PLACEHOLDER_FIELD_FINAL_URLS:
                                $sitelinkFromFeed->setFinalUrls(
                                    $attributeValue->getStringValues()
                                );
                                break;
                            case self::PLACEHOLDER_FIELD_FINAL_MOBILE_URLS:
                                $sitelinkFromFeed->setFinalMobileUrls(
                                    $attributeValue->getStringValues()
                                );
                                break;
                            case self::PLACEHOLDER_FIELD_TRACKING_URL_TEMPLATE:
                                $sitelinkFromFeed->setTrackingUrlTemplate(
                                    $attributeValue->getStringValue()
                                );
                                break;
                            case self::PLACEHOLDER_FIELD_LINE2:
                                $sitelinkFromFeed->setLine2($attributeValue->getStringValue());
                                break;
                            case self::PLACEHOLDER_FIELD_LINE3:
                                $sitelinkFromFeed->setLine3($attributeValue->getStringValue());
                                break;
                        }
                    }
                }
                $sitelinks[$feedItem->getFeedItemId()] = $sitelinkFromFeed;
            }
        }

        return $sitelinks;
    }
private static function getSitelinksFromFeed ( AdWordsServices $ adWordsServices , AdWordsSession $ session , $ feedId ) { printf ( "Processing feed ID %d...\n" , $ feedId ) ; $ sitelinks = [ ] ; // Retrieve all the feed items from the feed. $ feedItems = self :: getFeedItems ( $ adWordsServices , $ session , $ feedId ) ; if ( $ feedItems !== null ) { // Retrieve the feed's attribute mapping. $ attributeFieldMappings = self :: getAttributeFieldMappings ( $ adWordsServices , $ session , $ feedId , self :: PLACEHOLDER_TYPE_SITELINKS ) ; foreach ( $ feedItems as $ feedItem ) { $ sitelinkFromFeed = new SitelinkFromFeed ( $ feedItem -> getFeedId ( ) , $ feedItem -> getFeedItemId ( ) ) ; foreach ( $ feedItem -> getAttributeValues ( ) as $ attributeValue ) { // This attribute hasn't been mapped to a field. if ( array_key_exists ( $ attributeValue -> getFeedAttributeId ( ) , $ attributeFieldMappings ) === false ) { continue ; } // Get the list of all the fields to which this attribute has been // mapped. foreach ( $ attributeFieldMappings [ $ attributeValue -> getFeedAttributeId ( ) ] as $ fieldId ) { // Read the appropriate value depending on the ID of the mapped // field. switch ( $ fieldId ) { case self :: PLACEHOLDER_FIELD_TEXT : $ sitelinkFromFeed -> setText ( $ attributeValue -> getStringValue ( ) ) ; break ; case self :: PLACEHOLDER_FIELD_URL : $ sitelinkFromFeed -> setUrl ( $ attributeValue -> getStringValue ( ) ) ; break ; case self :: PLACEHOLDER_FIELD_FINAL_URLS : $ sitelinkFromFeed -> setFinalUrls ( $ attributeValue -> getStringValues ( ) ) ; break ; case self :: PLACEHOLDER_FIELD_FINAL_MOBILE_URLS : $ sitelinkFromFeed -> setFinalMobileUrls ( $ attributeValue -> getStringValues ( ) ) ; break ; case self :: PLACEHOLDER_FIELD_TRACKING_URL_TEMPLATE : $ sitelinkFromFeed -> setTrackingUrlTemplate ( $ attributeValue -> getStringValue ( ) ) ; break ; case self :: PLACEHOLDER_FIELD_LINE2 : $ sitelinkFromFeed -> setLine2 ( $ attributeValue -> getStringValue ( ) ) ; break ; case self :: PLACEHOLDER_FIELD_LINE3 : $ sitelinkFromFeed -> setLine3 ( $ attributeValue -> getStringValue ( ) ) ; break ; } } } $ sitelinks [ $ feedItem -> getFeedItemId ( ) ] = $ sitelinkFromFeed ; } } return $ sitelinks ; }
Gets sitelinks from the specified feed.
Gets sitelinks from the specified feed .