public function updateViability(Elementtype $elementtype, array $parentIds)
    {
        $viabilityRepository = $this->entityManager->getRepository('PhlexibleElementtypeBundle:ElementtypeApply');

        $viabilities = $viabilityRepository->findBy(['elementtypeId' => $elementtype->getId()]);

        foreach ($viabilities as $index => $viability) {
            if (in_array($viability->getUnderElementtypeId(), $parentIds)) {
                unset($parentIds[array_search($viability->getUnderElementtypeId(), $parentIds)]);
                unset($viabilities[$index]);
            }
        }

        foreach ($parentIds as $parentId) {
            $viability = new ElementtypeApply();
            $viability
                ->setElementtypeId($elementtype->getId())
                ->setUnderElementtypeId($parentId);

            $this->entityManager->persist($viability);
        }

        foreach ($viabilities as $viability) {
            $this->entityManager->remove($viability);
        }

        $this->entityManager->flush();
    }