99 lines
2.6 KiB
PHP
99 lines
2.6 KiB
PHP
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
/**
|
|
* This class provides product categories
|
|
*
|
|
* @package OSB
|
|
* @subpackage Page
|
|
* @category Controllers
|
|
* @author Deon George
|
|
* @copyright (c) 2010 Deon George
|
|
* @license http://dev.leenooks.net/license.html
|
|
*/
|
|
class Controller_Product extends Controller_TemplateDefault {
|
|
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>';
|
|
$output .= HTML::anchor('product/category/'.$pco->id,$a);
|
|
$output .= '</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() {
|
|
$id = $this->request->param('id');
|
|
|
|
$cat = ORM::factory('Product_Category',$id);
|
|
|
|
if (! $cat->loaded())
|
|
HTTP::redirect('welcome/index');
|
|
|
|
BreadCrumb::name($this->request->uri(),$cat->name);
|
|
BreadCrumb::url('product','product/categorys');
|
|
BreadCrumb::url('product/category','product/categorys');
|
|
|
|
Block::add(array(
|
|
'title'=>sprintf('%s: %s',_('Category'),$cat->name),
|
|
'body'=>View::factory($this->viewpath().'/view')
|
|
->set('results',$this->_get_category($cat->id))
|
|
->set('cat',$cat->id),
|
|
));
|
|
}
|
|
|
|
/**
|
|
* Obtain a list of pages in a category
|
|
*/
|
|
private function _get_category($id) {
|
|
return ORM::factory('Product')->list_category($id);
|
|
}
|
|
|
|
/**
|
|
* 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,unserialize($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->product_translate->find()->description_short,
|
|
'body'=>View::factory($this->viewpath())
|
|
->set('record',$po),
|
|
));
|
|
}
|
|
}
|
|
?>
|