From cb264d00c37adc89abf3cfed46c0f9e49a380b5f Mon Sep 17 00:00:00 2001
From: holema
Date: Sat, 27 Mar 2021 10:29:27 +0100
Subject: [PATCH 1/2] add a max Participants to public rooms
---
assets/js/app.js | 46 ++++++++++++++++--------
src/Controller/ShareLinkController.php | 12 ++++---
src/Entity/Rooms.php | 17 +++++++++
src/Form/Type/PublicRegisterType.php | 2 ++
src/Form/Type/RoomType.php | 2 ++
src/Migrations/Version20210327084427.php | 31 ++++++++++++++++
src/Service/SubcriptionService.php | 5 +++
templates/base/__newRoomModal.html.twig | 7 ++++
templates/share_link/subscribe.html.twig | 2 ++
translations/form.de.yml | 1 +
translations/form.en.yml | 1 +
translations/form.fr.yml | 1 +
translations/messages+intl-icu.en.xlf | 10 ++++--
translations/messages+intl-icu.fr.xlf | 10 ++++--
14 files changed, 123 insertions(+), 24 deletions(-)
create mode 100644 src/Migrations/Version20210327084427.php
diff --git a/assets/js/app.js b/assets/js/app.js
index 85754eb81..9c32aecc3 100644
--- a/assets/js/app.js
+++ b/assets/js/app.js
@@ -22,6 +22,7 @@ import listPlugin from '@fullcalendar/list';
import Chart from 'chart.js';
import autosize from 'autosize'
import ClipboardJS from 'clipboard'
+
$.urlParam = function (name) {
var results = new RegExp('[\?&]' + name + '=([^]*)').exec(window.location.href);
if (results == null) {
@@ -118,13 +119,15 @@ $(document).on('click', '.loadContent', function (e) {
});
});
-function initServerFeatures(){
+
+function initServerFeatures() {
getMoreFeature($('.moreFeatures').val())
- $('.moreFeatures').change(function (){
- getMoreFeature($(this).val());
+ $('.moreFeatures').change(function () {
+ getMoreFeature($(this).val());
})
}
+
$('#loadContentModal').on('shown.bs.modal', function (e) {
$('.flatpickr').flatpickr({
minDate: "today",
@@ -148,7 +151,21 @@ $('#loadContentModal').on('shown.bs.modal', function (e) {
}
});
- $(".copyLink").click(function(){
+ if (typeof $('room_public') !== 'undefined') {
+ if ($('#room_public').prop('checked')) {
+ $('#maxParticipants').collapse('show')
+ } else {
+ $('#maxParticipants').collapse('hide')
+ }
+ $('#room_public').change(function (){
+ if ($('#room_public').prop('checked')) {
+ $('#maxParticipants').collapse('show')
+ } else {
+ $('#maxParticipants').collapse('hide')
+ }
+ })
+ }
+ $(".copyLink").click(function () {
var $temp = $("");
$("body").append($temp);
$temp.val($(element).text()).select();
@@ -166,14 +183,14 @@ $('#loadContentModal').on('shown.bs.modal', function (e) {
});
});
-$(document).on( 'click','.directSend', function(e) {
+$(document).on('click', '.directSend', function (e) {
var $url = $(this).prop('href');
var $targetUrl = $(this).data('url');
var target = $(this).data('target');
e.preventDefault();
- $.get($url,function (){
- $(target).closest('div').load($targetUrl +' ' +target);
+ $.get($url, function () {
+ $(target).closest('div').load($targetUrl + ' ' + target);
})
});
$(".clickable-row").click(function () {
@@ -240,15 +257,16 @@ function initDropDown() {
}
-function getMoreFeature(id){
- if(typeof id !== 'undefined'){
- $.getJSON(moreFeatureUrl,'id='+id,function (data){
+
+function getMoreFeature(id) {
+ if (typeof id !== 'undefined') {
+ $.getJSON(moreFeatureUrl, 'id=' + id, function (data) {
var feature = data.feature;
for (var prop in feature) {
- if(feature[prop] == true){
- $('#'+prop).removeClass('d-none')
- }else {
- $('#'+prop).addClass('d-none')
+ if (feature[prop] == true) {
+ $('#' + prop).removeClass('d-none')
+ } else {
+ $('#' + prop).addClass('d-none')
}
}
})
diff --git a/src/Controller/ShareLinkController.php b/src/Controller/ShareLinkController.php
index 1ccb610f5..66936caf5 100644
--- a/src/Controller/ShareLinkController.php
+++ b/src/Controller/ShareLinkController.php
@@ -46,11 +46,11 @@ public function index(Rooms $rooms): Response
*/
public function participants($uid, Request $request, SubcriptionService $subcriptionService, TranslatorInterface $translator, PexelService $pexelService): Response
{
- $rooms = null;
+ $rooms = new Rooms();
$moderator = false;
- $rooms = $this->em->getRepository(Rooms::class)->findOneBy(array('uidParticipant' => $uid));
+ $rooms = $this->em->getRepository(Rooms::class)->findOneBy(array('uidParticipant' => $uid,'public'=>true));
if (!$rooms) {
- $rooms = $this->em->getRepository(Rooms::class)->findOneBy(array('uidModerator' => $uid));
+ $rooms = $this->em->getRepository(Rooms::class)->findOneBy(array('uidModerator' => $uid,'public'=>true));
if ($rooms) {
$moderator = true;
}
@@ -58,6 +58,7 @@ public function participants($uid, Request $request, SubcriptionService $subcrip
if (!$rooms || $rooms->getModerator() === null) {
return $this->redirectToRoute('join_index_no_slug', ['snack' => $translator->trans('Fehler, Bitte kontrollieren Sie ihre Daten.'), 'color'=>'danger']);
}
+
$data = array('email' => '');
$form = $this->createForm(PublicRegisterType::class, $data);
$form->handleRequest($request);
@@ -65,7 +66,10 @@ public function participants($uid, Request $request, SubcriptionService $subcrip
$snack = $translator->trans('Bitte geben Sie ihre Daten ein');
$color = 'success';
$server = null;
-
+ if($rooms->getMaxParticipants() && (sizeof($rooms->getUser()->toArray()) >= $rooms->getMaxParticipants())){
+ $snack = $translator->trans('Die maximale Teilnehmeranzahl ist bereits erreicht.');
+ $color ='danger';
+ }
if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData();
diff --git a/src/Entity/Rooms.php b/src/Entity/Rooms.php
index 1e3dd7980..dc685f5b0 100644
--- a/src/Entity/Rooms.php
+++ b/src/Entity/Rooms.php
@@ -121,6 +121,11 @@ class Rooms
*/
private $subscribers;
+ /**
+ * @ORM\Column(type="integer", nullable=true)
+ */
+ private $maxParticipants;
+
public function __construct()
{
$this->user = new ArrayCollection();
@@ -420,4 +425,16 @@ public function removeSubscriber(Subscriber $subscriber): self
return $this;
}
+
+ public function getMaxParticipants(): ?int
+ {
+ return $this->maxParticipants;
+ }
+
+ public function setMaxParticipants(?int $maxParticipants): self
+ {
+ $this->maxParticipants = $maxParticipants;
+
+ return $this;
+ }
}
diff --git a/src/Form/Type/PublicRegisterType.php b/src/Form/Type/PublicRegisterType.php
index 78f7f69e2..949c2c415 100644
--- a/src/Form/Type/PublicRegisterType.php
+++ b/src/Form/Type/PublicRegisterType.php
@@ -21,6 +21,8 @@ public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
+ ->add('firstName', TextType::class, ['attr' => ['placeholder' => 'label.vorname'], 'label' => false, 'required' => true, 'translation_domain' => 'form'])
+ ->add('lastName', TextType::class, ['attr' => ['placeholder' => 'label.nachname'], 'label' => false, 'required' => true, 'translation_domain' => 'form'])
->add('email', TextType::class, ['attr' => ['placeholder' => 'label.email'], 'label' => false, 'required' => true, 'translation_domain' => 'form'])
->add('subscribe', SubmitType::class, ['attr' => array('class' => 'btn btn-outline-secondary btn-block p-3'), 'label' => 'label.subscribe', 'translation_domain' => 'form']);
}
diff --git a/src/Form/Type/RoomType.php b/src/Form/Type/RoomType.php
index fa85806e8..cf1216706 100644
--- a/src/Form/Type/RoomType.php
+++ b/src/Form/Type/RoomType.php
@@ -61,6 +61,8 @@ public function buildForm(FormBuilderInterface $builder, array $options)
->add('dissallowPrivateMessage',CheckboxType::class,array('required'=>false,'label' => 'label.dissallowPrivateMessage', 'translation_domain' => 'form'))
->add('public',CheckboxType::class,array('required'=>false,'label' => 'label.puplicRoom', 'translation_domain' => 'form'))
->add('showRoomOnJoinpage',CheckboxType::class,array('required'=>false,'label' => 'label.showRoomOnJoinpage', 'translation_domain' => 'form'))
+ ->add('maxParticipants',NumberType::class,array('required'=>false,'label' => 'label.maxParticipants', 'translation_domain' => 'form'))
+
->add('submit', SubmitType::class, ['attr' => array('class' => 'btn btn-outline-primary'), 'label' => 'label.speichern', 'translation_domain' => 'form']);
}
diff --git a/src/Migrations/Version20210327084427.php b/src/Migrations/Version20210327084427.php
new file mode 100644
index 000000000..ff8256cb1
--- /dev/null
+++ b/src/Migrations/Version20210327084427.php
@@ -0,0 +1,31 @@
+addSql('ALTER TABLE rooms ADD max_participants INT DEFAULT NULL');
+ }
+
+ public function down(Schema $schema) : void
+ {
+ // this down() migration is auto-generated, please modify it to your needs
+ $this->addSql('ALTER TABLE rooms DROP max_participants');
+ }
+}
diff --git a/src/Service/SubcriptionService.php b/src/Service/SubcriptionService.php
index a1948d6fe..98eff11a1 100644
--- a/src/Service/SubcriptionService.php
+++ b/src/Service/SubcriptionService.php
@@ -84,6 +84,11 @@ public function acceptSub(?Subscriber $subscriber){
$res['message'] =$this->translator->trans('Danke für die Anmeldung. ');
$res['title'] =$this->translator->trans('Erfolgreich bestätigt');
if($subscriber){
+ if(sizeof($subscriber->getRoom()->getUser()) >= $subscriber->getRoom()->getMaxParticipants()){
+ $res['message'] =$this->translator->trans('Die maximale Teilnehmeranzahl ist bereits erreicht.');
+ $res['title'] =$this->translator->trans('Fehler');
+ return $res;
+ }
try {
$subscriber->getUser()->addRoom($subscriber->getRoom());
$user = $subscriber->getUser();
diff --git a/templates/base/__newRoomModal.html.twig b/templates/base/__newRoomModal.html.twig
index 7d95183bd..4e37da53e 100644
--- a/templates/base/__newRoomModal.html.twig
+++ b/templates/base/__newRoomModal.html.twig
@@ -37,6 +37,13 @@
{{ form_row(form.public) }}
+
+
+
+ {{ form_row(form.maxParticipants) }}
+
+
+
{{ form_row(form.showRoomOnJoinpage) }}
diff --git a/templates/share_link/subscribe.html.twig b/templates/share_link/subscribe.html.twig
index 28424201d..abdcbb006 100644
--- a/templates/share_link/subscribe.html.twig
+++ b/templates/share_link/subscribe.html.twig
@@ -73,6 +73,8 @@
{{ 'Melden Sie sich an und schreiben Sie sich auf der Teilnehmerliste ein'|trans }}