<?php
namespace Gh\Gloggiheime\Controller;

use FluidTYPO3\Flux\Controller\AbstractFluxController;

/**
 * My custom ContentController to render my package's Content templates.
 *
 * @package Gloggiheime
 * @subpackage Controller
 */
class ContentController extends AbstractFluxController {

	/**
	 * bookingRepository
	 *
	 * @var \Gh\Gloggiheime\Domain\Repository\BookingRepository
	 * @inject
	 */
	protected $bookingRepository = NULL;

	/**
	 * heimeRepository
	 *
	 * @var \Gh\Gloggiheime\Domain\Repository\HeimeRepository
	 * @inject
	 */

	protected $heimeRepository = NULL;


	public function bookingAction() {

		// Fix for stupid Extbase Persistency problems in Repository

		$ext_conf = $this->getData();
		$heim_id = $ext_conf[settings][flexform][heim_id];
		$end_date_months = $ext_conf[settings][flexform][monate];

		$heime = $this->heimeRepository->findAll();
		$this->view->assign('heime', $heime);

		// $bookings = $this->bookingRepository->findAll();
		// $this->view->assign('bookings', $bookings);

	   	$query = $this->bookingRepository->createQuery();

	    $date_start = new \DateTime('-1 month');
	    // $date_end = new \DateTime('+'.end_date_months.' month');

	    $query->matching(
	        $query->greaterThanOrEqual('from_booking', $date_start->format('Y-m-d H:i:s'))
	    		);

	    debug($query);

		$bookings = $query->execute();
		$this->view->assign('bookings', $bookings);

		$heim = $this->heimeRepository->findByUid($heim_id);
		$this->view->assign('selectedheim', $heim);

	}

	public function preiseAction() {
		// print($this);
		$heime = $this->heimeRepository->findAll();
		$this->view->assign('heime', $heime);

	}

	public function mapAction() {

		$ext_conf = $this->getData();
		$heim_id = $ext_conf[settings][flexform][heim_id];

		$heimsingle = $this->heimeRepository->findByUid($heim_id);
		$this->view->assign('heimsingle', $heimsingle);

		// print($this);
		$heime = $this->heimeRepository->findAll();
		$this->view->assign('heime', $heime);

	}

	public function detailsAction() {

		$ext_conf = $this->getData();
		$heim_id = $ext_conf[settings][flexform][heim_id];

		$heim = $this->heimeRepository->findByUid($heim_id);
		$this->view->assign('heim', $heim);

	}

}
?>
