Modules

Controller_Comments
extends Controller
extends Kohana_Controller

Comment controller

package
Gleez
category
Comment
author
Sandeep Sangamreddi - Gleez
copyright
© 2011 Gleez Technologies
license
http://gleezcms.org/license

Class declared in MODPATH/gleez/classes/controller/comments.php on line 12.

Properties

public Request $request

Request that created the controller

public Response $response

The response that will be returned from controller

protected $config

protected $group

protected $model

protected $per_page

protected $supported_formats

protected $view

Methods

public action_public( ) (defined in Controller_Comments)

Retrieve public list of good comments

Source Code

public function action_public()
       {
	$id = $this->request->param('id', 0);

	// Comment must have a parent
	if ($id == 0)
	{
		Kohana::$log->add(LOG::INFO, 'Attempt to load all public comments without a defined parent');
		//$this->request->response = FALSE;
		return;
	}
	else
	{
		$this->create_list('publish', FALSE);
	}
}

public before( ) (defined in Controller_Comments)

Perform format check

Source Code

public function before()
       {
	// Make sure request is an internal request
	if ($this->request === Request::initial())
	{
		Kohana::$log->add(LOG::ERROR, 'Attempt was made to access comments controller externally');
		$this->request->redirect('');
	}

	// Test to ensure the format requested is supported
	//if ( ! in_array($this->request->param('format'), $this->supported_formats))
	//	throw new Kohana_Exception('File not found');

               // Get group settings
	$group = $this->request->param('group');
	$config = Kohana::$config->load($group);
	$this->per_page = $config['comments_per_page'];
	//$this->view     = $config['view'];
	$this->config   = $config;
	$this->group   = $group;

	return parent::before();
}

public __construct( Request $request , Response $response ) (defined in Kohana_Controller)

Creates a new controller instance. Each controller must be constructed with the request object that created it.

Parameters

  • Request $request required - Request that created the controller
  • Response $response required - The request's response

Return Values

  • void

Source Code

public function __construct(Request $request, Response $response)
{
	// Assign the request to the controller
	$this->request = $request;

	// Assign a response to the controller
	$this->response = $response;
}

public after( ) (defined in Kohana_Controller)

Automatically executed after the controller action. Can be used to apply transformation to the request response, add extra output, and execute other custom code.

Return Values

  • void

Source Code

public function after()
{
	// Nothing by default
}

protected create_list( ) (defined in Controller_Comments)

List comments

Source Code

protected function create_list($state = 'publish', $admin = FALSE, $uri = '')
{
               // Get parent id
               $parent_id = (int) $this->request->param('id', 0);
       
               $posts = ORM::factory('comment')->where('status', '=', $state);

               if ( $parent_id )
	{
		$posts->where('post_id', '=', $parent_id);
	
		$uri = $source = $this->group.'/'.$parent_id;
		$uri = Path::alias($source);
	}
       
               // Get total number of comments
               $total  = $posts->reset(FALSE)->count_all();

	// Check if there are any comments to display
	if ($total == 0) return;

               // Determine pagination offset
	$page   = $this->request->param('page', 1);
	$offset = ($page - 1) * $this->per_page;

	// Create pagination
	$pagination = Pagination::factory(array(
		'current_page'   => array('source'=>'cms', 'key'=>'page'),
		'total_items'    => $total,
		'items_per_page' => $this->per_page,
		'uri'		 => $uri,
	));
       
               // Execute query               
               $comments = $posts->order_by('created', 'ASC')->limit($this->per_page)->offset($offset)->find_all();
       
               // If no comments found (bad offset/page)
	if (count($comments) == 0)
	{
		Kohana::$log->add(LOG::INFO, 'No comments found for state='.$state.', page='.$page);
		//$this->response->body = FALSE;
		return;
	}

               /*// Setup admin view
	$admin_view = View::factory($this->view.'/admin')
		->set('is_ham', ($state == 'ham'))
		->set('is_spam', ($state == 'spam'));
               */
       
	// Setup view with data
	$list = View::factory($this->view.'/list')
                               ->set('count', $total)
                               ->set('pagination', $pagination)
                               ->set('comments', $comments);

	// Set request response
	$this->response->body( $list );
}
Documentation comments powered by Disqus