Exemple #1
0
                $i = 0;
                //$data[$ky] = array();
                $r[$ky] = array();
            }
            //$data[$ky][] = $row;
            if (!isset($colors[$i])) {
                $i = 0;
            }
            $r[$ky][] = '{label: \'' . addslashes($row->name) . '\', data: ' . number_format($row->value) . ', color: \'' . $colors[$i] . '\'}' . "\n";
            if ($row->rank != '0') {
                $total += $row->value;
            }
            $names[] = $row->name;
            $i++;
        }
        $codes = \Hubzero\Geocode\Geocode::getCodesByNames($names);
        $cls = 'even';
        //$pie = array();
        $i = 0;
        $total = $total ? $total : 1;
        foreach ($dataset as $row) {
            if ($row->rank == '0') {
                continue;
            }
            if ($row->name == '?') {
                $row->name = Lang::txt('PLG_RESOURCES_USAGE_UNIDENTIFIED');
            }
            $cls = $cls == 'even' ? 'odd' : 'even';
            ?>
							<tr rel="<?php 
            echo $row->name;
Exemple #2
0
 /**
  * Get data for orgs, countries, domains for a given time period
  * (1 = country, 2 = domain, 3 = org)
  *
  * @param      integer $id       Resource ID
  * @param      string  $datetime Timestamp YYYY-MM-DD
  * @return     array
  */
 public function getTopValues($id, $datetime)
 {
     $period = Request::getInt('period', 14);
     $colors = array($this->params->get('pie_chart_color1', '#7c7c7c'), $this->params->get('pie_chart_color2', '#515151'), $this->params->get('pie_chart_color3', '#d9d9d9'), $this->params->get('pie_chart_color4', '#3d3d3d'), $this->params->get('pie_chart_color5', '#797979'), $this->params->get('pie_chart_color6', '#595959'), $this->params->get('pie_chart_color7', '#e5e5e5'), $this->params->get('pie_chart_color8', '#828282'), $this->params->get('pie_chart_color9', '#404040'), $this->params->get('pie_chart_color10', '#6a6a6a'), $this->params->get('pie_chart_color1', '#bcbcbc'), $this->params->get('pie_chart_color2', '#515151'), $this->params->get('pie_chart_color3', '#d9d9d9'), $this->params->get('pie_chart_color4', '#3d3d3d'), $this->params->get('pie_chart_color5', '#797979'), $this->params->get('pie_chart_color6', '#595959'), $this->params->get('pie_chart_color7', '#e5e5e5'), $this->params->get('pie_chart_color8', '#828282'), $this->params->get('pie_chart_color9', '#404040'), $this->params->get('pie_chart_color10', '#3a3a3a'));
     $json = new stdClass();
     $database = App::get('db');
     $tid = $this->getTid($id, $datetime, $period);
     $orgs = $this->getTopValue($id, 3, $tid, $datetime, $period);
     $r = array();
     if ($orgs) {
         $i = 0;
         foreach ($orgs as $row) {
             $ky = str_replace('-', '/', str_replace('-00 00:00:00', '-01', $row->datetime));
             if ($row->datetime && preg_match("/([0-9]{4})-([0-9]{2})-([0-9]{2})[ ]([0-9]{2}):([0-9]{2}):([0-9]{2})/", $row->datetime, $regs)) {
                 $ky = $regs[1] . '/' . $regs[2] . '/01';
                 //mktime($regs[4], $regs[5], $regs[6], , $regs[3], );
             }
             if (!isset($r[$ky])) {
                 $i = 0;
                 $r[$ky] = array();
             }
             if (!isset($colors[$i])) {
                 $i = 0;
             }
             $obj = new stdClass();
             $obj->label = $row->name;
             $obj->data = (int) $row->value;
             $obj->color = $colors[$i];
             $obj->code = '';
             $r[$ky][] = $obj;
             //'{label: \'' . addslashes($row->name) . '\', data: ' . number_format($row->value) . ', color: \'' . $colors[$i] . '\'}';
             $i++;
         }
     }
     $json->orgs = $r;
     $countries = $this->getTopValue($id, 1, $tid, $datetime, $period);
     $r = array();
     if ($countries) {
         $names = array();
         foreach ($countries as $row) {
             $names[] = $row->name;
         }
         $codes = \Hubzero\Geocode\Geocode::getCodesByNames($names);
         $i = 0;
         foreach ($countries as $row) {
             $ky = str_replace('-', '/', str_replace('-00 00:00:00', '-01', $row->datetime));
             if ($row->datetime && preg_match("/([0-9]{4})-([0-9]{2})-([0-9]{2})[ ]([0-9]{2}):([0-9]{2}):([0-9]{2})/", $row->datetime, $regs)) {
                 $ky = $regs[1] . '/' . $regs[2] . '/01';
                 //mktime($regs[4], $regs[5], $regs[6], , $regs[3], );
             }
             if (!isset($r[$ky])) {
                 $i = 0;
                 $r[$ky] = array();
             }
             if (!isset($colors[$i])) {
                 $i = 0;
             }
             $obj = new stdClass();
             $obj->label = $row->name;
             $obj->data = (int) $row->value;
             $obj->color = $colors[$i];
             $obj->code = isset($codes[$row->name]) ? strtolower($codes[$row->name]['code']) : '';
             $r[$ky][] = $obj;
             //'{label: \'' . addslashes($row->name) . '\', data: ' . number_format($row->value) . ', color: \'' . $colors[$i] . '\'}';
             $i++;
         }
     }
     $json->countries = $r;
     $domains = $this->getTopValue($id, 2, $tid, $datetime, $period);
     $r = array();
     if ($domains) {
         $i = 0;
         foreach ($domains as $row) {
             $ky = str_replace('-', '/', str_replace('-00 00:00:00', '-01', $row->datetime));
             if ($row->datetime && preg_match("/([0-9]{4})-([0-9]{2})-([0-9]{2})[ ]([0-9]{2}):([0-9]{2}):([0-9]{2})/", $row->datetime, $regs)) {
                 $ky = $regs[1] . '/' . $regs[2] . '/01';
                 //mktime($regs[4], $regs[5], $regs[6], , $regs[3], );
             }
             if (!isset($r[$ky])) {
                 $i = 0;
                 $r[$ky] = array();
             }
             if (!isset($colors[$i])) {
                 $i = 0;
             }
             $obj = new stdClass();
             $obj->label = $row->name;
             $obj->data = (int) $row->value;
             $obj->color = $colors[$i];
             $obj->code = '';
             $r[$ky][] = $obj;
             //'{label: \'' . addslashes($row->name) . '\', data: ' . number_format($row->value) . ', color: \'' . $colors[$i] . '\'}';
             $i++;
         }
     }
     $json->domains = $r;
     ob_clean();
     echo json_encode($json);
     die;
 }