Esempio n. 1
0
 /**
  * @param $entity
  * @param $field
  * @return null|object
  * @throws \Doctrine\ORM\ORMException
  * @throws \Doctrine\ORM\OptimisticLockException
  * @throws \Doctrine\ORM\TransactionRequiredException
  */
 protected function refreshEntityField($entity, $field)
 {
     $accessor = PropertyAccess::createPropertyAccessor();
     if ($accessor->isReadable($entity, $field)) {
         $field = $accessor->getValue($entity, $field);
         if (empty($field) && $this->entityManager->contains($entity)) {
             $this->entityManager->refresh($entity);
         }
         // if
     }
     // if
     return $this;
 }
 /**
  * Refresh an entity
  *
  * @param object $entity
  * @return       $this
  */
 public function refresh($entity)
 {
     if ($this->supports($entity)) {
         $this->entityManager->refresh($entity);
     }
     return $this;
 }
Esempio n. 3
0
 public function postFormSubmit(FormSubmitEvent $event)
 {
     $post = $event->getPost();
     $values = $post->getValueSet()->getValues();
     $this->entityManager->refresh($post);
     foreach ($values as $value) {
         if ($value instanceof AttachmentValue) {
             $media = $this->mediaManager->createMedia();
             $media->setFile($value->getFile());
             $media->setProvider('file');
             $value->setAttachment($media);
         }
     }
     $this->entityManager->persist($post);
     $this->entityManager->flush();
 }
Esempio n. 4
0
 public function leave($id, UserInterface $user, $farewellMessage = 'Elvis has left the building.')
 {
     $channel = $this->find($id);
     $repo = $this->em->getRepository('SiciarekChatBundle:ChatChannelAssignee');
     $qb = $repo->createQueryBuilder('a')->leftJoin('a.channel', 'c')->andWhere('c.id = :channel')->andWhere('a.assigneeId = :id')->andWhere('a.assigneeClass = :class')->setParameters(['channel' => $id, 'id' => $user->getId(), 'class' => get_class($user)]);
     $query = $qb->getQuery();
     $assignee = $query->getSingleResult();
     $channel->removeAssignee($assignee);
     $this->em->remove($assignee);
     $this->em->flush();
     $this->em->refresh($channel);
     if ($channel->getAssignees()->count() === 0) {
         $this->em->remove($channel);
         $this->em->flush();
     }
     $this->getContainer()->get('chat.message')->send($farewellMessage, $id);
     return true;
 }
 /**
  * @param string $name
  * @param string $default
  * @return string
  */
 public function content($name, $default = 'no content')
 {
     /** @var Content $content */
     $content = $this->entityManager->getRepository('Ist1ContentBundle:Content')->findOneBy(['name' => $name]);
     if (!$content) {
         $content = new Content($name, $default);
     }
     /** @var \Gedmo\Translatable\Entity\Repository\TranslationRepository $translationRepo */
     $translationRepo = $this->entityManager->getRepository('Gedmo\\Translatable\\Entity\\Translation');
     $translations = $translationRepo->findTranslations($content);
     $locale = $this->requestStack->getCurrentRequest()->getLocale();
     if (!array_key_exists($locale, $translations)) {
         $content->setTranslatableLocale($locale);
         $this->entityManager->persist($content);
         $this->entityManager->flush();
     }
     $content->setTranslatableLocale($locale);
     $this->entityManager->refresh($content);
     return $content->getContent();
 }
Esempio n. 6
0
 /**
  * @param FormSubmitEvent $event
  */
 public function postFormSubmit(FormSubmitEvent $event)
 {
     $post = $event->getPost();
     $values = $post->getValueSet()->getValues();
     $this->entityManager->refresh($post);
     foreach ($values as $value) {
         if ($value instanceof AttachmentValue) {
             // Avoid saving the attachment when it's empty and not required
             if (null === $value->getFile() && !$value->getAttribute()->getRequired()) {
                 continue;
             }
             $media = $this->mediaManager->createMedia();
             $media->setFile($value->getFile());
             $media->setProvider('file');
             $value->setAttachment($media);
         }
     }
     $this->entityManager->persist($post);
     $this->entityManager->flush();
 }
Esempio n. 7
0
 /**
  * Detach given and create new keyword entity.
  *
  * @param CategoryInterface $category
  * @param Keyword $keyword
  *
  * @return Keyword
  */
 private function handleDetach(KeywordInterface $keyword, CategoryInterface $category)
 {
     $keywordString = $keyword->getKeyword();
     $keywordLocale = $keyword->getLocale();
     // if keyword wont be deleted (because of multiple references)
     // refresh it to be sure hat changes wont be written to
     // database.
     $this->entityManager->refresh($keyword);
     // delete old keyword from category
     $this->delete($keyword, $category);
     // create new keyword
     $newEntity = $this->keywordRepository->createNew();
     $newEntity->setKeyword($keywordString);
     $newEntity->setLocale($keywordLocale);
     // add new keyword to category
     return $this->save($newEntity, $category);
 }