Example #1
0
 protected function getPropertiesByClass(\core_kernel_classes_Class $type)
 {
     if (!isset($this->propertyCache[$type->getUri()])) {
         $this->propertyCache[$type->getUri()] = $type->getProperties(true);
         // alternativly use non recursiv and union with getPropertiesByClass of parentclasses
     }
     return $this->propertyCache[$type->getUri()];
 }
Example #2
0
 /**
  * Delete a subclass
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param core_kernel_classes_Class $clazz            
  * @return boolean
  */
 public function deleteClass(core_kernel_classes_Class $clazz)
 {
     $returnValue = (bool) false;
     if ($clazz->isSubClassOf($this->getRootClass()) && !$clazz->equals($this->getRootClass())) {
         $returnValue = true;
         $subclasses = $clazz->getSubClasses(false);
         foreach ($subclasses as $subclass) {
             $returnValue = $returnValue && $this->deleteClass($subclass);
         }
         foreach ($clazz->getProperties() as $classProperty) {
             $returnValue = $returnValue && $this->deleteClassProperty($classProperty);
         }
         $returnValue = $returnValue && $clazz->delete();
     } else {
         common_Logger::w('Tried to delete class ' . $clazz->getUri() . ' as if it were a subclass of ' . $this->getRootClass()->getUri());
     }
     return (bool) $returnValue;
 }
Example #3
0
 public function testModel()
 {
     // We must have a property dedicated to Roles in the Generis User class.
     $userClass = new core_kernel_classes_Class(CLASS_GENERIS_USER);
     $this->assertTrue($userClass->exists());
     // The userClass must have a dedicated userRoles property.
     $this->assertTrue(array_key_exists(PROPERTY_USER_ROLES, $userClass->getProperties()));
     // The class that gather all Roles instances together must exist.
     $roleClass = new core_kernel_classes_Class(CLASS_ROLE);
     $this->assertTrue($roleClass->exists());
     // The Role class must have the right properties (isSystem and includesRole)
     $roleClassProperties = $roleClass->getProperties();
     $this->assertTrue(array_key_exists(PROPERTY_ROLE_ISSYSTEM, $roleClassProperties));
     $this->assertTrue(array_key_exists(PROPERTY_ROLE_INCLUDESROLE, $roleClassProperties));
     // The Generis Role must exist after installation.
     $generisRole = new core_kernel_classes_Resource(INSTANCE_ROLE_GENERIS);
     $this->assertTrue($generisRole->exists());
 }
 /**
  * Get the properties of the rdfs Property class
  *
  * @access public
  * @author Bertrand Chevrier, <*****@*****.**>
  * @param  string mode
  * @return array
  */
 public static function getPropertyProperties($mode = 'simple')
 {
     $returnValue = array();
     switch ($mode) {
         case 'simple':
             $defaultUris = array(PROPERTY_IS_LG_DEPENDENT);
             break;
         case 'advanced':
         default:
             $defaultUris = array(RDFS_LABEL, PROPERTY_WIDGET, RDFS_RANGE, PROPERTY_IS_LG_DEPENDENT);
             break;
     }
     $resourceClass = new core_kernel_classes_Class(RDF_PROPERTY);
     foreach ($resourceClass->getProperties() as $property) {
         if (in_array($property->getUri(), $defaultUris)) {
             array_push($returnValue, $property);
         }
     }
     return (array) $returnValue;
 }
 /**
  * Render the add property sub form.
  * @throws Exception
  * @return void
  * @requiresRight classUri WRITE
  */
 public function removeClassProperty()
 {
     $success = false;
     if (!tao_helpers_Request::isAjax()) {
         throw new Exception("wrong request mode");
     }
     $class = new core_kernel_classes_Class($this->getRequestParameter('classUri'));
     $property = new core_kernel_classes_Property($this->getRequestParameter('uri'));
     //delete property mode
     foreach ($class->getProperties() as $classProperty) {
         if ($classProperty->equals($property)) {
             $indexes = $property->getPropertyValues(new core_kernel_classes_Property(INDEX_PROPERTY));
             //delete property and the existing values of this property
             if ($property->delete(true)) {
                 //delete index linked to the property
                 foreach ($indexes as $indexUri) {
                     $index = new core_kernel_classes_Resource($indexUri);
                     $index->delete(true);
                 }
                 $success = true;
                 break;
             }
         }
     }
     if ($success) {
         return $this->returnJson(array('success' => true));
     } else {
         $this->returnError(__('Unable to remove the property.'));
     }
 }
Example #6
0
 /**
  * Get the Search Indexes of a given $class.
  * 
  * The returned array is an associative array where keys are the Property URI
  * the Search Index belongs to, and the values are core_kernel_classes_Resource objects
  * corresponding to Search Index definitions.
  * 
  * @param \core_kernel_classes_Class $class
  * @param boolean $recursive Whether or not to look for Search Indexes that belong to sub-classes of $class. Default is true.
  * @return Index[] An array of Search Index to $class.
  */
 public static function getIndexesByClass(\core_kernel_classes_Class $class, $recursive = true)
 {
     $returnedIndexes = array();
     // Get properties to the root class hierarchy.
     $properties = $class->getProperties(true);
     foreach ($properties as $prop) {
         $propUri = $prop->getUri();
         $indexes = self::getIndexes($prop);
         if (count($indexes) > 0) {
             if (isset($returnedIndexes[$propUri]) === false) {
                 $returnedIndexes[$propUri] = array();
             }
             foreach ($indexes as $index) {
                 $returnedIndexes[$propUri][] = new Index($index->getUri());
             }
         }
     }
     return $returnedIndexes;
 }
 /**
  * Format an RDFS Class to an array
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @param  Class clazz
  * @return array
  */
 public function toArray(core_kernel_classes_Class $clazz)
 {
     $returnValue = array();
     $properties = $clazz->getProperties(false);
     foreach ($clazz->getInstances(false) as $instance) {
         $data = array();
         foreach ($properties as $property) {
             $data[$property->getLabel()] = null;
             $values = $instance->getPropertyValues($property);
             if (count($values) > 1) {
                 $data[$property->getLabel()] = $values;
             } elseif (count($values) == 1) {
                 $data[$property->getLabel()] = $values[0];
             }
         }
         array_push($returnValue, $data);
     }
     return (array) $returnValue;
 }
Example #8
0
 public function testGetProperties()
 {
     $list = new core_kernel_classes_Class(RDF_LIST);
     $properties = $list->getProperties();
     $this->assertTrue(count($properties) == 2);
     $expectedResult = array(RDF_FIRST, RDF_REST);
     foreach ($properties as $property) {
         $this->assertTrue($property instanceof core_kernel_classes_Property);
         $this->assertTrue(in_array($property->getUri(), $expectedResult));
         if ($property->getUri() === RDF_FIRST) {
             $this->assertEquals($property->getRange()->getUri(), RDFS_RESOURCE);
             $this->assertEquals($property->getLabel(), 'first');
             $this->assertEquals($property->getComment(), 'The first item in the subject RDF list.');
         }
         if ($property->getUri() === RDF_REST) {
             $this->assertEquals($property->getRange()->getUri(), RDF_LIST);
             $this->assertEquals($property->getLabel(), 'rest');
             $this->assertEquals($property->getComment(), 'The rest of the subject RDF list after the first item.');
         }
     }
     $class = $list->createSubClass('toto', 'toto');
     $properties2 = $class->getProperties(true);
     $this->assertFalse(empty($properties2));
     $class->delete();
 }