예제 #1
0
 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')));
 }
예제 #2
0
 /**
  * @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;
 }
예제 #3
0
 /**
  * {@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();
 }
예제 #4
0
 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());
 }
 private function deletePerson(Person $person, OutputInterface $output)
 {
     $em = $this->getContainer()->get('doctrine.orm.entity_manager');
     $people_res = $em->getRepository('ActsCamdramBundle:Person');
     $mapped_people = $people_res->findBy(array('mapped_to' => $person));
     foreach ($mapped_people as $mapped_person) {
         $this->deletePerson($mapped_person, $output);
     }
     if (count($person->getUsers()) == 0 && count($person->getExternalUsers()) == 0) {
         $em->remove($person);
         $output->writeln('Deleted ' . $person->getName());
     } else {
         $person->setMappedTo(null);
     }
 }
예제 #6
0
 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));
 }
예제 #7
0
 private function linkPeople(Person $p1, Person $p2, OutputInterface $output)
 {
     $em = $this->getContainer()->get('doctrine.orm.entity_manager');
     $count1 = count($p1->getRoles());
     $count2 = count($p2->getRoles());
     if ($count1 < $count2) {
         $temp = $p2;
         $p2 = $p1;
         $p1 = $temp;
     }
     foreach ($p2->getRoles() as $role) {
         $role->setPerson($p1);
     }
     foreach ($p2->getUsers() as $u) {
         $u->setPerson($p1);
     }
     $output->writeln('Merged person ' . $p2->getName() . ' into ' . $p1->getName());
     $alias = new NameAlias();
     $p1->addAlias($alias);
     $alias->setName($p2->getName());
     $em->persist($alias);
     $em->remove($p2);
     $em->flush();
 }
예제 #8
0
 /**
  * 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();
 }