<commit_before><?php
/**
 * Litus is a project by a group of students from the KU Leuven. The goal is to create
 * various applications to support the IT needs of student unions.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 *
 * @license http://litus.cc/LICENSE
 */

namespace SportBundle\Controller\Admin;

use CommonBundle\Component\Util\AcademicYear,
    CommonBundle\Component\Util\WebSocket as WebSocketUtil,
    CommonBundle\Entity\General\AcademicYear as AcademicYearEntity,
    DateInterval,
    DateTime,
    SportBundle\Entity\Group,
    SportBundle\Entity\Runner,
    Zend\View\Model\ViewModel;

/**
 * RunController
 *
 * @author <NAME> <<EMAIL>>
 */
class RunController extends \CommonBundle\Component\Controller\ActionController\AdminController
{
    public function queueAction()
    {
        return new ViewModel(
            array(
                'socketUrl' => $this->getSocketUrl(),
                'authSession' => $this->getAuthentication()
                    ->getSessionObject(),
                'key' => $this->getEntityManager()
                    ->getRepository('CommonBundle\Entity\General\Config')
                    ->getConfigValue('sport.queue_socket_key'),
            )
        );
    }

    public function lapsAction()
    {
        $paginator = $this->paginator()->createFromQuery(
            $this->getEntityManager()
                ->getRepository('SportBundle\Entity\Lap')
                ->findAllPreviousLapsQuery($this->getAcademicYearEntity()),
            $this->getParam('page')
        );

        foreach ($paginator as $lap) {
            $lap->setEntityManager($this->getEntityManager());
        }

        return new ViewModel(
            array(
                'paginator' => $paginator,
                'paginationControl' => $this->paginator()->createControl(true),
                'academicYear' => $this->getAcademicYearEntity(),
            )
        );
    }

    public function groupsAction()
    {
        $paginator = $this->paginator()->createFromEntity(
            'SportBundle\Entity\Group',
            $this->getParam('page'),
            array(
                'academicYear' => $this->getAcademicYearEntity(),
            ),
            array(
                'name' => 'ASC',
            )
        );

        foreach ($paginator as $group) {
            $group->setEntityManager($this->getEntityManager());
        }

        return new ViewModel(
            array(
                'paginator' => $paginator,
                'paginationControl' => $this->paginator()->createControl(true),
                'academicYear' => $this->getAcademicYearEntity(),
            )
        );
    }

    public function editGroupAction()
    {
        if (!($group = $this->getGroupEntity())) {
            return new ViewModel();
        }

        $form = $this->getForm('sport_group_edit');

        if ($this->getRequest()->isPost()) {
            $formData = $this->getRequest()->getPost();
            $form->setData($formData);

            if ($form->isValid()) {
                $formData = $form->getData();

                $academic = $this->getEntityManager()
                    ->getRepository('CommonBundle\Entity\User\Person\Academic')
                    ->findOneById($formData['person']['id']);

                $repositoryCheck = $this->getEntityManager()
                    ->getRepository('SportBundle\Entity\Runner')
                    ->findOneByUniversityIdentification($academic->getUniversityIdentification());

                if (null === $repositoryCheck) {
                    $department = $this->getEntityManager()
                        ->getRepository('SportBundle\Entity\Department')
                        ->findOneById($formData['department']);

                    $newRunner = new Runner(
                        $academic->getFirstName(),
                        $academic->getLastName(),
                        $group->getAcadmicYear(),
                        $academic,
                        $group,
                        $department
                    );

                    $this->getEntityManager()->persist($newRunner);
                } else {
                    $repositoryCheck->setGroup($group);
                }

                $this->getEntityManager()->flush();

                $this->flashMessenger()->success(
                    'Success',
                    'The group was successfully edited!'
                );

                $this->redirect()->toRoute(
                    'sport_admin_run',
                    array(
                        'action' => 'groups',
                    )
                );

                return new ViewModel();
            }
        }

        return new ViewModel(
            array(<commit_msg>Fix addition of runners to groups<commit_after><?php
/**
 * Litus is a project by a group of students from the KU Leuven. The goal is to create
 * various applications to support the IT needs of student unions.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 *
 * @license http://litus.cc/LICENSE
 */

namespace SportBundle\Controller\Admin;

use CommonBundle\Component\Util\AcademicYear,
    CommonBundle\Component\Util\WebSocket as WebSocketUtil,
    CommonBundle\Entity\General\AcademicYear as AcademicYearEntity,
    DateInterval,
    DateTime,
    SportBundle\Entity\Group,
    SportBundle\Entity\Runner,
    Zend\View\Model\ViewModel;

/**
 * RunController
 *
 * @author <NAME> <<EMAIL>>
 */
class RunController extends \CommonBundle\Component\Controller\ActionController\AdminController
{
    public function queueAction()
    {
        return new ViewModel(
            array(
                'socketUrl' => $this->getSocketUrl(),
                'authSession' => $this->getAuthentication()
                    ->getSessionObject(),
                'key' => $this->getEntityManager()
                    ->getRepository('CommonBundle\Entity\General\Config')
                    ->getConfigValue('sport.queue_socket_key'),
            )
        );
    }

    public function lapsAction()
    {
        $paginator = $this->paginator()->createFromQuery(
            $this->getEntityManager()
                ->getRepository('SportBundle\Entity\Lap')
                ->findAllPreviousLapsQuery($this->getAcademicYearEntity()),
            $this->getParam('page')
        );

        foreach ($paginator as $lap) {
            $lap->setEntityManager($this->getEntityManager());
        }

        return new ViewModel(
            array(
                'paginator' => $paginator,
                'paginationControl' => $this->paginator()->createControl(true),
                'academicYear' => $this->getAcademicYearEntity(),
            )
        );
    }

    public function groupsAction()
    {
        $paginator = $this->paginator()->createFromEntity(
            'SportBundle\Entity\Group',
            $this->getParam('page'),
            array(
                'academicYear' => $this->getAcademicYearEntity(),
            ),
            array(
                'name' => 'ASC',
            )
        );

        foreach ($paginator as $group) {
            $group->setEntityManager($this->getEntityManager());
        }

        return new ViewModel(
            array(
                'paginator' => $paginator,
                'paginationControl' => $this->paginator()->createControl(true),
                'academicYear' => $this->getAcademicYearEntity(),
            )
        );
    }

    public function editGroupAction()
    {
        if (!($group = $this->getGroupEntity())) {
            return new ViewModel();
        }

        $form = $this->getForm('sport_group_edit');

        if ($this->getRequest()->isPost()) {
            $formData = $this->getRequest()->getPost();
            $form->setData($formData);

            if ($form->isValid()) {
                $formData = $form->getData();

                $academic = $this->getEntityManager()
                    ->getRepository('CommonBundle\Entity\User\Person\Academic')
                    ->findOneById($formData['person']['id']);

                $repositoryCheck = $this->getEntityManager()
                    ->getRepository('SportBundle\Entity\Runner')
                    ->findOneByUniversityIdentification($academic->getUniversityIdentification());

                if (null === $repositoryCheck) {
                    $department = $this->getEntityManager()
                        ->getRepository('SportBundle\Entity\Department')
                        ->findOneById($formData['department']);

                    $newRunner = new Runner(
                        $academic->getFirstName(),
                        $academic->getLastName(),
                        $group->getAcademicYear(),
                        $academic,
                        $group,
                        $department
                    );

                    $this->getEntityManager()->persist($newRunner);
                } else {
                    $repositoryCheck->setGroup($group);
                }

                $this->getEntityManager()->flush();

                $this->flashMessenger()->success(
                    'Success',
                    'The group was successfully edited!'
                );

                $this->redirect()->toRoute(
                    'sport_admin_run',
                    array(
                        'action' => 'groups',
                    )
                );

                return new ViewModel();
            }
        }

        return new ViewModel(
            array(
{'fraction_non_alphanumeric': 0.1342791487661105, 'fraction_numerical': 0.0, 'mean_word_length': 1.635597682991048, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 203, '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': '1082049', 'n_tokens_mistral': 2649, 'n_tokens_neox': 2463, 'n_words': 436}