Last active
December 25, 2015 10:29
-
-
Save KeKs0r/6961782 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Finds and displays a BetRound entity. | |
* | |
* @Route("/{id}/add", name="betround_add") | |
* @ParamConverter("betRound", class="StregoTippBundle:BetRound") | |
* @Template() | |
*/ | |
public function addAction(BetRound $betRound) | |
{ | |
$user = $this->getSecurityContext($betRound)->getToken()->getUser(); | |
$userGroup = new UserGroup(); | |
foreach ($betRound->getUsers() as $user) { | |
$userGroup->addUser($user); | |
} | |
$form = $this->createForm(new UserGroupQuickType(), $userGroup); | |
$request = $this->getRequest(); | |
if ('POST' === $request->getMethod()) { | |
$form->submit($request); | |
if ($form->isValid()) { | |
/** @var $myUserManager UserManager */ | |
$myUserManager = $this->container->get('strego_user.user_manager'); | |
$group = $form->getData(); | |
foreach ($group->getUsers() as $toInvite) { | |
if (!$betRound->getUserGroup()->hasUser($toInvite)) { | |
$myUserManager->joinGroup($betRound->getUserGroup(), $toInvite); | |
} | |
} | |
$this->getDoctrine()->getManager()->flush(); | |
$this->get('session')->getFlashBag()->add('success', 'Erfolgreich eingeladen!'); | |
return $this->redirect($this->generateUrl('betround_show', array('id' => $betRound->getId()))); | |
} | |
} | |
return array( | |
'form' => $form->createView(), | |
'betRound' => $betRound | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* | |
* @Route("/{slug}/add", name="strego_user_group_add") | |
* @ParamConverter("userGroup", class="StregoUserBundle:UserGroup") | |
* @Template() | |
*/ | |
public function addAction(UserGroup $userGroup) | |
{ | |
$tempGroup = new UserGroup(); | |
foreach ($userGroup->getUsers() as $user) { | |
$tempGroup->addUser($user); | |
} | |
$form = $this->container->get('form.factory')->create(new UserGroupQuickType(), $tempGroup); | |
$request = $this->container->get('request'); | |
if ('POST' === $request->getMethod()) { | |
$form->submit($request); | |
if ($form->isValid()) { | |
$group = $form->getData(); | |
/** @var $myUserManager UserManager */ | |
$myUserManager = $this->container->get('strego_user.user_manager'); | |
/** @var $em EntityManager */ | |
$em = $this->container->get('em'); | |
foreach ($group->getUsers() as $toInvite) { | |
$myUserManager->joinGroup($userGroup, $toInvite); | |
} | |
$em->persist($userGroup); | |
$em->flush($userGroup); | |
} | |
} | |
return array( | |
'form' => $form->createView(), | |
'userGroup' => $userGroup | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function joinGroup(UserGroup $userGroup, User $user = null) | |
{ | |
if ($user === null) { | |
$user = $this->securityContext->getToken()->getUser(); | |
} | |
if (!$userGroup->getUsers()->contains($user)) { | |
print('<br>invite:' . $user); | |
$userGroup->addUser($user); | |
$this->em->persist($userGroup); | |
$this->dispatcher->dispatch( | |
UserEvents::USER_USERGROUP_JOIN, | |
new UserGroupUserEvent($userGroup, $user) | |
); | |
} else { | |
print('<br>is already in:' . $user); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment