/**
  * Do removing content from the content editing form.
  *
  * @param  \BackBee\CoreDomain\ClassContent\AbstractClassContent $content
  * @param  type                                       $value
  * @param  \BackBee\CoreDomain\ClassContent\AbstractClassContent $parent
  *
  * @return type
  *
  * @throws ClassContentException
  */
 public function removeFromPost(AbstractClassContent $content, $value = null, AbstractClassContent $parent = null)
 {
     if (null !== ($draft = $content->getDraft())) {
         $draft->setState(Revision::STATE_TO_DELETE);
     }
     return $content;
 }
Exemplo n.º 2
0
 /**
  * Return the user's draft of a content, optionally checks out a new one if not exists.
  *
  * @param  AbstractClassContent $content
  * @param  BBUserToken          $token
  * @param  boolean              $checkoutOnMissing If true, checks out a new revision if none was found
  *
  * @return Revision|null
  */
 public function getDraft(AbstractClassContent $content, TokenInterface $token, $checkoutOnMissing = false)
 {
     if (null === ($revision = $content->getDraft())) {
         try {
             if (false === $this->_em->contains($content)) {
                 $content = $this->_em->find(get_class($content), $content->getUid());
                 if (null === $content) {
                     return;
                 }
             }
             $q = $this->createQueryBuilder('r')->andWhere('r._content = :content')->andWhere('r._owner = :owner')->andWhere('r._state IN (:states)')->orderBy('r._revision', 'desc')->orderBy('r._modified', 'desc')->setParameters(['content' => $content, 'owner' => '' . UserSecurityIdentity::fromToken($token), 'states' => [Revision::STATE_ADDED, Revision::STATE_MODIFIED, Revision::STATE_CONFLICTED]])->getQuery();
             $revision = $q->getSingleResult();
         } catch (\Exception $e) {
             if ($checkoutOnMissing) {
                 $revision = $this->checkout($content, $token);
                 $this->_em->persist($revision);
             } else {
                 $revision = null;
             }
         }
     }
     return $revision;
 }