<?php
/**
 * Netgo_News extension
 * 
 * NOTICE OF LICENSE
 * 
 * This source file is subject to the MIT License
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/mit-license.php
 * 
 * @category       Netgo
 * @package        Netgo_News
 * @copyright      Copyright (c) 2015
 * @license        http://opensource.org/licenses/mit-license.php MIT License
 */
/**
 * News front contrller
 *
 * @category    Netgo
 * @package     Netgo_News
 * @author      Ultimate Module Creator
 */
class Netgo_News_NewsController
    extends Mage_Core_Controller_Front_Action {
    /**
      * default action
      * @access public
      * @return void
      * @author Ultimate Module Creator
      */
    public function indexAction(){
         $this->loadLayout();
         $this->_initLayoutMessages('catalog/session');
         $this->_initLayoutMessages('customer/session');
         $this->_initLayoutMessages('checkout/session');
         if (Mage::helper('netgo_news/news')->getUseBreadcrumbs()){
             if ($breadcrumbBlock = $this->getLayout()->getBlock('breadcrumbs')){
                 $breadcrumbBlock->addCrumb('home', array(
                            'label'    => Mage::helper('netgo_news')->__('Home'),
                            'link'     => Mage::getUrl(),
                        )
                 );
                 $breadcrumbBlock->addCrumb('newss', array(
                            'label'    => Mage::helper('netgo_news')->__('News'),
                            'link'    => '',
                    )
                 );
             }
         }
        $this->renderLayout();
    }
    /**
     * init News
     * @access protected
     * @return Netgo_News_Model_Entity
     * @author Ultimate Module Creator
     */
    protected function _initNews(){
        $newsId   = $this->getRequest()->getParam('id', 0);
        $news     = Mage::getModel('netgo_news/news')
                        ->setStoreId(Mage::app()->getStore()->getId())
                        ->load($newsId);
        if (!$news->getId()){
            return false;
        }
        elseif (!$news->getStatus()){
            return false;
        }
        return $news;
    }
    /**
      * view news action
      * @access public
      * @return void
      * @author Ultimate Module Creator
      */
    public function viewAction(){
        $news = $this->_initNews();
        if (!$news) {
            $this->_forward('no-route');
            return;
        }
        Mage::register('current_news', $news);
        $this->loadLayout();
        $this->_initLayoutMessages('catalog/session');
        $this->_initLayoutMessages('customer/session');
        $this->_initLayoutMessages('checkout/session');
        if ($root = $this->getLayout()->getBlock('root')) {
            $root->addBodyClass('news-news news-news' . $news->getId());
        }
        if (Mage::helper('netgo_news/news')->getUseBreadcrumbs()){
            if ($breadcrumbBlock = $this->getLayout()->getBlock('breadcrumbs')){
                $breadcrumbBlock->addCrumb('home', array(
                            'label'    => Mage::helper('netgo_news')->__('Home'),
                            'link'     => Mage::getUrl(),
                        )
                );
                $breadcrumbBlock->addCrumb('newss', array(
                            'label'    => Mage::helper('netgo_news')->__('News'),
                            'link'    => Mage::helper('netgo_news/news')->getNewssUrl(),
                    )
                );
                $breadcrumbBlock->addCrumb('news', array(
                            'label'    => $news->getTitle(),
                            'link'    => '',
                    )
                );
            }
        }
        $this->renderLayout();
    }
}
