3 namespace Mixstore\UserBundle\Controller
;
5 use Symfony\Component\HttpFoundation\Response
;
6 use Symfony\Bundle\FrameworkBundle\Controller\Controller
;
7 use Mixstore\StoreBundle\Entity\Language
;
9 class MyAdminController
extends Controller
12 private function checkSuperAdmin()
14 $sadmin = $this->getUser();
15 if (is_null($sadmin) || !in_array('ROLE_SUPER_ADMIN', $sadmin->getRoles()))
16 //TODO: nice error page
17 return $this->redirect($this->generateUrl('mixstore_static_home'));
20 //set initial languages
21 public function setLanguageAction()
23 $this->checkSuperAdmin();
25 $em = $this->getDoctrine()->getManager();
26 foreach (array('C', 'C#', 'C++', 'Fortran', 'Java', 'Julia', 'Lua', 'MATLAB', 'Octave', 'Python', 'R', 'Scilab') as $lgName)
27 $em->persist(new Language($lgName));
30 return new Response('OK');
33 public function addLanguageAction($lgname)
35 $this->checkSuperAdmin();
37 $em = $this->getDoctrine()->getManager();
38 $em->persist(new Language($lgname));
41 return new Response('OK');
44 public function usersAction()
46 $this->checkSuperAdmin();
48 return $this->render('MixstoreUserBundle:Admin:users.html.twig', array(
52 ->getRepository('MixstoreUserBundle:User')
57 public function toggleAction()
59 $this->checkSuperAdmin();
61 //get id of user to toggle
62 $userId = $this->getRequest()->get('id');
64 $em = $this->getDoctrine()->getManager();
66 ->getRepository('MixstoreUserBundle:User')
67 ->findById($userId)[0];
69 if (in_array('ROLE_ADMIN', $user->getRoles()))
70 $user->setRoles(array('ROLE_USER'));
72 $user->setRoles(array('ROLE_ADMIN'));
78 //dummy unused answer (no error case for the moment)
79 return new Response('OK');
82 public function deleteAction($id)
84 $this->checkSuperAdmin();
86 $em = $this->getDoctrine()->getManager();
88 ->getRepository('MixstoreUserBundle:User')
93 return new Response('OK');
96 //unique usage: set super admin
97 public function setsaAction()
99 $em = $this->getDoctrine()->getManager();
101 ->getRepository('MixstoreUserBundle:User')
102 ->findById(1)[0]; //HACK: hard-coded ID
104 $sadmin->setRoles(array('ROLE_ADMIN', 'ROLE_SUPER_ADMIN'));
105 $em->persist($sadmin);
108 return new response('OK');