2012-07-07 20:15:36 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace KekRozsak\AdminBundle\Controller;
|
|
|
|
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
2012-07-15 12:56:31 +00:00
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
|
2012-08-28 15:30:00 +00:00
|
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
2012-09-10 12:00:02 +00:00
|
|
|
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
|
2012-08-28 17:23:42 +00:00
|
|
|
use JMS\DiExtraBundle\Annotation as DI;
|
2012-07-07 20:15:36 +00:00
|
|
|
|
2012-09-10 12:00:02 +00:00
|
|
|
use KekRozsak\FrontBundle\Entity\Group;
|
|
|
|
use KekRozsak\SecurityBundle\Entity\User;
|
|
|
|
|
2012-07-13 10:07:21 +00:00
|
|
|
/**
|
|
|
|
* @Route("/admin")
|
|
|
|
*/
|
2012-07-07 20:15:36 +00:00
|
|
|
class DefaultController extends Controller
|
|
|
|
{
|
2012-08-16 13:52:41 +00:00
|
|
|
/**
|
2012-08-28 17:23:42 +00:00
|
|
|
* @var Symfony\Component\Security\Core\SecurityContext $securityContext
|
|
|
|
*
|
|
|
|
* @DI\Inject("security.context")
|
|
|
|
*/
|
|
|
|
private $securityContext;
|
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
/**
|
2012-08-29 10:43:25 +00:00
|
|
|
* @Route("/regisztraltak.html", name="KekRozsakAdminBundle_manage_regs")
|
2012-08-16 13:52:41 +00:00
|
|
|
* @Template()
|
|
|
|
*/
|
|
|
|
public function manageRegsAction()
|
|
|
|
{
|
2012-09-10 12:00:02 +00:00
|
|
|
$objectIdentity = new ObjectIdentity(User::ACL_OID, 'KekRozsak\\SecurityBundle\\Entity\\User');
|
|
|
|
|
|
|
|
if (!$this->securityContext->isGranted('OWNER', $objectIdentity)) {
|
2012-08-28 15:30:00 +00:00
|
|
|
throw new AccessDeniedException('Ehhez a művelethez nincs jogosultságod.');
|
|
|
|
}
|
2012-09-10 12:00:02 +00:00
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
$users = $this->getDoctrine()->getEntityManager()->createQuery('SELECT u FROM KekRozsakSecurityBundle:User u WHERE u.acceptedBy IS NULL')->getResult();
|
2012-08-28 15:30:00 +00:00
|
|
|
$request = $this->getRequest();
|
|
|
|
|
|
|
|
if ($request->getMethod() == 'POST') {
|
|
|
|
if (is_numeric($userid = $request->get('userid'))) {
|
|
|
|
if (($user = $this->getDoctrine()->getRepository('KekRozsakSecurityBundle:User')->findOneById($userid)) != null) {
|
2012-08-29 10:45:35 +00:00
|
|
|
$activeUser = $this->$securityContext->getToken()->getUser();
|
2012-08-28 15:30:00 +00:00
|
|
|
$user->setAcceptedBy($activeUser);
|
|
|
|
$em = $this->getDoctrine()->getEntityManager();
|
|
|
|
$em->persist($user);
|
|
|
|
$em->flush();
|
|
|
|
|
|
|
|
return $this->redirect($this->generateUrl('KekRozsakAdminBundle_manage_regs'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-13 10:07:21 +00:00
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
return array(
|
|
|
|
'users' => $users,
|
|
|
|
);
|
|
|
|
}
|
2012-07-16 12:16:10 +00:00
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
/**
|
2012-08-29 10:43:25 +00:00
|
|
|
* @Route("/csoport-jelentkezok.html", name="KekRozsakAdminBundle_groupJoinRequests")
|
2012-08-16 13:52:41 +00:00
|
|
|
* @Template()
|
|
|
|
*/
|
|
|
|
public function groupJoinRequestsAction()
|
|
|
|
{
|
2012-08-28 17:23:42 +00:00
|
|
|
$user = $this->securityContext->getToken()->getUser();
|
|
|
|
$request = $this->getRequest();
|
2012-09-10 12:00:02 +00:00
|
|
|
$objectIdentity = new ObjectIdentity(Group::ACL_OID, 'KekRozsak\\FrontBundle\\Entity\\Group');
|
|
|
|
$groupRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:Group');
|
2012-08-28 17:23:42 +00:00
|
|
|
|
2012-09-10 12:00:02 +00:00
|
|
|
if (!$this->securityContext->isGranted('OWNER', $objectIdentity)) {
|
2012-08-28 17:23:42 +00:00
|
|
|
$myGroups = $groupRepo->findByLeader($user);
|
|
|
|
} else {
|
|
|
|
$myGroups = $groupRepo->findAll();
|
|
|
|
}
|
2012-07-16 12:16:10 +00:00
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
if ($request->getMethod() == 'POST') {
|
|
|
|
if ($request->request->has('group') && $request->request->has('user')) {
|
|
|
|
$userRepo = $this->getDoctrine()->getRepository('KekRozsakSecurityBundle:User');
|
|
|
|
$aUser = $userRepo->findOneById($request->request->get('user'));
|
|
|
|
$aGroup = $groupRepo->findOneById($request->request->get('group'));
|
|
|
|
if ($aUser && $aGroup) {
|
2012-08-28 17:23:42 +00:00
|
|
|
if (
|
|
|
|
($aGroup->getLeader() == $user)
|
2012-09-10 12:00:02 +00:00
|
|
|
|| $this->securityContext->isGranted('OWNER', $objectIdentity)
|
2012-08-28 17:23:42 +00:00
|
|
|
) {
|
|
|
|
$membershipRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:UserGroupMembership');
|
|
|
|
$membershipObject = $membershipRepo->findOneBy(array('user' => $aUser, 'group' => $aGroup));
|
|
|
|
if ($membershipObject) {
|
|
|
|
$membershipObject->setMembershipAcceptedAt(new \DateTime('now'));
|
|
|
|
$membershipObject->setMembershipAcceptedBy($user);
|
2012-07-16 12:16:10 +00:00
|
|
|
|
2012-08-28 17:23:42 +00:00
|
|
|
$em = $this->getDoctrine()->getEntityManager();
|
|
|
|
$em->persist($membershipObject);
|
|
|
|
$em->flush();
|
2012-07-16 12:16:10 +00:00
|
|
|
|
2012-08-28 17:23:42 +00:00
|
|
|
return $this->redirect($this->generateUrl('KekRozsakAdminBundle_groupJoinRequests'));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
throw new AccessDeniedException('Csak a csoport vezetője hagyhatja jóvá a jelentkezéseket!');
|
2012-08-16 13:52:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-16 12:16:10 +00:00
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
return array(
|
|
|
|
'groups' => $myGroups,
|
|
|
|
);
|
|
|
|
}
|
2012-07-16 12:16:10 +00:00
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
/**
|
2012-08-29 10:43:25 +00:00
|
|
|
* @Route("/csoport-jelentkezok/elutasitas.html", name="KekRozsakAdminBundle_groupJoinDecline")
|
2012-08-16 13:52:41 +00:00
|
|
|
* @Template()
|
|
|
|
*/
|
|
|
|
public function groupJoinDeclineAction()
|
|
|
|
{
|
|
|
|
// TODO: A reason must be written to decline a join request!
|
|
|
|
return array(
|
|
|
|
);
|
|
|
|
}
|
2012-07-07 20:15:36 +00:00
|
|
|
}
|