<commit_before><?php

namespace Application\Controller\MembersArea;

use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\StreamedResponse;

class ParticipantsController
{
    public function indexAction(Request $request, Application $app)
    {
        $data = array();

        if (! $app['security']->isGranted('ROLE_PARTICIPANTS_EDITOR')
            && ! $app['security']->isGranted('ROLE_ADMIN')) {
            $app->abort(403);
        }

        $limitPerPage = $request->query->get('limit_per_page', 8);
        $currentPage = $request->query->get('page');

        $participantResults = $app['orm.em']
            ->createQueryBuilder()
            ->select('p')
            ->from('Application\Entity\ParticipantEntity', 'p')
        ;

        $pagination = $app['paginator']->paginate(
            $participantResults,
            $currentPage,
            $limitPerPage,
            array(
                'route' => 'members-area.participants',
                'defaultSortFieldName' => 'p.timeCreated',
                'defaultSortDirection' => 'desc',
            )
        );

        $data['pagination'] = $pagination;

        return new Response(
            $app['twig']->render(
                'contents/members-area/participants/index.html.twig',
                $data
            )
        );
    }

    public function exportAction(Request $request, Application $app)
    {
        // WIP
        $response = new StreamedResponse();
        $response->setCallback(function() use ($app) {
            $handle = fopen('php://output', 'w+');

            fputcsv(
                $handle,
                array(
                    'ID',
                    'Name',
                    'Email',
                    'Time',
                ),
                ';'
            );

            $participants = $app['orm.em']
                ->getRepository('Application\Entity\ParticipantEntity')
                ->findAll()
            ;

            foreach( $participants as $participant )
            {
                fputcsv(
                    $handle,
                    array(
                        $participant->getId(),
                        $participant->getName(),
                        $participant->getEmail(),
                        $participant->getTimeCreated()->format(DATE_ATOM),
                    ),
                    ';'
                 );
            }

            fclose($handle);
        });

        $response->setStatusCode(200);
        $response->headers->set('Content-Type', 'text/csv; charset=utf-8');
        $response->headers->set('Content-Disposition','attachment; filename="participants.csv"');

        return $response;
    }

    public function newAction(Request $request, Application $app)
    {
        $data = array();

        if (! $app['security']->isGranted('ROLE_PARTICIPANTS_EDITOR')
            && ! $app['security']->isGranted('ROLE_ADMIN')) {
            $app->abort(403);
        }<commit_msg>Added via participant to export<commit_after><?php

namespace Application\Controller\MembersArea;

use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\StreamedResponse;

class ParticipantsController
{
    public function indexAction(Request $request, Application $app)
    {
        $data = array();

        if (! $app['security']->isGranted('ROLE_PARTICIPANTS_EDITOR')
            && ! $app['security']->isGranted('ROLE_ADMIN')) {
            $app->abort(403);
        }

        $limitPerPage = $request->query->get('limit_per_page', 8);
        $currentPage = $request->query->get('page');

        $participantResults = $app['orm.em']
            ->createQueryBuilder()
            ->select('p')
            ->from('Application\Entity\ParticipantEntity', 'p')
        ;

        $pagination = $app['paginator']->paginate(
            $participantResults,
            $currentPage,
            $limitPerPage,
            array(
                'route' => 'members-area.participants',
                'defaultSortFieldName' => 'p.timeCreated',
                'defaultSortDirection' => 'desc',
            )
        );

        $data['pagination'] = $pagination;

        return new Response(
            $app['twig']->render(
                'contents/members-area/participants/index.html.twig',
                $data
            )
        );
    }

    public function exportAction(Request $request, Application $app)
    {
        // WIP
        $response = new StreamedResponse();
        $response->setCallback(function() use ($app) {
            $handle = fopen('php://output', 'w+');

            fputcsv(
                $handle,
                array(
                    'ID',
                    'Name',
                    'Email',
                    'Via',
                    'Time',
                ),
                ';'
            );

            $participants = $app['orm.em']
                ->getRepository('Application\Entity\ParticipantEntity')
                ->findAll()
            ;

            foreach( $participants as $participant )
            {
                fputcsv(
                    $handle,
                    array(
                        $participant->getId(),
                        $participant->getName(),
                        $participant->getEmail(),
                        $participant->getVia(),
                        $participant->getTimeCreated()->format(DATE_ATOM),
                    ),
                    ';'
                 );
            }

            fclose($handle);
        });

        $response->setStatusCode(200);
        $response->headers->set('Content-Type', 'text/csv; charset=utf-8');
        $response->headers->set('Content-Disposition','attachment; filename="participants.csv"');

        return $response;
    }

    public function newAction(Request $request, Application $app)
    {
        $data = array();

        if (! $app['security']->isGranted('ROLE_PARTICIPANTS_EDITOR')
            && ! $app['security']->isGranted('ROLE_ADMIN')) {
            $app->abort(403);
        }
{'fraction_non_alphanumeric': 0.13769390692467615, 'fraction_numerical': 0.003518311210618903, 'mean_word_length': 1.5505709624796085, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 66, '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': '3139990', 'n_tokens_mistral': 1720, 'n_tokens_neox': 1593, 'n_words': 236}