<commit_before><?php

namespace Devlabs\SportifyBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;

class AdminController extends Controller
{
    /**
     * @Route("/admin", name="admin_index")
     */
    public function indexAction(Request $request)
    {
        // if user is not logged in, redirect to login page
        $securityContext = $this->container->get('security.authorization_checker');
        if (!$securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
            return $this->redirectToRoute('fos_user_security_login');
        }

        // Load the data for the current user into an object
        $user = $this->getUser();

        // continue only if user has Admin access, else redirect to Home
        if ($user->getEmail() !== '<EMAIL>') {
            return $this->redirectToRoute('home');
        }

        // Get an instance of the Entity Manager
        $em = $this->getDoctrine()->getManager();

        $tournament = $em->getRepository('DevlabsSportifyBundle:Tournament')
            ->findOneById(12);

        $dataUpdatesManager = $this->get('app.data_updates.manager');
        $dataUpdatesManager->setEntityManager($em);

//        $dataUpdatesManager->updateTeamsByTournament($tournament);

        $formData = array();

        $form = $this->createFormBuilder($formData)
            ->add('task_type', ChoiceType::class, array(
                'choices'  => array(
                    'Matches update - Next 7 days' => 'fixtures-next7days',
                    'Matches update - Past 1 day' => 'fixtures-past1day',
                    'Scores update all' => 'scores-update-all'
                )))
            ->add('button', SubmitType::class, array('label' => 'Select'))
            ->getForm();

        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $data = $form->getData();

            // Get instance of the Slack service and send notification
            $slack = $this->get('app.slack');
            $slack->setUrl('<KEY>');
            $slack->setChannel('#sportify');

            if ($data['task_type'] === 'fixtures-next7days') {
                // set dateFrom and dateTo to respectively today and 1 week on
                $dateFrom = date("Y-m-d");
                $dateTo = date("Y-m-d", time() + 604800);

                $slackText = '<!channel>: Match fixtures updated for next 7 days.';

                $dataUpdatesManager->updateFixtures($dateFrom, $dateTo);
            } else if ($data['task_type'] === 'fixtures-past1day') {
                // set dateFrom and dateTo to respectively yesterday and today<commit_msg>Fix Admin page task notify Slack message<commit_after><?php

namespace Devlabs\SportifyBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;

class AdminController extends Controller
{
    /**
     * @Route("/admin", name="admin_index")
     */
    public function indexAction(Request $request)
    {
        // if user is not logged in, redirect to login page
        $securityContext = $this->container->get('security.authorization_checker');
        if (!$securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
            return $this->redirectToRoute('fos_user_security_login');
        }

        // Load the data for the current user into an object
        $user = $this->getUser();

        // continue only if user has Admin access, else redirect to Home
        if ($user->getEmail() !== '<EMAIL>') {
            return $this->redirectToRoute('home');
        }

        // Get an instance of the Entity Manager
        $em = $this->getDoctrine()->getManager();

        $tournament = $em->getRepository('DevlabsSportifyBundle:Tournament')
            ->findOneById(12);

        $dataUpdatesManager = $this->get('app.data_updates.manager');
        $dataUpdatesManager->setEntityManager($em);

//        $dataUpdatesManager->updateTeamsByTournament($tournament);

        $formData = array();

        $form = $this->createFormBuilder($formData)
            ->add('task_type', ChoiceType::class, array(
                'choices'  => array(
                    'Matches update - Next 7 days' => 'fixtures-next7days',
                    'Matches update - Past 1 day' => 'fixtures-past1day',
                    'Scores update all' => 'scores-update-all'
                )))
            ->add('button', SubmitType::class, array('label' => 'Select'))
            ->getForm();

        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $data = $form->getData();

            // Get instance of the Slack service and send notification
            $slack = $this->get('app.slack');
            $slack->setUrl('https://<KEY>');
            $slack->setChannel('#sportify');

            if ($data['task_type'] === 'fixtures-next7days') {
                // set dateFrom and dateTo to respectively today and 1 week on
                $dateFrom = date("Y-m-d");
                $dateTo = date("Y-m-d", time() + 604800);

                $slackText = '<!channel>: Match fixtures added for next 7 days.';

                $dataUpdatesManager->updateFixtures($dateFrom, $dateTo);
            } else if ($data['task_type'] === 'fixtures-past1day') {
                // set dateFrom and dateTo to respectively yesterday and today
{'fraction_non_alphanumeric': 0.13883645100394715, 'fraction_numerical': 0.00549167667753561, 'mean_word_length': 2.43834808259587, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 71, 'https://': 1, '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': '2562388', 'n_tokens_mistral': 1657, 'n_tokens_neox': 1572, 'n_words': 357}