Current File : /home/users/barii/public_html/finansenl.com.pl/wodki/application/classes/Controller/News.php
<?php defined('SYSPATH') or die('No direct script access.');

class Controller_News extends Controller_Frontend {

	public function action_index()
	{
		$page = !empty($_GET['page']) ? addslashes($_GET['page']) : 1;
		$page = ($page-1)*Kohana::$config->load('site.itemPerPage');
		
		$this->template->title = __t('News');
		
		
		$news = ORM::Factory('News')
			->where('status','=', 1);
			
		$users_test = clone $news;
		$users_test = $users_test->find_all();
		
		$news = $news
			->limit(Kohana::$config->load('site.itemPerPage'))
			->offset($page)
			->find_all();
		
		
		$this->pagination = new Pagination(array(
			'items_per_page' => Kohana::$config->load('site.itemPerPage'), 
			'style' => 'kogio',
			'total_items' => $users_test->count()
		));
		
        $this->template->content = View::factory('news/index')
									->bind('news', $news)
									
									->bind('pagination', $this->pagination)
									->bind('page', $page);
	}
	
	public function action_show()
	{
		$id = Request::current()->param('id');
		
		$news = ORM::Factory('News', $id);
		
		$news_list = ORM::Factory('News')
			->where('status','=', 1);
			
		$news_list = $news_list->find_all();
		
		$today_date_1 = strtotime( date('d-m-Y 00:00:00') );
		$today_date_2 = strtotime( date('d-m-Y 23:59:59') );
			
			$news_today = ORM::Factory('News')
				->where('user_id','=', $news->user_id)
				->where('date','>=', $today_date_1)
				->where('date','<=', $today_date_2)
				->find_all();
				
				
		$this->template->title = __t('Aktualności');
        $this->template->content = View::factory('news/show')
									->bind('news', $news)
									->bind('news_today', $news_today)
									->bind('news_list', $news_list);
	}
	
	
}