public function memberListAction() { $em = $this->get('doctrine')->getManager(); $usergroup = new UserGroup($this->get('database_connection')); $users = $usergroup->getList('Loper'); $total = 0; $stats = []; $securityContext = $this->container->get('security.context'); if ($securityContext->isGranted('ROLE_ADMIN')) { $schemas = $em->getRepository('ZabutoBuurtpreventieBundle:Loopschema')->findAllHistory(); $total = count($schemas); $current = (int) date_format(new DateTime(), 'm'); foreach ($schemas as $schema) { $userId = $schema->getLoper()->getId(); $month = (int) $schema->getDatum()->format('m'); // Huidige maand overslaan. De activiteit wordt berekend // over de voorgaande (afgeronde) maanden. if ($month == $current) { continue; } // Activiteit per maand en totale activiteit van deze loper if (isset($stats[$userId])) { $stats[$userId]['total']++; $isSetMonth = isset($stats[$userId]['activity'][$month]); if ($isSetMonth) { $stats[$userId]['activity'][$month]++; } else { $stats[$userId]['activity'][$month] = 1; } } else { $stats[$userId]['total'] = 1; $stats[$userId]['activity'] = array($month => 1); } } } return $this->render('ZabutoUserBundle:User:member-list.html.twig', array('users' => $users, 'stats' => $stats, 'total' => $total)); }
/** * Aanmelding voor nieuwe datum * * @param string $date * @return \Symfony\Component\HttpFoundation\Response */ public function addDateFormAction($date) { $securityContext = $this->container->get('security.context'); $date = new DateTime($date); $user = $securityContext->getToken()->getUser(); $em = $this->get('doctrine')->getManager(); $repo = $em->getRepository('ZabutoBuurtpreventieBundle:Loopschema'); $afgemeld = $repo->findAllInactiveForDate($date, $user); $usergroup = new UserGroup($this->get('database_connection')); $loopschema = new Loopschema(); $loopschema->setDatum($date); $toelichting = new Looptoelichting(); $loopschema->addToelichting($toelichting); $form = $this->createForm(new LoopschemaNieuwFormType(), $loopschema); $form->setData($loopschema); $isAdmin = false; if ($securityContext->isGranted('ROLE_ADMIN')) { $isAdmin = true; } // Aanpassing m.b.t. tijden voor loopschemas // Men kan zelf een tijd aangeven voor een loopschema // of een bestaande tijd selecteren. $schemas = $repo->findAllActiveForDate($date); $tijden = []; $aangemeld = []; foreach ($schemas as $schema) { $tijd = $schema->getDatum()->format('H:i'); $actueel = $schema->getActueel(); if ($actueel == 1 && $tijd != '00:00') { $loperId = $schema->getLoper()->getId(); $tijden[] = $tijd; if (array_key_exists($tijd, $aangemeld)) { $aangemeld[$tijd][] = $loperId; } else { $aangemeld[$tijd] = [$loperId]; } } } $toelichtingen = $em->getRepository('ZabutoBuurtpreventieBundle:Looptoelichting')->findForDate($date); $tijden = array_unique($tijden); $lopers = []; // Aanpassing voor de beheerder: de beheerder kan voortaan // zelf lopers inplannen voor een bepaalde datum. if ($isAdmin) { $groupId = $usergroup->findGroupId("Loper"); // Genereer een lijst met lopers if ($groupId !== false) { $lopers = $usergroup->findGroupMembers($groupId); } } $data = array('entity' => $loopschema, 'form' => $form->createView(), 'action' => $this->generateUrl('buurtpreventie_loper_nieuwe_datum_schema_post', array('date' => $loopschema->getDatum()->format('Y-m-d'))), 'afgemeld' => $afgemeld, 'tijden' => $tijden, 'lopers' => $lopers, 'is_admin' => $isAdmin, 'aangemeld' => $aangemeld, 'toelichtingen' => $toelichtingen); return $this->render('ZabutoBuurtpreventieBundle:Loperschema:add-form.html.twig', $data); }