2010-11-29 22:41:08 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class supports Services
|
|
|
|
*
|
2013-03-19 22:35:19 +00:00
|
|
|
* @package ADSL
|
2010-11-29 22:41:08 +00:00
|
|
|
* @category Models
|
|
|
|
* @author Deon George
|
2013-03-19 22:35:19 +00:00
|
|
|
* @copyright (c) 2009-2013 Open Source Billing
|
2010-11-29 22:41:08 +00:00
|
|
|
* @license http://dev.osbill.net/license.html
|
|
|
|
*/
|
2013-01-10 11:25:19 +00:00
|
|
|
class Model_Service_Plugin_Adsl extends Model_Service_Plugin {
|
2010-11-29 22:41:08 +00:00
|
|
|
protected $_table_name = 'service__adsl';
|
|
|
|
protected $_updated_column = FALSE;
|
|
|
|
|
|
|
|
// Relationships
|
|
|
|
protected $_belongs_to = array(
|
|
|
|
'service'=>array(),
|
|
|
|
);
|
|
|
|
|
2011-09-28 06:46:22 +00:00
|
|
|
protected $_has_one = array(
|
2013-04-04 22:42:29 +00:00
|
|
|
'adsl_plan'=>array('model'=>'ADSL_Plan','far_key'=>'provided_adsl_plan_id','foreign_key'=>'id'),
|
2011-09-28 06:46:22 +00:00
|
|
|
);
|
|
|
|
|
2011-07-14 09:09:03 +00:00
|
|
|
protected $_display_filters = array(
|
|
|
|
'service_connect_date'=>array(
|
|
|
|
array('Config::date',array(':value')),
|
|
|
|
),
|
2013-01-23 11:17:22 +00:00
|
|
|
'service_contract_date'=>array(
|
|
|
|
array('Config::date',array(':value')),
|
|
|
|
),
|
2011-07-14 09:09:03 +00:00
|
|
|
);
|
|
|
|
|
2011-09-28 06:46:22 +00:00
|
|
|
// Required abstract functions
|
2011-12-29 02:52:24 +00:00
|
|
|
public function admin_update() {
|
|
|
|
return View::factory('service/admin/adsl/update')
|
|
|
|
->set('mediapath',Route::get('default/media'))
|
2011-09-28 06:46:22 +00:00
|
|
|
->set('so',$this);
|
|
|
|
}
|
|
|
|
|
2012-10-08 12:52:21 +00:00
|
|
|
/**
|
|
|
|
* When does this service expire
|
|
|
|
*/
|
|
|
|
public function expire() {
|
|
|
|
// @todo This should work out if the invoices are currently due, then the expire is the invoice date, otherwise the next invoice date.
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-09-28 06:46:22 +00:00
|
|
|
public function name() {
|
|
|
|
return $this->service_number;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function product() {
|
|
|
|
if ($this->provided_adsl_plan_id)
|
|
|
|
return $this->adsl_plan;
|
|
|
|
else
|
|
|
|
return $this->service->product->plugin();
|
|
|
|
}
|
|
|
|
|
2011-12-29 02:52:24 +00:00
|
|
|
public function service_view() {
|
|
|
|
return View::factory('service/user/plugin/adsl/view')
|
|
|
|
->set('so',$this);
|
|
|
|
}
|
|
|
|
|
2012-06-22 05:12:59 +00:00
|
|
|
public function username_value() {
|
|
|
|
return $this->service_username;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function password_value() {
|
|
|
|
return $this->service_password;
|
|
|
|
}
|
|
|
|
|
2010-11-29 22:41:08 +00:00
|
|
|
/**
|
|
|
|
* Return the IP Address for the service
|
|
|
|
*/
|
|
|
|
public function ipaddress() {
|
|
|
|
return $this->ipaddress ? $this->ipaddress : _('Dynamic');
|
|
|
|
}
|
|
|
|
|
2011-08-02 06:20:11 +00:00
|
|
|
public function contract_date_start() {
|
2013-01-23 11:17:22 +00:00
|
|
|
return Config::date($this->service_contract_date);
|
2011-08-02 06:20:11 +00:00
|
|
|
}
|
|
|
|
|
2010-11-29 22:41:08 +00:00
|
|
|
public function contract_date_end() {
|
2013-01-23 11:17:22 +00:00
|
|
|
return Config::date(strtotime(sprintf('+%s months',$this->contract_term),$this->service_contract_date));
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
|
2012-03-30 04:13:01 +00:00
|
|
|
public function hasOffpeak() {
|
|
|
|
return ((is_null($this->product()->base_down_offpeak) OR $this->product()->base_down_offpeak) AND (is_null($this->product()->base_up_offpeak) OR $this->product()->base_up_offpeak)) ? TRUE : FALSE;
|
|
|
|
}
|
|
|
|
|
2010-11-29 22:41:08 +00:00
|
|
|
/**
|
|
|
|
* This function will return the months that have traffic data.
|
|
|
|
* This array can be used in a select list to display the traffic for that month
|
|
|
|
*/
|
|
|
|
public function get_traffic_months() {
|
|
|
|
$keys = $months = array();
|
|
|
|
|
|
|
|
foreach ($this->get_traffic_data_monthly() as $metric => $data)
|
|
|
|
$keys = array_unique(array_merge($keys,array_keys($data)));
|
|
|
|
|
|
|
|
foreach ($keys as $v)
|
|
|
|
$months[$v] = $v;
|
|
|
|
|
|
|
|
arsort($months);
|
|
|
|
|
|
|
|
return $months;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate the total traffic used in a month
|
|
|
|
*/
|
2011-10-14 05:44:12 +00:00
|
|
|
private function get_traffic_data_month($period=NULL,$cache=NULL) {
|
2013-04-05 12:50:08 +00:00
|
|
|
$result = array();
|
2010-11-29 22:41:08 +00:00
|
|
|
|
2011-10-14 05:44:12 +00:00
|
|
|
foreach ($this->get_traffic_data_daily($period,TRUE,$cache) as $tdata)
|
2010-11-29 22:41:08 +00:00
|
|
|
foreach ($tdata as $k => $v)
|
2013-04-05 12:50:08 +00:00
|
|
|
if (isset($result[$k]))
|
|
|
|
$result[$k] += $v;
|
2010-11-29 22:41:08 +00:00
|
|
|
else
|
2013-04-05 12:50:08 +00:00
|
|
|
$result[$k] = $v;
|
2010-11-29 22:41:08 +00:00
|
|
|
|
2013-04-05 12:50:08 +00:00
|
|
|
return $result;
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an array of the data used in a month by day
|
|
|
|
*/
|
2011-10-14 05:44:12 +00:00
|
|
|
public function get_traffic_data_daily($period=NULL,$bydate=FALSE,$cache=NULL) {
|
2013-04-05 12:50:08 +00:00
|
|
|
$result = array();
|
2011-10-14 05:44:12 +00:00
|
|
|
|
|
|
|
// @temp - caching is broken?
|
|
|
|
$cache=0;
|
2010-11-29 22:41:08 +00:00
|
|
|
if (is_null($period))
|
|
|
|
$period = strtotime('yesterday');
|
|
|
|
|
2013-01-10 11:25:19 +00:00
|
|
|
$t = ORM::factory('Service_Plugin_Adsl_Traffic')
|
2010-11-29 22:41:08 +00:00
|
|
|
->where('service','=',$this->service_username)
|
|
|
|
->and_where('date','>=',date('Y-m-d',mktime(0,0,0,date('m',$period),1,date('Y',$period))))
|
2011-10-14 05:44:12 +00:00
|
|
|
->and_where('date','<=',date('Y-m-d',strtotime('last day of '.date('M Y',$period))))
|
|
|
|
->cached($cache);
|
|
|
|
|
|
|
|
foreach ($t->find_all() as $to) {
|
|
|
|
$day = date('d',strtotime($to->date));
|
|
|
|
|
2010-11-29 22:41:08 +00:00
|
|
|
if ($bydate)
|
2013-04-05 12:50:08 +00:00
|
|
|
$result[$day] = $to->traffic($this->service->product->plugin());
|
2010-11-29 22:41:08 +00:00
|
|
|
else
|
2011-10-14 05:44:12 +00:00
|
|
|
foreach ($to->traffic($this->service->product->plugin()) as $k => $v)
|
2013-04-05 12:50:08 +00:00
|
|
|
$result[$k][$day] = $v;
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
|
2013-04-05 12:50:08 +00:00
|
|
|
return $result;
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an array of the data used in a year by month
|
|
|
|
*/
|
|
|
|
public function get_traffic_data_monthly($period=NULL,$bydate=FALSE) {
|
2013-04-05 12:50:08 +00:00
|
|
|
$result = array();
|
2011-10-14 05:44:12 +00:00
|
|
|
|
2010-11-29 22:41:08 +00:00
|
|
|
if (is_null($period))
|
|
|
|
$period = strtotime('yesterday');
|
|
|
|
|
2013-01-10 11:25:19 +00:00
|
|
|
$t = ORM::factory('Service_Plugin_Adsl_Traffic')
|
2010-11-29 22:41:08 +00:00
|
|
|
->select(
|
|
|
|
array('date_format(date,\'%y-%m\')','month'),
|
|
|
|
array('sum(up_peak)','up_peak'),
|
|
|
|
array('sum(up_offpeak)','up_offpeak'),
|
|
|
|
array('sum(down_peak)','down_peak'),
|
|
|
|
array('sum(down_offpeak)','down_offpeak')
|
|
|
|
)
|
|
|
|
->where('service','=',$this->service_username)
|
|
|
|
->and_where('date','>=',date('Y-m-d',mktime(0,0,0,date('m',$period),1,date('Y',$period)-1)))
|
|
|
|
->and_where('date','<=',date('Y-m-d',strtotime('last day of '.date('M Y',$period))))
|
|
|
|
->group_by('date_format(date,\'%Y-%m\')');
|
|
|
|
|
2011-10-14 05:44:12 +00:00
|
|
|
foreach ($t->find_all() as $to)
|
2010-11-29 22:41:08 +00:00
|
|
|
if ($bydate)
|
2013-04-05 12:50:08 +00:00
|
|
|
$result[$to->month] = $to->traffic($this->service->product->plugin());
|
2010-11-29 22:41:08 +00:00
|
|
|
else
|
2011-10-14 05:44:12 +00:00
|
|
|
foreach ($to->traffic($this->service->product->plugin()) as $k => $v)
|
2013-04-05 12:50:08 +00:00
|
|
|
$result[$k][$to->month] = $v;
|
2010-11-29 22:41:08 +00:00
|
|
|
|
2013-04-05 12:50:08 +00:00
|
|
|
return $result;
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
|
2011-10-14 05:44:12 +00:00
|
|
|
public function traffic_month($month,$string=TRUE,$cache=NULL) {
|
|
|
|
return $string ? implode('/',$this->get_traffic_data_month($month,$cache)) :
|
|
|
|
$this->get_traffic_data_month($month,$cache);
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function traffic_lastmonth($string=TRUE) {
|
2011-07-22 01:04:20 +00:00
|
|
|
// We need it to be last month as of yesterday
|
|
|
|
return $this->traffic_month(strtotime('last month')-86400,$string);
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function traffic_thismonth($string=TRUE) {
|
|
|
|
return $this->traffic_month(strtotime('yesterday'),$string);
|
|
|
|
}
|
|
|
|
|
2011-08-02 06:48:41 +00:00
|
|
|
public function traffic_lastmonth_exceed($all=FALSE,$date=NULL) {
|
2013-04-05 12:50:08 +00:00
|
|
|
$result = array();
|
2010-11-29 22:41:08 +00:00
|
|
|
|
2011-08-02 06:48:41 +00:00
|
|
|
if (is_null($date))
|
2011-10-14 05:44:12 +00:00
|
|
|
$date = strtotime('last month')-86400;
|
2011-08-02 06:48:41 +00:00
|
|
|
|
2011-10-14 05:44:12 +00:00
|
|
|
foreach ($this->traffic_month($date,FALSE,0) as $k => $v) {
|
2010-11-29 22:41:08 +00:00
|
|
|
// We shouldnt need to eval for nulls, since the traffic calc does that
|
2011-09-28 06:46:22 +00:00
|
|
|
if ($all OR ($v > $this->service->product->plugin()->$k)) {
|
2013-04-05 12:50:08 +00:00
|
|
|
$result[$k]['allowance'] = $this->service->product->plugin()->$k;
|
|
|
|
$result[$k]['used'] = $v;
|
|
|
|
$result[$k]['shaped'] = (! empty($this->service->product->plugin()->extra_shaped) AND $this->service->product->plugin()->extra_shaped AND $v > $this->service->product->plugin()->$k) ? TRUE : FALSE;
|
|
|
|
$result[$k]['excess'] = (! empty($this->service->product->plugin()->extra_charged) AND $this->service->product->plugin()->extra_charged AND $v > $this->service->product->plugin()->$k) ? $v-$this->service->product->plugin()->$k : 0;
|
|
|
|
$result[$k]['rate'] = $this->service->product->plugin()->{ADSL::map($k)};
|
|
|
|
$result[$k]['charge'] = ceil(($result[$k]['excess'])/1000)*$result[$k]['rate'];
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-05 12:50:08 +00:00
|
|
|
return $result;
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function template_variables($array) {
|
|
|
|
$friendly = array(
|
|
|
|
'base_down_peak'=>'Peak',
|
|
|
|
'base_down_offpeak'=>'OffPeak',
|
|
|
|
'cumulative_base_down_peak'=>'Total Peak',
|
|
|
|
'cumulative_base_down_offpeak'=>'Total OffPeak',
|
|
|
|
);
|
|
|
|
|
2013-04-05 12:50:08 +00:00
|
|
|
$result = array();
|
2011-08-25 23:21:39 +00:00
|
|
|
if ($this->service->product->prod_plugin_file != 'ADSL')
|
|
|
|
throw new Kohana_Exception('Huh? How did this get called, for a non ADSL product (:ppf)',array(':ppf'=>$this->service_id));
|
|
|
|
|
|
|
|
$allowance = $this->service->product->plugin()->allowance(FALSE);
|
2010-11-29 22:41:08 +00:00
|
|
|
|
|
|
|
$period = strtotime('yesterday');
|
|
|
|
$traffic_data = $this->get_traffic_data_daily($period,FALSE);
|
|
|
|
$traffic = $this->get_traffic_data_month($period);
|
|
|
|
|
|
|
|
$traffic_type = $this->get_traffic_data_daily($period,TRUE);
|
|
|
|
$day = count($traffic_type) ? max(array_keys($traffic_type)) : 1;
|
2011-07-22 01:04:20 +00:00
|
|
|
$date = mktime(0,0,0,date('n',$period),$day,date('Y',$period));
|
|
|
|
$daysleft = date('d',strtotime('last day of',$date))-$day;
|
2010-11-29 22:41:08 +00:00
|
|
|
|
2012-12-10 21:48:30 +00:00
|
|
|
$google = GoogleChart::factory('Legacy')
|
|
|
|
->type('vertical_bar')
|
|
|
|
->title(sprintf('DSL traffic usage as at %s',Config::date($date)));
|
2010-11-29 22:41:08 +00:00
|
|
|
|
|
|
|
foreach ($traffic_data as $k => $details)
|
2013-01-04 04:13:48 +00:00
|
|
|
$google->sdata(array('yl'=>($x=isset($friendly[$k]) ? $friendly[$k] : $k)),array($x=>$traffic_data[$k]));
|
2010-11-29 22:41:08 +00:00
|
|
|
|
|
|
|
// Work out comulative numbers
|
|
|
|
foreach ($traffic_data as $k => $details)
|
2013-01-04 04:13:48 +00:00
|
|
|
$google->sdata(array('yr'=>($x=isset($friendly['cumulative'.$k]) ? $friendly['cumulative'.$k] : 'cumulative'.$k)),array($x=>$this->cumulative($traffic_data[$k])));
|
2010-11-29 22:41:08 +00:00
|
|
|
|
|
|
|
foreach ($array as $item) {
|
|
|
|
switch ($item) {
|
|
|
|
case 'MONTH_GRAPH': $value = (string)$google; break;
|
2012-12-10 21:48:30 +00:00
|
|
|
case 'MONTH_TABLE': $value = $google->table(FALSE,array(
|
2011-07-22 01:04:20 +00:00
|
|
|
'table'=>'style="border: 1px solid #bebcb7; padding: 5px 5px; background: none repeat scroll 0% 0% #f8f7f5; font-size: 70%;"',
|
2010-11-29 22:41:08 +00:00
|
|
|
)); break;
|
|
|
|
|
|
|
|
case 'OFFPEAK_ALLOWANCE': $value = isset($allowance['base_down_offpeak']) ? $allowance['base_down_offpeak'].' MB' : '-'; break;
|
|
|
|
case 'OFFPEAK_USAGE': $value = isset($traffic['base_down_offpeak']) ? $traffic['base_down_offpeak'].' MB' : '-'; break;
|
|
|
|
|
|
|
|
case 'PEAK_ALLOWANCE': $value = isset($allowance['base_down_peak']) ? $allowance['base_down_peak'].' MB' : '-'; break;
|
|
|
|
case 'PEAK_USAGE': $value = isset($traffic['base_down_peak']) ? $traffic['base_down_peak'].' MB' : '-'; break;
|
|
|
|
|
|
|
|
case 'OFFPEAK_AVERAGE': $value = isset($traffic['base_down_offpeak']) ? round($traffic['base_down_offpeak']/$day,2).' MB' : '-'; break;
|
|
|
|
case 'OFFPEAK_AVERAGE_REMAIN': $value = ((isset($traffic['base_down_offpeak']) AND ($allowance['base_down_offpeak'] > $traffic['base_down_offpeak']) AND $daysleft) ? round(($allowance['base_down_offpeak']-$traffic['base_down_offpeak'])/$daysleft,2).' MB' : '-'); break;
|
|
|
|
|
|
|
|
case 'PEAK_AVERAGE': $value = isset($traffic['base_down_peak']) ? round($traffic['base_down_peak']/$day,2).' MB' : '-'; break;
|
|
|
|
case 'PEAK_AVERAGE_REMAIN': $value = ((isset($traffic['base_down_peak']) AND ($allowance['base_down_peak'] > $traffic['base_down_peak']) AND $daysleft) ? round(($allowance['base_down_peak']-$traffic['base_down_peak'])/$daysleft,2).' MB' : '-'); break;
|
|
|
|
|
|
|
|
case 'SERVICE_NUMBER': $value = $this->service_number; break;
|
|
|
|
case 'USAGE_DATE': $value = Config::date($date); break;
|
|
|
|
case 'USER_NAME': $value = $this->service->account->name(); break;
|
|
|
|
default:
|
|
|
|
$value = '';
|
|
|
|
}
|
|
|
|
|
2013-04-05 12:50:08 +00:00
|
|
|
$result[$item] = $value;
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
|
2013-04-05 12:50:08 +00:00
|
|
|
return $result;
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function will take an array of numbers and change it into a cumulative array
|
|
|
|
*/
|
|
|
|
public function cumulative($array) {
|
|
|
|
$result = array();
|
|
|
|
$s = 0;
|
|
|
|
|
|
|
|
foreach ($array as $k => $v)
|
|
|
|
$result[$k] = ($s += $v);
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if we alert traffic
|
|
|
|
*
|
|
|
|
* We alert traffic if:
|
|
|
|
* + 80% of usage every 3 days
|
|
|
|
* + average daily usage > allowance every 5 days
|
|
|
|
* + last day of the period
|
|
|
|
*/
|
|
|
|
public function report_traffic() {
|
2011-08-25 23:21:39 +00:00
|
|
|
if ($this->service->product->prod_plugin_file != 'ADSL')
|
|
|
|
throw new Kohana_Exception('Huh? How did this get called, for a non ADSL product (:ppf)',array(':ppf'=>$this->service_id));
|
|
|
|
|
|
|
|
$allowance = $this->service->product->plugin()->allowance(FALSE);
|
2010-11-29 22:41:08 +00:00
|
|
|
|
|
|
|
$period = strtotime('yesterday');
|
|
|
|
$traffic_data = $this->get_traffic_data_daily($period,FALSE);
|
|
|
|
$traffic = $this->get_traffic_data_month($period);
|
|
|
|
|
|
|
|
$traffic_type = $this->get_traffic_data_daily($period,TRUE);
|
2011-08-25 23:21:39 +00:00
|
|
|
// @todo If no data comes in, then this can be stuck reporting traffic for an old date.
|
2010-11-29 22:41:08 +00:00
|
|
|
$day = count($traffic_type) ? max(array_keys($traffic_type)) : 1;
|
2012-06-22 05:12:59 +00:00
|
|
|
$lastday = date('d',strtotime('last day of',$period));
|
2010-11-29 22:41:08 +00:00
|
|
|
|
|
|
|
foreach ($traffic as $k => $v) {
|
|
|
|
// If we are the last day of the period
|
|
|
|
if ($day == $lastday AND $v)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
// If we are at 80% usage
|
2011-08-25 23:21:39 +00:00
|
|
|
if ($v/($allowance[$k] > 0 ? $allowance[$k] : 1) >= .8 AND $day%3 == 0)
|
2010-11-29 22:41:08 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
// If our average is greater than our allowance
|
2011-08-25 23:21:39 +00:00
|
|
|
if ($day%5 == 0 AND ($v/$day > $allowance[$k]/$day))
|
2010-11-29 22:41:08 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we get here, then we dont need to report usage.
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-07-14 09:09:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get specific service details for use in other modules
|
|
|
|
* For Example: Invoice
|
|
|
|
*
|
|
|
|
* @todo Make the rendered items configurable
|
2011-09-28 06:46:22 +00:00
|
|
|
* @todo Change this method name, now that it is public
|
2011-07-14 09:09:03 +00:00
|
|
|
*/
|
2011-09-28 06:46:22 +00:00
|
|
|
public function _details($type) {
|
2011-07-14 09:09:03 +00:00
|
|
|
switch ($type) {
|
2011-09-28 06:46:22 +00:00
|
|
|
case 'invoice_detail_items':
|
2011-07-14 09:09:03 +00:00
|
|
|
return array(
|
2011-10-11 08:52:31 +00:00
|
|
|
_('Service Address')=>$this->service_address ? $this->display('service_address') : '>NotSet<',
|
2011-08-02 06:48:41 +00:00
|
|
|
_('Contract Until')=>$this->contract_date_end(),
|
2011-07-14 09:09:03 +00:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
default:
|
2011-09-28 06:46:22 +00:00
|
|
|
return parent::$_details($type);
|
2011-07-14 09:09:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render a google chart of traffic
|
|
|
|
*/
|
2011-07-22 01:04:20 +00:00
|
|
|
public function graph_traffic($month=NULL) {
|
2012-12-10 21:48:30 +00:00
|
|
|
$google = GoogleChart::factory('Legacy')
|
|
|
|
->type('vertical_bar');
|
2011-07-14 09:09:03 +00:00
|
|
|
|
|
|
|
// If we came in via a post to show a particular month, then show that, otherwise show the yearly result
|
|
|
|
if (! is_null($month) AND trim($month)) {
|
2012-12-10 21:48:30 +00:00
|
|
|
$google->title(sprintf('DSL traffic usage for %s',$_POST['month']));
|
2011-07-14 09:09:03 +00:00
|
|
|
$traffic_data = $this->get_traffic_data_daily(strtotime($_POST['month'].'-01'));
|
|
|
|
|
|
|
|
foreach ($traffic_data as $k => $details)
|
2013-01-04 04:13:48 +00:00
|
|
|
$google->sdata(array('yl'=>($x=isset($friendly[$k]) ? $friendly[$k] : $k)),array($x=>$traffic_data[$k]));
|
2011-07-14 09:09:03 +00:00
|
|
|
|
|
|
|
foreach ($traffic_data as $k => $details)
|
2013-01-04 04:13:48 +00:00
|
|
|
$google->sdata(array('yr'=>($x=isset($friendly['cumulative'.$k]) ? $friendly['cumulative'.$k] : 'cumulative'.$k)),array($x=>$this->cumulative($traffic_data[$k])));
|
2011-07-14 09:09:03 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
// @todo Change the date to the last record date
|
2012-12-10 21:48:30 +00:00
|
|
|
$google->title(sprintf('Monthly DSL traffic usage as at %s',Config::date(strtotime('yesterday'))));
|
2011-07-14 09:09:03 +00:00
|
|
|
$traffic_data = $this->get_traffic_data_monthly();
|
|
|
|
|
|
|
|
foreach ($traffic_data as $k => $details)
|
2013-01-04 04:13:48 +00:00
|
|
|
$google->sdata(array('yl'=>($x=isset($friendly[$k]) ? $friendly[$k] : $k)),array($x=>$traffic_data[$k]));
|
2011-07-14 09:09:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (string)$google;
|
|
|
|
}
|
2011-07-22 01:04:20 +00:00
|
|
|
|
|
|
|
public function table_traffic($month=NULL) {
|
2011-09-28 06:46:22 +00:00
|
|
|
return View::factory('service/user/plugin/adsl/table_traffic')
|
2011-07-22 01:04:20 +00:00
|
|
|
->set('traffic',$this->traffic_month((! is_null($month) AND trim($month)) ? strtotime($month.'-01') : NULL,FALSE));
|
|
|
|
}
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
?>
|