/** * Build and persist a PLN. * * @param string $name * @param ObjectManager $manager * * @return Pln */ private function buildPln($name, ObjectManager $manager) { $pln = new Pln(); $pln->setName($name); $manager->persist($pln); return $pln; }
/** * Create a form to edit user access to a PLN. * * This is a custom form, not attached to any specific entity. * * @param Pln $pln * @param User[] $users * @return Form the form */ private function createEditAccessForm(Pln $pln, $users) { $accessManager = $this->get('lom.access'); // The form requires data, so give it some uneditable text to start. $defaultData = array('message' => 'Edit users access.'); $builder = $this->createFormBuilder($defaultData, array('action' => $this->generateUrl('pln_updateaccess', array('id' => $pln->getId())), 'method' => 'POST')); // Options for the access form. $choices = array('PLNADMIN' => 'Admin', 'DEPOSIT' => 'Deposit', 'MONITOR' => 'Monitor'); foreach ($users as $user) { // Admins have total access if ($user->hasRole('ROLE_ADMIN')) { continue; } // find $user's current access level $value = null; foreach (array_keys($choices) as $permission) { if ($accessManager->hasAccess($permission, $pln, $user)) { $value = $permission; break; } } // create the widget. $builder->add('user_' . $user->getId(), 'choice', array('label' => $user->getUsername(), 'choices' => $choices, 'empty_value' => 'No access', 'data' => $value, 'multiple' => false, 'expanded' => false, 'mapped' => false, 'required' => false)); } $builder->add('submit', 'submit', array('label' => 'Update')); return $builder->getForm(); }