function testBuildAds()
 {
     $bck = $this->item->gag_id;
     $this->item->gag_id = '';
     $this->assertFalse($this->item->buildAds());
     $this->item->gag_id = $bck;
     $this->assertFalse($this->item->buildAds());
     $this->assertFalse($this->item->buildAds(null));
     $this->assertFalse($this->item->buildAds(array()));
     $this->item->m_ad_types = array("GoogleAdRealEstateRU");
     $this->assertFalse($this->item->buildAds(array()));
     $this->assertFalse($this->item->buildAds(array("a")));
     $this->maindb->executeSQL("SELECT * FROM realestate WHERE l_isActive = 1 ORDER BY RAND() LIMIT 1", $res, $bulk);
     $record = $res[0];
 }
             }
         }
     }
     $prev_make = $val['l_make'];
     if ($kk > 60000) {
         break 2;
     }
     $k = 0;
     echo $c . "/" . ++$i . "/" . $total . "\r\n";
     $ag = new GoogleAdGroup($db);
     $ag->m_sMainTable = 'vehicles';
     $ag->gag_l_id = $val['l_id'];
     $ag->createName($val);
     $ag->save();
     $ag->m_aKeywords[] = array('keyword' => $val['l_make'], 'url' => "http://vehicles.pingola.ru.msn.com/search/" . str_replace(" ", "+", $val['l_make']) . "?make=" . str_replace(" ", "+", $val['l_make']) . "&share&refGoogle=Network=_{network}_&Keyword=_{keyword}_&MatchType=_{matchtype}_&Ad=_{creative}_&AdPos=_{adposition}_");
     $ag->buildAds(array('GoogleAdVehiclesRU', 'GoogleAdVehiclesRU3', 'GoogleAdVehiclesRU4'), $val);
     //, 'GoogleAdRealEstateRU2', 'GoogleAdRealEstateRU3', 'GoogleAdRealEstateRU4'), $val);
     if (!$ag->is_has_ads) {
         echo "no good ads\r\n";
         continue;
     }
     $c++;
     if ($c == 2000) {
         $c = 0;
         $campaign = new GoogleCampaign($db);
         $campaign->ga_campaign_name = CAMPAIGN_NAME_BASE . " " . date("Y-m-d H i");
         $campaign->save();
     }
     echo "{$kk} keywords\r\n";
 }
 $cur += $step;
$main_db->executeSQL("SELECT *, count(*) as cnt FROM realestate\n\tWHERE \tl_deal_type = 0 and \n\t\t\tl_www_id = 1369 and \n\t\t\tl_isActive = 1 and \n\t\t\tl_d_price > 10000 and\n\t\t\tl_assetType = 'Квартира'\n\tGROUP BY \n\t\tl_geo_city \n\tORDER BY \n\t\tcnt DESC \n\tLIMIT 20", $resultArry, $rowsAffected);
if (!$rowsAffected) {
    break;
}
$total = $rowsAffected;
foreach ($resultArry as $val) {
    $campaign = new GoogleCampaign($db);
    $campaign->ga_campaign_name = "Real Estate Sale " . $val['l_geo_city'];
    $campaign->save();
    echo $c . "/" . ++$i . "/" . $total . "\r\n";
    $ag = new GoogleAdGroup($db);
    $ag->m_sMainTable = 'realestate';
    $ag->gag_l_id = $val['l_id'];
    $ag->createName();
    $ag->save();
    $ag->buildAds(array('GoogleAdRealEstateRU5', 'GoogleAdRealEstateRU6', 'GoogleAdRealEstateRU7', 'GoogleAdRealEstateRU12', 'GoogleAdRealEstateRU13'), $val);
    $ag->buildRealestateKeywordsRU($val);
    $ag->saveAds($fp, $campaign->ga_campaign_name);
    if (!$ag->is_has_ads) {
        echo "no good ads\r\n";
        continue;
    }
    $ag->m_aKeywords = array_unique($ag->m_aKeywords);
    foreach ($ag->m_aKeywords as $val2) {
        fputs($fp, "{$campaign->ga_campaign_name},,,,,," . $ag->gag_name . "," . MAX_CPC . "," . DEFAULT_MATCH_TYPE . ",{$val2}\r\n");
    }
    $c++;
    $main_db->executeSQL("SELECT *, count(*) as cnt FROM realestate\n\tWHERE \tl_deal_type = 1 and \n\t\t\tl_www_id = 1369 and \n\t\t\tl_isActive = 1 and \n\t\t\tl_d_price > 1000 and\n\t\t\tl_geo_city LIKE '%{$val['l_geo_city']}%' and\n\t\t\tl_assetType = 'Квартира'\n\tGROUP BY \n\t\tl_geo_city \n\tORDER BY \n\t\tcnt DESC \n\tLIMIT 1", $resultArry2, $rowsAffected2);
    echo $c . "/" . ++$i . "/" . $total . "\r\n";
    $ag->m_aKeywords = array();
    $ag->ads = array();
$fp = fopen("../output/" . str_replace(" ", "_", $campaign->ga_campaign_name) . ".csv", "w+");
fputs($fp, "Campaign,Daily Budget,Language,Location,Proximity Targets,Ad Schedule,Ad Group,Max CPC,Keyword Type,Keyword,Headline,Description Line 1,Description Line 2,Display URL,Destination URL\r\n");
$cur = 0;
$step = 10000;
$i = 0;
$c = 0;
$main_db->executeSQL("SELECT l_geo_city, l_rooms, l_assetType, min(l_d_price) as l_d_price, count(*) as cnt FROM realestate WHERE l_www_id = 16 and l_isActive = 1 and l_d_price > 1500 and l_rooms < 4 and l_deal_type = 0 GROUP BY l_geo_city, l_rooms, l_assetType HAVING cnt > 10 ORDER BY cnt DESC", $resultArry, $rowsAffected);
$total = $rowsAffected;
foreach ($resultArry as $val) {
    echo $c . "/" . ++$i . "\r\n";
    $ag = new GoogleAdGroup($db);
    $ag->m_sMainTable = 'realestate';
    $ag->gag_l_id = $val['l_id'];
    $ag->gag_name = "Group " . $c;
    $ag->save();
    $ag->buildAds(array("GoogleAdRealEstateIL"), $val);
    $ag->buildRealEstateKeywordsIL($val);
    $ag->saveAds($fp, $campaign->ga_campaign_name);
    if (!$ag->is_has_ads) {
        echo "no good ads\r\n";
        continue;
    }
    foreach ($ag->m_aKeywords as $val) {
        fputs($fp, "{$campaign->ga_campaign_name},,,,,," . $ag->gag_name . "," . MAX_CPC . "," . DEFAULT_MATCH_TYPE . ",{$val}\r\n");
    }
    $c++;
    if ($c == 2000) {
        $c = 0;
        $campaign = new GoogleCampaign($db);
        $campaign->ga_campaign_name = CAMPAIGN_NAME_BASE . " " . date("Y-m-d H i");
        $campaign->save();
Example #5
0
$i = 0;
$c = 0;
do {
    $main_db->executeSQL("SELECT l_make, l_model, l_year, l_owners, min(l_price) as l_d_price, count(*) as cnt FROM vehicles WHERE l_isActive = 1 and l_price > 3000 and l_owners = 'שניה' GROUP BY l_make, l_model, l_year HAVING cnt > 5 ORDER BY l_id DESC LIMIT {$cur}, {$step}", $resultArry, $rowsAffected);
    if (!$rowsAffected) {
        break;
    }
    $total = $rowsAffected;
    foreach ($resultArry as $val) {
        echo $c . "/" . ++$i . "/" . $total . "\r\n";
        $ag = new GoogleAdGroup($db);
        $ag->m_sMainTable = 'vehicles';
        $ag->gag_l_id = $val['l_id'];
        $ag->gag_name = $val['l_make'] . " " . $val['l_model'] . " " . $val['l_year'] . " " . $i;
        $ag->save();
        $ag->buildAds(array('GoogleAdVehicles17072011_1IL', 'GoogleAdVehicles17072011_2IL', 'GoogleAdVehicles17072011_3IL', 'GoogleAdVehicles17072011_4IL', 'GoogleAdVehicles17072011_5IL', 'GoogleAdVehicles17072011_6IL', 'GoogleAdVehicles17072011_7IL'), $val);
        $ag->saveAds($fp, $campaign->ga_campaign_name);
        if (!$ag->is_has_ads) {
            echo "no good ads\r\n";
            continue;
        }
        $ag->buildVehiclesKeywordsIL($val);
        foreach ($ag->m_aKeywords as $val) {
            fputs($fp, "{$campaign->ga_campaign_name},,,,,," . $ag->gag_name . "," . MAX_CPC . "," . DEFAULT_MATCH_TYPE . ",{$val}\r\n");
        }
        $c++;
        if ($c == 2000) {
            $c = 0;
            $campaign = new GoogleCampaign($db);
            $campaign->ga_campaign_name = CAMPAIGN_NAME_BASE . " " . date("Y-m-d H i");
            $campaign->save();
fputs($fp, "Campaign,Daily Budget,Language,Location,Proximity Targets,Ad Schedule,Ad Group,Max CPC,Keyword Type,Keyword,Headline,Description Line 1,Description Line 2,Display URL,Destination URL\r\n");
$cur = 0;
$step = 10000;
$i = 0;
$c = 0;
do {
    $main_db->executeSQL("SELECT * FROM vehicles WHERE l_www_id = 16 and l_isActive = 1 and l_price > 1000 ORDER BY l_id DESC LIMIT {$cur}, {$step}", $resultArry, $rowsAffected);
    $total = $rowsAffected;
    foreach ($resultArry as $val) {
        echo $c . "/" . ++$i . "/" . $total . "\r\n";
        $ag = new GoogleAdGroup($db);
        $ag->m_sMainTable = 'vehicles';
        $ag->gag_l_id = $val['l_id'];
        $ag->createName();
        $ag->save();
        $ag->buildAds(array('GoogleAdVehiclesIL'), $val);
        $ag->buildVehiclesKeywordsIL($val);
        $ag->saveAds($fp, $campaign->ga_campaign_name);
        if (!$ag->is_has_ads) {
            echo "no good ads\r\n";
            continue;
        }
        foreach ($ag->m_aKeywords as $val) {
            fputs($fp, "{$campaign->ga_campaign_name},,,,,," . $ag->gag_name . "," . MAX_CPC . "," . DEFAULT_MATCH_TYPE . ",{$val}\r\n");
        }
        $c++;
        if ($c == 2000) {
            $c = 0;
            $campaign = new GoogleCampaign($db);
            $campaign->ga_campaign_name = CAMPAIGN_NAME_BASE . " " . date("Y-m-d H i");
            $campaign->save();
 if (!$rowsAffected) {
     break;
 }
 $total = $rowsAffected;
 foreach ($resultArry as $val) {
     $asset_types = explode("/", $val['l_assettype']);
     foreach ($asset_types as $asset_type) {
         $val['l_assettype_en'] = assetTypeEn($asset_type);
         $val['l_assettype'] = $asset_type;
         echo $c . "/" . ++$i . "/" . $total . "\r\n";
         $ag = new GoogleAdGroup($db);
         $ag->m_sMainTable = 'realestate';
         $ag->gag_l_id = $val['l_id'];
         $ag->createName($val);
         $ag->save();
         $ag->buildAds(array('GoogleAdRealEstateRU9', 'GoogleAdRealEstateRU10', 'GoogleAdRealEstateRU11', 'GoogleAdRealEstateRU12', 'GoogleAdRealEstateRU13'), $val);
         //), $val);
         $ag->buildRealestateKeywordsRU($val);
         $ag->saveAds($fp, $campaign->ga_campaign_name);
         if (!$ag->is_has_ads) {
             echo "no good ads\r\n";
             continue;
         }
         //$ag->m_aKeywords = array_unique($ag->m_aKeywords);
         //echo "Keywords count = ". count($ag->m_aKeywords)." ";
         $kc = 0;
         foreach ($ag->m_aKeywords as $v) {
             echo $v['keyword'] . "\n\r";
             $kc++;
             $k++;
             $kk++;