Пример #1
0
 public function get_liveview($campaign)
 {
     date_default_timezone_set('Europe/London');
     $time_limit = $this->param('showtime');
     $stats = \Model_Dialler_Campaign_Call::find()->where('campaign', $campaign);
     if (!is_null($time_limit)) {
         $time_strings = array('10m' => '10 minutes ago', '30m' => '30 minutes ago', '1h' => '1 hour ago', '2h' => '2 hours ago', '6h' => '6 hours ago', '12h' => '12 hours ago', '1d' => '1 day ago', '1w' => '1 week ago');
         $stats = $stats->where('date', '>=', date("Y-m-d H:i:s", strtotime($time_strings[$time_limit])));
     } else {
         $stats = $stats->where('date', '>=', date("Y-m-d 08:50:00"))->where('date', '<=', date("Y-m-d 20:10:00"));
     }
     $stats = $stats->order_by('date', 'asc')->get();
     $calls = array('label' => "Calls Made", 'data' => array());
     $answers = array('label' => "Calls Answered", 'data' => array());
     foreach ($stats as $stat) {
         $calls['data'][] = array((int) strtotime($stat->date) * 1000, (int) $stat->calls_made);
         $answers['data'][] = array((int) strtotime($stat->date) * 1000, (int) $stat->calls_answered);
     }
     $this->response(array('calls_made' => $calls, 'calls_answered' => $answers));
 }