<?php


namespace Publicador\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\Http\Request;
use Zend\Debug\Debug;

class PublicadorController extends AbstractActionController
{
	protected $seccionesTable;
	
    public function indexAction(){
		$request = new Request();
		
		$matches = $this->getEvent()->getRouteMatch();
		$id      = $matches->getParam('id', false);
		echo $id;

		$tabla = $this->getServiceLocator()->get('Publicador\Model\SeccionesTable');
        
		

        return new ViewModel(array( 
			'secciones' => $tabla->fetchAll() ,
		));
    } 
	
	public function seccionAction(){
		$request = new Request();
		
		$matches = $this->getEvent()->getRouteMatch();
		$id      = $matches->getParam('id', false);
		
		$sm = $this->getServiceLocator();
        $materiales = $sm->get('Publicador\Model\MaterialesTable');
        $contenidos = $sm->get('Publicador\Model\ContenidosTable');
		//Debug::dump($materiales->getMaterialesFK($id));
		//Debug::dump($contenidos->fetchAllStrategy());
		
		return new ViewModel(array( 
			'materiales' => $materiales->getMaterialesFK($id) ,
			'contenidos' => $contenidos->fetchAllStrategy($id , (isset($_GET['filtro']) ? $_GET['filtro'] : null)) ,
			
		));
	}	
	
	public function detalleAction(){
		$request = new Request();
		
		$matches = $this->getEvent()->getRouteMatch();
		$id      = $matches->getParam('id', false);
		
		$sm = $this->getServiceLocator();
		$contenidos = $sm->get('Publicador\Model\ContenidosTable');
		
		$view['detalle'] = 	$contenidos->detalle($id);
		//Debug::dump($view);
		return new ViewModel($view);
	}
	
	/*
	public function setSeccionesTable(SeccionesTable $seccionesTable){
        $this->seccionesTable = $seccionesTable;
        return $this;
    }*/
	
	public function getSeccionesTable(){
        if (!$this->seccionesTable) {
            $sm = $this->getServiceLocator();
            $this->seccionesTable = $sm->get('Publicador\Model\SeccionesTable');
        }
        return $this->seccionesTable;
    }
	
	
}