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 {
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>sprintf('%s: %s',_('Category'),$cat->name),
|
2011-12-21 01:39:21 +00:00
|
|
|
'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) {
|
2011-09-28 06:46:22 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
// 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_id)))
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>$po->product_translate->find()->description_short,
|
2011-12-21 01:39:21 +00:00
|
|
|
'body'=>View::factory($this->viewpath())
|
2010-11-29 22:41:08 +00:00
|
|
|
->set('record',$po),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|