This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/modules/adsl/classes/Model/ADSL/Supplier/Plan.php

111 lines
2.6 KiB
PHP
Raw Normal View History

2013-10-10 02:44:53 +00:00
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class supports ADSL Plans
*
* @package ADSL
* @category Models
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Model_ADSL_Supplier_Plan extends ORM_OSB {
// Relationships
protected $_belongs_to = array(
'supplier'=>array('model'=>'ADSL_Supplier'),
);
2013-10-10 02:44:53 +00:00
protected $_has_many = array(
'plan'=>array('model'=>'Product_Plugin_Adsl','far_key'=>'id'),
2013-10-10 02:44:53 +00:00
);
protected $_sorting = array(
'product_id'=>'ASC',
'product_desc'=>'ASC',
2013-10-10 02:44:53 +00:00
);
protected $_form = array('id'=>'id','value'=>'name()');
2013-10-10 02:44:53 +00:00
/**
* Filters used to format the display of values into friendlier values
2013-10-10 02:44:53 +00:00
*/
protected $_display_filters = array(
'base_cost'=>array(
array('Tax::add',array(':value')),
array('Currency::display',array(':value')),
),
'extra_down_peak'=>array(
array('Tax::add',array(':value')),
array('Currency::display',array(':value')),
),
'extra_down_offpeak'=>array(
array('Tax::add',array(':value')),
array('Currency::display',array(':value')),
),
'extra_up_peak'=>array(
array('Tax::add',array(':value')),
array('Currency::display',array(':value')),
),
'extra_up_offpeak'=>array(
array('Tax::add',array(':value')),
array('Currency::display',array(':value')),
),
'status'=>array(
array('StaticList_YesNo::get',array(':value',TRUE)),
),
);
// Map the table fields
private $_map = array(
'base_up_offpeak'=>'extra_up_offpeak',
'base_down_offpeak'=>'extra_down_offpeak',
'base_up_peak'=>'extra_up_peak',
'base_down_peak'=>'extra_down_peak',
);
private $_metrics = array(
'base_up_peak'=>'base_up_peak',
'base_up_offpeak'=>'base_up_offpeak',
'base_down_peak'=>'base_down_peak',
'base_down_offpeak'=>'base_down_offpeak',
);
/**
* Display the cost for extra traffic
*/
public function cost_extra(array $data=array(),$format=FALSE) {
$result = array();
if (! $data)
$data = $this->traffic_data();
foreach ($data as $k => $v)
$result[$k] = $this->display($this->_map[$k]);
return $format ? join('/',array_values($result)) : $result;
2013-10-10 02:44:53 +00:00
}
/**
* ADSL Plan Name
*/
2016-08-03 04:00:51 +00:00
public function name($variable=NULL) {
return sprintf('%s: %s',$this->product_id,$this->product_desc);
2013-10-08 02:34:56 +00:00
}
/**
* Collapse our traffic data into an array as per $this->_metric
*/
public function traffic_data() {
$result = array();
foreach ($this->_metrics as $metric=>$v) {
if (! isset($result[$v]))
$result[$v] = 0;
$result[$v] += $this->{$metric};
}
2013-10-10 02:44:53 +00:00
return $result;
2013-10-10 02:44:53 +00:00
}
}
?>