/**
     * {@inheritDoc}
     *
     * Persist and flush (persisting an already managed document has no effect
     * and does not hurt).
     *
     * @throws \Exception will throw some exception if storing fails, type is
     *      depending on the doctrine implemenation.
     */
    public function store(EntityInterface $entity)
    {
        $this->om->persist($entity->getObject());
        $this->om->flush();

        return true;
    }
Esempio n. 2
0
 /**
  * {@inheritDoc}
  *
  * @api
  */
 public function renderStart($tag_name = false)
 {
     if (is_string($tag_name)) {
         $this->_tag_name = $tag_name;
     }
     $attributesToSkip = array();
     if ($this->_parent && $this->_parent->isRendering()) {
         //remove about to work around a VIE bug with nested identical about attributes
         $attributesToSkip[] = 'about';
     }
     $template = explode('__CONTENT__', $this->_template);
     $template = $template[0];
     $replace = array("__TAG_NAME__" => $this->_tag_name, " __ATTRIBUTES__" => $this->renderAttributes($attributesToSkip));
     $this->_is_rendering = true;
     return strtr($template, $replace);
 }
Esempio n. 3
0
 private function _convertToJsonld($object, EntityInterface $entity)
 {
     $jsonld = array();
     $jsonld['@subject'] = $this->jsonldEncode($this->_mapper->createSubject($object));
     foreach ($entity->getChildDefinitions() as $node) {
         if ($node instanceof PropertyInterface) {
             $rdf_name = $node->getProperty();
             $expanded_name = $this->_expandPropertyName($rdf_name, $entity);
             $jsonld[$expanded_name] = $this->_mapper->getPropertyValue($object, $node);
         }
     }
     return $jsonld;
 }
 /**
  * Reorder the children of the collection node according to the expected order.
  *
  * To make this as fail safe as possible we sort with the sort method below that makes sure
  * no children are deleted if they are not part in the array of passed children
  * ($expectedOrder).
  *
  * Also the sorting ensures that other children before the children to sort in the list
  * stay in front and those originally after in the back ...
  *
  * @param EntityInterface $entity
  * @param CollectionInterface $node
  * @param $expectedOrder array of subjects
  */
 public function orderChildren(EntityInterface $entity, CollectionInterface $node, $expectedOrder)
 {
     array_walk($expectedOrder, array($this, 'getNodeName'));
     $childrenCollection = $this->getChildren($entity->getObject(), $node);
     $children = $childrenCollection->toArray();
     $childrenNames = array_keys($children);
     $childrenNames = $this->sort($childrenNames, $expectedOrder);
     $childrenCollection->clear();
     foreach ($childrenNames as $name) {
         $childrenCollection->set($name, $children[$name]);
     }
 }
Esempio n. 5
0
 /**
  * Never call this method directly, but use createWithParent on your CollectionDefinition
  * to get a collection tied to concrete data.
  *
  * @private
  *
  * @param EntityInterface $parent
  */
 public function loadFromParent(EntityInterface $parent)
 {
     $this->_children = array();
     $object = $parent->getObject();
     $parentMapper = $parent->getMapper();
     $children = $parentMapper->getChildren($object, $this);
     // create entities for children
     foreach ($children as $child) {
         if (count($this->_typenames) === 1) {
             $type = $this->_typeFactory->getTypeByRdf(current($this->_typenames));
         } else {
             $type = $this->_typeFactory->getTypeByObject($child);
         }
         foreach ($type->getVocabularies() as $prefix => $uri) {
             $this->setAttribute('xmlns:' . $prefix, $uri);
         }
         $this->_children[] = $type->createWithObject($child);
     }
     if ($this->_parent->isEditable($object) && sizeof($this->_children) == 0 && count($this->_typenames) == 1) {
         // create an empty element to allow adding new elements to an empty editable collection
         $type = $this->_typeFactory->getTypeByRdf(reset($this->_typenames));
         $mapper = $type->getMapper();
         $object = $mapper->prepareObject($type, $object);
         $entity = $type->createWithObject($object);
         if ($entity instanceof NodeInterface) {
             /** @var $entity NodeInterface */
             $entity->setAttribute('style', 'display:none');
         }
         $this->_children[] = $entity;
     }
 }