More Standardisation work.

This commit is contained in:
Deon George
2016-08-03 14:00:51 +10:00
parent 85f08bbb0a
commit 5f84d2c14f
38 changed files with 276 additions and 100 deletions

View File

@@ -13,6 +13,8 @@
* + queue: PROVISION (to be provisioned)
*/
class Model_Service extends ORM_OSB {
private $_plugin = NULL;
// Relationships
protected $_has_one = array(
'service_billing'=>array('far_key'=>'account_billing_id','foreign_key'=>'id'),
@@ -79,11 +81,41 @@ class Model_Service extends ORM_OSB {
'price_override',
);
protected $_form = array('id'=>'id','value'=>'service_name()');
protected $_form = array('id'=>'id','value'=>'name()');
// Cache our calls to our plugins
public static $plugin = array();
/** REQUIRED ABSTRACT METHODS **/
/**
* Display the service product name
*/
public function name($variable=NULL) {
if (! $variable instanceOf Model_Language)
$variable = Company::instance()->language();
return $this->product->name($variable).(($x=$this->namesub($variable)) ? ': '.$x : '');
}
public function namesub($variable=NULL) {
return is_null($plugin=$this->_plugin()) ? '' : $plugin->name($variable);
}
public function refnum($short=FALSE) {
return ($short ? '' : sprintf('%02s-',Site::id())).sprintf('%05s',$this->id);
}
/** LOCAL METHODS **/
private function _plugin() {
if (! $this->_plugin AND $this->product->prod_plugin_file) {
$this->_plugin = ORM::factory(Kohana::classname(sprintf('Service_Plugin_%s',$this->product->prod_plugin_file)),array('service_id'=>$this->id));
}
return $this->_plugin;
}
/**
* Get the additional charges associated with this service
*/
@@ -200,13 +232,6 @@ class Model_Service extends ORM_OSB {
->order_by('date_stop','DESC');
}
/**
* Display the service product name
*/
public function name() {
return is_null($plugin=$this->plugin()) ? $this->product->title() : $plugin->name();
}
/**
* Returns the date that an item has been paid to
*/
@@ -270,13 +295,6 @@ class Model_Service extends ORM_OSB {
return $this->service_change->where_active()->where_open()->and_where('complete','!=',1)->or_where('complete','IS',null)->where_close()->find();
}
/**
* Return a descriptive name for this service
*/
public function service_name($chars=NULL) {
return HTML::abbr(is_null($x=$this->plugin()) ? $this->name() : $x->service_name(),$chars);
}
/**
* Return the service charge
*/
@@ -323,7 +341,7 @@ class Model_Service extends ORM_OSB {
/**
* Search for services matching a term
*/
public function list_autocomplete($term,$index,$value,array $label,array $limit=array(),array $options=NULL) {
public function list_autocomplete($term,$index,$value,array $label,array $limit=array(),array $options=array()) {
// We only show service numbers.
if (! is_numeric($term) AND (! $limit))
return array();
@@ -364,7 +382,7 @@ class Model_Service extends ORM_OSB {
if ($so->product->prod_plugin_file == $cat)
array_push($result,$so);
Sort::MASort($result,'service_name()');
Sort::MASort($result,array('name()'));
return $result;
}