<?php

/**
 * Created by PhpStorm.
 * User: ondra
 * Date: 24.10.17
 * Time: 11:04.
 */

namespace KupShop\ContentBundle\Controller;

use KupShop\ContentBundle\View\NewsletterSubscribeView;
use KupShop\ContentBundle\View\NewsletterUnsubscribeView;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;

class NewsletterController extends AbstractController
{
    /**
     * @return \Symfony\Component\HttpFoundation\Response
     *
     * @Route("/newsletter/subscribe/")
     */
    public function subscribeAction(Request $request, NewsletterSubscribeView $view)
    {
        $view->setRequest($request);

        return $view->getResponse();
    }

    /**
     * @return \Symfony\Component\HttpFoundation\Response
     *
     *  @Route("/newsletter/unsubscribe/")
     */
    public function unsubscribeAction(Request $request, NewsletterUnsubscribeView $view)
    {
        $view->setRequest($request);

        return $view->getResponse();
    }

    /**
     * @Route("/newsletter/")
     */
    public function otherAction(Request $request, NewsletterSubscribeView $subscribeView, NewsletterUnsubscribeView $unsubscribeView)
    {
        $id = intval(getVal('ID'));
        $date = sqlFormatInput(getVal('date'));

        if (getVal('subscribe') !== null) {
            return $this->subscribeAction($request, $subscribeView);
        } elseif (getVal('unsubscribe') !== null) {
            return $this->unsubscribeAction($request, $unsubscribeView);
        }

        if (empty($id) || empty($date)) {
            redirection('INDEX');
        }

        // ###############################
        // LOAD NEWSLETTER
        $text = '';

        if (empty($text)) {
            redirection('INDEX');
        }
    }
}
