Ejemplo n.º 1
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();
 }
Ejemplo n.º 2
0
 public function generateRoles($characters, $is_musical)
 {
     $roles = array();
     $order = 0;
     foreach ($characters as $character) {
         $role = new Role();
         $role->setType('cast');
         $role->setRole($character);
         $role->setPerson($this->getRandomPerson());
         $role->setOrder($order++);
         $roles[] = $role;
     }
     //Random decide how many of the technical roles in include
     $max = mt_rand(3, count($this->roles) - 1);
     $order = 0;
     for ($i = 0; $i <= $max; $i++) {
         $role = new Role();
         $role->setType('prod');
         $role->setRole($this->roles[$i]);
         $role->setPerson($this->getRandomPerson());
         $role->setOrder($order++);
         $roles[] = $role;
     }
     if ($is_musical) {
         $num = mt_rand(4, 10);
         $order = 0;
         for ($i = 0; $i < $num; $i++) {
             $role = new Role();
             $role->setType('band');
             $role->setRole($this->musicians[mt_rand(0, count($this->musicians) - 1)]);
             $role->setPerson($this->getRandomPerson());
             $role->setOrder($order++);
             $roles[] = $role;
         }
     }
     return $roles;
 }
Ejemplo n.º 3
0
 private function updateSearchIndex(Role $role)
 {
     if ($this->personObjectPersister instanceof ObjectPersisterInterface) {
         $this->personObjectPersister->replaceOne($role->getPerson());
     }
 }