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/service/classes/model/service.php

161 lines
3.9 KiB
PHP
Raw Normal View History

2010-11-29 22:41:08 +00:00
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class supports Services
*
* @package OSB
* @subpackage Service
* @category Models
* @author Deon George
* @copyright (c) 2010 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Model_Service extends ORMOSB {
// Relationships
protected $_has_many = array(
'invoice'=>array('through'=>'invoice_item'),
);
protected $_has_one = array(
2011-07-13 22:59:32 +00:00
'service_adsl'=>array('far_key'=>'id'),
2011-07-14 09:09:03 +00:00
'service_domain'=>array('far_key'=>'id'),
2010-11-29 22:41:08 +00:00
);
protected $_belongs_to = array(
'product'=>array(),
'account'=>array(),
);
2011-05-14 07:35:33 +00:00
/**
* Filters used to format the display of values into friendlier values
*/
protected $_display_filters = array(
'active'=>array(
array('StaticList_YesNo::display',array(':value')),
),
2011-07-14 09:09:03 +00:00
'date_last_invoice'=>array(
array('Config::date',array(':value')),
),
2011-05-14 07:35:33 +00:00
'date_next_invoice'=>array(
array('Config::date',array(':value')),
),
'recur_schedule'=>array(
array('StaticList_RecurSchedule::display',array(':value')),
),
2010-11-29 22:41:08 +00:00
'price'=>array(
2011-05-14 07:35:33 +00:00
array('Tax::add',array(':value')),
array('Currency::display',array(':value')),
2010-11-29 22:41:08 +00:00
),
);
2011-07-14 09:09:03 +00:00
/**
* The service_name should be implemented in child objects.
* It renders the name of the service, typically used on invoice
*/
protected function _service_name() {
throw new Kohana_Exception(':method not defined in child class :class',array(':method'=>__METHOD__,':class'=>get_class($this)));
}
/**
* The service_view should be implemented in child objects.
* It renders the details of the ordered service
*/
protected function _service_view() {
throw new Kohana_Exception(':method not defined in child class :class',array(':method'=>__METHOD__,':class'=>get_class($this)));
}
/**
* The _details should be implemented in child objects.
*/
protected function _details($type) {
throw new Kohana_Exception(':method not defined in child class :class',array(':method'=>__METHOD__,':class'=>get_class($this)));
}
protected function _admin_update() {
throw new Kohana_Exception(':method not defined in child class :class',array(':method'=>__METHOD__,':class'=>get_class($this)));
}
/**
* Return the object of the product plugin
*/
private function plugin() {
2011-07-14 09:09:03 +00:00
if (! $this->product->prod_plugin_file)
return NULL;
if (! is_numeric($this->product->prod_plugin_data))
throw new Kohana_Exception('Missing plugin_id for :product (:type)',array(':product'=>$this->product->id,':type'=>$this->product->prod_plugin_file));
$spn = sprintf('%s_%s',get_class($this),$this->product->prod_plugin_file);
return new $spn(array('service_id'=>$this->id));
}
2010-11-29 22:41:08 +00:00
/**
* Display the service number
*/
2011-07-14 09:09:03 +00:00
public function id() {
2010-11-29 22:41:08 +00:00
return sprintf('%05s',$this->id);
}
2011-07-14 09:09:03 +00:00
/**
* Display the service product name
*/
public function name() {
return $this->product->name();
}
/**
* Display the product feature summary
*/
public function product_feature_summary() {
return $this->product->feature_summary();
}
/**
* Display the service details
*/
public function service_view() {
if (is_null($plugin = $this->plugin()))
return HTML::nbsp('');
2010-11-29 22:41:08 +00:00
else
2011-07-14 09:09:03 +00:00
return $plugin->_service_view();
2010-11-29 22:41:08 +00:00
}
2011-07-14 09:09:03 +00:00
public function service_name() {
if (is_null($plugin = $this->plugin()))
return $this->name();
else
return $plugin->_service_name();
}
/**
* Render some details for specific calls, eg: invoice
*/
public function details($type) {
switch ($type) {
case 'invoice':
if (is_null($plugin = $this->plugin()))
return array();
else
return $plugin->_details($type);
break;
default:
throw new Kohana_Exception('Unkown detail request :type',array(':type'=>$type));
}
}
public function admin_update() {
if (is_null($plugin = $this->plugin()))
return NULL;
else
return $plugin->_admin_update();
2010-11-29 22:41:08 +00:00
}
// @todo To implement
/**
* Calculate the tax for this item
*/
public function tax() {
return $this->price * .1;
}
}
?>