<?php
/**
 * Generated: 2014-03-14 09:25:59
 * @author Rtn_Module_Tool
 */
class News_Controller_IndexController extends Main_News_Controller_IndexController {
	
	private $_images;
	
	public function init() {
                parent::init();
                $this->_images = 'public' . News_Module_Module::getInstance()->getSiteImgPath();
        }
	
	public function indexAction() {
		$this->view->news = News_Model_Newsentry::getLatest(3);
	}
	
	public function showAllAction(){
            $this->view->news = $allNews = R::findAll(News_Model_Newsentry::NAME, 'active = TRUE ORDER BY `order` DESC');
            $this->view->imagesPath = $this->_images;
        
        if (NULL === $page = $this->_getParam('page')){
                $page = 1;
		}
        
        $news = array();
        foreach($allNews as $beanNews){
                $news[] = $beanNews->export();
        }
        
        $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_Array($news));
        $paginator->setCurrentPageNumber($page);
        $paginator->setItemCountPerPage(3);
        
		$this->view->paginator = $paginator;
	}

	public function showAction() {
		if (NULL === $beanId = $this->_getParam('id')){
                        $this->_redirect('/');
		}
		
		$model = new News_Model_Newsentry();
		
		$this->view->new = $bean = $model->getNews($beanId);
		if($bean->extension){
			$originalSlidePath = $this->_images . $bean->id . '.' . $bean->extension;
			$this->view->image = '/' . $originalSlidePath;
		}else{
			$this->view->image = null;
		}
	}
}