Beispiel #1
0
 /**
  * Import the properties of the resource
  * 
  * @param core_kernel_classes_Resource $resource
  * @param array $propertiesValues
  * @param array $map
  * @param core_kernel_classes_Class $class
  * @return common_report_Report
  */
 private function importProperties(core_kernel_classes_Resource $resource, $propertiesValues, $map, $class)
 {
     if (isset($propertiesValues[RDF_TYPE])) {
         // assuming single Type
         if (count($propertiesValues[RDF_TYPE]) > 1) {
             return new common_report_Report(common_report_Report::TYPE_ERROR, __('Resource not imported due to multiple types'));
         } else {
             foreach ($propertiesValues[RDF_TYPE] as $k => $v) {
                 $classType = isset($map[$v['value']]) ? new core_kernel_classes_Class($map[$v['value']]) : $class;
                 //$resource->setType($classType);
                 $classType->createInstance(null, null, $resource->getUri());
             }
         }
         unset($propertiesValues[RDF_TYPE]);
     }
     if (isset($propertiesValues[RDFS_SUBCLASSOF])) {
         $resource = new core_kernel_classes_Class($resource);
         // assuming single subclass
         if (isset($propertiesValues[RDF_TYPE]) && count($propertiesValues[RDF_TYPE]) > 1) {
             return new common_report_Report(common_report_Report::TYPE_ERROR, __('Resource not imported due to multiple super classes'));
         }
         foreach ($propertiesValues[RDFS_SUBCLASSOF] as $k => $v) {
             $classSup = isset($map[$v['value']]) ? new core_kernel_classes_Class($map[$v['value']]) : $class;
             $resource->setSubClassOf($classSup);
         }
         unset($propertiesValues[RDFS_SUBCLASSOF]);
     }
     foreach ($propertiesValues as $prop => $values) {
         $property = new core_kernel_classes_Property(isset($map[$prop]) ? $map[$prop] : $prop);
         foreach ($values as $k => $v) {
             $value = isset($map[$v['value']]) ? $map[$v['value']] : $v['value'];
             if (isset($v['lang'])) {
                 $resource->setPropertyValueByLg($property, $value, $v['lang']);
             } else {
                 $resource->setPropertyValue($property, $value);
             }
         }
     }
     $msg = $resource instanceof core_kernel_classes_Class ? __('Successfully imported class "%s"', $resource->getLabel()) : __('Successfully imported "%s"', $resource->getLabel());
     return new common_report_Report(common_report_Report::TYPE_SUCCESS, $msg, $resource);
 }
 /**
  * Short description of method createSubClass
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @param  Class clazz
  * @param  string label
  * @param  string comment
  * @param  string uri
  * @return core_kernel_classes_Class
  */
 public static function createSubClass(core_kernel_classes_Class $clazz, $label = '', $comment = '', $uri = '')
 {
     $returnValue = null;
     $class = new core_kernel_classes_Class(RDFS_CLASS);
     $instance = self::createInstance($class, $label, $comment, $uri);
     $returnValue = new core_kernel_classes_Class($instance->getUri());
     $returnValue->setSubClassOf($clazz);
     return $returnValue;
 }
 public function testCreateMediaInstance()
 {
     $fileTmp = dirname(__DIR__) . '/sample/Brazil.png';
     $this->initializeMock($fileTmp);
     $lang = 'EN-en';
     $classUri = $this->testClass->getUri();
     //clear previous tests
     $root = new \core_kernel_classes_Class($classUri);
     $link = $this->mediaService->createMediaInstance($fileTmp, $classUri, $lang);
     $root = new \core_kernel_classes_Class($classUri);
     $instances = $root->getInstances();
     /** @var \core_kernel_classes_Resource $instance */
     $instance = array_pop($instances);
     $thing = $instance->getUniquePropertyValue(new \core_kernel_classes_Property(MEDIA_LINK));
     $linkResult = $thing instanceof \core_kernel_classes_Resource ? $thing->getUri() : (string) $thing;
     $this->assertInstanceOf('\\core_kernel_classes_Resource', $instance, 'It should create an instance under the class in parameter');
     $this->assertEquals('Brazil.png', $instance->getLabel(), 'The instance label is wrong');
     $this->assertInternalType('string', $link, 'The method return should be a string');
     $this->assertEquals($instance->getUri(), $link, 'The instance link is wrong');
     $this->assertEquals($linkResult, 'MyGreatLink', 'The returned link is wrong');
     $this->assertEquals($lang, $instance->getUniquePropertyValue(new \core_kernel_classes_Property(MEDIA_LANGUAGE)), 'The instance language is wrong');
     $root->delete(true);
     $root->setSubClassOf($this->mediaService->getRootClass());
 }