Esempio n. 1
0
 function getActiveAdGroups()
 {
     $soapClients =& APIlityClients::getClients();
     $someSoapClient = $soapClients->getAdGroupClient();
     $soapParameters = "<getActiveAdGroups>\n                           <campaignID>" . $this->getId() . "</campaignID>\n                         </getActiveAdGroups>";
     // query the google servers for all adgroups of the campaign
     $allAdGroups = array();
     $allAdGroups = $someSoapClient->call("getActiveAdGroups", $soapParameters);
     $soapClients->updateSoapRelatedData(extractSoapHeaderInfo($someSoapClient->getHeaders()));
     if ($someSoapClient->fault) {
         pushFault($someSoapClient, $_SERVER['PHP_SELF'] . ":getActiveAdGroups()", $soapParameters);
         return false;
     }
     $allAdGroups = makeNumericArray($allAdGroups);
     // return only paused and active adgroups
     $allAdGroupObjects = array();
     if (!isset($allAdGroups['getActiveAdGroupsReturn'])) {
         return $allAdGroupObjects;
     }
     foreach ($allAdGroups['getActiveAdGroupsReturn'] as $adGroup) {
         $adGroupObject = receiveAdGroup($adGroup);
         if (isset($adGroupObject)) {
             array_push($allAdGroupObjects, $adGroupObject);
         }
     }
     return $allAdGroupObjects;
 }
Esempio n. 2
0
 function getAllCriteria()
 {
     $soapClients =& APIlityClients::getClients();
     $someSoapClient = $soapClients->getCriterionClient();
     $soapParameters = "<getAllCriteria>\n                            <adGroupId>" . $this->getId() . "</adGroupId>\n                          </getAllCriteria>";
     // query the google servers for all criteria
     $allCriteria = array();
     $allCriteria = $someSoapClient->call("getAllCriteria", $soapParameters);
     $soapClients->updateSoapRelatedData(extractSoapHeaderInfo($someSoapClient->getHeaders()));
     if ($someSoapClient->fault) {
         pushFault($someSoapClient, $_SERVER['PHP_SELF'] . ":getAllCriteria()", $soapParameters);
         return false;
     }
     // when we have only one criterion in the adgroup return a (one criterion
     // element) array  anyway
     $allCriteria = makeNumericArray($allCriteria);
     $allCriterionObjects = array();
     if (!isset($allCriteria['getAllCriteriaReturn'])) {
         return $allCriterionObjects;
     }
     foreach ($allCriteria['getAllCriteriaReturn'] as $criterion) {
         $criterionObject = receiveCriterion($criterion);
         if (isset($criterionObject)) {
             array_push($allCriterionObjects, $criterionObject);
         }
     }
     return $allCriterionObjects;
 }
Esempio n. 3
0
function getMccAlerts()
{
    $soapClients =& APIlityClients::getClients();
    $someSoapClient = $soapClients->getAccountClient();
    // prepare soap parameters
    $soapParameters = "<getMccAlerts></getMccAlerts>";
    // execute soap call
    $mccAlerts = $someSoapClient->call("getMccAlerts", $soapParameters);
    $soapClients->updateSoapRelatedData(extractSoapHeaderInfo($someSoapClient->getHeaders()));
    if ($someSoapClient->fault) {
        pushFault($someSoapClient, $_SERVER['PHP_SELF'] . ":getMccAlerts()", $soapParameters);
        return false;
    }
    // make sure we return an array
    if (isset($mccAlerts['getMccAlertsReturn'])) {
        $mccAlerts['getMccAlertsReturn'] = makeNumericArray($mccAlerts['getMccAlertsReturn']);
        return $mccAlerts['getMccAlertsReturn'];
    }
    return array();
}
Esempio n. 4
0
function getAdGroupList($adGroupIds)
{
    $soapClients =& APIlityClients::getClients();
    $someSoapClient = $soapClients->getAdGroupClient();
    $soapParameters = '<getAdGroupList>';
    foreach ($adGroupIds as $adGroupId) {
        $soapParameters .= '<ids>' . $adGroupId . '</ids>';
    }
    $soapParameters .= '</getAdGroupList>';
    // query the google servers for all adgroups
    $allAdGroups = array();
    $allAdGroups = $someSoapClient->call('getAdGroupList', $soapParameters);
    $soapClients->updateSoapRelatedData(extractSoapHeaderInfo($someSoapClient->getHeaders()));
    if ($someSoapClient->fault) {
        pushFault($someSoapClient, $_SERVER['PHP_SELF'] . ':getAdGroupList()', $soapParameters);
        return false;
    }
    // when we have only one adgroup in the campaign return a (one adgroup
    // element) array  anyway
    $allAdGroups = makeNumericArray($allAdGroups);
    $allAdGroupObjects = array();
    if (!isset($allAdGroups['getAdGroupListReturn'])) {
        return $allAdGroupObjects;
    }
    foreach ($allAdGroups['getAdGroupListReturn'] as $adGroup) {
        $adGroupObject = receiveAdGroup($adGroup);
        if (isset($adGroupObject)) {
            array_push($allAdGroupObjects, $adGroupObject);
        }
    }
    return $allAdGroupObjects;
}
Esempio n. 5
0
function getMyVideos()
{
    $soapClients =& APIlityClients::getClients();
    $someSoapClient = $soapClients->getAdClient();
    $soapParameters = "<getMyVideos></getMyVideos>";
    $videos = $someSoapClient->call("getMyVideos", $soapParameters);
    $soapClients->updateSoapRelatedData(extractSoapHeaderInfo($someSoapClient->getHeaders()));
    if ($someSoapClient->fault) {
        pushFault($someSoapClient, $_SERVER['PHP_SELF'] . ":getMyVideos()", $soapParameters);
        return false;
    }
    return makeNumericArray($videos);
}
Esempio n. 6
0
function addCampaignList($campaigns)
{
    // update the google server
    $soapClients =& APIlityClients::getClients();
    $someSoapClient = $soapClients->getCampaignClient();
    $soapParameters = "<addCampaignList>";
    foreach ($campaigns as $campaign) {
        $newGeoTargetsXml = "";
        $languagesXml = "";
        $networkTargetingXml = "";
        $newGeoTargetsXml .= "<countryTargets>";
        if ($campaign['geoTargets']['countryTargets']['countries']) {
            foreach ($campaign['geoTargets']['countryTargets']['countries'] as $country) {
                $newGeoTargetsXml .= "<countries>" . trim($country) . "</countries>";
            }
        }
        if (isset($campaign['geoTargets']['countryTargets']['excludedCountries']) && $campaign['geoTargets']['countryTargets']['excludedCountries']) {
            foreach ($campaign['geoTargets']['countryTargets']['excludedCountries'] as $excludedCountry) {
                $newGeoTargetsXml .= "<excludedCountries>" . trim($excludedCountry) . "</excludedCountries>";
            }
        }
        $newGeoTargetsXml .= "</countryTargets><regionTargets>";
        if ($campaign['geoTargets']['regionTargets']['regions']) {
            foreach ($campaign['geoTargets']['regionTargets']['regions'] as $region) {
                $newGeoTargetsXml .= "<regions>" . trim($region) . "</regions>";
            }
        }
        if (isset($campaign['geoTargets']['regionTargets']['excludedRegions']) && $campaign['geoTargets']['regionTargets']['excludedRegions']) {
            foreach ($campaign['geoTargets']['regionTargets']['excludedRegions'] as $excludedRegion) {
                $newGeoTargetsXml .= "<excludedRegions>" . trim($excludedRegion) . "</excludedRegions>";
            }
        }
        $newGeoTargetsXml .= "</regionTargets><metroTargets>";
        if ($campaign['geoTargets']['metroTargets']['metros']) {
            foreach ($campaign['geoTargets']['metroTargets']['metros'] as $metro) {
                $newGeoTargetsXml .= "<metros>" . trim($metro) . "</metros>";
            }
        }
        if (isset($campaign['geoTargets']['metroTargets']['excludedMetros']) && $campaign['geoTargets']['metroTargets']['excludedMetros']) {
            foreach ($campaign['geoTargets']['metroTargets']['excludedMetros'] as $excludedMetro) {
                $newGeoTargetsXml .= "<excludedMetros>" . trim($excludedMetro) . "</excludedMetros>";
            }
        }
        $newGeoTargetsXml .= "</metroTargets><cityTargets>";
        if ($campaign['geoTargets']['cityTargets']['cities']) {
            foreach ($campaign['geoTargets']['cityTargets']['cities'] as $city) {
                $newGeoTargetsXml .= "<cities>" . trim($city) . "</cities>";
            }
        }
        if (isset($campaign['geoTargets']['cityTargets']['excludedCities']) && $campaign['geoTargets']['cityTargets']['excludedCities']) {
            foreach ($campaign['geoTargets']['cityTargets']['excludedCities'] as $excludedCity) {
                $newGeoTargetsXml .= "<excludedCities>" . trim($excludedCity) . "</excludedCities>";
            }
        }
        $newGeoTargetsXml .= "</cityTargets><proximityTargets>";
        if ($campaign['geoTargets']['proximityTargets']['circles']) {
            foreach ($campaign['geoTargets']['proximityTargets']['circles'] as $circle) {
                $newGeoTargetsXml .= "<circles>";
                $newGeoTargetsXml .= "<latitudeMicroDegrees>" . $circle['latitudeMicroDegrees'] . "</latitudeMicroDegrees>";
                $newGeoTargetsXml .= "<longitudeMicroDegrees>" . $circle['longitudeMicroDegrees'] . "</longitudeMicroDegrees>";
                $newGeoTargetsXml .= "<radiusMeters>" . $circle['radiusMeters'] . "</radiusMeters>";
                $newGeoTargetsXml .= "</circles>";
            }
        }
        $newGeoTargetsXml .= "</proximityTargets>";
        if (!empty($campaign['targetAll'])) {
            $newGeoTargetsXml .= "<targetAll>true</targetAll>";
        }
        // expecting array("en", "fr", "gr")
        if (strcasecmp($campaign['languages'][0], "all") != 0) {
            foreach ($campaign['languages'] as $language) {
                $languagesXml .= "<languages>" . trim($language) . "</languages>";
            }
        }
        foreach ($campaign['networkTargeting'] as $networkTargeting) {
            $networkTargetingXml .= "<networkTypes>" . trim($networkTargeting) . "</networkTypes>";
        }
        $adSchedulingXml = "";
        if (!empty($campaign['adScheduling'])) {
            $adSchedulingXml .= "<schedule><status>" . $campaign['adScheduling']['status'] . "</status>";
            foreach ($campaign['adScheduling']['intervals'] as $interval) {
                $adSchedulingXml .= "<intervals>\n                                 <multiplier>" . $interval['multiplier'] . "</multiplier>\n                                 <day>" . $interval['day'] . "</day>\n                                 <startHour>" . $interval['startHour'] . "</startHour>\n                                 <startMinute>" . $interval['startMinute'] . "</startMinute>\n                                 <endHour>" . $interval['endHour'] . "</endHour>\n                                 <endMinute>" . $interval['endMinute'] . "</endMinute>\n                               </intervals>";
            }
            $adSchedulingXml .= "</schedule>";
        }
        $budgetOptimizerSettingsXml = "";
        if (!empty($campaign['budgetOptimizerSettings'])) {
            if ($campaign['budgetOptimizerSettings']['enabled']) {
                $campaign['budgetOptimizerSettings']['enabled'] = "true";
            } else {
                $campaign['budgetOptimizerSettings']['enabled'] = "false";
            }
            if ($campaign['budgetOptimizerSettings']['takeOnOptimizedBids']) {
                $campaign['budgetOptimizerSettings']['takeOnOptimizedBids'] = "true";
            } else {
                $campaign['budgetOptimizerSettings']['takeOnOptimizedBids'] = "false";
            }
            $budgetOptimizerSettingsXml .= "<budgetOptimizerSettings>\n                                          <bidCeiling>" . $campaign['budgetOptimizerSettings']['bidCeiling'] * EXCHANGE_RATE . "\n                                          </bidCeiling>\n                                          <enabled>" . $campaign['budgetOptimizerSettings']['enabled'] . "\n                                          </enabled>\n                                          <takeOnOptimizedBids>" . $campaign['budgetOptimizerSettings']['takeOnOptimizedBids'] . "\n                                          </takeOnOptimizedBids>\n                                        </budgetOptimizerSettings>";
        }
        // only send a start day if it is necessary
        $startDateXml = "";
        if (!empty($campaign['startDate'])) {
            $startDateXml = "<startDay>" . $campaign['startDate'] . "</startDay>";
        } else {
            $startDateXml = "";
        }
        // only send an end day if it is necessary
        $endDateXml = "";
        if (!empty($campaign['endDate'])) {
            $endDateXml = "<endDay>" . $campaign['endDate'] . "</endDay>";
        } else {
            $endDateXml = "";
        }
        // think in micros
        $campaign['budgetAmount'] = $campaign['budgetAmount'] * EXCHANGE_RATE;
        $soapParameters .= "<campaigns>\n                            <budgetAmount>" . $campaign['budgetAmount'] . "</budgetAmount>\n                            <budgetPeriod>" . $campaign['budgetPeriod'] . "</budgetPeriod>\n                            <name>" . $campaign['name'] . "</name>\n                            <status>" . $campaign['status'] . "</status>" . $startDateXml . $endDateXml . "\n                            <networkTargeting>" . $networkTargetingXml . "\n                            </networkTargeting>\n                            <languageTargeting>" . $languagesXml . "</languageTargeting>\n                            <geoTargeting>" . $newGeoTargetsXml . "</geoTargeting>" . $adSchedulingXml . "\n                          </campaigns>";
    }
    $soapParameters .= "</addCampaignList>";
    // add the campaigns to the google servers
    $someCampaigns = $someSoapClient->call("addCampaignList", $soapParameters);
    $soapClients->updateSoapRelatedData(extractSoapHeaderInfo($someSoapClient->getHeaders()));
    if ($someSoapClient->fault) {
        pushFault($someSoapClient, $_SERVER['PHP_SELF'] . ":addCampaignList()", $soapParameters);
        return false;
    }
    $someCampaigns = makeNumericArray($someCampaigns);
    // create local objects
    $campaignObjects = array();
    foreach ($someCampaigns['addCampaignListReturn'] as $someCampaign) {
        $campaignObject = receiveCampaign($someCampaign, 'addCampaignList');
        if (isset($campaignObject)) {
            array_push($campaignObjects, $campaignObject);
        }
    }
    return $campaignObjects;
}
function getCriterionList($adGroupId, $criteriaIds)
{
    $soapClients =& APIlityClients::getClients();
    $someSoapClient = $soapClients->getCriterionClient();
    $criteriaIdsXml = '';
    foreach ($criteriaIds as $criteriaId) {
        $criteriaIdsXml .= '<criterionIds>' . $criteriaId . '</criterionIds>';
    }
    $soapParameters = '<getCriteria>
                         <adGroupId>' . $adGroupId . '</adGroupId>' . $criteriaIdsXml . '
                       </getCriteria>';
    // query the google servers for all criteria
    $listCriteria = $someSoapClient->call('getCriteria', $soapParameters);
    $soapClients->updateSoapRelatedData(extractSoapHeaderInfo($someSoapClient->getHeaders()));
    if ($someSoapClient->fault) {
        pushFault($someSoapClient, $_SERVER['PHP_SELF'] . ':getCriteriaList()', $soapParameters);
        return false;
    }
    // when we have only one criterion in the adgroup return a (one criterion
    // element) array  anyway
    $listCriteria = makeNumericArray($listCriteria);
    $listCriterionObjects = array();
    if (isset($listCriteria['getCriteriaReturn'])) {
        foreach ($listCriteria['getCriteriaReturn'] as $criterion) {
            $criterionObject = receiveCriterion($criterion);
            if (isset($criterionObject)) {
                array_push($listCriterionObjects, $criterionObject);
            }
        }
    }
    return $listCriterionObjects;
}