examples/AdWords/v201809/CampaignManagement/AddCompleteCampaignsUsingBatchJob.php
private static function buildAdGroupOperations(
        $namePrefix,
        array $campaignOperations
    ) {
        $operations = [];
        foreach ($campaignOperations as $campaignOperation) {
            for ($i = 0; $i < self::NUMBER_OF_ADGROUPS_TO_ADD; $i++) {
                $adGroup = new AdGroup();
                $adGroup->setCampaignId($campaignOperation->getOperand()->getId());
                $adGroup->setId(--self::$temporaryId);
                $adGroup->setName(
                    sprintf(
                        'Batch Ad Group %s.%s',
                        $namePrefix,
                        strval($adGroup->getId())
                    )
                );

                $biddingStrategyConfiguration = new BiddingStrategyConfiguration();
                $money = new Money();
                $money->setMicroAmount(10000000);
                $bid = new CpcBid();
                $bid->setBid($money);
                $biddingStrategyConfiguration->setBids([$bid]);

                $adGroup->setBiddingStrategyConfiguration(
                    $biddingStrategyConfiguration
                );

                $operation = new AdGroupOperation();
                $operation->setOperand($adGroup);
                $operation->setOperator(Operator::ADD);

                $operations[] = $operation;
            }
        }

        return $operations;
    }
private static function buildAdGroupOperations(
        $namePrefix,
        array $campaignOperations
    ) {
        $operations = [];
        foreach ($campaignOperations as $campaignOperation) {
            for ($i = 0; $i < self::NUMBER_OF_ADGROUPS_TO_ADD; $i++) {
                $adGroup = new AdGroup();
                $adGroup->setCampaignId($campaignOperation->getOperand()->getId());
                $adGroup->setId(--self::$temporaryId);
                $adGroup->setName(
                    sprintf(
                        'Batch Ad Group %s.%s',
                        $namePrefix,
                        strval($adGroup->getId())
                    )
                );

                $biddingStrategyConfiguration = new BiddingStrategyConfiguration();
                $money = new Money();
                $money->setMicroAmount(10000000);
                $bid = new CpcBid();
                $bid->setBid($money);
                $biddingStrategyConfiguration->setBids([$bid]);

                $adGroup->setBiddingStrategyConfiguration(
                    $biddingStrategyConfiguration
                );

                $operation = new AdGroupOperation();
                $operation->setOperand($adGroup);
                $operation->setOperator(Operator::ADD);

                $operations[] = $operation;
            }
        }

        return $operations;
    }
private static function buildAdGroupOperations ( $ namePrefix , array $ campaignOperations ) { $ operations = [ ] ; foreach ( $ campaignOperations as $ campaignOperation ) { for ( $ i = 0 ; $ i < self :: NUMBER_OF_ADGROUPS_TO_ADD ; $ i ++ ) { $ adGroup = new AdGroup ( ) ; $ adGroup -> setCampaignId ( $ campaignOperation -> getOperand ( ) -> getId ( ) ) ; $ adGroup -> setId ( -- self :: $ temporaryId ) ; $ adGroup -> setName ( sprintf ( 'Batch Ad Group %s.%s' , $ namePrefix , strval ( $ adGroup -> getId ( ) ) ) ) ; $ biddingStrategyConfiguration = new BiddingStrategyConfiguration ( ) ; $ money = new Money ( ) ; $ money -> setMicroAmount ( 10000000 ) ; $ bid = new CpcBid ( ) ; $ bid -> setBid ( $ money ) ; $ biddingStrategyConfiguration -> setBids ( [ $ bid ] ) ; $ adGroup -> setBiddingStrategyConfiguration ( $ biddingStrategyConfiguration ) ; $ operation = new AdGroupOperation ( ) ; $ operation -> setOperand ( $ adGroup ) ; $ operation -> setOperator ( Operator :: ADD ) ; $ operations [ ] = $ operation ; } } return $ operations ; }
Builds objects of AdGroupOperation for creating ad groups for campaigns in
the specified campaign operations.

@param string $namePrefix a prefix string used to name ad groups
@param CampaignOperation[] $campaignOperations an array of
CampaignOperation
@return array an array of AdGroupOperation
Builds objects of AdGroupOperation for creating ad groups for campaigns in the specified campaign operations .