Esempio n. 1
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;
 }
 /**
  *
  * Determine the title of the entity to be created, following this logic:
  *
  * 1. is there a getTitle method with a value set
  * 2. is there a property containing "title" in rdf definition
  * 3. take the first property defined in rdf and take first 50 characters
  * 4. give up
  *
  * @param EntityInterface $entity
  * @throws \RuntimeException
  * @return mixed|string
  */
 private function determineEntityTitle(EntityInterface $entity)
 {
     $object = $entity->getObject();
     //is there a getTitle method?
     if (method_exists($object, 'getTitle') && $object->getTitle()) {
         return $object->getTitle();
     } else {
         //try to get a property containing title in the rdf description
         foreach ($entity->getChildDefinitions() as $node) {
             if (!$node instanceof \Midgard\CreatePHP\Entity\PropertyInterface || strpos($node->getProperty(), "title") === false) {
                 continue;
             }
             return $entity->getMapper()->getPropertyValue($object, $node);
         }
         //try to get the first property to create a guessed title of max 50 characters
         foreach ($entity->getChildDefinitions() as $node) {
             if (!$node instanceof \Midgard\CreatePHP\Entity\PropertyInterface) {
                 continue;
             }
             return substr($entity->getMapper()->getPropertyValue($object, $node), 0, 49);
         }
         //give up
         throw new RuntimeException('No title could be found four your new node.');
     }
 }