Internal overhaul

This commit is contained in:
Deon George
2013-11-28 17:41:34 +11:00
parent 0ed5e5163d
commit f8a5b153cf
91 changed files with 1570 additions and 1619 deletions

View File

@@ -29,6 +29,8 @@ class Model_Service extends ORM_OSB {
'account'=>array(),
);
protected $_save_message = TRUE;
// Validation rules
public function rules() {
$x = Arr::merge(parent::rules(), array(
@@ -167,7 +169,7 @@ class Model_Service extends ORM_OSB {
$iio->find();
$x = (! $iio->loaded() AND $this->date_next_invoice) ? $this->date_next_invoice-86400 : $iio->date_stop;
$x = (! $iio->loaded() AND $this->date_next_invoice) ? $this->date_next_invoice-86400 : ($iio->total() < 0 ? $iio->date_start-86400 : $iio->date_stop);
return $format ? Config::date($x) : $x;
}
@@ -255,7 +257,7 @@ class Model_Service extends ORM_OSB {
* Return a descriptive name for this service
*/
public function service_name() {
return is_null($plugin=$this->plugin()) ? $this->name() : $plugin->service_name();
return is_null($x=$this->plugin()) ? $this->name() : $x->service_name();
}
/**
@@ -286,16 +288,17 @@ class Model_Service extends ORM_OSB {
case 'invoice_detail_items':
return is_null($plugin) ? array() : $plugin->_details($type);
case 'service_view':
return is_null($plugin) ? HTML::nbsp('') : $plugin->render_view();
default:
throw new Kohana_Exception('Unkown detail request :type',array(':type'=>$type));
}
}
public function service_view() {
return ! is_object($x=$this->plugin()) ? HTML::nbsp('') : $x->render_view();
}
public function transactions() {
return $this->invoice_item->order_by('date_start')->order_by('date_stop');
return $this->invoice_item->order_by('date_start','ASC')->order_by('product_id','ASC')->order_by('date_stop','ASC');
}
/** LIST FUNCTIONS **/

View File

@@ -13,6 +13,10 @@ abstract class Model_Service_Plugin extends ORM_OSB {
// Reset any sorting that may be defined in our parent
protected $_sorting = array();
protected $_belongs_to = array(
'service'=>array(),
);
/**
* When does our service expire
*/
@@ -26,56 +30,43 @@ abstract class Model_Service_Plugin extends ORM_OSB {
/**
* The table attributes that provide username/password values
*/
abstract public function password_value();
abstract public function username_value();
/**
* Get specific service details for use in other modules
* For Example: Invoice
*
* @todo Make the rendered items configurable
* @todo Change this method name, now that it is public
*/
public function _details($type) {
switch ($type) {
// Nothing to add for invoices
case 'invoice_detail_items':
return array();
default:
throw new Kohana_Exception('Unkown detail request :type',array(':type'=>$type));
}
}
abstract public function password();
abstract public function username();
/**
* Provide the button that launches the management of this service, generally from a 3rd party
*/
public function manage_button() {
protected function manage() {
// Dont show the manage button for expired or inactive services
if (! $this->service->status OR $this->service->expiring())
return FALSE;
static $k = '';
static $x = '';
// If $k is already set, we've rendered this JS
if ($k)
return TRUE;
// If $x is already set, we've rendered this JS
if (! $x) {
$x = Random::char();
$k = Random::char();
Session::instance()->set('manage_button',$k);
Session::instance()->set('manage_button',$x);
Script::add(array('type'=>'stdin','data'=>'
$(document).ready(function() {
var x=0;
$("button[name=submit]").click(function() {
var t=$(this).val().split(":");
if (x++) { alert("Session expired, please refresh the page!"); return false; }
$.getJSON("'.URL::link('user','service/ajaxmanage/'.$this->service_id,TRUE).'", { k: "'.$k.'",t: t[1] }, function(data) {
$.each(data, function(key, val) { $("#"+key+"_"+t[0]+"_"+t[1]).val(val); });
}).error(function() { alert("There was a problem with the request"); return false; }).success(
function() { $("form[id=id_"+t[0]+"_"+t[1]+"]").submit(); });
});
});'
));
Script::factory()
->type('stdin')
->data('
$(document).ready(function() {
var x=0;
$("button[name=submit]").click(function() {
var t=$(this).val().split(":");
if (x++) { alert("Session expired, please refresh the page!"); return false; }
$.getJSON("'.URL::link('user','service/ajaxmanage/'.$this->service_id,TRUE).'", { k: "'.$x.'",t: t[1] },
function(data) {$.each(data, function(key, val) { $("#"+key+"_"+t[0]+"_"+t[1]).val(val); }); })
.error(function() { alert("There was a problem with the request"); return false; })
.success(function() { $("form[id=id_"+t[0]+"_"+t[1]+"]").submit(); });
});
});'
);
}
return TRUE;
}
@@ -109,5 +100,23 @@ function() { $("form[id=id_"+t[0]+"_"+t[1]+"]").submit(); });
public function service_name() {
return sprintf('%s - %s',$this->service->product->title(),$this->name());
}
/**
* Get specific service details for use in other modules
* For Example: Invoice
*
* @todo Make the rendered items configurable
* @todo Change this method name, now that it is public
*/
public function _details($type) {
switch ($type) {
// Nothing to add for invoices
case 'invoice_detail_items':
return array();
default:
throw new Kohana_Exception('Unkown detail request :type',array(':type'=>$type));
}
}
}
?>