Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
vjekoart committed Jul 30, 2015
2 parents 49989b9 + b7d9642 commit 1d57040
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 148 deletions.
149 changes: 67 additions & 82 deletions Controller/PresentationAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Validator\Constraints\DateTime;
use Netgen\LiveVotingBundle\Service\PresentationService\Record\PresentationRecord;
use Doctrine\ORM\EntityRepository;

/**
* Presentation controller. (admin)
Expand All @@ -31,8 +33,8 @@ class PresentationAdminController extends Controller
public function indexAction($event_id)
{
$em = $this->getDoctrine()->getManager();
$event = $em->getRepository('LiveVotingBundle:Event')->find($event_id);
$entities = $em->getRepository('LiveVotingBundle:Presentation')->findBy(array('event'=>$event));
$event = $em->getRepository('LiveVotingBundle:Event')->findOneById($event_id);
$entities = $this->get('live_voting.doctrine_presentation_repo')->find(array('event_id' => $event_id));
/**
* @var $client JoindInClient
*/
Expand All @@ -57,17 +59,17 @@ function($ent) use ($that) {
*/
public function createAction(Request $request, $event_id)
{
$entity = new Presentation();
$event = $this->getDoctrine()->getRepository('LiveVotingBundle:Event')->find($event_id);
$entity->setEvent($event);
$entity = new PresentationRecord();
$entity->setEventId($event_id);
$form = $this->createCreateForm($entity);
$form->handleRequest($request);

if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$entity->upload();
$em->persist($entity);
$em->flush();
$entity->presenterName = $form->getData()['presenterName'];
$entity->presenterSurname = $form->getData()['presenterSurname'];
$entity->setUserId($form->getData()['user']->getId());

$this->get('live_voting.doctrine_presentation_repo')->save($entity);

$request->getSession()->getFlashBag()->add(
'message', 'You have created new presentation.'
Expand All @@ -84,19 +86,45 @@ public function createAction(Request $request, $event_id)

/**
* Creates a form to create a Presentation entity.
* @param Presentation $entity The entity
* @param PresentationRecord $entity The entity
* @return \Symfony\Component\Form\Form The form
*/
private function createCreateForm(Presentation $entity)
{
$form = $this->createForm(new PresentationType(), $entity, array(
'action' => $this->generateUrl('admin_presentation_create', array('event_id'=>$entity->getEvent()->getId())),
'method' => 'POST',
));

$form->add('submit', 'submit', array('label' => 'Create'));
private function createCreateForm(PresentationRecord $entity){
$form = $this->createFormBuilder()
->add('presentationRecord', new PresentationType(), array('data'=>$entity))
->add('presenterName')
->add('presenterSurname')
->add('user', 'entity', array(
'class' => 'LiveVotingBundle:User',
'property' => 'email',
))
->add('submit', 'submit', array('label' => 'Create'))
->setMethod('POST')
->setAction($this->generateUrl('admin_presentation_create', array('event_id'=>$entity->getEventId())));
return $form->getForm();
}

return $form;
/**
* Creates a form to edit a Presentation entity.
* @param Presentation $entity The entity
* @return \Symfony\Component\Form\Form The form
*/
private function createEditForm(PresentationRecord $entity){
$em = $this->getDoctrine()->getManager();

$form = $this->createFormBuilder()
->add('presentationRecord', new PresentationType(), array('data'=>$entity))
->add('presenterName', 'text', array('data' => $entity->presenterName))
->add('presenterSurname', 'text', array('data' => $entity->presenterSurname))
->add('user', 'entity', array(
'class' => 'LiveVotingBundle:User',
'property' => 'email',
'data' => $em->getReference("LiveVotingBundle:User", $entity->getUserId())
))
->add('submit', 'submit', array('label' => 'Edit'))
->setMethod('POST')
->setAction($this->generateUrl('admin_presentation_update', array('id' => $entity->getId())));
return $form->getForm();
}

/**
Expand All @@ -105,14 +133,13 @@ private function createCreateForm(Presentation $entity)
*/
public function newAction($event_id)
{
$entity = new Presentation();
$entity = new PresentationRecord();
$event = $this->getDoctrine()->getRepository('LiveVotingBundle:Event')->find($event_id);
$entity->setEvent($event);
$entity->setEventId($event_id);

$form = $this->createCreateForm($entity);
$form = $this->createCreateForm($entity);
$form->remove('votingEnabled');
return $this->render('LiveVotingBundle:Presentation:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
'event_id' => $event_id
));
Expand All @@ -126,13 +153,7 @@ public function newAction($event_id)
*/
public function editAction($id)
{
$em = $this->getDoctrine()->getManager();

$entity = $em->getRepository('LiveVotingBundle:Presentation')->find($id);

if (!$entity) {
throw $this->createNotFoundException('Unable to find Presentation entity.');
}
$entity = $this->get('live_voting.doctrine_presentation_repo')->findOne($id);

$editForm = $this->createEditForm($entity);

Expand All @@ -141,51 +162,30 @@ public function editAction($id)

return $this->render('LiveVotingBundle:Presentation:edit.html.twig', array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'event_id' => $entity->getEvent()->getId()
'form' => $editForm->createView()
));
}

/**
* Creates a form to edit a Presentation entity.
* @param Presentation $entity The entity
* @return \Symfony\Component\Form\Form The form
*/
private function createEditForm(Presentation $entity)
{
$form = $this->createForm(new PresentationType(), $entity, array(
'action' => $this->generateUrl('admin_presentation_update', array('id' => $entity->getId())),
'method' => 'PUT',

));

$form->add('submit', 'submit', array('label' => 'Update'));

return $form;
}
/**
* Edits an existing Presentation entity.
*/
public function updateAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$entity = $this->get('live_voting.doctrine_presentation_repo')->findOne($id);

$entity = $em->getRepository('LiveVotingBundle:Presentation')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Presentation entity.');
}
$old_image = $entity->getImage();
$editForm = $this->createEditForm($entity);
$editForm->handleRequest($request);
if ($editForm->isValid()) {
$entity->upload();
if($entity->getImage() == null) $entity->setImage($old_image);
$em->flush();
$entity->presenterName = $editForm->getData()['presenterName'];
$entity->presenterSurname = $editForm->getData()['presenterSurname'];
$entity->setUserId($editForm->getData()['user']->getId());

$this->get('live_voting.doctrine_presentation_repo')->update($entity);

$request->getSession()->getFlashBag()->add(
'message', 'Your changes were saved.'
);
return $this->redirect($this->generateUrl('admin_presentation', array('event_id' => $entity->getEvent()->getId())));
return $this->redirect($this->generateUrl('admin_presentation', array('event_id' => $entity->getEventId())));
}

return $this->render('LiveVotingBundle:Presentation:edit.html.twig', array(
Expand All @@ -199,11 +199,11 @@ public function updateAction(Request $request, $id)
* so users can vote on it.
* @param Presentation $entity The entity
*/
public function createEnableDisableForm(Presentation $entity){
public function createEnableDisableForm(PresentationRecord $entity){
$form = $this->createFormBuilder();
$form->setMethod('PUT');
$form->setAction($this->generateUrl('admin_presentation_vote_enable', array('id'=>$entity->getId())));
if($entity->getVotingEnabled()==False)
if($entity->isVotingEnabled()==False)
$form->add('disable', 'submit', array('label'=>'Disabled', 'attr'=>array('class'=>'btn btn-danger')));
else
$form->add('enable', 'submit', array('label'=>'Enabled', 'attr'=>array('class'=>'btn btn-success')));
Expand All @@ -217,25 +217,20 @@ public function createEnableDisableForm(Presentation $entity){
* @param Presenatation Id $id
*/
public function enableDisableAction(Request $request, $id){
$em = $this->getDoctrine()->getManager();
$entity = $this->get('live_voting.doctrine_presentation_repo')->findOne($id);

$entity = $em->getRepository('LiveVotingBundle:Presentation')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Presentation entity.');
}

$form = $this->createEnableDisableForm($entity, 'enabled', array());
$form = $this->createEnableDisableForm($entity);
$form->handleRequest($request);
if ($form->isValid()) {
if($form->getClickedButton()->getName()=='disable'){
$entity->setVotingEnabled(true);
}else{
$entity->setVotingEnabled(false);
}
$em->flush();
$this->get('live_voting.doctrine_presentation_repo')->update($entity);
}

return $this->redirect($this->generateUrl('admin_presentation', array('event_id' => $entity->getEvent()->getId())));
return $this->redirect($this->generateUrl('admin_presentation', array('event_id' => $entity->getEventId())));

}

Expand All @@ -244,18 +239,8 @@ public function enableDisableAction(Request $request, $id){
* @param Presenatation Id $id
*/
public function deleteAction($id){
$em = $this->getDoctrine()->getManager();

$entity = $em->getRepository('LiveVotingBundle:Presentation')->find($id);
$eventId = $entity->getEvent()->getId();

if (!$entity) {
throw $this->createNotFoundException('Presentation is already removed.');
}

$em->remove($entity);
$em->flush();

$eventId = $this->get('live_voting.doctrine_presentation_repo')->findOne($id)->getEventId();
$entity = $this->get('live_voting.doctrine_presentation_repo')->destroy($id);
return $this->redirect($this->generateUrl('admin_presentation', array('event_id' => $eventId )));
}

Expand Down
34 changes: 15 additions & 19 deletions Controller/PresentationUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Netgen\LiveVotingBundle\Entity\Presentation;
use Netgen\LiveVotingBundle\Form\PresentationUserType;
use Netgen\LiveVotingBundle\Service\PresentationService\Record\PresentationRecord;


class PresentationUserController extends Controller
Expand All @@ -17,8 +18,11 @@ public function indexAction()
$user_id = $this->getUser()->getId();
$em = $this->getDoctrine()->getManager();
$user = $em->getRepository('LiveVotingBundle:User')->find($user_id);
$entities = $em->getRepository('LiveVotingBundle:Presentation')->findByUser($this->getUser());

$entities = $this->get('live_voting.doctrine_presentation_repo')->find(array('user'=>$user));

$that = $this;

return $this->render('LiveVotingBundle:Presentation:user.html.twig', array(
'entities' => array_map(
function ($ent) use ($that) {
Expand All @@ -29,11 +33,11 @@ function ($ent) use ($that) {

}

public function createEnableDisableForm(Presentation $entity){
public function createEnableDisableForm(PresentationRecord $entity){
$form = $this->createFormBuilder();
$form->setMethod('PUT');
$form->setAction($this->generateUrl('admin_presentation_vote_enable', array('id'=>$entity->getId())));
if($entity->getVotingEnabled()==False)
if($entity->isVotingEnabled()==False)
$form->add('disable', 'submit', array('label'=>'Disabled', 'attr'=>array('class'=>'btn btn-danger')));
else
$form->add('enable', 'submit', array('label'=>'Enabled', 'attr'=>array('class'=>'btn btn-success')));
Expand All @@ -43,22 +47,19 @@ public function createEnableDisableForm(Presentation $entity){

public function editAction($id)
{
$em = $this->getDoctrine()->getManager();

$entity = $em->getRepository('LiveVotingBundle:Presentation')->find($id);

if (!$entity) {
throw $this->createNotFoundException('Unable to find Presentation entity.');
}
$entity = $this->get('live_voting.doctrine_presentation_repo')->findOne($id);

$editForm = $this->createEditForm($entity);

$event = $this->getDoctrine()->getManager()->getRepository('LiveVotingBundle:Event')->findOneById($entity->getEventId());

// Not needed in edit page
$editForm->remove('votingEnabled');

return $this->render('LiveVotingBundle:Presentation:useredit.html.twig', array(
'entity' => $entity,
'edit_form' => $editForm->createView()
'edit_form' => $editForm->createView(),
'event' => $event
));
}

Expand All @@ -67,7 +68,7 @@ public function editAction($id)
* @param Presentation $entity The entity
* @return \Symfony\Component\Form\Form The form
*/
private function createEditForm(Presentation $entity)
private function createEditForm(PresentationRecord $entity)
{
$form = $this->createForm(new PresentationUserType(), $entity, array(
'action' => $this->generateUrl('user_presentation_update', array('id' => $entity->getId())),
Expand All @@ -81,19 +82,14 @@ private function createEditForm(Presentation $entity)
}
public function updateAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$entity = $this->get('live_voting.doctrine_presentation_repo')->findOne($id);

$entity = $em->getRepository('LiveVotingBundle:Presentation')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Presentation entity.');
}

$editForm = $this->createEditForm($entity);
$editForm->handleRequest($request);

if ($editForm->isValid()) {
$entity->upload();
$em->flush();
$this->get('live_voting.doctrine_presentation_repo')->update($entity);

$request->getSession()->getFlashBag()->add(
'message', 'Your changes were saved.'
Expand Down
17 changes: 7 additions & 10 deletions Form/PresentationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,17 @@ class PresentationType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('presenterName', 'text' ,array('attr' => array('class' => 'form-control')))
->add('presenterSurname', 'text' ,array('attr' => array('class' => 'form-control')))
->add('presentationName', 'text' ,array('attr' => array('class' => 'form-control')))
->add('name', 'text' ,array('attr' => array('class' => 'form-control')))
->add('description', 'textarea' ,array('attr' => array('class' => 'form-control', 'rows' => "7")))
->add('image', 'file', array(
->add('image_url', 'file', array(
'data_class' => null,
'required' => false
))
->add('globalBrake', 'checkbox', array('attr' => array('class' => 'form-control'), "label" => "Global break (lunch, pause, etc.)"))
->add('globalBrake', 'checkbox', array('attr' => array('class' => 'form-control'), "label" => "Global break (lunch, pause, etc.)", 'required' => false))
->add('hall', 'text' ,array('attr' => array('class' => 'form-control')))
->add('user', 'entity' ,array('attr' => array('class' => 'form-control'), 'class' => 'LiveVotingBundle:User', 'property' => 'email'))
->add('begin')
->add('end')
->add('joind_in_id', 'text', array('attr' => array('class' => 'form-control')))
->add('begin', 'datetime')
->add('end', 'datetime')
->add('joind_in_id', 'text', array('attr' => array('class' => 'form-control', 'required' => false)))
//->add('event', 'entity', array('class'=>'Netgen\LiveVotingBundle\Entity\Event', 'disabled'=>true))
;
}
Expand All @@ -39,7 +36,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Netgen\LiveVotingBundle\Entity\Presentation',
'data_class' => 'Netgen\LiveVotingBundle\Service\PresentationService\Record\PresentationRecord',
'attr' => array('style'=>'width:300px;margin-left:10px;', 'role'=>'form')
));
}
Expand Down
Loading

0 comments on commit 1d57040

Please sign in to comment.