Multi enhancements, including auto serialization, product editing

This commit is contained in:
Deon George
2012-03-30 15:13:01 +11:00
parent d9c3394b0f
commit 6807b6ab52
30 changed files with 445 additions and 115 deletions

View File

@@ -41,6 +41,19 @@ class Model_Product extends ORMOSB {
),
);
// Our attributes that are arrays, we'll convert/unconvert them
protected $_serialize_column = array(
'price_group',
);
public function rules() {
return array_merge(parent::rules(),array(
'price_group'=>array(
array('ORMOSB::serialize_array',array(':model',':field',':value')),
),
));
}
/**
* Return the object of the product plugin
*/
@@ -81,14 +94,14 @@ class Model_Product extends ORMOSB {
// @todo Need to work out our default groups elsewhere, not in product
// All users are members of the all user group "0"
$groups = array(0);
$pg = unserialize($this->price_group);
if (Auth::instance()->logged_in())
foreach (Auth::instance()->get_user()->group->find_all() as $go)
array_push($groups,$go->id);
// Work out the best price for the user
$price = array();
foreach (unserialize($this->price_group) as $bill_freq => $pg) {
if (is_array($this->price_group))
foreach ($this->price_group as $bill_freq => $pg) {
if (isset($pg['show']) AND $pg['show'])
foreach ($groups as $gid) {
if (! empty($pg[$gid])) {
@@ -133,6 +146,50 @@ class Model_Product extends ORMOSB {
echo '';
}
/**
* Enable the plugin to store data
*/
public function admin_update() {
if (is_null($plugin = $this->plugin()))
return NULL;
else
return $plugin->admin_update();
}
/**
* Is price shown for a specific period
*/
public function isPriceShown($p) {
$x = $this->keyget('price_group',$p);
return (isset($x['show']) AND $x['show']) ? TRUE : FALSE;
}
/**
* Return the configured price groups for this product
*/
public function availPriceGroups() {
// @todo This needs to be worked out dynamically
return array(0,2);
}
/**
* Return the available pricing options
*/
public function availPriceOptions() {
// @todo This needs to be worked out dynamically
return array('price_base','price_setup');
}
/**
* Return the price for the particle group and price option for the period
*/
public function price($grp,$period,$option) {
$x = $this->keyget('price_group',$period);
return isset($x[$grp][$option]) ? $x[$grp][$option] : NULL;
}
/**
* List the number of services using this product
*/
@@ -151,14 +208,20 @@ class Model_Product extends ORMOSB {
* Return the products for a given category
* @todo This shouldnt be here.
*/
public function list_category($cat) {
public function list_category($cat,$active=TRUE) {
$results = array();
foreach ($this->where('active','=',TRUE)->find_all() as $po) {
if ($active)
$cats = $this->where('active','=',TRUE);
else
$cats = $this;
foreach ($cats->find_all() as $po) {
if ($c = unserialize($po->avail_category) AND in_array($cat,$c))
array_push($results,$po);
}
Sort::MAsort($results,'position,price_base');
return $results;
}
}

View File

@@ -0,0 +1,20 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class product access to product category translation.
*
* @package OSB
* @subpackage Product
* @category Models
* @author Deon George
* @copyright (c) 2010 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Model_Product_Category_Translate extends ORMOSB {
protected $_table_name = 'product_cat_translate';
protected $_belongs_to = array(
'product_category'=>array(),
);
}
?>

View File

@@ -14,6 +14,12 @@ abstract class Model_Product_Plugin extends ORMOSB {
// Reset any sorting that may be defined in our parent
protected $_sorting = array();
/**
* The admin_update should be implemented in plugins.
* It is used to update the plugin specific product information
*/
abstract public function admin_update();
/**
* The feature summary should be implemented in plugins.
* It is displayed on the product overview page, as a summary of the products features.

View File

@@ -11,6 +11,8 @@
* @license http://dev.osbill.net/license.html
*/
class Model_Product_Translate extends ORMOSB {
protected $_updated_column = FALSE;
protected $_belongs_to = array(
'product'=>array(),
);