<commit_before><?php

namespace Dzangocart\Bundle\SubscriptionBundle\Controller;

use Dzangocart\Bundle\SubscriptionBundle\Propel\Plan;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

use Symfony\Bundle\FrameworkBundle\Routing\Router;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\Form\FormFactory;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Session;

class SignupController
{
    protected $class;
    protected $query_class;
    protected $session;
    protected $router;
    protected $templating;
    protected $target_on_success;
    protected $form_factory;

    public function __construct(FormFactory $form_factory, Session $session, Router $router, EngineInterface $templating, $class, $target_on_success)
    {
        $this->class = $class;
        $this->query_class = $class . 'Query';
        $this->session = $session;
        $this->router = $router;
        $this->templating = $templating;
        $this->target_on_success = $target_on_success;
        $this->form_factory = $form_factory;
    }

    /**
     * @Template()
     */
    public function signupAction(Request $request)
    {
        $subscription = $this->session->get('dzangocart_subscription_entity');

        if (!$subscription) {
            $subscription = new $this->class();
        }

        $form = $this->form_factory->create(
            'dzangocart_subscription_signup',
            $subscription,
            array(
                'action' => $this->router->generate('dzangocart_subscription_signup')
            )
        );

        $form->handleRequest($request);

        if ($form->isValid()) {

            if ($subscription->getPlanId() == 'trial') {
                $subscription->setPlanId(Plan::getDefaultPlanForTrial()->getId());

                // TODO set expiry date to x day from current date

                $this->session->set('dzangocart_subscription_entity', $subscription);

                if ($request->isXmlHttpRequest()) {
                    return new JsonResponse(
                        array(
                            'redirectUrl' => $this->router->generate($this->target_on_success)
                        )
                    );
                }

                return new RedirectResponse($this->router->generate($this->target_on_success));
            }

            $this->session->set('dzangocart_subscription_entity', $subscription);

            // TODO redirect to paid registration page
        }

        return array(
            'form' => $form->createView()
        );
    }
}<commit_msg>added expiry date to trial subscription<commit_after><?php

namespace Dzangocart\Bundle\SubscriptionBundle\Controller;

use Dzangocart\Bundle\SubscriptionBundle\Propel\Plan;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

use Symfony\Bundle\FrameworkBundle\Routing\Router;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\Form\FormFactory;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Session;

class SignupController
{
    protected $class;
    protected $query_class;
    protected $session;
    protected $router;
    protected $templating;
    protected $target_on_success;
    protected $form_factory;

    public function __construct(FormFactory $form_factory, Session $session, Router $router, EngineInterface $templating, $class, $target_on_success)
    {
        $this->class = $class;
        $this->query_class = $class . 'Query';
        $this->session = $session;
        $this->router = $router;
        $this->templating = $templating;
        $this->target_on_success = $target_on_success;
        $this->form_factory = $form_factory;
    }

    /**
     * @Template()
     */
    public function signupAction(Request $request)
    {
        $subscription = $this->session->get('dzangocart_subscription_entity');

        if (!$subscription) {
            $subscription = new $this->class();
        }

        $form = $this->form_factory->create(
            'dzangocart_subscription_signup',
            $subscription,
            array(
                'action' => $this->router->generate('dzangocart_subscription_signup')
            )
        );

        $form->handleRequest($request);

        if ($form->isValid()) {

            if ($subscription->getPlanId() == 'trial') {
                $trial_plan = Plan::getDefaultPlanForTrial();
                $subscription->setPlanId($trial_plan->getId());

                $now = date('Y-m-d', time());
                $expiry_date = date('Y-m-d', strtotime($now . ' + 30 days'));

                $subscription->setExpiresAt($expiry_date);

                $this->session->set('dzangocart_subscription_entity', $subscription);

                if ($request->isXmlHttpRequest()) {
                    return new JsonResponse(
                        array(
                            'redirectUrl' => $this->router->generate($this->target_on_success)
                        )
                    );
                }

                return new RedirectResponse($this->router->generate($this->target_on_success));
            }

            $this->session->set('dzangocart_subscription_entity', $subscription);

            // TODO redirect to paid registration page
        }

        return array(
            'form' => $form->createView()
        );
    }
}
{'fraction_non_alphanumeric': 0.11924023918396061, 'fraction_numerical': 0.00035174111853675694, 'mean_word_length': 2.395223880597015, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 72, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5540681', 'n_tokens_mistral': 1553, 'n_tokens_neox': 1528, 'n_words': 256}