private function createPerson($name) { $email = $name . '@mail.es'; $web = 'http://www.url.com'; $phone = '+34986123456'; $honorific = 'honorific'; $firm = 'firm'; $post = 'post'; $bio = 'Biografía extensa de la persona'; $person = new Person(); $person->setName($name); $person->setEmail($email); $person->setWeb($web); $person->setPhone($phone); $person->setHonorific($honorific); $person->setFirm($firm); $person->setPost($post); $person->setBio($bio); $this->dm->persist($person); $this->dm->flush(); return $person; }
public function testFindSeriesByPersonId() { $broadcast = new Broadcast(); $broadcast->setBroadcastTypeId(Broadcast::BROADCAST_TYPE_PUB); $broadcast->setDefaultSel(true); $this->dm->persist($broadcast); $this->dm->flush(); $series1 = $this->factoryService->createSeries(); $title1 = 'Series 1'; $series1->setTitle($title1); $series2 = $this->factoryService->createSeries(); $title2 = 'Series 2'; $series2->setTitle($title2); $series3 = $this->factoryService->createSeries(); $title3 = 'Series 3'; $series3->setTitle($title3); $this->dm->persist($series1); $this->dm->persist($series2); $this->dm->persist($series3); $personJohn = new Person(); $nameJohn = 'John Smith'; $personJohn->setName($nameJohn); $personBob = new Person(); $nameBob = 'Bob Clark'; $personBob->setName($nameBob); $personKate = new Person(); $nameKate = 'Kate Simmons'; $personKate->setName($nameKate); $this->dm->persist($personJohn); $this->dm->persist($personBob); $this->dm->persist($personKate); $roleActor = new Role(); $codActor = 'actor'; $roleActor->setCod($codActor); $rolePresenter = new Role(); $codPresenter = 'presenter'; $rolePresenter->setCod($codPresenter); $this->dm->persist($roleActor); $this->dm->persist($rolePresenter); $this->dm->flush(); $mm11 = $this->factoryService->createMultimediaObject($series1); $title11 = 'Multimedia Object 11'; $mm11->setTitle($title11); $mm11->addPersonWithRole($personJohn, $roleActor); $mm11->addPersonWithRole($personBob, $roleActor); $mm11->addPersonWithRole($personJohn, $rolePresenter); $mm12 = $this->factoryService->createMultimediaObject($series1); $title12 = 'Multimedia Object 12'; $mm12->setTitle($title12); $mm12->addPersonWithRole($personBob, $roleActor); $mm12->addPersonWithRole($personBob, $rolePresenter); $mm13 = $this->factoryService->createMultimediaObject($series1); $title13 = 'Multimedia Object 13'; $mm13->setTitle($title13); $mm13->addPersonWithRole($personKate, $roleActor); $mm21 = $this->factoryService->createMultimediaObject($series2); $title21 = 'Multimedia Object 21'; $mm21->setTitle($title21); $mm21->addPersonWithRole($personKate, $rolePresenter); $mm21->addPersonWithRole($personKate, $roleActor); $mm31 = $this->factoryService->createMultimediaObject($series3); $title31 = 'Multimedia Object 31'; $mm31->setTitle($title31); $mm31->addPersonWithRole($personJohn, $rolePresenter); $mm32 = $this->factoryService->createMultimediaObject($series3); $title32 = 'Multimedia Object 3212312'; $mm32->setTitle($title32); $mm32->addPersonWithRole($personJohn, $roleActor); $mm32->addPersonWithRole($personBob, $roleActor); $mm32->addPersonWithRole($personJohn, $rolePresenter); $this->dm->persist($mm11); $this->dm->persist($mm12); $this->dm->persist($mm13); $this->dm->persist($mm21); $this->dm->persist($mm31); $this->dm->persist($mm32); $this->dm->persist($series1); $this->dm->persist($series2); $this->dm->persist($series3); $this->dm->flush(); $seriesKate = $this->repo->findSeriesByPersonId($personKate->getId()); $this->assertEquals(2, count($seriesKate)); $this->assertEquals(array($series1, $series2), array_values($seriesKate->toArray())); $seriesJohn = $this->repo->findSeriesByPersonId($personJohn->getId()); $this->assertEquals(2, count($seriesJohn)); $this->assertEquals(array($series1, $series3), array_values($seriesJohn->toArray())); $seriesBob = $this->repo->findSeriesByPersonId($personBob->getId()); $this->assertEquals(2, count($seriesBob)); $this->assertEquals(array($series1, $series3), array_values($seriesBob->toArray())); $seriesJohnActor = $this->repo->findByPersonIdAndRoleCod($personJohn->getId(), $roleActor->getCod()); $seriesJohnPresenter = $this->repo->findByPersonIdAndRoleCod($personJohn->getId(), $rolePresenter->getCod()); $seriesBobActor = $this->repo->findByPersonIdAndRoleCod($personBob->getId(), $roleActor->getCod()); $seriesBobPresenter = $this->repo->findByPersonIdAndRoleCod($personBob->getId(), $rolePresenter->getCod()); $seriesKateActor = $this->repo->findByPersonIdAndRoleCod($personKate->getId(), $roleActor->getCod()); $seriesKatePresenter = $this->repo->findByPersonIdAndRoleCod($personKate->getId(), $rolePresenter->getCod()); $this->assertEquals(2, count($seriesJohnActor)); $this->assertTrue(in_array($series1, $seriesJohnActor->toArray())); $this->assertFalse(in_array($series2, $seriesJohnActor->toArray())); $this->assertTrue(in_array($series3, $seriesJohnActor->toArray())); $this->assertEquals(2, count($seriesJohnPresenter)); $this->assertTrue(in_array($series1, $seriesJohnPresenter->toArray())); $this->assertFalse(in_array($series2, $seriesJohnPresenter->toArray())); $this->assertTrue(in_array($series3, $seriesJohnPresenter->toArray())); $this->assertEquals(2, count($seriesBobActor)); $this->assertTrue(in_array($series1, $seriesBobActor->toArray())); $this->assertFalse(in_array($series2, $seriesBobActor->toArray())); $this->assertTrue(in_array($series3, $seriesBobActor->toArray())); $this->assertEquals(1, count($seriesBobPresenter)); $this->assertTrue(in_array($series1, $seriesBobPresenter->toArray())); $this->assertFalse(in_array($series2, $seriesBobPresenter->toArray())); $this->assertFalse(in_array($series3, $seriesBobPresenter->toArray())); $this->assertEquals(2, count($seriesKateActor)); $this->assertTrue(in_array($series1, $seriesKateActor->toArray())); $this->assertTrue(in_array($series2, $seriesKateActor->toArray())); $this->assertFalse(in_array($series3, $seriesKateActor->toArray())); $this->assertEquals(1, count($seriesKatePresenter)); $this->assertFalse(in_array($series1, $seriesKatePresenter->toArray())); $this->assertTrue(in_array($series2, $seriesKatePresenter->toArray())); $this->assertFalse(in_array($series3, $seriesKatePresenter->toArray())); }
private function load_people_multimediaobject($multimediaObject, $name, $role) { $personService = $this->getContainer()->get('pumukitschema.person'); $person = new Person(); $person->setName($name); $personService->savePerson($person); $multimediaObject = $personService->createRelationPerson($person, $role, $multimediaObject); }
/** * Create relation * * @ParamConverter("multimediaObject", class="PumukitSchemaBundle:MultimediaObject", options={"id" = "mmId"}) * @ParamConverter("role", class="PumukitSchemaBundle:Role", options={"id" = "roleId"}) * @Template("PumukitNewAdminBundle:Person:createrelation.html.twig") */ public function createRelationAction(MultimediaObject $multimediaObject, Role $role, Request $request) { $person = new Person(); $person->setName(preg_replace('/\\d+ - /', '', $request->get('name'))); $translator = $this->get('translator'); $locale = $request->getLocale(); $form = $this->createForm(new PersonType($translator, $locale), $person); if ($request->isMethod('PUT') || $request->isMethod('POST')) { if ($form->bind($request)->isValid()) { try { $personService = $this->get('pumukitschema.person'); $multimediaObject = $personService->createRelationPerson($person, $role, $multimediaObject); } catch (\Exception $e) { $this->get('session')->getFlashBag()->add('error', $e->getMessage()); } $template = $multimediaObject->isPrototype() ? '_template' : ''; } else { $errors = $this->get('validator')->validate($person); $textStatus = ''; foreach ($errors as $error) { $textStatus .= $error->getPropertyPath() . ' value ' . $error->getInvalidValue() . ': ' . $error->getMessage() . '. '; } return new Response($textStatus, 409); } return $this->render('PumukitNewAdminBundle:Person:listrelation.html.twig', array('people' => $multimediaObject->getPeopleByRole($role, true), 'role' => $role, 'mm' => $multimediaObject, 'template' => $template)); } $template = $multimediaObject->isPrototype() ? '_template' : ''; return array('person' => $person, 'role' => $role, 'mm' => $multimediaObject, 'template' => $template, 'form' => $form->createView()); }
private function createPersonFromLDAP($cn = '', $mail = '') { $dm = $this->get('doctrine_mongodb.odm.document_manager'); $ldapService = $this->get('pumukit_ldap.ldap'); try { $aux = $ldapService->getListUsers('', $mail); if (0 === count($aux)) { throw new \InvalidArgumentException('There is no LDAP user with the name "' . $cn . '" and email "' . $mail . '"'); } $person = new Person(); $person->setName($aux[0]['cn']); $person->setEmail($aux[0]['mail']); $dm->persist($person); $dm->flush(); } catch (\Exception $e) { throw $e; } return $person; }
public function testGetterAndSetter() { $email = '*****@*****.**'; $name = 'name'; $web = 'web'; $phone = 'phone'; $honorific = 'Mr'; $firm = 'firm'; $post = 'post'; $bio = 'Biography of this person'; $locale = 'es'; $person = new Person(); $person->setLocale($locale); $person->setEmail($email); $person->setName($name); $person->setWeb($web); $person->setPhone($phone); $person->setHonorific($honorific); $person->setFirm($firm); $person->setPost($post); $person->setBio($bio); $this->assertEquals($email, $person->getEmail()); $this->assertEquals($name, $person->getName()); $this->assertEquals($web, $person->getWeb()); $this->assertEquals($phone, $person->getPhone()); $this->assertEquals($honorific, $person->getHonorific()); $this->assertEquals($firm, $person->getFirm()); $this->assertEquals($post, $person->getPost()); $this->assertEquals($bio, $person->getBio()); $this->assertEquals($locale, $person->getLocale()); $this->assertEquals($honorific . ' ' . $name, $person->getHName()); $this->assertEquals($post . ' ' . $firm . ' ' . $bio, $person->getOther()); $this->assertEquals($post . ', ' . $firm . ', ' . $bio, $person->getInfo()); $bio = ''; $person->setBio($bio); $this->assertEquals($post . ', ' . $firm, $person->getInfo()); $honorificEs = 'Don'; $firmEs = 'Firma de esta persona'; $postEs = 'Post de esta persona'; $bioEs = 'Biografía de esta persona'; $i18nHonorific = array('en' => $honorific, 'es' => $honorificEs); $i18nFirm = array('en' => $firm, 'es' => $firmEs); $i18nPost = array('en' => $post, 'es' => $postEs); $i18nBio = array('en' => $bio, 'es' => $bioEs); $person->setI18nHonorific($i18nHonorific); $person->setI18nFirm($i18nFirm); $person->setI18nPost($i18nPost); $person->setI18nBio($i18nBio); $this->assertEquals($i18nHonorific, $person->getI18nHonorific()); $this->assertEquals($i18nFirm, $person->getI18nFirm()); $this->assertEquals($i18nPost, $person->getI18nPost()); $this->assertEquals($i18nBio, $person->getI18nBio()); $honorific = null; $firm = null; $post = null; $bio = null; $person->setHonorific($honorific); $person->setFirm($firm); $person->setPost($post); $person->setBio($bio); $this->assertEquals($honorific, $person->getHonorific()); $this->assertEquals($firm, $person->getFirm()); $this->assertEquals($post, $person->getPost()); $this->assertEquals($bio, $person->getBio()); }
public function syncPeople(MultimediaObject $mmobj, $parsedTerena) { foreach ($parsedTerena['people'] as $contributor) { $person = $this->personRepo->findOneByName($contributor['name']); if (!isset($person)) { //If the person doesn't exist, create a new one. $person = new Person(); $person->setName($contributor['name']); $this->personService->savePerson($person); } $role = $this->roleRepo->findOneByCod($contributor['role']); if (!isset($role)) { //Workaround for PuMuKIT. The 'Cod' field is not consistent, some are lowercase, some are ucfirst $role = $this->roleRepo->findOneByCod(ucfirst($contributor['role'])); } if (!isset($role)) { //If the role doesn't exist, use 'Participant'. $role = $this->roleRepo->findOneByCod('Participant'); // <-- This cod is ucfirst, but others are lowercase. } $this->personService->createRelationPerson($person, $role, $mmobj, false); } }
private function createNewPerson($name = 'name', $email = '*****@*****.**') { $web = 'web'; $phone = 'phone'; $honorific = 'Mr'; $firm = 'firm'; $post = 'post'; $bio = 'Biography of this person'; $person = new Person(); $person->setEmail($email); $person->setName($name); $person->setWeb($web); $person->setPhone($phone); $person->setHonorific($honorific); $person->setFirm($firm); $person->setPost($post); $person->setBio($bio); $this->dm->persist($person); $this->dm->flush(); return $person; }
/** * @expectedException Exception * @expectedExceptionMessage remove Person with id */ public function testDeletePerson() { $this->assertEquals(0, count($this->repo->findAll())); $person = new Person(); $person->setName('Person'); $this->dm->persist($person); $this->dm->flush(); $this->assertEquals(1, count($this->repo->findAll())); $this->personService->deletePerson($person); $this->assertEquals(0, count($this->repo->findAll())); $personBob = new Person(); $personBob->setName('Bob'); $roleActor = new Role(); $codActor = 'actor'; $roleActor->setCod($codActor); $this->dm->persist($personBob); $this->dm->persist($roleActor); $this->dm->flush(); $broadcast = new Broadcast(); $broadcast->setBroadcastTypeId(Broadcast::BROADCAST_TYPE_PUB); $broadcast->setDefaultSel(true); $this->dm->persist($broadcast); $this->dm->flush(); $series = $this->factoryService->createSeries(); $mm = $this->factoryService->createMultimediaObject($series); $mm->setTitle('Multimedia Object'); $mm->addPersonWithRole($personBob, $roleActor); $this->dm->persist($mm); $this->dm->persist($series); $this->dm->flush(); $this->assertEquals(1, count($this->repo->findAll())); $this->personService->deletePerson($personBob); $this->assertEquals(1, count($this->repo->findAll())); }