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

95 lines
2.5 KiB
PHP
Raw Normal View History

2010-11-29 22:41:08 +00:00
<?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 {
2012-01-29 06:23:24 +00:00
public function action_categorys() {
$output = '<div id="category">';
$output .= '<ul>';
2012-08-01 12:43:33 +00:00
foreach (ORM::factory('product_category')->list_active() as $pco) {
2012-01-29 06:23:24 +00:00
$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;
}
2010-11-29 22:41:08 +00:00
/**
* 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) {
$cat = ORM::factory('product_category',$id);
if (! $cat->loaded())
2011-05-14 07:35:33 +00:00
Request::current()->redirect('welcome/index');
2010-11-29 22:41:08 +00:00
Breadcrumb::name($this->request->uri(),$cat->name);
Breadcrumb::url('product','product/categorys');
Breadcrumb::url('product/category','product/categorys');
2010-11-29 22:41:08 +00:00
Block::add(array(
'title'=>sprintf('%s: %s',_('Category'),$cat->name),
'body'=>View::factory($this->viewpath().'/view')
2010-11-29 22:41:08 +00:00
->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);
2010-11-29 22:41:08 +00:00
}
/**
* Show a product
*/
public function action_view($id) {
$po = ORM::factory('product',$id);
if (! $po->loaded())
2011-05-14 07:35:33 +00:00
Request::current()->redirect('product_category/index');
2010-11-29 22:41:08 +00:00
Breadcrumb::name($this->request->uri(),$po->product_translate->find()->name);
Breadcrumb::url('product','product/categorys');
2010-11-29 22:41:08 +00:00
// 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
2011-12-27 01:06:04 +00:00
if (! $co->loaded() OR ! in_array($co->id,unserialize($po->avail_category)))
2011-05-14 07:35:33 +00:00
Request::current()->redirect('product_category/index');
2010-11-29 22:41:08 +00:00
Breadcrumb::name('product/view',$co->name);
Breadcrumb::url('product/view','product/category/'.$co->id);
2010-11-29 22:41:08 +00:00
}
Block::add(array(
'title'=>$po->product_translate->find()->description_short,
'body'=>View::factory($this->viewpath())
2010-11-29 22:41:08 +00:00
->set('record',$po),
));
}
}
?>