Skip to content

Commit

Permalink
Merge pull request #6 from Darkenend/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Darkenend authored May 23, 2020
2 parents 5eb1e02 + f0c0d90 commit 71a32f0
Showing 8 changed files with 122 additions and 19 deletions.
32 changes: 22 additions & 10 deletions src/Controller/MessageController.php
Original file line number Diff line number Diff line change
@@ -4,9 +4,9 @@

use App\Entity\Conversation;
use App\Entity\Message;
use App\Form\ConversationType;
use App\Form\MessageType;
use DateTimeImmutable;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@@ -21,7 +21,7 @@
class MessageController extends AbstractController
{
/**
* @Route("/", name="_home")
* @Route("/dash", name="_home")
*/
public function index()
{
@@ -35,23 +35,17 @@ public function index()
}

/**
* @Route("/{id}", name="_conversation")
* @Route("/conversation/{id}", name="_conversation")
*/
public function conversation($id, ?Request $request, LoggerInterface $logger): Response {
public function conversation($id, ?Request $request): Response {
$conversation = $this->getDoctrine()->getRepository(Conversation::class)->find($id);
$message = new Message();
$form = $this->createForm(MessageType::class, $message);
$logger->debug("", ['isset_request'=>isset($request)]);
if (isset($request)) $form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$logger->debug("Form Submitted & Valid");
$message->setConversationId($conversation);
$logger->debug("Conversation ID", ['conversationid' => $message->getConversationId()]);
$message->setCreator($this->getUser());
$logger->debug("Creator", ['creator' => $message->getCreator()->__toString()]);
$message->setTimestamp(new DateTimeImmutable());
$logger->debug("Timestamp", ['ts' => $message->getTimestamp()->format('F jS \\a\\t g:ia')]);
$logger->debug("Message", ['msg' => $message->getMessage()]);
$em = $this->getDoctrine()->getManager();
$em->persist($message);
$em->flush();
@@ -61,4 +55,22 @@ public function conversation($id, ?Request $request, LoggerInterface $logger): R
'form' => $form->createView()
]);
}

/**
* @Security("is_granted('ROLE_ADMIN')")
* @Route("/create", name="_create")
*/
public function createConversation(?Request $request): Response {
$conversation = new Conversation();
$form = $this->createForm(ConversationType::class, $conversation);
if (isset($request)) $form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($conversation);
$em->flush();
}
return $this->render('message/create.html.twig', [
'form'=>$form->createView()
]);
}
}
8 changes: 6 additions & 2 deletions src/Controller/RaceController.php
Original file line number Diff line number Diff line change
@@ -91,9 +91,13 @@ private function generateEntrylist($entrylist): void
}
$entrylist_json = $entrylist_json.'],"raceNumber":'.$entry->getRacenumber().',';
$entrylist_json = $entrylist_json.'"forcedCarModel":'.$entry->getCarmodel();
$entrylist_json = !next($entrylist) ? $entrylist_json . '}' : $entrylist_json . '},';
if (!next($entrylist)) {
$entrylist_json = $entrylist_json . '}';
} else {
$entrylist_json = $entrylist_json . '},';
}
}
$entrylist_json = $entrylist_json.'], "forceEntryList": 0}';
$entrylist_json = $entrylist_json.'], "forceEntryList": 1}';
$filepath = $_SERVER['APP_FOLDER']."\cfg\\entrylist.json";
file_put_contents($filepath, $entrylist_json);
}
4 changes: 2 additions & 2 deletions src/Controller/ServerConfigController.php
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ public function configuration(Request $request): Response
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$formdata = $form->getData();
$configstring = "{\"udpPort\": ".$formdata['port'].",\"tcpPort\": ".$formdata['port'].",\"maxConnections\": ".$formdata['maxConnections'].",\"lanDiscovery\": 0,\"registerToLobby\": 0,\"configVersion\": 1}";
$configstring = "{\"udpPort\": ".$formdata['port'].",\"tcpPort\": ".$formdata['port'].",\"maxConnections\": ".$formdata['maxConnections'].",\"lanDiscovery\": 1,\"registerToLobby\": 0,\"configVersion\": 1}";
$this->dumpJSON($_SERVER['APP_FOLDER']."\cfg\\configuration.json", $configstring);
return $this->render('server_config/index.html.twig', [
'message' => "configuration.json has been generated"
@@ -61,7 +61,7 @@ public function settings(Request $request): Response
else $helper1 = 0;
if ($formdata['shortFormationLap']) $helper2 = 1;
else $helper2 = 0;
$configstring = "{\"serverName\": \"".$formdata['serverName']."\",\"adminPassword\": \"".$formdata['adminPassword']."\",\"trackMedalsRequirement\": 3,\"safetyRatingRequirement\": 50, \"racecraftRatingRequirement\": -1,\"maxCarSlots\": ".$formdata['maxCarSlots'].",\"dumpLeaderboards\": 1,\"isRaceLocked\": 0,\"randomizeTrackWhenEmpty\": 0,\"centralEntryListPath\": \"\",\"allowAutoDQ\": ".$helper1.",\"shortFormationLap\": ".$helper2.",\"dumpEntryList\": 0,\"formationLapType\": ".$formdata['formationLapType']."}";
$configstring = "{\"serverName\": \"".$formdata['serverName']."\",\"adminPassword\": \"".$formdata['adminPassword'].", \"racecraftRatingRequirement\": -1,\"maxCarSlots\": ".$formdata['maxCarSlots'].",\"dumpLeaderboards\": 1,\"isRaceLocked\": 0,\"randomizeTrackWhenEmpty\": 0,\"centralEntryListPath\": \"\",\"allowAutoDQ\": ".$helper1.",\"shortFormationLap\": ".$helper2.",\"dumpEntryList\": 0,\"formationLapType\": ".$formdata['formationLapType']."}";
$this->dumpJSON($_SERVER['APP_FOLDER']."\cfg\\settings.json", $configstring);
return $this->render('server_config/index.html.twig', [
'message' => "settings.json has been generated"
4 changes: 1 addition & 3 deletions src/Controller/TeamController.php
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@
use App\Entity\TeamDrivers;
use App\Entity\User;
use App\Form\ChampionshipSignupType;
use Psr\Log\LoggerInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
@@ -103,7 +102,7 @@ public function invite(int $driverid, int $teamid): Response
/**
* @Route("/signup/{teamid}", name="_signup")
*/
public function signUpFor(int $teamid, ?Request $request, LoggerInterface $logger): Response
public function signUpFor(int $teamid, ?Request $request): Response
{
$currentUserRank = $this->getDoctrine()->getRepository(TeamDrivers::class)->findOneBy([
'team' => $teamid,
@@ -120,7 +119,6 @@ public function signUpFor(int $teamid, ?Request $request, LoggerInterface $logge
}
else $result = 0;
if ($form->isSubmitted() && $form->isValid()) {
$logger->debug('Form Submitted & Valid');
if (is_null($this->getDoctrine()->getRepository(ChampionshipEntries::class)->findBy(['team'=>$team, 'championship' => $championshipsignup->getChampionship()]))) $result = 3;
else {
$entitymanager = $this->getDoctrine()->getManager();
17 changes: 16 additions & 1 deletion src/DataFixtures/AppFixtures.php
Original file line number Diff line number Diff line change
@@ -44,6 +44,9 @@ public function load(ObjectManager $manager)
$team_4 = new Team();
$team_4->setName("Darkenend Team");
$team_4->setPrivacy(2);
$team_5 = new Team();
$team_5->setName("Dano Team");
$team_5->setPrivacy(2);

// Usuarios
$user_1 = new User();
@@ -97,6 +100,10 @@ public function load(ObjectManager $manager)
$teamdriver_5->setDriver($user_4);
$teamdriver_5->setTeam($team_2);
$teamdriver_5->setRank(1);
$teamdriver_9 = new TeamDrivers();
$teamdriver_9->setDriver($user_4);
$teamdriver_9->setTeam($team_5);
$teamdriver_9->setRank(2);
$user_5->setName("Jimmy");
$user_5->setLastname("Broadbent");
$user_5->setSteamid("76561198042232268");
@@ -170,7 +177,7 @@ public function load(ObjectManager $manager)
$race_4->setRaceLength(180);
$race_4->setGreenflagtime(DateTime::createFromFormat('U', '1567341000'));
$race_4->setComplete(false);
$race_5->setTrack("mount_panorama_2019");
$race_5->setTrack("brands_hatch_2019");
$race_5->setAmbientTemp(20);
$race_5->setCloudLevel(0.1);
$race_5->setRain(0);
@@ -265,6 +272,11 @@ public function load(ObjectManager $manager)
$entrylist_5_1->setRacenumber(273);
$entrylist_5_1->setRaceId($race_5);
$entrylist_5_1->setCarmodel(23);
$entrylist_5_2 = new TeamEntryList();
$entrylist_5_2->setTeamId($team_5);
$entrylist_5_2->setRacenumber(74);
$entrylist_5_2->setRaceId($race_5);
$entrylist_5_2->setCarmodel(22);

// Campeonatos
$championship = new Championship();
@@ -321,6 +333,7 @@ public function load(ObjectManager $manager)
$manager->persist($team_2);
$manager->persist($team_3);
$manager->persist($team_4);
$manager->persist($team_5);
$manager->persist($user_1);
$manager->persist($user_2);
$manager->persist($user_3);
@@ -335,6 +348,7 @@ public function load(ObjectManager $manager)
$manager->persist($teamdriver_6);
$manager->persist($teamdriver_7);
$manager->persist($teamdriver_8);
$manager->persist($teamdriver_9);
$manager->persist($race_1);
$manager->persist($race_2);
$manager->persist($race_3);
@@ -350,6 +364,7 @@ public function load(ObjectManager $manager)
$manager->persist($entrylist_3_2);
$manager->persist($entrylist_3_3);
$manager->persist($entrylist_5_1);
$manager->persist($entrylist_5_2);
$manager->persist($championship);
$manager->persist($championshipEntry_1);
$manager->persist($championshipEntry_2);
33 changes: 33 additions & 0 deletions src/Form/ConversationType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App\Form;

use App\Entity\Conversation;
use App\Entity\User;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class ConversationType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('user', EntityType::class, [
'class' => User::class
])
->add('topic', TextType::class)
->add('submit', SubmitType::class)
;
}

public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Conversation::class,
]);
}
}
34 changes: 34 additions & 0 deletions templates/message/create.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{% extends 'base.html.twig' %}

{% block title %}RLM | Create Conversation{% endblock %}

{% block body %}
<nav aria-label="breadcrumb">
<ol class="breadcrumb bg-light">
<li class="breadcrumb-item">
<a href="{{ path('user_home') }}">
Home
</a>
</li>
<li class="breadcrumb-item">
<a href="{{ path('message_home') }}">
Message Board
</a>
</li>
<li class="breadcrumb-item active" aria-current="page">
Create Conversation
</li>
</ol>
</nav>
{{ form_start(form) }}
<div class="row">
<div class="col-3">
{{ form_row(form.user) }}
</div>
<div class="col">
{{ form_row(form.topic) }}
</div>
</div>
{{ form_row(form.submit) }}
{{ form_end(form) }}
{% endblock %}
9 changes: 8 additions & 1 deletion templates/message/index.html.twig
Original file line number Diff line number Diff line change
@@ -9,8 +9,15 @@
<li class="breadcrumb-item active" aria-current="page">Message Board</li>
</ol>
</nav>
{% if conversations|length != 0 %}
{% if conversations|length != 0 or is_granted('ROLE_ADMIN') %}
<ul class="list-group">
{% if is_granted('ROLE_ADMIN') %}
<li class="list-group-item list-group-item-info">
<a href="{{ path('message_create') }}">
Create New Conversation
</a>
</li>
{% endif %}
{% for conversation in conversations %}
<li class="list-group-item">
<a href="{{ path('message_conversation', {'id': conversation.id}) }}">

0 comments on commit 71a32f0

Please sign in to comment.