/**
  * Remove Tag from Multimedia Object
  *
  * @param MultimediaObject $mmobj
  * @param string $tagId
  * @param  boolean          $executeFlush
  * @return Array[Tag] removed tags
  */
 public function removeTagFromMultimediaObject(MultimediaObject $mmobj, $tagId, $executeFlush = true)
 {
     $removeTags = array();
     $tag = $this->repository->find($tagId);
     if (!$tag) {
         throw new \Exception("Tag with id " . $tagId . " not found.");
     }
     do {
         $children = $tag->getChildren();
         if (!$mmobj->containsAnyTag($children->toArray())) {
             $removeTags[] = $tag;
             $removed = $mmobj->removeTag($tag);
             if ($removed && !$mmobj->isPrototype()) {
                 $tag->decreaseNumberMultimediaObjects();
             }
             $this->dm->persist($tag);
         } else {
             break;
         }
     } while ($tag = $tag->getParent());
     $this->dm->persist($mmobj);
     if ($executeFlush) {
         $this->dm->flush();
     }
     return $removeTags;
 }
 /**
  * Update relation
  *
  * @Template("PumukitNewAdminBundle:Person:updaterelation.html.twig")
  * @ParamConverter("multimediaObject", class="PumukitSchemaBundle:MultimediaObject", options={"id" = "mmId"})
  * @ParamConverter("role", class="PumukitSchemaBundle:Role", options={"id" = "roleId"})
  */
 public function updateRelationAction(MultimediaObject $multimediaObject, Role $role, Request $request)
 {
     $personService = $this->get('pumukitschema.person');
     $person = $personService->findPersonById($request->get('id'));
     $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 {
                 $person = $personService->updatePerson($person);
             } catch (\Exception $e) {
                 $this->get('session')->getFlashBag()->add('error', $e->getMessage());
             }
             $template = $multimediaObject->isPrototype() ? '_template' : '';
             return $this->render('PumukitNewAdminBundle:Person:listrelation.html.twig', array('people' => $multimediaObject->getPeopleByRole($role, true), 'role' => $role, 'mm' => $multimediaObject, 'template' => $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);
         }
     }
     $template = $multimediaObject->isPrototype() ? '_template' : '';
     return array('person' => $person, 'role' => $role, 'mm' => $multimediaObject, 'template' => $template, 'form' => $form->createView());
 }
 /**
  * @Route("/listautocomplete/{mmId}/{roleId}", name="pumukit_ldap_person_listautocomplete")
  * @ParamConverter("multimediaObject", class="PumukitSchemaBundle:MultimediaObject", options={"id" = "mmId"})
  * @ParamConverter("role", class="PumukitSchemaBundle:Role", options={"id" = "roleId"})
  * @Template()
  */
 public function listautocompleteAction(MultimediaObject $multimediaObject, Role $role, Request $request)
 {
     $template = $multimediaObject->isPrototype() ? '_template' : '';
     return array('mm' => $multimediaObject, 'role' => $role, 'template' => $template);
 }