public function testOtherProfile() { $person1 = new Person(); $person1->setName('John Smith'); $person2 = new Person(); $person2->setName('Joe Bloggs'); $this->user->setPerson($person2); $this->assertEquals(ProfileVoter::ACCESS_DENIED, $this->voter->vote($this->token, $person1, array('EDIT'))); }
/** * @Given /^the person "([^"]*)"$/ */ public function createPerson($person_name) { $person = new Person(); $person->setName($person_name); $em = $this->getEntityManager(); $em->persist($person); $em->flush(); return $person; }
/** * {@inheritDoc} */ public function load(ObjectManager $manager) { $file = __DIR__ . '/../../Resources/data/people.yml'; $data = Yaml::parse(file_get_contents($file)); foreach ($data as $item) { $person = new Person(); $person->setName($item['name']); $person->setDescription($item['description']); $manager->persist($person); } $manager->flush(); }
public function testFindCanonicalPerson_mapped() { $person1 = new Person(); $person1->setName('Fred Smith'); $this->em->persist($person1); $person2 = new Person(); $person2->setName('Freddie Smith'); $person2->setMappedTo($person1); $this->em->persist($person2); $this->em->flush(); $person = $this->getRepository()->findCanonicalPerson('Freddie Smith'); $this->assertEquals('Fred Smith', $person->getName()); }
public function linkPersonAction(Request $request) { $user = $this->get('security.context')->getToken()->getUser(); if ($user->getPerson()) { $this->redirect($this->generateUrl('camdram_security_setup_roles')); } $people_res = $this->getDoctrine()->getRepository('ActsCamdramBundle:Person'); $people = $people_res->findWithSimilarName($user->getName()); $utils = $this->get('camdram.security.name_utils'); $people = $utils->filterPossibleUsers($user->getName(), $people); if (count($people) == 0) { $this->redirect($this->generateUrl('camdram_security_setup_roles')); } if ($request->getMethod() == 'POST') { $person_ids = array_keys($this->getRequest()->get('link_people', array())); $selected_people = array(); foreach ($person_ids as $id) { foreach ($people as $p) { if ($p->getId() == $id) { $selected_people[] = $p; } } } $em = $this->getDoctrine()->getManager(); if (count($selected_people) == 0) { $p = new Person(); $p->setName($user->getName()); $user->setPerson($p); $em->persist($p); } else { $person = $this->mergePeople($people); $user->setPerson($person); } $em->flush(); return $this->redirect($this->generateUrl('camdram_security_setup')); } return $this->render('ActsCamdramSecurityBundle:Setup:link_person.html.twig', array('people' => $people)); }
/** * Utility function for adding a person to this show. A new person * record is created if they don't already exist. * * @param Show $show This show. * @param string $role_type The type of role ('cast', 'band', 'prod') * @param string $role_name Director, Producer, Macbeth.. * @param string $person_name The person's name */ private function addRoleToShow(Show $show, $role_type, $role_name, $person_name) { $role = new Role(); $role->setType($role_type); $role->setRole($role_name); $em = $this->getDoctrine()->getManager(); $person_repo = $em->getRepository('ActsCamdramBundle:Person'); /* Try and find the person. Add a new person if they don't exist. */ $person = $person_repo->findCanonicalPerson($person_name); if ($person == null) { $person = new Person(); $person->setName($person_name); $em->persist($person); } $role->setPerson($person); /* Append this role to the list of roles of this type. */ $order = $this->getDoctrine()->getRepository('ActsCamdramBundle:Role')->getMaxOrderByShowType($show, $role->getType()); $role->setOrder(++$order); $role->setShow($show); $em->persist($role); $person->addRole($role); $show->addRole($role); $em->flush(); }