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()]; }
/** * Check if the Class in parameter is a subclass of Subject * * @access public * @author Joel Bout, <*****@*****.**> * @param \core_kernel_classes_Class $clazz * @return boolean */ public function isSubjectClass(\core_kernel_classes_Class $clazz) { $returnValue = (bool) false; if ($clazz->getUri() == $this->subjectClass->getUri()) { $returnValue = true; } else { foreach ($this->subjectClass->getSubClasses(true) as $subclass) { if ($clazz->getUri() == $subclass->getUri()) { $returnValue = true; break; } } } return (bool) $returnValue; }
/** * Starts the import based on the form * * @param \core_kernel_classes_Class $class * @param \tao_helpers_form_Form $form * @return \common_report_Report $report */ public function import($class, $form) { //as upload may be called multiple times, we remove the session lock as soon as possible session_write_close(); try { $file = $form->getValue('source'); $service = MediaService::singleton(); $classUri = $class->getUri(); if (is_null($this->instanceUri) || $this->instanceUri === $classUri) { //if the file is a zip do a zip import if ($file['type'] !== 'application/zip') { if (!$service->createMediaInstance($file["uploaded_file"], $classUri, \tao_helpers_Uri::decode($form->getValue('lang')), $file["name"])) { $report = \common_report_Report::createFailure(__('Fail to import media')); } else { $report = \common_report_Report::createSuccess(__('Media imported successfully')); } } else { $zipImporter = new ZipImporter(); $report = $zipImporter->import($class, $form); } } else { if ($file['type'] !== 'application/zip') { $service->editMediaInstance($file["uploaded_file"], $this->instanceUri, \tao_helpers_Uri::decode($form->getValue('lang'))); $report = \common_report_Report::createSuccess(__('Media imported successfully')); } else { $report = \common_report_Report::createFailure(__('You can\'t upload a zip file as a media')); } } return $report; } catch (\Exception $e) { $report = \common_report_Report::createFailure($e->getMessage()); return $report; } }
/** * Get the list of items to populate the checkbox tree of related items. * It prints to the HTTP response the tree data formated using json. * @return void */ public function getTreeData() { if ($this->hasRequestParameter('classUri')) { $classUri = tao_helpers_Uri::decode($this->getRequestParameter('classUri')); $class = new core_kernel_classes_Class($classUri); $hideNode = true; } elseif ($this->hasRequestParameter('rootNode')) { $class = new core_kernel_classes_Class($this->getRequestParameter('rootNode')); $hideNode = false; } else { throw new common_Exception('Missing node information for ' . __FUNCTION__); } $openNodes = array($class->getUri()); if ($this->hasRequestParameter('openNodes') && is_array($this->getRequestParameter('openNodes'))) { $openNodes = array_merge($openNodes, $this->getRequestParameter('openNodes')); } $limit = $this->hasRequestParameter('limit') ? $this->getRequestParameter('limit') : 10; $offset = $this->hasRequestParameter('offset') ? $this->getRequestParameter('offset') : 0; $showInst = $this->hasRequestParameter('hideInstances') ? !$this->getRequestParameter('hideInstances') : true; $propertyFilter = $this->getTreeFilter(); $factory = new tao_models_classes_GenerisTreeFactory(); $array = $factory->buildTree($class, $showInst, $openNodes, $limit, $offset, $propertyFilter); if ($hideNode) { $array = isset($array['children']) ? $array['children'] : array(); } header('Content-Type : application/json'); echo json_encode($array); }
public function testHardModel() { $this->hardify(); $referencer = ResourceReferencer::singleton(); $propertyProxy = PropertyProxy::singleton(); $proxy = ResourceProxy::singleton(); $domainProperty = new core_kernel_classes_Property(RDFS_DOMAIN); $rangeProperty = new core_kernel_classes_Property(RDFS_RANGE); $literalClass = new core_kernel_classes_Class(RDFS_LITERAL); $subClassOfProperty = new core_kernel_classes_Property(RDFS_SUBCLASSOF); $this->assertTrue($this->targetActorsProperty->exists()); $this->assertTrue($this->targetMovieClass->exists()); $this->assertTrue($this->targetWorkClass->isSubclassOf($this->taoClass)); $this->assertTrue($this->targetWorkClass->getOnePropertyValue($subClassOfProperty)->getUri() == $this->taoClass->getUri()); $this->assertTrue($referencer->isClassReferenced($this->targetWorkClass)); $this->assertFalse(is_a($proxy->getImpToDelegateTo($this->targetWorkClass), 'core_kernel_persistence_smoothsql_Class')); $this->assertFalse(is_a($proxy->getImpToDelegateTo($this->targetMovieClass), 'core_kernel_persistence_smoothsql_Class')); $this->assertTrue($this->targetAuthorProperty->getOnePropertyValue($domainProperty)->getUri() == $this->targetWorkClass->getUri()); $this->assertTrue($this->targetAuthorProperty->getOnePropertyValue($rangeProperty)->getUri() == RDFS_LITERAL); $this->assertTrue($this->targetMovieClass->isSubclassOf($this->targetWorkClass)); $this->assertTrue($this->targetMovieClass->getOnePropertyValue($subClassOfProperty)->getUri() == $this->targetWorkClass->getUri()); $this->assertTrue($referencer->isClassReferenced($this->targetMovieClass)); $this->assertTrue($this->targetProducerProperty->getOnePropertyValue($domainProperty)->getUri() == $this->targetMovieClass->getUri()); $this->assertTrue($this->targetProducerProperty->getOnePropertyValue($rangeProperty)->getUri() == RDFS_LITERAL); $this->assertTrue($this->targetActorsProperty->getOnePropertyValue($domainProperty)->getUri() == $this->targetMovieClass->getUri()); $this->assertTrue($this->targetActorsProperty->getOnePropertyValue($rangeProperty)->getUri() == RDFS_LITERAL); $this->assertTrue($this->targetRelatedMoviesProperty->getOnePropertyValue($domainProperty)->getUri() == $this->targetMovieClass->getUri()); $this->assertTrue($this->targetRelatedMoviesProperty->getOnePropertyValue($rangeProperty)->getUri() == $this->targetMovieClass->getUri()); $parentClasses = $this->targetMovieClass->getParentClasses(); $this->assertEquals(1, count($parentClasses)); $this->assertTrue(array_key_exists($this->targetWorkClass->getUri(), $parentClasses)); $prop = new core_kernel_classes_Property($this->targetRelatedMoviesProperty); $this->assertTrue($prop->isMultiple()); }
public function getData() { if (!tao_helpers_Request::isAjax()) { throw new common_exception_IsAjaxAction(__FUNCTION__); } if ($this->hasRequestParameter('classUri')) { $classUri = tao_helpers_Uri::decode($this->getRequestParameter('classUri')); $class = new core_kernel_classes_Class($classUri); $hideNode = true; } elseif ($this->hasRequestParameter('rootNode')) { $class = new core_kernel_classes_Class($this->getRequestParameter('rootNode')); $hideNode = false; } else { throw new common_Exception('Missing node information for ' . __FUNCTION__); } $openNodes = array($class->getUri()); if ($this->hasRequestParameter('openNodes') && is_array($this->getRequestParameter('openNodes'))) { $openNodes = array_merge($openNodes, $this->getRequestParameter('openNodes')); } $limit = $this->hasRequestParameter('limit') ? $this->getRequestParameter('limit') : self::DEFAULT_LIMIT; $offset = $this->hasRequestParameter('offset') ? $this->getRequestParameter('offset') : 0; $showInst = $this->hasRequestParameter('hideInstances') ? !$this->getRequestParameter('hideInstances') : true; $factory = new tao_models_classes_GenerisTreeFactory(); $array = $factory->buildTree($class, $showInst, $openNodes, $limit, $offset); if ($hideNode) { $array = isset($array['children']) ? $array['children'] : array(); } echo json_encode($array); }
/** * (non-PHPdoc) * * @see \oat\tao\model\media\MediaBrowser::getDirectory */ public function getDirectory($parentLink = '', $acceptableMime = array(), $depth = 1) { if ($parentLink == '') { $class = new \core_kernel_classes_Class($this->rootClassUri); } else { $class = new \core_kernel_classes_Class(\tao_helpers_Uri::decode($parentLink)); } $data = array('path' => 'taomedia://mediamanager/' . \tao_helpers_Uri::encode($class->getUri()), 'label' => $class->getLabel()); if ($depth > 0) { $children = array(); foreach ($class->getSubClasses() as $subclass) { $children[] = $this->getDirectory($subclass->getUri(), $acceptableMime, $depth - 1); } // add a filter for example on language (not for now) $filter = array(); foreach ($class->searchInstances($filter) as $instance) { try { $file = $this->getFileInfo($instance->getUri()); if (count($acceptableMime) == 0 || in_array($file['mime'], $acceptableMime)) { $children[] = $file; } } catch (\tao_models_classes_FileNotFoundException $e) { \common_Logger::e($e->getMessage()); } } $data['children'] = $children; } else { $data['parent'] = $parentLink; } return $data; }
/** * remove a campaign class * * @access public * @author Joel Bout, <*****@*****.**> * @param Class clazz * @return boolean */ public function deleteCampaignClass(core_kernel_classes_Class $clazz) { $returnValue = (bool) false; if (!is_null($clazz)) { if ($this->isCampaignClass($clazz) && $clazz->getUri() != $this->campaignClass->getUri()) { $returnValue = $clazz->delete(); } } return (bool) $returnValue; }
/** * 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; }
/** * recursivly add permissions to a class and all instances */ public static function addPermissionToClass(\core_kernel_classes_Class $class, $userUri, $rights) { $dbAccess = new DataBaseAccess(); $dbAccess->addPermissions($userUri, $class->getUri(), $rights); foreach ($class->getInstances(false) as $instance) { $dbAccess->addPermissions($userUri, $instance->getUri(), $rights); } foreach ($class->getSubClasses(false) as $subclass) { self::addPermissionToClass($subclass, $userUri, $rights); } }
/** * Starts the import based on the form * * @param \core_kernel_classes_Class $class * @param \tao_helpers_form_Form $form * @return \common_report_Report $report */ public function import($class, $form) { //as upload may be called multiple times, we remove the session lock as soon as possible session_write_close(); try { $file = $form->getValue('source'); $service = MediaService::singleton(); $classUri = $class->getUri(); if (is_null($this->instanceUri) || $this->instanceUri === $classUri) { //if the file is a zip do a zip import if ($file['type'] !== 'application/zip') { try { self::isValidSharedStimulus($file['uploaded_file']); $filepath = $file['uploaded_file']; $name = $file['name']; if (!$service->createMediaInstance($filepath, $classUri, \tao_helpers_Uri::decode($form->getValue('lang')), $name, 'application/qti+xml')) { $report = \common_report_Report::createFailure(__('Fail to import Shared Stimulus')); } else { $report = \common_report_Report::createSuccess(__('Shared Stimulus imported successfully')); } } catch (XmlStorageException $e) { // The shared stimulus is not qti compliant, display error $report = \common_report_Report::createFailure($e->getMessage()); } } else { $report = $this->zipImporter->import($class, $form); } } else { if ($file['type'] !== 'application/zip') { self::isValidSharedStimulus($file['uploaded_file']); $filepath = $file['uploaded_file']; if (in_array($file['type'], array('application/xml', 'text/xml'))) { $name = basename($file['name'], 'xml'); $name .= 'xhtml'; $filepath = dirname($file['name']) . '/' . $name; \tao_helpers_File::copy($file['uploaded_file'], $filepath); } if (!$service->editMediaInstance($filepath, $this->instanceUri, \tao_helpers_Uri::decode($form->getValue('lang')))) { $report = \common_report_Report::createFailure(__('Fail to edit shared stimulus')); } else { $report = \common_report_Report::createSuccess(__('Shared Stimulus edited successfully')); } } else { $report = $this->zipImporter->edit(new \core_kernel_classes_Resource($this->instanceUri), $form); } } return $report; } catch (\Exception $e) { $report = \common_report_Report::createFailure($e->getMessage()); return $report; } }
/** * Short description of method createInstance * * @access public * @author Jerome Bogaerts, <*****@*****.**> * @param Class clazz * @param string label * @param string comment * @param string uri * @return core_kernel_classes_Resource */ public static function createInstance(core_kernel_classes_Class $clazz, $label = '', $comment = '', $uri = '') { $returnValue = null; $newUri = !empty($uri) ? self::checkProvidedUri($uri) : common_Utils::getNewUri(); $newResource = new core_kernel_classes_Class($newUri); $propertiesValues = array(RDF_TYPE => $clazz->getUri()); if (!empty($label)) { $propertiesValues[RDFS_LABEL] = $label; } if (!empty($comment)) { $propertiesValues[RDFS_COMMENT] = $comment; } $check = $newResource->setPropertiesValues($propertiesValues); if ($check) { $returnValue = $newResource; } else { $msg = "Failed to create an instance of class '" . $clazz->getUri() . "'."; throw new common_Exception($msg); common_Logger::e($msg); } return $returnValue; }
public function indexTypes() { $toDo = array(); foreach ($this->resource->getTypes() as $class) { $toDo[] = $class->getUri(); // $document->addField(Document\Field::Text('class', $class->getLabel())); } $done = array(RDFS_RESOURCE, TAO_OBJECT_CLASS); $toDo = array_diff($toDo, $done); $classes = array(); while (!empty($toDo)) { $class = new \core_kernel_classes_Class(array_pop($toDo)); $classes[] = $class->getUri(); foreach ($class->getParentClasses() as $parent) { if (!in_array($parent->getUri(), $done)) { $toDo[] = $parent->getUri(); } } $done[] = $class->getUri(); } $this->document->type_r = $classes; }
public function testClassIterator() { $expected = array($this->topClass->getUri()); foreach ($this->topClass->getSubClasses(true) as $resource) { $expected[] = $resource->getUri(); } sort($expected); $iterator = new core_kernel_classes_ClassIterator($this->topClass); $found1 = array(); foreach ($iterator as $resource) { $this->assertIsA($resource, 'core_kernel_classes_Class'); $found1[] = $resource->getUri(); } sort($found1); $this->assertEquals($expected, $found1); $iterator = new core_kernel_classes_ClassIterator($this->emptyClass); $found2 = array(); foreach ($iterator as $instance) { $found2[] = $instance->getUri(); } $this->assertEquals(1, $iterator->key()); $this->assertEquals(array($this->emptyClass->getUri()), $found2); }
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()); }
/** * 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; }
/** * (non-PHPdoc) * @see tao_models_classes_export_ExportHandler::export() */ public function export($formValues, $destination) { $file = null; if (isset($formValues['filename']) && isset($formValues['resource'])) { $class = new core_kernel_classes_Class($formValues['resource']); common_Logger::i('Exporting ' . $class->getUri()); $adapter = new tao_helpers_data_GenerisAdapterRdf(); $rdf = $adapter->export($class); if (!empty($rdf)) { $name = $formValues['filename'] . '_' . time() . '.rdf'; $path = tao_helpers_File::concat(array($destination, $name)); if (file_put_contents($path, $rdf)) { $file = $path; } } } return $file; }
/** * @author Bertrand Chevrier, <*****@*****.**> * @param core_kernel_classes_Class $range * @param boolean $recursive * @return array */ public function rangeToTree(core_kernel_classes_Class $range, $recursive = false) { $data = array(); foreach ($range->getSubClasses(false) as $rangeClass) { $classData = array('data' => $rangeClass->getLabel(), 'attributes' => array('id' => tao_helpers_Uri::encode($rangeClass->getUri()), 'class' => 'node-instance')); $children = $this->rangeToTree($rangeClass, true); if (count($children) > 0) { $classData['state'] = 'closed'; $classData['children'] = $children; } $data[] = $classData; } if (!$recursive) { $returnValue = array('data' => $range->getLabel(), 'attributes' => array('id' => tao_helpers_Uri::encode($range->getUri()), 'class' => 'node-class'), 'children' => $data); } else { $returnValue = $data; } return $returnValue; }
public function testImportXml() { $sharedImporter = new SharedStimulusImporter(); $filename = dirname(__DIR__) . '/sample/sharedStimulus/sharedStimulus.xml'; $tmpDir = \tao_helpers_File::createTempDir(); copy($filename, $tmpDir . basename($filename)); $filename = $tmpDir . basename($filename); $finalFilename = $tmpDir . 'sharedStimulus.xml'; $myClass = new \core_kernel_classes_Class('http://fancyDomain.com/tao.rdf#fancyUri'); $info = finfo_open(FILEINFO_MIME_TYPE); $file['type'] = finfo_file($info, $filename); finfo_close($info); $file['uploaded_file'] = $filename; $file['name'] = basename($filename); $form = $sharedImporter->getForm(); $form->setValues(array('source' => $file, 'lang' => 'EN_en')); $this->service->expects($this->once())->method('createMediaInstance')->with($finalFilename, $myClass->getUri(), 'EN_en', basename($filename))->willReturn('myGreatLink'); $report = $sharedImporter->import($myClass, $form); $this->assertEquals(\common_report_Report::TYPE_SUCCESS, $report->getType(), __('Report should be success')); $this->assertEquals(__('Shared Stimulus imported successfully'), $report->getMessage(), __('Report message is wrong')); }
/** * @dataProvider sharedStimulusImportProvider */ public function testImport($filename, $expectedReport, $called) { if (file_exists($filename)) { $tmpDir = \tao_helpers_File::createTempDir(); copy($filename, $tmpDir . basename($filename)); $filename = $tmpDir . basename($filename); } $myClass = new \core_kernel_classes_Class('http://fancyDomain.com/tao.rdf#fancyUri'); $file['uploaded_file'] = $filename; $file['name'] = basename($filename); $form = new FileImportForm($myClass->getUri()); $form = $form->getForm(); $form->setValues(array('source' => $file, 'lang' => 'EN_en')); if ($called) { $this->service->expects($this->once())->method('createMediaInstance')->willReturn('myGreatLink'); } $report = $this->packageImporter->import($myClass, $form); /** @var \common_report_Report $expectedReport*/ $expectedReport->setMessage(preg_replace('/%s/', 'imported', $expectedReport->getMessage())); $this->assertEquals($expectedReport->getType(), $report->getType(), __('Report should be success')); $this->assertEquals($expectedReport->getMessage(), $report->getMessage(), __('Report message is wrong')); }
/** * @param Document $document */ protected function indexTypes(Document $document) { $toDo = array(); foreach ($this->resource->getTypes() as $class) { $toDo[] = $class->getUri(); $document->addField(Document\Field::Text('class', $class->getLabel())); } $done = array(RDFS_CLASS, TAO_OBJECT_CLASS); $toDo = array_diff($toDo, $done); $classLabels = array(); while (!empty($toDo)) { $class = new \core_kernel_classes_Class(array_pop($toDo)); $classLabels[] = $class->getLabel(); foreach ($class->getParentClasses() as $parent) { if (!in_array($parent->getUri(), $done)) { $toDo[] = $parent->getUri(); } } $done[] = $class->getUri(); } $field = Document\Field::Keyword('class_r', $classLabels); $field->isStored = false; $document->addField($field); }
/** * search the instances of an ontology * @return */ public function search() { $found = false; try { $clazz = $this->getCurrentClass(); } catch (Exception $e) { common_Logger::i('Search : could not find current class switch to root class'); $clazz = $this->getRootClass(); } $formContainer = $this->getSearchForm($clazz); $myForm = $formContainer->getForm(); if (tao_helpers_Context::check('STANDALONE_MODE')) { $standAloneElt = tao_helpers_form_FormFactory::getElement('standalone', 'Hidden'); $standAloneElt->setValue(true); $myForm->addElement($standAloneElt); } if ($myForm->isSubmited()) { if ($myForm->isValid()) { $filters = $myForm->getValues('filters'); $model = array(); foreach ($filters as $propUri => $filter) { if (preg_match("/^http/", $propUri) && !empty($filter)) { $property = new core_kernel_classes_Property($propUri); $model[$property->getUri()] = array('id' => $property->getUri(), 'label' => $property->getLabel(), 'sortable' => true); } else { unset($filters[$propUri]); } } $clazz = new core_kernel_classes_Class($myForm->getValue('clazzUri')); if (!array_key_exists(RDFS_LABEL, $model)) { $labelProp = new core_kernel_classes_Property(RDFS_LABEL); $model = array_merge(array($labelProp->getUri() => array('id' => $labelProp->getUri(), 'label' => $labelProp->getLabel(), 'sortable' => true)), $model); } $params = $myForm->getValues('params'); if (!isset($params['recursive'])) { // 0 => Current class + sub-classes, 10 => Current class only $params['recursive'] = true; } else { $params['recursive'] = false; } $params['like'] = false; return $this->returnJson(array('url' => _url('searchResults', null, null, array('classUri' => $clazz->getUri())), 'params' => $params, 'model' => $model, 'filters' => $filters, 'result' => true)); } } $this->setData('myForm', $myForm->render()); $this->setData('formTitle', __('Search')); $this->setView('form/search.tpl', 'tao'); }
/** * returns the nodes to open in order to display * all the listed resources to be visible * * @param array $resources list of resources to show * @param core_kernel_classes_Class $rootNode root node of the tree * @return array array of the uris of the nodes to open */ public static function getNodesToOpen($uris, core_kernel_classes_Class $rootNode) { // this array is in the form of // URI to test => array of uris that depend on the URI $toTest = array(); foreach ($uris as $uri) { $resource = new core_kernel_classes_Resource($uri); foreach ($resource->getTypes() as $type) { $toTest[$type->getUri()] = array(); } } $toOpen = array($rootNode->getUri()); while (!empty($toTest)) { reset($toTest); list($classUri, $depends) = each($toTest); unset($toTest[$classUri]); if (in_array($classUri, $toOpen)) { $toOpen = array_merge($toOpen, $depends); } else { $class = new core_kernel_classes_Class($classUri); foreach ($class->getParentClasses(false) as $parent) { if ($parent->getUri() == RDFS_CLASS) { continue; } if (!isset($toTest[$parent->getUri()])) { $toTest[$parent->getUri()] = array(); } $toTest[$parent->getUri()] = array_merge($toTest[$parent->getUri()], array($classUri), $depends); } } } return $toOpen; }
/** * Short description of method remove * * @access public * @author Jehan Bihin, <*****@*****.**> * @param string $roleUri * @param string $accessUri * @return mixed */ public function remove($roleUri, $accessUri) { $module = new core_kernel_classes_Resource($accessUri); $role = new core_kernel_classes_Class($roleUri); $accessProperty = new core_kernel_classes_Property(funcAcl_models_classes_AccessService::PROPERTY_ACL_GRANTACCESS); // Retrieve the module ID. $uri = explode('#', $module->getUri()); list($type, $extId, $modId) = explode('_', $uri[1]); // access via extension? $extAccess = funcAcl_helpers_Cache::getExtensionAccess($extId); if (in_array($roleUri, $extAccess)) { // remove access to extension $extUri = $this->makeEMAUri($extId); funcAcl_models_classes_ExtensionAccessService::singleton()->remove($roleUri, $extUri); // add access to all other controllers foreach (funcAcl_helpers_Model::getModules($extId) as $eModule) { if (!$module->equals($eModule)) { $this->add($roleUri, $eModule->getUri()); $this->getEventManager()->trigger(new AccessRightRemovedEvent($roleUri, $eModule->getUri())); //$role->setPropertyValue($accessProperty, $eModule->getUri()); } } //funcAcl_helpers_Cache::flushExtensionAccess($extId); } // Remove the access to the module for this role. $role->removePropertyValue($accessProperty, $module->getUri()); $this->getEventManager()->trigger(new AccessRightRemovedEvent($roleUri, $accessUri)); funcAcl_helpers_Cache::cacheModule($module); // Remove the access to the actions corresponding to the module for this role. foreach (funcAcl_helpers_Model::getActions($module) as $actionResource) { funcAcl_models_classes_ActionAccessService::singleton()->remove($role->getUri(), $actionResource->getUri()); } funcAcl_helpers_Cache::cacheModule($module); }
public function rangeToTree(core_kernel_classes_Class $range, $recursive = true) { $openNodes = array_reduce($range->getSubClasses(true), function ($carry, $item) { if (!$carry) { $carry = []; } $carry[] = $item->getUri(); return $carry; }); $openNodes[] = $range->getUri(); $factory = new GenerisTreeFactory(true, $openNodes, 10, 0); $array = $factory->buildTree($range); return $array; }
/** * Get additional properties used during class' compilation. * This function is usefull specially during unhardening * * @access public * @author Joel Bout, <*****@*****.**> * @param Class clazz * @return array */ public function getAdditionalProperties(\core_kernel_classes_Class $clazz) { $returnValue = array(); $dbWrapper = \core_kernel_classes_DbWrapper::singleton(); $query = "SELECT property_uri \n\t\t\tFROM class_additional_properties, class_to_table \n\t\t\tWHERE class_additional_properties.class_id = class_to_table.id\n\t\t\tAND class_to_table.uri = ?"; $result = $dbWrapper->query($query, array($clazz->getUri())); while ($row = $result->fetch()) { $returnValue[] = new \core_kernel_classes_Property($row['property_uri']); } return (array) $returnValue; }
/** * Enable you to get the properties of a class. * The advantage of this method is to limit the level of recusrivity in the * It get the properties up to the defined top class * * @access public * @author Bertrand Chevrier, <*****@*****.**> * @param core_kernel_classes_Class $clazz * @param core_kernel_classes_Class $topLevelClazz * @return array */ public static function getClassProperties(core_kernel_classes_Class $clazz, core_kernel_classes_Class $topLevelClazz = null) { $returnValue = array(); if (is_null($topLevelClazz)) { $topLevelClazz = new core_kernel_classes_Class(TAO_OBJECT_CLASS); } if ($clazz->getUri() == $topLevelClazz->getUri()) { $returnValue = $clazz->getProperties(false); return (array) $returnValue; } //determine the parent path $parents = array(); $top = false; do { if (!isset($lastLevelParents)) { $parentClasses = $clazz->getParentClasses(false); } else { $parentClasses = array(); foreach ($lastLevelParents as $parent) { $parentClasses = array_merge($parentClasses, $parent->getParentClasses(false)); } } if (count($parentClasses) == 0) { break; } $lastLevelParents = array(); foreach ($parentClasses as $parentClass) { if ($parentClass->getUri() == RDFS_CLASS) { continue; } if ($parentClass->getUri() == $topLevelClazz->getUri()) { $parents[$parentClass->getUri()] = $parentClass; $top = true; break; } $allParentClasses = $parentClass->getParentClasses(true); if (array_key_exists($topLevelClazz->getUri(), $allParentClasses)) { $parents[$parentClass->getUri()] = $parentClass; } $lastLevelParents[$parentClass->getUri()] = $parentClass; } } while (!$top); foreach ($parents as $parent) { $returnValue = array_merge($returnValue, $parent->getProperties(false)); } $returnValue = array_merge($returnValue, $clazz->getProperties(false)); return (array) $returnValue; }
/** * Calling this method will transfer all instances of $class from the statements table * to specific optimized relational tables. * * During optimization, the current user has all privileges on the persistent memory. At * the end of the process, the old privileges will be set back. * * The $options array can contain the following key => values (all booleans): * * - recursive: compile the target class and its subclasses (default: false). * - append: append data to the existing optimized table if it already exists (default: false). * - rmSources: remove the triples in the statement table after transfer (default: true). * * @access public * @author Bertrand Chevrier, <*****@*****.**> * @param \core_kernel_classes_Class class * @param array options * @return boolean Will return true if it succeeds, false otherwise. */ public function hardify(\core_kernel_classes_Class $class, $options = array()) { $returnValue = (bool) false; $oldUpdatableModels = core_kernel_persistence_smoothsql_SmoothModel::getUpdatableModelIds(); try { // Give access to all models during hardification. core_kernel_persistence_smoothsql_SmoothModel::forceUpdatableModelIds(self::getAllModelIds()); $classLabel = $class->getLabel(); \common_Logger::i("Hardifying class {$classLabel}", array("GENERIS")); if (defined("DEBUG_PERSISTENCE") && DEBUG_PERSISTENCE) { if (in_array($class->getUri(), self::$debug_tables)) { return; } \common_Logger::d('hardify ' . $class->getUri()); self::$debug_tables[] = $class->getUri(); $countStatement = $this->countStatements(); } if (in_array($class->getUri(), self::$blackList)) { return $returnValue; } // ENTER IN SMOOTH SQL MODE PersistenceProxy::forceMode(PERSISTENCE_SMOOTH); //recursive will hardify the class and it's subclasses in the same table! isset($options['recursive']) ? $recursive = $options['recursive'] : ($recursive = false); //createForeigns will hardify the class that are range of the properties isset($options['createForeigns']) ? $createForeigns = $options['createForeigns'] : ($createForeigns = false); //check if we append the data in case the hard table exists or truncate the table and add the new rows isset($options['append']) ? $append = $options['append'] : ($append = false); //if true, the instances of the class will be removed from the statements table! isset($options['rmSources']) ? $rmSources = (bool) $options['rmSources'] : ($rmSources = false); //if defined, we took all the properties of the class and it's parents till the topclass isset($options['topclass']) ? $topclass = $options['topclass'] : ($topclass = new \core_kernel_classes_Class(RDFS_RESOURCE)); //if defined, compile the additional properties isset($options['additionalProperties']) ? $additionalProperties = $options['additionalProperties'] : ($additionalProperties = array()); //if defined, reference the additional class to the table isset($options['referencesAllTypes']) ? $referencesAllTypes = $options['referencesAllTypes'] : ($referencesAllTypes = false); $tableName = '_' . Utils::getShortName($class); $myTableMgr = new TableManager($tableName); $referencer = ResourceReferencer::singleton(); //get the table columns from the class properties $columns = array(); $ps = new PropertySwitcher($class); $properties = $ps->getProperties($additionalProperties); $columns = $ps->getTableColumns($additionalProperties, self::$blackList); //init the count value in hardened classes: if (isset($this->hardenedClasses[$class->getUri()])) { PersistenceProxy::restoreImplementation(); return true; //already being compiled } else { $this->hardenedClasses[$class->getUri()] = 0; } if (!$append || $append && !$myTableMgr->exists()) { //create the table if ($myTableMgr->exists()) { $myTableMgr->remove(); } $myTableMgr->create($columns); //reference the class $referencer->referenceClass($class, array("topclass" => $topclass, "additionalProperties" => $additionalProperties)); if ($referencesAllTypes) { $referencer->referenceInstanceTypes($class); } } //insert the resources $startIndex = 0; $instancePackSize = 100; $instances = $class->getInstances(false, array('offset' => $startIndex, 'limit' => $instancePackSize)); $count = count($instances); $notDeletedInstances = array(); do { //reset timeout: //set_time_limit(30); \helpers_TimeOutHelper::setTimeOutLimit(\helpers_TimeOutHelper::MEDIUM); $rows = array(); foreach ($instances as $index => $resource) { if ($referencer->isResourceReferenced($resource)) { PersistenceProxy::forceMode(PERSISTENCE_HARD); $resource->delete(); PersistenceProxy::restoreImplementation(); } $row = array('uri' => $resource->getUri()); foreach ($properties as $property) { $propValue = $resource->getOnePropertyValue($property); $row[Utils::getShortName($property)] = $propValue; } $rows[] = $row; } $rowMgr = new RowManager($tableName, $columns); $rowMgr->insertRows($rows); foreach ($instances as $resource) { $referencer->referenceResource($resource, $tableName, null, true); if ($rmSources) { //remove exported resources in smooth sql, if required: // Be carefull, the resource can still exist even if // delete returns true. Indeed, modelIds can be mixed between // multiple models and only a part of the triples that consitute // the resource might have been deleted. if (!$resource->delete() || $resource->exists()) { //@TODO : modified resource::delete() because resource not in local modelId cannot be deleted $notDeletedInstances[] = $resource->getUri(); $startIndex++; } } } if (!$rmSources) { //increment start index only if not removed $startIndex += $instancePackSize; } //record hardened instances number if (isset($this->hardenedClasses[$class->getUri()])) { $this->hardenedClasses[$class->getUri()] += $count; } else { $this->hardenedClasses[$class->getUri()] = $count; } //update instance array and count value $instances = $class->getInstances(false, array('offset' => $startIndex, 'limit' => $instancePackSize)); foreach ($notDeletedInstances as $uri) { unset($instances[$uri]); } $count = count($instances); \helpers_TimeOutHelper::reset(); } while ($count > 0); $returnValue = true; // Treat subclasses of the current class if ($recursive) { foreach ($class->getSubClasses(true) as $subClass) { $returnValue = $this->hardify($subClass, array_merge($options, array('recursive' => false, 'append' => true))); } } //reset cache: $referencer->clearCaches(); // EXIT SMOOTH SQL MODE PersistenceProxy::restoreImplementation(); if (defined("DEBUG_PERSISTENCE") && DEBUG_PERSISTENCE) { $this->unhardify($class, array_merge($options, array('recursive' => false, 'removeForeigns' => false))); \common_Logger::d('unhardened result statements ' . $this->countStatements() . ' / ' . $countStatement); } // Give the normal rights on models to the session. core_kernel_persistence_smoothsql_SmoothModel::forceUpdatableModelIds($oldUpdatableModels); } catch (Exception $e) { \common_Logger::e('An error occured during hardification: ' . $e->getMessage()); core_kernel_persistence_smoothsql_SmoothModel::forceUpdatableModelIds($oldUpdatableModels); } return (bool) $returnValue; }
/** * Short description of method removeType * * @access public * @author Joel Bout, <*****@*****.**> * @param Resource resource * @param Class class * @return boolean */ public function removeType(core_kernel_classes_Resource $resource, core_kernel_classes_Class $class) { $returnValue = (bool) false; $query = 'DELETE FROM statements WHERE subject = ? AND predicate = ? AND ' . $this->getPersistence()->getPlatForm()->getObjectTypeCondition() . ' = ?'; //be sure the property we try to remove is included in an updatable model $query .= ' AND ' . $this->getModelWriteSqlCondition(); $returnValue = $this->getPersistence()->exec($query, array($resource->getUri(), RDF_TYPE, $class->getUri())); $returnValue = true; return (bool) $returnValue; }
/** * Short description of method setRange * * @access public * @author Jerome Bogaerts, <*****@*****.**> * @param Resource resource * @param Class class * @return core_kernel_classes_Class */ public function setRange(core_kernel_classes_Resource $resource, core_kernel_classes_Class $class) { $returnValue = null; $rangeProp = new core_kernel_classes_Property(RDFS_RANGE, __METHOD__); $returnValue = $this->setPropertyValue($resource, $rangeProp, $class->getUri()); return $returnValue; }