/**
  * Delete a subclass
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  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 = $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 #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
 /**
  * Whenever or not the current resource is
  * an instance of the specified class
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Class class
  * @return boolean
  */
 public function isInstanceOf(core_kernel_classes_Class $class)
 {
     $returnValue = (bool) false;
     foreach ($this->getTypes() as $type) {
         if ($class->equals($type) || $type->isSubClassOf($class)) {
             $returnValue = true;
             break;
         }
     }
     return (bool) $returnValue;
 }
 /**
  * is the class either the campaign class or a subclass of it
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Class clazz
  * @return boolean
  */
 public function isCampaignClass(core_kernel_classes_Class $clazz)
 {
     return $this->campaignClass->equals($clazz) || $clazz->isSubClassOf($this->campaignClass);
 }
 /**
  * 
  * @param string $path
  * @return \core_kernel_classes_Class
  */
 private function getOrCreatePath($path)
 {
     if ($path === '') {
         $clazz = $this->getRootClass();
     } else {
         $clazz = new \core_kernel_classes_Class(\tao_helpers_uri::decode($path));
         if (!$clazz->isSubClassOf($this->getRootClass()) && !$clazz->equals($this->getRootClass()) && !$clazz->exists()) {
             // consider $path to be a label
             $found = false;
             foreach ($this->getRootClass()->getSubClasses() as $subclass) {
                 if ($subclass->getLabel() === $path) {
                     $found = true;
                     $clazz = $subclass;
                     break;
                 }
             }
             if (!$found) {
                 $clazz = $this->getRootClass()->createSubClass($path);
             }
         }
     }
     return $clazz;
 }
 public function testSetType()
 {
     $this->hardify();
     $this->setProperties();
     $this->targetSongClass = $this->targetWorkClass->createSubClass('Song', 'The Song Class');
     $instance = $this->targetWorkClass->createInstance('setType test instance');
     $sanityCheckInstance = $this->targetWorkClass->createInstance('sanityCheck setType test');
     // verify everything is sane to begin with
     $this->assertIsA($instance, 'core_kernel_classes_resource');
     $this->assertTrue($instance->exists());
     $this->assertIsA($sanityCheckInstance, 'core_kernel_classes_resource');
     $this->assertTrue($sanityCheckInstance->exists());
     $instfound = 0;
     $sanityfound = 0;
     foreach ($this->targetWorkClass->getInstances() as $workInst) {
         if ($workInst->equals($instance)) {
             $instfound++;
         }
         if ($workInst->equals($sanityCheckInstance)) {
             $sanityfound++;
         }
     }
     $this->assertEquals($instfound, 1);
     $this->assertEquals($sanityfound, 1);
     foreach ($this->targetSongClass->getInstances() as $songInst) {
         $this->assertFalse($songInst->equals($instance), 'instance in getInstances of targetSongclass');
         $this->assertFalse($songInst->equals($sanityCheckInstance), 'sanity check instance in getInstances of targetSongclass');
     }
     $types = $instance->getTypes();
     $this->assertEquals(count($types), 1);
     $this->assertTrue($this->targetWorkClass->equals(current($types)));
     // remove the old type (targetWorkClass)
     $this->assertTrue($instance->removeType($this->targetWorkClass));
     $types = $instance->getTypes();
     $this->assertEquals(count($types), 0);
     $sanityfound = 0;
     foreach ($this->targetWorkClass->getInstances() as $workInst) {
         if ($workInst->equals($sanityCheckInstance)) {
             $sanityfound++;
         }
         $this->assertFalse($workInst->equals($instance), 'instance still in getInstances() of class after removeType()');
     }
     $this->assertEquals($sanityfound, 1);
     foreach ($this->targetSongClass->getInstances() as $songInst) {
         $this->assertFalse($songInst->equals($instance), 'instance in getInstances of targetSongclass');
         $this->assertFalse($songInst->equals($sanityCheckInstance), 'sanity check instance in getInstances of targetSongclass');
     }
     // set the new type (targetSongClass)
     $this->assertTrue($instance->setType($this->targetSongClass));
     $types = $instance->getTypes();
     $this->assertEquals(count($types), 1);
     $this->assertTrue($this->targetSongClass->equals(current($types)));
     $sanityfound = 0;
     foreach ($this->targetWorkClass->getInstances() as $workInst) {
         if ($workInst->equals($sanityCheckInstance)) {
             $sanityfound++;
         }
         $this->assertFalse($workInst->equals($instance), 'instance still in getInstances() of class after removeType()');
     }
     $this->assertEquals($sanityfound, 1);
     $instfound = 0;
     foreach ($this->targetSongClass->getInstances() as $songInst) {
         if ($songInst->equals($instance)) {
             $instfound++;
         }
         $this->assertFalse($songInst->equals($sanityCheckInstance), 'sanity check instance in getInstances of targetSongclass');
     }
     $this->assertEquals($instfound, 1);
     // cleanup and check cleanup
     $this->assertTrue($instance->delete());
     $this->assertFalse($instance->exists());
     $this->assertTrue($sanityCheckInstance->delete());
     $this->assertFalse($sanityCheckInstance->exists());
     foreach ($this->targetWorkClass->getInstances() as $workInst) {
         $this->assertFalse($workInst->equals($instance), 'instance still in getInstances() of class targetWorkClass after delete()');
         $this->assertFalse($workInst->equals($sanityCheckInstance), 'instance still in getInstances() of class targetWorkClass after delete()');
     }
     foreach ($this->targetSongClass->getInstances() as $songInst) {
         $this->assertFalse($songInst->equals($instance), 'instance still in getInstances() of class targetSongClass after delete()');
         $this->assertFalse($songInst->equals($sanityCheckInstance), 'instance still in getInstances() of class targetSongClass after delete()');
     }
 }