/**
 * Adds sitelinks items to the feed.
 * @param AdWordsUser $user the user to run the example with
 * @param map $sitelinksData IDs associated to created sitelinks feed metadata
 */
function CreateSiteLinksFeedItems(AdWordsUser $user, $sitelinksData)
{
    // Get the FeedItemService, which loads the required classes.
    $feedItemService = $user->GetService('FeedItemService', ADWORDS_VERSION);
    // Create operations to add FeedItems.
    $home = NewSiteLinkFeedItemAddOperation($sitelinksData, 'Home', 'http://www.example.com', 'Home line 1', 'Home line 2');
    $stores = NewSiteLinkFeedItemAddOperation($sitelinksData, 'Stores', 'http://www.example.com/stores', 'Stores line 1', 'Stores line 2');
    $onSale = NewSiteLinkFeedItemAddOperation($sitelinksData, 'On Sale', 'http://www.example.com/sale', 'On Sale line 1', 'On Sale line 2');
    $support = NewSiteLinkFeedItemAddOperation($sitelinksData, 'Support', 'http://www.example.com/support', 'Support line 1', 'Support line 2');
    $products = NewSiteLinkFeedItemAddOperation($sitelinksData, 'Products', 'http://www.example.com/products', 'Products line 1', 'Products line 2');
    $aboutUs = NewSiteLinkFeedItemAddOperation($sitelinksData, 'About Us', 'http://www.example.com/about', 'About Us line 1', 'About Us line 2');
    $operations = array($home, $stores, $onSale, $support, $products, $aboutUs);
    $result = $feedItemService->mutate($operations);
    $sitelinksData['siteLinkFeedItemIds'] = array();
    foreach ($result->value as $feedItem) {
        printf("FeedItem with feedItemId %d was added.\n", $feedItem->feedItemId);
        $sitelinksData['siteLinkFeedItemIds'][] = $feedItem->feedItemId;
    }
    return $sitelinksData;
}
/**
 * Add legacy sitelinks to the sitelinks feed.
 *
 * @param FeedItemService $feedItemService The service instance.
 * @param array $siteLinksFeed The feed for adding sitelinks.
 * @param array $siteLinks legacySiteLinks the SiteLinksFeed info
 * @return array The list of feed items that were added to the feed.
 */
function CreateSiteLinkFeedItems(FeedItemService $feedItemService, $siteLinksFeed, $sitelinks)
{
    $siteLinkFeedItemIds = array();
    // Create operation for adding each legacy sitelink to the sitelinks feed.
    $operations = array();
    foreach ($sitelinks as $siteLink) {
        $operations[] = NewSiteLinkFeedItemAddOperation($siteLinksFeed, $siteLink->displayText, $siteLink->destinationUrl);
    }
    $result = $feedItemService->mutate($operations);
    // Retrieve the feed item ids.
    foreach ($result->value as $item) {
        $siteLinkFeedItemIds[] = $item->feedItemId;
    }
    return $siteLinkFeedItemIds;
}