Created
November 15, 2013 23:25
-
-
Save andiraduta/7493431 to your computer and use it in GitHub Desktop.
Ia lista de campanii cu lead-uri din 2Parale (ordonate crescator dupa valoarea lead-ului)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function recursive_campaigns($api_url, &$campaigns, &$page) { | |
global $url; | |
$response = file_get_contents($api_url); | |
$json_obj = json_decode($response); | |
if( count($json_obj) > 1 ) { | |
foreach($json_obj as $obj) { | |
if( $obj->campaign->default_lead_commission_rate != "" ) { | |
$campaigns[] = array( | |
'name' => $obj->campaign->name, | |
'lead' => $obj->campaign->default_lead_commission_rate, | |
'lead_type' => $obj->campaign->default_lead_commission_type | |
); | |
} | |
} | |
} | |
// it has more results -> get next page | |
if( count($json_obj) == 50 ) { | |
$page++; | |
recursive_campaigns($url.'&page='.$page, $campaigns, $page); | |
} | |
} | |
$campaigns = array(); | |
$page = 1; | |
$url = "http://api.2parale.ro/campaigns.json?perpage=50"; | |
// get list of campaigns with leads | |
recursive_campaigns($url, $campaigns, $page); | |
// sort | |
usort($campaigns, function($a, $b) { | |
if( $a['lead'] == $b['lead'] ) | |
return 0; | |
return $a['lead'] < $b['lead'] ? -1 : 1; | |
}); | |
//echo "Pages: ". $page ."<br />"; | |
echo "<pre>"; | |
print_r($campaigns); | |
echo "</pre>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment