<?php


/*
 * created on 16.10.2007
 * project: zf-konference
 * author: Vlastimil Vávrů (http://vavru.cz)
 * version: $
 */

class IndexController extends Zend_Controller_Action {
	private $_articleService;

	/**
	 * Initialization - invoked in constructor.
	 */
	public function init() {
		$this->_articleService = Zend_Registry :: get('articleService');
		$this->view->addHelperPath('../application/views/helpers', 'Venturia_View_Helper');
		$this->view->wwwroot = $this->_request->getBaseUrl();
	}

	/**
	 * The default action - show the home page.
	 */
	public function indexAction() {
		$page = max(0, ( int ) $this->_getParam('strana') - 1);
		$maxResults = $this->_getParam('strana') === 'all' ? null : 1;
		$firstResult = $page * $maxResults;
		$articles = $this->_articleService->findArticles(null, 'date desc', $maxResults, $firstResult);
		$this->view->articles = $articles;
		$this->view->page = $page;
		$this->view->url = $this->_request->getBaseUrl() . $this->_request->getPathInfo();

	}

	/**
	 * Show article detail page.
	 */
	public function articleAction() {
		$article = $this->_articleService->getArticleByRewriteString($this->_request->articleRewriteString);
		if ($article == null) {
			$this->_forward('error404', 'error');
			return;
		}

		$this->view->title = $article->name;
		$this->view->article = $article;
		$this->view->notices = $this->_helper->getHelper('FlashMessenger')->getMessages();
	}
}