<commit_before><?php

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

/*
  Controller de campagne (sécurisé)
 */
$securedCampagneController = $app['controllers_factory'];
$securedCampagneController->before($mustBeLogged);

$securedCampagneController->get('/new', function() use($app) {
            $campagne = $app['campagneService']->getBlankCampagne();
            return $app->render('campagne_form.html.twig', ['campagne' => $campagne, 'error' => ""]);
        })->bind("campagne_new");

$securedCampagneController->get('/{id}/edit', function($id) use($app) {
            $campagne = $app['campagneService']->getCampagne($id);
            return $app->render('campagne_form.html.twig', ['campagne' => $campagne, 'error' => ""]);
        })->bind("campagne_edit");

$securedCampagneController->get('/{campagne_id}/config/edit', function($campagne_id) use($app) {
            $campagne = $app['campagneService']->getCampagneConfig($campagne_id);
            return $app->render('campagne_config_form.html.twig', ['campagne_id' => $campagne['campagne_id'], 'campagne' => $campagne, 'is_mj' => true, 'error' => ""]);
        })->bind("campagne_config_edit");

$securedCampagneController->post('/config/save', function(Request $request) use($app) {
            try {
                $app['campagneService']->updateCampagneConfig($request);
                return $app->redirect($app->path('campagne_config_edit', array('campagne_id' => $request->get('campagne_id'))));
            } catch (Exception $e) {
                $campagne = $app['campagneService']->getFormCampagneConfig($request);
                return $app->render('campagne_config_form.html.twig', ['campagne_id' => $request->get('campagne_id'), 'campagne' => $campagne, 'is_mj' => true, 'error' => $e->getMessage()]);
            }
        })->bind("campagne_config_save");


$securedCampagneController->get('/join/{id}', function($id) use($app) {
            try {
                $campagne = $app['campagneService']->addJoueur($id, $app['session']->get('user')['id']);
                return $app->redirect($app->path('campagne_my_list'));
            } catch (Exception $e) {
                $campagnes = $app['campagneService']->getOpenCampagne();
                return $app->render('campagne_list.html.twig', ['campagnes' => $campagnes, 'error' => $e->getMessage()]);
            }
        })->bind("campagne_join");

$securedCampagneController->get('/join/{id}/valid/{user_id}', function($id, $user_id) use($app) {
            try {
                $app['campagneService']->validJoueur($id, $user_id);
                $perso = $app['persoService']->getPersonnage(true, $id, $user_id);
                $config = $app['campagneService']->getCampagneConfig($id);
                $app['persoService']->setTechnical($perso['id'], $config['template']);
                return $app->redirect($app->path('campagne', array('id' => $id)));
            } catch (Exception $e) {
                $campagnes = $app['campagneService']->getOpenCampagne();
                return $app->render('campagne_list.html.twig', ['campagnes' => $campagnes, 'error' => $e->getMessage()]);
            }
        })->bind("campagne_join_valid");

$securedCampagneController->get('/quit/{id}', function($id) use($app) {
            try {
                $campagne = $app['campagneService']->removeJoueur($id, $app['session']->get('user')['id']);
                return $app->redirect($app->path('campagne_my_list'));
            } catch (Exception $e) {
                $campagnes = $app['campagneService']->getOpenCampagne();
                return $app->render('campagne_list.html.twig', ['campagnes' => $campagnes, 'error' => $e->getMessage()]);
            }
        })->bind("campagne_quit");
        
$securedCampagneController->get('/open_subscribe/{id}', function($id) use($app) {
            $campagne = $app['campagneService']->openSubscribe($id);
            return $app->redirect($app->path('campagne_my_list'));
        })->bind("campagne_open_subscribe");
        
$securedCampagneController->get('/close_subscribe/{id}', function($id) use($app) {
            $campagne = $app['campagneService']->closeSubscribe($id);
            return $app->redirect($app->path('campagne_my_list'));
        })->bind("campagne_close_subscribe");

$securedCampagneController->get('/ban/{id}/{user_id}', function($id, $user_id) use($app) {
            $user = $app['userService']->getById($user_id);
            $campagne = $app['campagneService']->getCampagne($id);<commit_msg>#13 - MP au joueur lorsque son inscription est validé<commit_after><?php

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

/*
  Controller de campagne (sécurisé)
 */
$securedCampagneController = $app['controllers_factory'];
$securedCampagneController->before($mustBeLogged);

$securedCampagneController->get('/new', function() use($app) {
            $campagne = $app['campagneService']->getBlankCampagne();
            return $app->render('campagne_form.html.twig', ['campagne' => $campagne, 'error' => ""]);
        })->bind("campagne_new");

$securedCampagneController->get('/{id}/edit', function($id) use($app) {
            $campagne = $app['campagneService']->getCampagne($id);
            return $app->render('campagne_form.html.twig', ['campagne' => $campagne, 'error' => ""]);
        })->bind("campagne_edit");

$securedCampagneController->get('/{campagne_id}/config/edit', function($campagne_id) use($app) {
            $campagne = $app['campagneService']->getCampagneConfig($campagne_id);
            return $app->render('campagne_config_form.html.twig', ['campagne_id' => $campagne['campagne_id'], 'campagne' => $campagne, 'is_mj' => true, 'error' => ""]);
        })->bind("campagne_config_edit");

$securedCampagneController->post('/config/save', function(Request $request) use($app) {
            try {
                $app['campagneService']->updateCampagneConfig($request);
                return $app->redirect($app->path('campagne_config_edit', array('campagne_id' => $request->get('campagne_id'))));
            } catch (Exception $e) {
                $campagne = $app['campagneService']->getFormCampagneConfig($request);
                return $app->render('campagne_config_form.html.twig', ['campagne_id' => $request->get('campagne_id'), 'campagne' => $campagne, 'is_mj' => true, 'error' => $e->getMessage()]);
            }
        })->bind("campagne_config_save");


$securedCampagneController->get('/join/{id}', function($id) use($app) {
            try {
                $campagne = $app['campagneService']->addJoueur($id, $app['session']->get('user')['id']);
                return $app->redirect($app->path('campagne_my_list'));
            } catch (Exception $e) {
                $campagnes = $app['campagneService']->getOpenCampagne();
                return $app->render('campagne_list.html.twig', ['campagnes' => $campagnes, 'error' => $e->getMessage()]);
            }
        })->bind("campagne_join");

$securedCampagneController->get('/join/{id}/valid/{user_id}', function($id, $user_id) use($app) {
            try {
                $app['campagneService']->validJoueur($id, $user_id);
                $perso = $app['persoService']->getPersonnage(true, $id, $user_id);
                $config = $app['campagneService']->getCampagneConfig($id);
                $app['persoService']->setTechnical($perso['id'], $config['template']);
                
                $user = $app['userService']->getById($user_id);
                $campagne = $app['campagneService']->getCampagne($id);
                $campagne_name = $campagne['name'];
                $url_forum = $app->path('forum_campagne', array('campagne_id' => $id));
                $url_perso = $app->path('perso_edit', array('campagne_id' => $id));
                $content = "
                    <p>Votre inscription à '$campagne_name' a été validé par le MJ.</p>
                    <p>Nous t'invitons à te manifester sur le Mod-Off de la partie. 
                    Le <a href='$url_forum'>forum de celle-ci est accessible ici.</a></p> 
                    <p>Ta <a href='$url_perso'>fiche de personnage est accessible ici.</a></p>
                    <br>
                    <p>Nous te souhaitons une bonne partie.</p>
                    <p>Ludiquement.</p>
                ";
                $destinataires = array($user['username']);
                $app['messagerieService']->sendMessageWith($app['session']->get('user')['id'], $app['session']->get('user')['login'], "Notification système - inscription validé", $content, $destinataires);
                return $app->redirect($app->path('campagne', array('id' => $id)));
            } catch (Exception $e) {
                $campagnes = $app['campagneService']->getOpenCampagne();
                return $app->render('campagne_list.html.twig', ['campagnes' => $campagnes, 'error' => $e->getMessage()]);
            }
        })->bind("campagne_join_valid");

$securedCampagneController->get('/quit/{id}', function($id) use($app) {
            try {
                $campagne = $app['campagneService']->removeJoueur($id, $app['session']->get('user')['id']);
                return $app->redirect($app->path('campagne_my_list'));
            } catch (Exception $e) {
                $campagnes = $app['campagneService']->getOpenCampagne();
                return $app->render('campagne_list.html.twig', ['campagnes' => $campagnes, 'error' => $e->getMessage()]);
            }
        })->bind("campagne_quit");
        
$securedCampagneController->get('/open_subscribe/{id}', function($id) use($app) {
            $campagne = $app['campagneService']->openSubscribe($id);
            return $app->redirect($app->path('campagne_my_list'));
        })->bind("campagne_open_subscribe");
        
$securedCampagneController->get('/close_subscribe/{id}', function($id) use($app) {
            $campagne = $app['campagneService']->closeSubscribe($id);
            return $app->redirect($app->path('campagne_my_list'));
        })->bind("campagne_close_subscribe");

$securedCampagneController->get('/ban/{id}/{user_id}', function($id, $user_id) use($app) {
            $user = $app['userService']->getById($user_id);
            $campagne = $app['campagneService']->getCampagne($id);
{'fraction_non_alphanumeric': 0.1964026689875254, 'fraction_numerical': 0.00019340489314379654, 'mean_word_length': 3.1252493019545273, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 197, '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': '6513243', 'n_tokens_mistral': 3197, 'n_tokens_neox': 3111, 'n_words': 421}