Ejemplo n.º 1
0
 public static function getActivitiesForAllServices($rawData, $services)
 {
     $temp = array();
     // Initializing the Data arrays for the chart
     foreach ($services as $service) {
         $temp[$service . '_likes'] = array();
         $temp[$service . '_dislikes'] = array();
     }
     // Sort data by date
     $rawData['data'] = ChartUtils::sortArrayByDate($rawData['data']);
     // Converting data into a chart usable format
     foreach ($rawData['data'] as $data) {
         foreach ($services as $service) {
             if (array_key_exists($service, $data)) {
                 array_push($temp[$service . '_likes'], $data[$service]['likes']);
                 array_push($temp[$service . '_dislikes'], $data[$service]['dislikes']);
             } else {
                 array_push($temp[$service . '_likes'], 0);
                 array_push($temp[$service . '_dislikes'], 0);
             }
         }
     }
     return $temp;
 }
Ejemplo n.º 2
0
function getChartLineRangeViewsData($rawData, $community = 'all')
{
    $res = array();
    $services = array('facebook', 'twitter', 'linkedin', 'google');
    $res['clickbacks'] = array();
    $res['views'] = array();
    $temp = array();
    // Initializing the Data arrays for the chart
    foreach ($services as $service) {
        $temp[$service . '_contacts'] = array();
        $temp[$service . '_clickbacks'] = array();
    }
    // Sort data by date
    $rawData['data'] = ChartUtils::sortArrayByDate($rawData['data']);
    // Converting data into a chart usable format
    foreach ($rawData['data'] as $data) {
        $cb = 0;
        foreach ($services as $service) {
            if (array_key_exists($service, $data)) {
                array_push($temp[$service . '_contacts'], $data[$service]['contacts']);
                array_push($temp[$service . '_clickbacks'], $data[$service]['clickbacks']);
                $cb += $data[$service]['clickbacks'];
            } else {
                array_push($temp[$service . '_contacts'], 0);
                array_push($temp[$service . '_clickbacks'], 0);
            }
        }
        //array_push($res['clickbacks'], $cb);
    }
    for ($i = 0; $i < count($temp['facebook_contacts']); $i++) {
        $res['views'][$i] = 0;
        if ($community == 'all') {
            $res['views'][$i] += $temp['facebook_contacts'][$i] + $temp['twitter_contacts'][$i] + $temp['google_contacts'][$i] + $temp['linkedin_contacts'][$i];
        } else {
            $res['views'][$i] += $temp[$community . '_contacts'][$i];
        }
        $res['clickbacks'][$i] = 0;
        if ($community == 'all') {
            $res['clickbacks'][$i] += $temp['facebook_clickbacks'][$i] + $temp['twitter_clickbacks'][$i] + $temp['google_clickbacks'][$i] + $temp['linkedin_clickbacks'][$i];
        } else {
            $res['clickbacks'][$i] += $temp[$community . '_clickbacks'][$i];
        }
    }
    // Addding some metadata from the filter like categories, range, etc.
    $metadata = ChartUtils::addFilterData($res, $rawData['filter']);
    $res['startdate'] = $metadata['startdate'];
    return json_encode($res);
}