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.php

78 lines
1.9 KiB
PHP
Raw Permalink Normal View History

2013-10-10 02:44:53 +00:00
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class supports ADSL Suppliers
*
* @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 extends ORM {
protected $_updated_column = FALSE;
2013-10-10 02:44:53 +00:00
// Relationships
protected $_has_many = array(
2013-11-28 06:41:34 +00:00
'plan'=>array('model'=>'ADSL_Supplier_Plan','foreign_key'=>'supplier_id','far_key'=>'id'),
2013-10-11 04:02:56 +00:00
'traffic'=>array('model'=>'Service_Plugin_Adsl_Traffic','foreign_key'=>'supplier_id','far_key'=>'id'),
2013-10-10 02:44:53 +00:00
);
2013-10-08 02:34:56 +00:00
protected $_form = array('id'=>'id','value'=>'name');
2013-10-10 02:44:53 +00:00
/**
* Return a list of plans that we provide by this supplier
* @deprecated
2013-10-10 02:44:53 +00:00
*/
2013-10-08 02:34:56 +00:00
public function plans($active=TRUE) {
2013-10-10 02:44:53 +00:00
$result = array();
2013-10-08 02:34:56 +00:00
foreach ($this->find_plans($active)->find_all() as $po)
foreach ($po->admin_plan()->find_all() as $apo)
2013-10-10 02:44:53 +00:00
$result[$apo->id] = $apo;
return $result;
}
2013-10-08 02:34:56 +00:00
/**
* Return the class that takes care of processing invoices
*/
public function billing() {
$b = Kohana::classname('ADSL_Billing_'.$this->name);
if (! class_exists($b))
throw HTTP_Exception::factory(501,'Billing class doesnt exist for :name',array(':name'=>$this->name));
return new $b;
}
/**
* Return a list of plans that this supplier makes available
*/
public function find_plans($active=TRUE) {
2013-11-28 06:41:34 +00:00
return $active ? $this->plan->where_active() : $this->plan;
2013-10-08 02:34:56 +00:00
}
2013-10-10 02:44:53 +00:00
/**
* Return a list of services for this supplier
*
* @param boolean $active TRUE List only active Services|False List all services
*/
public function services($active=TRUE) {
$result = array();
2013-10-10 02:44:53 +00:00
2013-10-08 02:34:56 +00:00
foreach ($this->find_plans(FALSE)->find_all() as $aspo) {
foreach ($aspo->plan->find_all() as $apo) {
2013-11-28 06:41:34 +00:00
foreach ($apo->products(FALSE) as $po) {
foreach ($po->service->list_active() as $so) {
array_push($result,$so);
}
}
}
}
2013-10-10 02:44:53 +00:00
return $result;
2013-10-10 02:44:53 +00:00
}
}
?>