Example #1
0
 function testAbstraction()
 {
     $d = new Date();
     $my = new myDate($d);
     $this->assertEquals($d->getDate(), $my->getDate());
 }
Example #2
0
 public static function getGraphData($sid = "all", $do = "event", $report = false, $date_range = null)
 {
     $date = new myDate($report);
     $viewdates = $date->getViewDates();
     Tz::$zone = $date->getZone();
     if ($report) {
         $type = $report->getType();
     } else {
         $type = $viewdates['type'];
     }
     $start = Tz::pickTime($date_range["start_date"] ? strtotime($date_range["start_date"]) : $viewdates[$type . '_start']);
     $end = Tz::pickTime($date_range["end_date"] ? strtotime($date_range["end_date"]) : $viewdates[$type . '_end']);
     $data = array();
     $resultSet = array();
     if ($do == "event") {
         switch ($type) {
             case 'day':
                 $resolution = 3600;
                 for ($time = $start; $time <= $end; $time += $resolution) {
                     $data[Tz::date('H', $time)] = self::executeCommand('eventhandler', $time, $time + $resolution, $sid);
                 }
                 break;
             case 'week':
                 $resolution = 86400;
                 for ($time = $start; $time <= $end; $time += $resolution) {
                     $data[Tz::date('Y-m-d', $time)] = self::executeCommand('eventhandler', $time, $time + $resolution, $sid);
                 }
                 break;
             case 'month':
                 $resolution = 86400;
                 for ($time = $start; $time <= $end; $time += $resolution) {
                     $data[Tz::date('Y-m-d', $time)] = self::executeCommand('eventhandler', $time, $time + $resolution, $sid);
                 }
                 break;
             case 'year':
                 while (true) {
                     $mend = strtotime('+1 month', $start) - 1;
                     $data[Tz::date('F', $start)] = self::executeCommand('eventhandler', $start, $mend, $sid);
                     $start = $mend + 1;
                     if ($start >= $end) {
                         break;
                     }
                 }
                 break;
             default:
                 list($start, $end) = $date->findWeek(time());
                 $start = Tz::pickTime($start);
                 $end = Tz::pickTime($end);
                 $resolution = 86400;
                 for ($time = $start; $time <= $end; $time += $resolution) {
                     $data[Tz::date('Y-m-d', $time)] = self::executeCommand('eventhandler', $time, $time + $resolution);
                 }
                 break;
         }
     } else {
         if ($do == "syslog") {
             switch ($type) {
                 case 'day':
                     $resolution = 3600;
                     $strData = self::executeCommand('syslogd', $start, $end, $sid, $resolution);
                     $arrData = json_decode($strData);
                     foreach ($arrData as $key => $indData) {
                         array_shift($indData);
                         array_shift($indData);
                         $data[Tz::date('H', $start + $resolution * $key)] = $indData;
                     }
                     break;
                 case 'week':
                     $resolution = 86400;
                     $strData = self::executeCommand('syslogd', $start, $end, $sid, $resolution);
                     $arrData = json_decode($strData);
                     foreach ($arrData as $key => $indData) {
                         array_shift($indData);
                         array_shift($indData);
                         $data[Tz::date('Y-m-d', $start + $resolution * $key)] = $indData;
                     }
                     break;
                 case 'month':
                     $resolution = 86400;
                     $strData = self::executeCommand('syslogd', $start, $end, $sid, $resolution);
                     $arrData = json_decode($strData);
                     foreach ($arrData as $key => $indData) {
                         array_shift($indData);
                         array_shift($indData);
                         $data[Tz::date('Y-m-d', $start + $resolution * $key)] = $indData;
                     }
                     break;
                 case 'year':
                     while (true) {
                         $mend = strtotime('+1 month', $start) - 1;
                         $strData = self::executeCommand('syslogd', $start, $mend, $sid, $mend - $start);
                         $arrData = json_decode($strData);
                         array_shift($arrData[0]);
                         array_shift($arrData[0]);
                         $data[Tz::date('F', $start)] = $arrData[0];
                         $start = $mend + 1;
                         if ($start >= $end) {
                             break;
                         }
                     }
                     //echo "<pre>";print_r($data);exit;
                     break;
                 default:
                     $resolution = 86400;
                     $strData = self::executeCommand('syslogd', $start, $end, $sid, $resolution);
                     $arrData = json_decode($strData);
                     foreach ($arrData as $key => $indData) {
                         array_shift($indData);
                         array_shift($indData);
                         $data[Tz::date('Y-m-d', $start + $resolution * $key)] = $indData;
                     }
                     break;
             }
         } else {
             if ($do == "syslogcnt") {
                 switch ($type) {
                     case 'day':
                         $resolution = 3600;
                         $strData = self::executeCommand('syslogd', $start, $end, $sid, $resolution);
                         $arrData = json_decode($strData);
                         foreach ($arrData as $key => $indData) {
                             $data[Tz::date('H', $start + $resolution * $key)] = $indData;
                         }
                         break;
                     case 'week':
                         $resolution = 86400;
                         $strData = self::executeCommand('syslogd', $start, $end, $sid, $resolution);
                         $arrData = json_decode($strData);
                         foreach ($arrData as $key => $indData) {
                             $data[Tz::date('Y-m-d', $start + $resolution * $key)] = $indData;
                         }
                         break;
                     case 'month':
                         $resolution = 86400;
                         $strData = self::executeCommand('syslogd', $start, $end, $sid, $resolution);
                         $arrData = json_decode($strData);
                         foreach ($arrData as $key => $indData) {
                             $data[Tz::date('Y-m-d', $start + $resolution * $key)] = $indData;
                         }
                         break;
                     case 'year':
                         while (true) {
                             $mend = strtotime('+1 month', $start) - 1;
                             $strData = self::executeCommand('syslogd', $start, $mend, $sid, $mend - $start);
                             $arrData = json_decode($strData);
                             $data[Tz::date('F', $start)] = $arrData[0];
                             $start = $mend + 1;
                             if ($start >= $end) {
                                 break;
                             }
                         }
                         //echo "<pre>";print_r($data);exit;
                         break;
                     default:
                         list($start, $end) = $date->findWeek(time());
                         $start = Tz::pickTime($start);
                         $end = Tz::pickTime($end);
                         $resolution = 86400;
                         for ($time = $start; $time <= $end; $time += $resolution) {
                             $data[Tz::date('Y-m-d', $time)] = self::executeCommand('syslogd', $time, $time + $resolution, $sid);
                         }
                         break;
                 }
             }
         }
     }
     if ($report) {
         if ($report->getType() == "day") {
             $str = trim(substr($date_range["start_date"], 0, strrpos($date_range["start_date"], " ")));
         }
         if ($do == "event" || $do == "syslog") {
             $tmp = array();
             $i = 0;
             foreach ($data as $key => $item) {
                 $key = trim($key);
                 if ($report->getType() == "day") {
                     $key = $str . " " . $key . ":00:00";
                 }
                 $tmp[$i] = $do == "syslog" ? $item : explode(",", trim($item));
                 $tmp[$i][] = $key;
                 $i++;
             }
             return $tmp;
         }
     }
     return $data;
 }