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

102 lines
2.7 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-11-09 23:13:57 +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
*/
2012-11-09 23:13:57 +00:00
public function action_category() {
$output = '';
$pco = ORM::factory('Product_Category',$this->request->param('id'));
2012-11-09 23:13:57 +00:00
if (! $pco->loaded())
HTTP::redirect('welcome/index');
2010-11-29 22:41:08 +00:00
if (! $pco->status AND ! Kohana::$config->load('debug')->show_inactive)
2012-11-09 23:13:57 +00:00
HTTP::redirect('welcome/index');
2010-11-29 22:41:08 +00:00
BreadCrumb::name($this->request->uri(),$pco->name);
2012-11-09 23:13:57 +00:00
BreadCrumb::url('product','product/categorys');
BreadCrumb::url('product/category','product/categorys');
2010-11-29 22:41:08 +00:00
foreach ($pco->products() as $po)
$output .= View::factory($this->viewpath().'/list_item')
->set('co',$pco)
->set('o',$po);
2010-11-29 22:41:08 +00:00
// 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,
));
2010-11-29 22:41:08 +00:00
}
/**
* Show a product
*/
2012-11-09 23:13:57 +00:00
public function action_view() {
$id = $this->request->param('id');
$po = ORM::factory('Product',$id);
2010-11-29 22:41:08 +00:00
if (! $po->loaded())
2012-11-09 23:13:57 +00:00
HTTP::redirect('Product_Category/index');
2010-11-29 22:41:08 +00:00
2012-11-09 23:13:57 +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'])) {
2012-11-09 23:13:57 +00:00
$co = ORM::factory('Product_Category',$_GET['cid']);
2010-11-29 22:41:08 +00:00
// If the product category doesnt exist, or doesnt match the product
if (! $co->loaded() OR ! in_array($co->id,$po->avail_category))
2012-11-09 23:13:57 +00:00
HTTP::redirect('Product_Category/index');
2010-11-29 22:41:08 +00:00
2012-11-09 23:13:57 +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),
));
}
}
?>