Minor fixes to statement, services and internal things
Many misc updates
This commit is contained in:
@@ -82,10 +82,10 @@ class Model_Service_Plugin_ADSL extends Model_Service_Plugin {
|
||||
/**
|
||||
* Calculate the total traffic used in a month
|
||||
*/
|
||||
private function get_traffic_data_month($period=NULL) {
|
||||
private function get_traffic_data_month($period=NULL,$cache=NULL) {
|
||||
$return = array();
|
||||
|
||||
foreach ($this->get_traffic_data_daily($period,TRUE) as $tdata)
|
||||
foreach ($this->get_traffic_data_daily($period,TRUE,$cache) as $tdata)
|
||||
foreach ($tdata as $k => $v)
|
||||
if (isset($return[$k]))
|
||||
$return[$k] += $v;
|
||||
@@ -98,49 +98,30 @@ class Model_Service_Plugin_ADSL extends Model_Service_Plugin {
|
||||
/**
|
||||
* Return an array of the data used in a month by day
|
||||
*/
|
||||
public function get_traffic_data_daily($period=NULL,$bydate=FALSE) {
|
||||
$cacheable = TRUE;
|
||||
public function get_traffic_data_daily($period=NULL,$bydate=FALSE,$cache=NULL) {
|
||||
$return = array();
|
||||
|
||||
// @temp - caching is broken?
|
||||
$cache=0;
|
||||
if (is_null($period))
|
||||
$period = strtotime('yesterday');
|
||||
|
||||
$cache = $this->service_id.date('M-Y',$period).$bydate;
|
||||
|
||||
// @todo This cache needs to be improved, so that we cache the query regardless of bydate setting
|
||||
if ($cacheable AND $return = Cache::instance(Config::cachetype())->get($cache))
|
||||
return $return;
|
||||
|
||||
$return = array();
|
||||
|
||||
$to = ORM::factory('service_plugin_adsl_traffic')
|
||||
$t = ORM::factory('service_plugin_adsl_traffic')
|
||||
->where('service','=',$this->service_username)
|
||||
->and_where('date','>=',date('Y-m-d',mktime(0,0,0,date('m',$period),1,date('Y',$period))))
|
||||
->and_where('date','<=',date('Y-m-d',strtotime('last day of '.date('M Y',$period))));
|
||||
->and_where('date','<=',date('Y-m-d',strtotime('last day of '.date('M Y',$period))))
|
||||
->cached($cache);
|
||||
|
||||
foreach ($to->find_all() as $traffic) {
|
||||
// Roll up the charges according to the configuration
|
||||
$data = ADSL::allowance(array(
|
||||
'base_down_peak'=>is_null($this->service->product->plugin()->base_down_peak) ? NULL : $traffic->down_peak,
|
||||
'base_down_offpeak'=>is_null($this->service->product->plugin()->base_down_offpeak) ? NULL : $traffic->down_offpeak,
|
||||
'base_up_peak'=>is_null($this->service->product->plugin()->base_up_peak) ? NULL : $traffic->up_peak,
|
||||
'base_up_offpeak'=>is_null($this->service->product->plugin()->base_up_offpeak) ? NULL : $traffic->up_offpeak,
|
||||
'extra_down_peak'=>$this->service->product->plugin()->extra_down_peak,
|
||||
'extra_down_offpeak'=>$this->service->product->plugin()->extra_down_offpeak,
|
||||
'extra_up_peak'=>$this->service->product->plugin()->extra_up_peak,
|
||||
'extra_up_offpeak'=>$this->service->product->plugin()->extra_up_offpeak,
|
||||
));
|
||||
foreach ($t->find_all() as $to) {
|
||||
$day = date('d',strtotime($to->date));
|
||||
|
||||
$day = date('d',strtotime($traffic->date));
|
||||
if ($bydate)
|
||||
$return[$day] = $data;
|
||||
$return[$day] = $to->traffic($this->service->product->plugin());
|
||||
else
|
||||
foreach ($data as $k => $v)
|
||||
foreach ($to->traffic($this->service->product->plugin()) as $k => $v)
|
||||
$return[$k][$day] = $v;
|
||||
}
|
||||
|
||||
// Cache our data
|
||||
// @todo Our cache time should be a configuration parameter
|
||||
Cache::instance(Config::cachetype())->set($cache,$return,43200);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
@@ -148,19 +129,12 @@ class Model_Service_Plugin_ADSL extends Model_Service_Plugin {
|
||||
* Return an array of the data used in a year by month
|
||||
*/
|
||||
public function get_traffic_data_monthly($period=NULL,$bydate=FALSE) {
|
||||
$cacheable = TRUE;
|
||||
$return = array();
|
||||
|
||||
if (is_null($period))
|
||||
$period = strtotime('yesterday');
|
||||
|
||||
$cache = $this->service_id.date('M-Y',$period).$bydate.__METHOD__;
|
||||
|
||||
// @todo This cache needs to be improved, so that we cache the query regardless of bydate setting
|
||||
if ($cacheable AND $return = Cache::instance(Config::cachetype())->get($cache))
|
||||
return $return;
|
||||
|
||||
$return = array();
|
||||
|
||||
$to = ORM::factory('service_plugin_adsl_traffic')
|
||||
$t = ORM::factory('service_plugin_adsl_traffic')
|
||||
->select(
|
||||
array('date_format(date,\'%y-%m\')','month'),
|
||||
array('sum(up_peak)','up_peak'),
|
||||
@@ -173,36 +147,19 @@ class Model_Service_Plugin_ADSL extends Model_Service_Plugin {
|
||||
->and_where('date','<=',date('Y-m-d',strtotime('last day of '.date('M Y',$period))))
|
||||
->group_by('date_format(date,\'%Y-%m\')');
|
||||
|
||||
foreach ($to->find_all() as $traffic) {
|
||||
// Roll up the charges according to the configuration
|
||||
$data = ADSL::allowance(array(
|
||||
'base_down_peak'=>is_null($this->service->product->plugin()->base_down_peak) ? NULL : $traffic->down_peak,
|
||||
'base_down_offpeak'=>is_null($this->service->product->plugin()->base_down_offpeak) ? NULL : $traffic->down_offpeak,
|
||||
'base_up_peak'=>is_null($this->service->product->plugin()->base_up_peak) ? NULL : $traffic->up_peak,
|
||||
'base_up_offpeak'=>is_null($this->service->product->plugin()->base_up_offpeak) ? NULL : $traffic->up_offpeak,
|
||||
'extra_down_peak'=>$this->service->product->plugin()->extra_down_peak,
|
||||
'extra_down_offpeak'=>$this->service->product->plugin()->extra_down_offpeak,
|
||||
'extra_up_peak'=>$this->service->product->plugin()->extra_up_peak,
|
||||
'extra_up_offpeak'=>$this->service->product->plugin()->extra_up_offpeak,
|
||||
));
|
||||
|
||||
foreach ($t->find_all() as $to)
|
||||
if ($bydate)
|
||||
$return[$traffic->month] = $data;
|
||||
$return[$to->month] = $to->traffic($this->service->product->plugin());
|
||||
else
|
||||
foreach ($data as $k => $v)
|
||||
$return[$k][$traffic->month] = $v;
|
||||
}
|
||||
|
||||
// Cache our data
|
||||
// @todo Our cache time should be a configuration parameter
|
||||
Cache::instance(Config::cachetype())->set($cache,$return,43200);
|
||||
foreach ($to->traffic($this->service->product->plugin()) as $k => $v)
|
||||
$return[$k][$to->month] = $v;
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function traffic_month($month,$string=TRUE) {
|
||||
return $string ? implode('/',$this->get_traffic_data_month($month)) :
|
||||
$this->get_traffic_data_month($month);
|
||||
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);
|
||||
}
|
||||
|
||||
public function traffic_lastmonth($string=TRUE) {
|
||||
@@ -218,9 +175,9 @@ class Model_Service_Plugin_ADSL extends Model_Service_Plugin {
|
||||
$return = array();
|
||||
|
||||
if (is_null($date))
|
||||
$date = strtotime('last month');
|
||||
$date = strtotime('last month')-86400;
|
||||
|
||||
foreach ($this->traffic_month($date,FALSE) as $k => $v) {
|
||||
foreach ($this->traffic_month($date,FALSE,0) as $k => $v) {
|
||||
// We shouldnt need to eval for nulls, since the traffic calc does that
|
||||
if ($all OR ($v > $this->service->product->plugin()->$k)) {
|
||||
$return[$k]['allowance'] = $this->service->product->plugin()->$k;
|
||||
|
@@ -25,5 +25,19 @@ class Model_Service_Plugin_ADSL_Traffic extends ORMOSB {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function traffic(Model_Product_Plugin_ADSL $plan) {
|
||||
// Roll up the charges according to the product plan configuration
|
||||
return ADSL::allowance(array(
|
||||
'base_down_peak'=>is_null($plan->base_down_peak) ? NULL : $this->down_peak,
|
||||
'base_down_offpeak'=>is_null($plan->base_down_offpeak) ? NULL : $this->down_offpeak,
|
||||
'base_up_peak'=>is_null($plan->base_up_peak) ? NULL : $this->up_peak,
|
||||
'base_up_offpeak'=>is_null($plan->base_up_offpeak) ? NULL : $this->up_offpeak,
|
||||
'extra_down_peak'=>$plan->extra_down_peak,
|
||||
'extra_down_offpeak'=>$plan->extra_down_offpeak,
|
||||
'extra_up_peak'=>$plan->extra_up_peak,
|
||||
'extra_up_offpeak'=>$plan->extra_up_offpeak,
|
||||
));
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -43,8 +43,8 @@ class Service_Traffic_ADSL_ExetelPE extends Service_Traffic_ADSL {
|
||||
// Start Session
|
||||
$request = Request::factory($this->so->stats_url)
|
||||
->method('POST')
|
||||
->post($this->login_user_field,$so->plugin()->service_username)
|
||||
->post($this->login_pass_field,$so->plugin()->service_password)
|
||||
->post($this->login_user_field,$so->plugin()->service_username == NULL ? '' : $so->plugin()->service_username)
|
||||
->post($this->login_pass_field,$so->plugin()->service_password == NULL ? '' : $so->plugin()->service_password)
|
||||
->post('doLogin',1)
|
||||
->post('submit','Login');
|
||||
|
||||
|
Reference in New Issue
Block a user