/**
  * 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;
 }
Example #2
0
 /**
  * Return the data of this content.
  *
  * @param  string  $var        The element to be return, if NULL, all datas are returned
  * @param  Boolean $forceArray Force the return as array
  *
  * @return mixed Could be either NULL or one or array of scalar, array, AbstractClassContent instance
  * @throws \BackBee\AutoLoader\Exception\ClassNotFoundException Occurs if the class of a subcontent can not be loaded
  */
 public function getData($var = null, $forceArray = false)
 {
     if ($this->hackflag) {
         foreach ($this->_data as $index => $data) {
             foreach ($data as $key => $value) {
                 if ('BackBee\\ClassContent\\ContentSet' == $key) {
                     unset($this->_data[$index][$key]);
                     $this->_data[$index]['BackBee\\CoreDomain\\ClassContent\\ContentSet'] = $value;
                 }
             }
         }
         $this->hackflag = false;
     }
     try {
         return parent::getData($var, $forceArray);
     } catch (UnknownPropertyException $e) {
         return;
     }
 }
Example #3
0
 public function tryResolveParentObject(AbstractClassContent $parent, AbstractClassContent $element)
 {
     foreach ($parent->getData() as $key => $values) {
         if (!is_array($values)) {
             $values = array($values);
         }
         foreach ($values as $value) {
             if ($value instanceof AbstractClassContent) {
                 if (!$value->isLoaded()) {
                     // try to load subcontent
                     if (null !== ($subcontent = $this->getApplication()->getEntityManager()->getRepository(\Symfony\Component\Security\Core\Util\ClassUtils::getRealClass($value))->load($value, $this->getRenderer()->getApplication()->getBBUserToken()))) {
                         $value = $subcontent;
                     }
                 }
                 if ($element->equals($value)) {
                     $this->__currentelement = $key;
                     $this->__object = $parent;
                     $this->_parentuid = $parent->getUid();
                 } else {
                     $this->tryResolveParentObject($value, $element);
                 }
             }
             if (null !== $this->__currentelement) {
                 break;
             }
         }
         if (null !== $this->__currentelement) {
             break;
         }
     }
 }