<commit_before><?php

namespace FrontendBundle\Controller;

use BackendBundle\Entity\Opening;
use BackendBundle\Form\OpeningType;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;

/**
 * {@inheritDoc}
 */
class CareersController extends Controller
{
    public function indexAction(Request $request)
    {
        if (!$this->getParameter('careers.apply.online')) {
            throw $this->createNotFoundException('Page not found!');
        }

        $form = $this->createForm(new OpeningType(true));
        $form->handleRequest($request);

        return $this->render('@Frontend/Careers/index.html.twig', [
            'form' => $form->createView(),
        ]);
    }

    public function findAction(Request $request, $business)
    {
        $paginator = $this->get('knp_paginator');

        $form = $this->createForm(new OpeningType(true));
        $form->handleRequest($request);

        $conditions = [];

        if (null !== $business && null === $form->getData()) {
            $conditions = [
                'business' => $business
            ];
        } else if (null !== $form->getData()) {
            /** @var Opening $opening */
            $opening = $form->getData();

            $conditions = array_merge([
                'business' => null !== $opening->getBusiness() ? $opening->getBusiness()->getSlug() : null,
                'opening' => null !== $opening->getPosition() ? $opening->getPosition()->getId() : null,
            ], $conditions);
        }

        $pagination = $paginator->paginate(
            $this->get('opening.manager')->findMatchingOpenings($conditions),
            $request->query->get('page', 1),
            $this->getParameter('deals.pagination.items')
        );

        $pagination->setTemplate('FrontendBundle::paginator.html.twig');

        return $this->render('@Frontend/Careers/find.html.twig', [
            'openings' => $pagination
        ]);
    }

    public function applyAction(Request $request, $slug)
    {
        $opening = $this->get('opening.manager')->findBySlug($slug);

        return $this->render('@Frontend/Careers/apply.html.twig', [
            'opening' => $opening,
        ]);
    }

    public function storeAction(Request $request)
    {
        $candidate = $this->get('opening.manager')->fromRequest($request);

        // validating the candidate data
        $validator = $this->get('validator');
        $errors = $validator->validate($candidate, null, array('application'));

        $errorsString = "";
        if (count($errors) > 0) {
            for ($i = 0; $i < count($errors); $i++) {
                $errorsString .= $errors->get($i)->getMessage();
            }
            return new JsonResponse(array('error' => $errorsString));
        } else {

            $this->get('opening.manager')->storeFilesFromRequest($request, $candidate);
            $this->get('opening.manager')->saveCandidate($candidate);
            $content = $this->renderView('@Backend/Emails/customer.html.twig', [
                'content' => sprintf('%s Has applied to the %s position (%s)',
                    $candidate->fullName(), $candidate->getOpening()->getPosition(),
                    (new \DateTime())->format('Y-m-d H:i:s'))
                ,
                'deals' => []
            ]);

//            $this->get('opening.manager')->notifyManager(
//                $candidate,
//                $this->getParameter('careers.notification.subject'),
//                $this->getParameter('customer.email.from'),
//                $content
//            );

            return new JsonResponse(['status' => 'ok']);
        }
    }<commit_msg>Fix bug in apply storing method<commit_after><?php

namespace FrontendBundle\Controller;

use BackendBundle\Entity\Opening;
use BackendBundle\Form\OpeningType;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;

/**
 * {@inheritDoc}
 */
class CareersController extends Controller
{
    public function indexAction(Request $request)
    {
        if (!$this->getParameter('careers.apply.online')) {
            throw $this->createNotFoundException('Page not found!');
        }

        $form = $this->createForm(new OpeningType(true));
        $form->handleRequest($request);

        return $this->render('@Frontend/Careers/index.html.twig', [
            'form' => $form->createView(),
        ]);
    }

    public function findAction(Request $request, $business)
    {
        $paginator = $this->get('knp_paginator');

        $form = $this->createForm(new OpeningType(true));
        $form->handleRequest($request);

        $conditions = [];

        if (null !== $business && null === $form->getData()) {
            $conditions = [
                'business' => $business
            ];
        } else if (null !== $form->getData()) {
            /** @var Opening $opening */
            $opening = $form->getData();

            $conditions = array_merge([
                'business' => null !== $opening->getBusiness() ? $opening->getBusiness()->getSlug() : null,
                'opening' => null !== $opening->getPosition() ? $opening->getPosition()->getId() : null,
            ], $conditions);
        }

        $pagination = $paginator->paginate(
            $this->get('opening.manager')->findMatchingOpenings($conditions),
            $request->query->get('page', 1),
            $this->getParameter('deals.pagination.items')
        );

        $pagination->setTemplate('FrontendBundle::paginator.html.twig');

        return $this->render('@Frontend/Careers/find.html.twig', [
            'openings' => $pagination
        ]);
    }

    public function applyAction(Request $request, $slug)
    {
        $opening = $this->get('opening.manager')->findBySlug($slug);

        return $this->render('@Frontend/Careers/apply.html.twig', [
            'opening' => $opening,
        ]);
    }

    public function storeAction(Request $request)
    {
        $candidate = $this->get('opening.manager')->fromRequest($request);

        // validating the candidate data
        $validator = $this->get('validator');
        $errors = $validator->validate($candidate, null, array('application'));

        $errorsString = "";
        if (count($errors) > 0) {
            for ($i = 0; $i < count($errors); $i++) {
                $errorsString .= $errors->get($i)->getMessage();
            }
            return new JsonResponse(array('error' => $errorsString));
        } else {

            $this->get('opening.manager')->storeFilesFromRequest($request, $candidate);
            $this->get('opening.manager')->saveCandidate($candidate);
            $content = $this->renderView('@Backend/Emails/customer.html.twig', [
                'content' => sprintf('%s Has applied to the %s position (%s)',
                    $candidate->fullName(), $candidate->getOpening()->getPosition(),
                    (new \DateTime())->format('Y-m-d H:i:s'))
                ,
                'deals' => []
            ]);

            $this->get('opening.manager')->notifyManager(
                $candidate,
                $this->getParameter('careers.notification.subject'),
                $this->getParameter('customer.email.from'),
                $content
            );

            return new JsonResponse(['status' => 'ok']);
        }
    }
{'fraction_non_alphanumeric': 0.16464646464646465, 'fraction_numerical': 0.0007575757575757576, 'mean_word_length': 2.37350936967632, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 121, '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': '6810455', 'n_tokens_mistral': 2213, 'n_tokens_neox': 2123, 'n_words': 345}