/** * @Route("/clients", name="showClients") * @Template() */ public function showClientsAction(Request $request) { $fsDiskUsage = (int) round($this->getFsUsed(Globals::getBackupDir()) * 100 / $this->getFsSize(Globals::getBackupDir()), 0, PHP_ROUND_HALF_UP); $repository = $this->getDoctrine()->getRepository('BinovoElkarBackupBundle:Client'); $query = $repository->createQueryBuilder('c')->addOrderBy('c.id', 'ASC')->getQuery(); $paginator = $this->get('knp_paginator'); $pagination = $paginator->paginate($query, $request->query->get('page', 1), $request->get('lines', $this->container->getParameter('pagination_lines_per_page'))); foreach ($pagination as $i => $client) { $client->setLogEntry($this->getLastLogForLink('%/client/' . $client->getId())); foreach ($client->getJobs() as $job) { $job->setLogEntry($this->getLastLogForLink('%/client/' . $client->getId() . '/job/' . $job->getId())); } } $this->info('View clients', array(), array('link' => $this->generateUrl('showClients'))); $this->getDoctrine()->getManager()->flush(); return $this->render('BinovoElkarBackupBundle:Default:clients.html.twig', array('pagination' => $pagination, 'fsDiskUsage' => $fsDiskUsage)); }
/** * @Route("/clients", name="showClients") * @Template() */ public function showClientsAction(Request $request) { $user = $this->get('security.context')->getToken()->getUser(); $actualuserid = $user->getId(); $fsDiskUsage = (int) round($this->getFsUsed(Globals::getBackupDir()) * 100 / $this->getFsSize(Globals::getBackupDir()), 0, PHP_ROUND_HALF_UP); $repository = $this->getDoctrine()->getRepository('BinovoElkarBackupBundle:Client'); $query = $repository->createQueryBuilder('c')->addOrderBy('c.id', 'ASC'); if (!$this->get('security.context')->isGranted('ROLE_ADMIN')) { // Limited view for non-admin users $query->where('c.owner = ?1'); //adding users and roles $query->setParameter(1, $actualuserid); } $query->getQuery(); $paginator = $this->get('knp_paginator'); $pagination = $paginator->paginate($query, $request->query->get('page', 1), $request->get('lines', $this->getUserPreference($request, 'linesperpage'))); foreach ($pagination as $i => $client) { $client->setLogEntry($this->getLastLogForLink('%/client/' . $client->getId())); foreach ($client->getJobs() as $job) { $job->setLogEntry($this->getLastLogForLink('%/client/' . $client->getId() . '/job/' . $job->getId())); } } $this->info('View clients', array(), array('link' => $this->generateUrl('showClients'))); $this->getDoctrine()->getManager()->flush(); return $this->render('BinovoElkarBackupBundle:Default:clients.html.twig', array('pagination' => $pagination, 'fsDiskUsage' => $fsDiskUsage)); }