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/product/classes/Controller/Product.php
2013-03-20 23:04:51 +11:00

103 lines
2.7 KiB
PHP

<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides product categories
*
* @package Product
* @category Controllers
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Controller_Product extends Controller_TemplateDefault {
/**
* Show a list of product categories
*/
public function action_categorys() {
$output = '<div id="category">';
$output .= '<ul>';
foreach (ORM::factory('Product_Category')->list_active() as $pco) {
$a = '<h3>'.$pco->display('name').'</h3>';
$a .= '<p>'.$pco->description().'</p>';
$output .= '<li>'.HTML::anchor('product/category/'.$pco->id,$a).'</li>';
}
$output .= '</ul>';
$output .= '</div>';
$this->template->content = $output;
}
/**
* Show the available topics in a category
*
* @todo Only show categories according to their validity dates
* @todo Obey sort order
*/
public function action_category() {
$output = '';
$pco = ORM::factory('Product_Category',$this->request->param('id'));
if (! $pco->loaded())
HTTP::redirect('welcome/index');
if (! $pco->status AND ! Kohana::$config->load('debug')->show_inactive)
HTTP::redirect('welcome/index');
BreadCrumb::name($this->request->uri(),$pco->name);
BreadCrumb::url('product','product/categorys');
BreadCrumb::url('product/category','product/categorys');
foreach ($pco->products() as $po)
$output .= View::factory($this->viewpath().'/list_item')
->set('co',$pco)
->set('o',$po);
// If our output is blank, then there are no products
if (! $output)
$output = _('Sorry, no pages were found in this category, or your account is not authorized for this category.');
Block::add(array(
'title'=>sprintf('%s: %s',_('Category'),$pco->name),
'body'=>$output,
));
}
/**
* Show a product
*/
public function action_view() {
$id = $this->request->param('id');
$po = ORM::factory('Product',$id);
if (! $po->loaded())
HTTP::redirect('Product_Category/index');
BreadCrumb::name($this->request->uri(),$po->product_translate->find()->name);
BreadCrumb::url('product','product/categorys');
// Work out our category id for the control line
if (! empty($_GET['cid'])) {
$co = ORM::factory('Product_Category',$_GET['cid']);
// If the product category doesnt exist, or doesnt match the product
if (! $co->loaded() OR ! in_array($co->id,$po->avail_category))
HTTP::redirect('Product_Category/index');
BreadCrumb::name('product/view',$co->name);
BreadCrumb::url('product/view','product/category/'.$co->id);
}
Block::add(array(
'title'=>$po->description_short(),
'body'=>View::factory($this->viewpath())
->set('record',$po),
));
}
}
?>