Made group creation possible (open groups only, yet)
This commit is contained in:
@@ -78,124 +78,6 @@ class DefaultController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/csoportok", name="KekRozsakFrontBundle_groupList")
|
||||
* @Template()
|
||||
*/
|
||||
public function groupListAction()
|
||||
{
|
||||
$groupRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:Group');
|
||||
$groups = $groupRepo->findAll(array('name' => 'DESC'));
|
||||
return array(
|
||||
'groups' => $groups,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/csoport/{groupSlug}", name="KekRozsakFrontBundle_groupView")
|
||||
* @Template()
|
||||
*/
|
||||
public function groupViewAction($groupSlug)
|
||||
{
|
||||
$groupRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:Group');
|
||||
if (!($group = $groupRepo->findOneBySlug($groupSlug)))
|
||||
throw $this->createNotFoundException('A kért csoport nem létezik!');
|
||||
|
||||
return array(
|
||||
'group' => $group,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/csoport/{groupSlug}/tagok", name="KekRozsakFrontBundle_groupMembers")
|
||||
* @Template()
|
||||
*/
|
||||
public function groupMembersAction($groupSlug)
|
||||
{
|
||||
$groupRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:Group');
|
||||
if (!($group = $groupRepo->findOneBySlug($groupSlug)))
|
||||
throw $this->createNotFoundException('A kért csoport nem létezik!');
|
||||
|
||||
return array(
|
||||
'group' => $group,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/csoport/{groupSlug}/dokumentumok", name="KekRozsakFrontBundle_groupDocuments")
|
||||
* @Template()
|
||||
*/
|
||||
public function groupDocumentsAction($groupSlug)
|
||||
{
|
||||
$groupRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:Group');
|
||||
if (!($group = $groupRepo->findOneBySlug($groupSlug)))
|
||||
throw $this->createNotFoundException('A kért csoport nem létezik!');
|
||||
|
||||
return array(
|
||||
'group' => $group,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/csoport/{groupSlug}/belepes", name="KekRozsakFrontBundle_groupJoin")
|
||||
* @Template()
|
||||
*/
|
||||
public function groupJoinAction($groupSlug)
|
||||
{
|
||||
$user = $this->get('security.context')->getToken()->getUser();
|
||||
$groupRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:Group');
|
||||
if (!($group = $groupRepo->findOneBySlug($groupSlug)))
|
||||
throw $this->createNotFoundException('A kért csoport nem létezik!');
|
||||
|
||||
if ($group->isMember($user))
|
||||
{
|
||||
return $this->redirect($this->generateUrl('KekRozsakFrontBundle_groupView', array($groupSlug => $group->getSlug())));
|
||||
}
|
||||
|
||||
if ($group->isRequested($user))
|
||||
{
|
||||
return array(
|
||||
'isRequested' => true,
|
||||
'needApproval' => false,
|
||||
'group' => $group,
|
||||
);
|
||||
}
|
||||
|
||||
$membership = new UserGroupMembership();
|
||||
$membership->setUser($user);
|
||||
$membership->setGroup($group);
|
||||
$membership->setMembershipRequestedAt(new \DateTime('now'));
|
||||
if ($group->isOpen())
|
||||
{
|
||||
$membership->setMembershipAcceptedAt(new \DateTime('now'));
|
||||
}
|
||||
|
||||
$em = $this->getDoctrine()->getEntityManager();
|
||||
$em->persist($membership);
|
||||
$em->flush();
|
||||
|
||||
if ($group->isOpen())
|
||||
{
|
||||
return $this->redirect($this->generateUrl('KekRozsakFrontBundle_groupView', array($groupSlug => $group->getSlug())));
|
||||
}
|
||||
else
|
||||
{
|
||||
$message = \Swift_Message::newInstance()
|
||||
->setSubject('Új jelentkező a csoportodban (' . $group->getName() . '): ' . $user->getDisplayName())
|
||||
// TODO: Make this a config parameter!
|
||||
->setFrom('info@blueroses.hu')
|
||||
->setTo($group->getLeader()->getEmail())
|
||||
->setBody($this->renderView('KekRozsakFrontBundle:Email:groupJoinRequest.txt.twig', array('user' => $user, 'group' => $group)));
|
||||
$this->get('mailer')->send($message);
|
||||
|
||||
return array(
|
||||
'isRequested' => false,
|
||||
'needApproval' => true,
|
||||
'group' => $group,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/dokumentum/{documentSlug}", name="KekRozsakFrontBundle_documentView")
|
||||
* @Template()
|
||||
|
175
src/KekRozsak/FrontBundle/Controller/GroupController.php
Normal file
175
src/KekRozsak/FrontBundle/Controller/GroupController.php
Normal file
@@ -0,0 +1,175 @@
|
||||
<?php
|
||||
|
||||
namespace KekRozsak\FrontBundle\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
|
||||
|
||||
use KekRozsak\FrontBundle\Entity\UserGroupMembership;
|
||||
use KekRozsak\FrontBundle\Entity\Group;
|
||||
|
||||
use KekRozsak\FrontBundle\Form\Type\GroupType;
|
||||
|
||||
use KekRozsak\FrontBundle\Extensions\Slugifier;
|
||||
|
||||
class GroupController extends Controller
|
||||
{
|
||||
/**
|
||||
* @Route("/csoportok", name="KekRozsakFrontBundle_groupList")
|
||||
* @Template()
|
||||
*/
|
||||
public function groupListAction()
|
||||
{
|
||||
$groupRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:Group');
|
||||
$groups = $groupRepo->findAll(array('name' => 'DESC'));
|
||||
return array(
|
||||
'groups' => $groups,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/csoport/{groupSlug}", name="KekRozsakFrontBundle_groupView")
|
||||
* @Template()
|
||||
*/
|
||||
public function groupViewAction($groupSlug)
|
||||
{
|
||||
$groupRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:Group');
|
||||
if (!($group = $groupRepo->findOneBySlug($groupSlug)))
|
||||
throw $this->createNotFoundException('A kért csoport nem létezik!');
|
||||
|
||||
return array(
|
||||
'group' => $group,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/csoport/{groupSlug}/tagok", name="KekRozsakFrontBundle_groupMembers")
|
||||
* @Template()
|
||||
*/
|
||||
public function groupMembersAction($groupSlug)
|
||||
{
|
||||
$groupRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:Group');
|
||||
if (!($group = $groupRepo->findOneBySlug($groupSlug)))
|
||||
throw $this->createNotFoundException('A kért csoport nem létezik!');
|
||||
|
||||
return array(
|
||||
'group' => $group,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/csoport/{groupSlug}/dokumentumok", name="KekRozsakFrontBundle_groupDocuments")
|
||||
* @Template()
|
||||
*/
|
||||
public function groupDocumentsAction($groupSlug)
|
||||
{
|
||||
$groupRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:Group');
|
||||
if (!($group = $groupRepo->findOneBySlug($groupSlug)))
|
||||
throw $this->createNotFoundException('A kért csoport nem létezik!');
|
||||
|
||||
return array(
|
||||
'group' => $group,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/csoport/{groupSlug}/belepes", name="KekRozsakFrontBundle_groupJoin")
|
||||
* @Template()
|
||||
*/
|
||||
public function groupJoinAction($groupSlug)
|
||||
{
|
||||
$user = $this->get('security.context')->getToken()->getUser();
|
||||
$groupRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:Group');
|
||||
if (!($group = $groupRepo->findOneBySlug($groupSlug)))
|
||||
throw $this->createNotFoundException('A kért csoport nem létezik!');
|
||||
|
||||
if ($group->isMember($user))
|
||||
{
|
||||
return $this->redirect($this->generateUrl('KekRozsakFrontBundle_groupView', array($groupSlug => $group->getSlug())));
|
||||
}
|
||||
|
||||
if ($group->isRequested($user))
|
||||
{
|
||||
return array(
|
||||
'isRequested' => true,
|
||||
'needApproval' => false,
|
||||
'group' => $group,
|
||||
);
|
||||
}
|
||||
|
||||
$membership = new UserGroupMembership();
|
||||
$membership->setUser($user);
|
||||
$membership->setGroup($group);
|
||||
$membership->setMembershipRequestedAt(new \DateTime('now'));
|
||||
if ($group->isOpen())
|
||||
{
|
||||
$membership->setMembershipAcceptedAt(new \DateTime('now'));
|
||||
}
|
||||
|
||||
$em = $this->getDoctrine()->getEntityManager();
|
||||
$em->persist($membership);
|
||||
$em->flush();
|
||||
|
||||
if ($group->isOpen())
|
||||
{
|
||||
return $this->redirect($this->generateUrl('KekRozsakFrontBundle_groupView', array($groupSlug => $group->getSlug())));
|
||||
}
|
||||
else
|
||||
{
|
||||
$message = \Swift_Message::newInstance()
|
||||
->setSubject('Új jelentkező a csoportodban (' . $group->getName() . '): ' . $user->getDisplayName())
|
||||
// TODO: Make this a config parameter!
|
||||
->setFrom('info@blueroses.hu')
|
||||
->setTo($group->getLeader()->getEmail())
|
||||
->setBody($this->renderView('KekRozsakFrontBundle:Email:groupJoinRequest.txt.twig', array('user' => $user, 'group' => $group)));
|
||||
$this->get('mailer')->send($message);
|
||||
|
||||
return array(
|
||||
'isRequested' => false,
|
||||
'needApproval' => true,
|
||||
'group' => $group,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/csoportok/uj", name="KekRozsakFrontBundle_groupCreate")
|
||||
* @Template()
|
||||
*/
|
||||
public function groupCreateAction()
|
||||
{
|
||||
$group = new Group();
|
||||
$form = $this->createForm(new GroupType(), $group);
|
||||
$request = $this->getRequest();
|
||||
|
||||
if ($request->getMethod() == 'POST')
|
||||
{
|
||||
$form->bindRequest($request);
|
||||
if ($form->isValid())
|
||||
{
|
||||
$slugifier = new Slugifier();
|
||||
$user = $this->get('security.context')->getToken()->getUser();
|
||||
|
||||
$group->setCreatedBy($user);
|
||||
$group->setSlug($slugifier->slugify($group->getName()));
|
||||
$group->setCreatedAt(new \DateTime('now'));
|
||||
$group->setOpen(true);
|
||||
|
||||
$em = $this->getDoctrine()->getEntityManager();
|
||||
$em->persist($group);
|
||||
$em->flush();
|
||||
|
||||
$membership = new UserGroupMembership($user, $group);
|
||||
$em->persist($membership);
|
||||
$em->flush();
|
||||
|
||||
return $this->redirect($this->generateUrl('KekRozsakFrontBundle_groupList'));
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'form' => $form->createView(),
|
||||
);
|
||||
}
|
||||
}
|
@@ -4,6 +4,8 @@ namespace KekRozsak\FrontBundle\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Symfony\Bridge\Doctrine\Validator\Constraints as DoctrineAssert;
|
||||
|
||||
use KekRozsak\SecurityBundle\Entity\User;
|
||||
use KekRozsak\FrontBundle\Entity\Document;
|
||||
@@ -12,6 +14,8 @@ use KekRozsak\FrontBundle\Entity\Document;
|
||||
* KekRozsak\FrontBundle\Entity\Group
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="groups")
|
||||
* @DoctrineAssert\UniqueEntity(fields="name", message="Ilyen nevű csoport már létezik. Kérlek, válassz másikat!")
|
||||
* @DoctrineAssert\UniqueEntity(fields="slug", message="Ilyen nevű csoport már létezik. Kérlek, válasz másikat!")
|
||||
*/
|
||||
class Group
|
||||
{
|
||||
@@ -70,6 +74,7 @@ class Group
|
||||
/**
|
||||
* @var string $name
|
||||
* @ORM\Column(type="string", length=50, nullable=false, unique=true)
|
||||
* @Assert\NotBlank()
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
|
@@ -15,6 +15,14 @@ use KekRozsak\SecurityBundle\Entity\User;
|
||||
*/
|
||||
class UserGroupMembership
|
||||
{
|
||||
public function __construct(\KekRozsak\SecurityBundle\Entity\User $user, \KekRozsak\FrontBundle\Entity\Group $group)
|
||||
{
|
||||
$this->setUser($user);
|
||||
$this->setGroup($group);
|
||||
$this->setMembershipRequestedAt(new \DateTime('now'));
|
||||
$this->setMembershipAcceptedAt(new \DateTime('now'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @var integer $id
|
||||
* @ORM\Id
|
||||
|
33
src/KekRozsak/FrontBundle/Extensions/Slugifier.php
Normal file
33
src/KekRozsak/FrontBundle/Extensions/Slugifier.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace KekRozsak\FrontBundle\Extensions;
|
||||
|
||||
class Slugifier
|
||||
{
|
||||
/**
|
||||
* Slugify string
|
||||
*
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
public function slugify($text)
|
||||
{
|
||||
$text = trim(preg_replace('~[^\\pL\d]+~u', '-', $text));
|
||||
|
||||
if (function_exists('iconv'))
|
||||
{
|
||||
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
|
||||
}
|
||||
|
||||
$text = strtolower($text);
|
||||
|
||||
$text = preg_replace('~[^-\w]+~', '', $text);
|
||||
|
||||
if (empty($text))
|
||||
{
|
||||
$text = 'n-a';
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
}
|
25
src/KekRozsak/FrontBundle/Form/Type/GroupType.php
Normal file
25
src/KekRozsak/FrontBundle/Form/Type/GroupType.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace KekRozsak\FrontBundle\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
class GroupType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->add('name', null, array(
|
||||
'label' => 'A csoport neve',
|
||||
));
|
||||
|
||||
$builder->add('description', 'ckeditor', array(
|
||||
'label' => 'A csoport leírása',
|
||||
));
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'group';
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
{% extends '::main_template.html.twig' %}
|
||||
{% block title %} - Csoport létrehozása{% endblock %}
|
||||
{% block content %}
|
||||
<h3>Csoport létrehozása</h3>
|
||||
<p>Warning</p>
|
||||
<form method="post" action="{{ path('KekRozsakFrontBundle_groupCreate') }}">
|
||||
{{ form_widget(form) }}
|
||||
<button type="submit">Létrehozás</button>
|
||||
</form>
|
||||
{% endblock content %}
|
@@ -26,7 +26,7 @@
|
||||
<span title="Már jelentkeztél, de a jelentkezésedet a csoport vezetője még nem fogadta el" class="ikon">[jelentkeztél ikon]</span>
|
||||
{% else %}
|
||||
{% if group.isOpen %}
|
||||
<a href="{{ path('KekRozsakFrontBundle_groupJoin, { groupSlug: group.slug }') }}"><span title="Nyílt csoport, kattints a belépéshez!" class="ikon">[nyílt ikon]</span></a>
|
||||
<a href="{{ path('KekRozsakFrontBundle_groupJoin', { groupSlug: group.slug }) }}"><span title="Nyílt csoport, kattints a belépéshez!" class="ikon">[nyílt ikon]</span></a>
|
||||
{% else %}
|
||||
<a href="{{ path('KekRozsakFrontBundle_groupJoin', { groupSlug: group.slug }) }}"><span title="Zárt csoport, kattints a jelentkezéshez!" class="ikon">[zárt ikon]</span></a>
|
||||
{% endif %}
|
||||
@@ -37,7 +37,7 @@
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
Új csoport létrehozása
|
||||
<a href="{{ path('KekRozsakFrontBundle_groupCreate') }}">Új csoport létrehozása</a>
|
||||
{% endblock content %}
|
||||
{% block bottomscripts %}
|
||||
<script type="text/javascript">
|
@@ -9,5 +9,5 @@
|
||||
<li><a href="{{ path('KekRozsakFrontBundle_groupDocuments', {groupSlug: group.slug }) }}">Dokumentumok</a></li>
|
||||
</ul>
|
||||
<h3>{{ group.name }}</h3>
|
||||
{{ group.description }}
|
||||
{{ group.description|raw }}
|
||||
{% endblock %}
|
Reference in New Issue
Block a user