Exemplo n.º 1
0
 /**
  * Checkouts a new revision for $content
  *
  * @param AbstractClassContent $content
  * @param BBUserToken          $token
  *
  * @return Revision
  */
 public function checkout(AbstractClassContent $content, TokenInterface $token)
 {
     $revision = new Revision();
     $revision->setAccept($content->getAccept());
     $revision->setContent($content);
     $revision->setData($content->getDataToObject());
     $revision->setLabel($content->getLabel());
     $maxEntry = (array) $content->getMaxEntry();
     $minEntry = (array) $content->getMinEntry();
     $revision->setMaxEntry($maxEntry);
     $revision->setMinEntry($minEntry);
     $revision->setOwner($token->getUser());
     $defaultParams = $content->getDefaultParams();
     foreach ($content->getAllParams() as $key => $param) {
         if ($defaultParams[$key]['value'] !== $param['value']) {
             $revision->setParam($key, $content->getParamValue($key));
         }
     }
     $revision->setRevision($content->getRevision() ? $content->getRevision() : 0);
     $revision->setState($content->getRevision() ? Revision::STATE_MODIFIED : Revision::STATE_ADDED);
     return $revision;
 }
Exemplo n.º 2
0
 /**
  * Executes revert action on content and its draft.
  *
  * @param  AbstractClassContent $content
  * @param  Revision             $draft
  * @param  array                $data
  *
  * @return ClassContentManager
  */
 private function executeRevert(AbstractClassContent $content, Revision $draft, array $data)
 {
     $content->setDraft(null);
     if ($content instanceof ContentSet) {
         if (isset($data['elements']) && true === $data['elements']) {
             $draft->clear();
             foreach ($content->getData() as $element) {
                 if ($element instanceof AbstractClassContent) {
                     $draft->push($element);
                 }
             }
         }
     } else {
         foreach ($content->getData() as $key => $element) {
             if (isset($data['elements']) && in_array($key, $data['elements'])) {
                 $draft->{$key} = $content->{$key};
             }
             if (in_array('Element\\Keyword', $content->getAccept()[$key])) {
                 $this->entityManager->getRepository('BackBee\\ClassContent\\Element\\Keyword')->cleanKeywordLinks($content, $element);
             }
         }
     }
     if (isset($data['parameters'])) {
         foreach ($content->getDefaultParams() as $key => $params) {
             if (in_array($key, $data['parameters'])) {
                 $draft->setParam($key, $content->getParamValue($key));
             }
         }
     }
     return $this;
 }