public function testImport() { $endpoint = ROOT_URL . 'taoQtiTest/RestQtiTests/import'; $file = __DIR__ . '/samples/archives/QTI 2.1/basic/Basic.zip'; $this->assertFileExists($file); $post_data = array('qtiPackage' => new \CURLFile($file)); $options = array(CURLOPT_POSTFIELDS => $post_data); $content = $this->curl($endpoint, CURLOPT_POST, "data", $options); $data = json_decode($content, true); $this->assertTrue(is_array($data), 'Should return json encoded array'); $this->assertTrue($data['success']); $this->assertTrue(isset($data['data'])); $this->assertTrue(is_array($data['data'])); $this->assertCount(1, $data['data']); $testData = reset($data['data']); $this->assertTrue(isset($testData['testId'])); $uri = $testData['testId']; $test = new \core_kernel_classes_Resource($uri); $this->assertTrue($test->exists()); $deletionCall = ROOT_URL . 'taoTests/RestTests?uri=' . urlencode($uri); $content = $this->curl($deletionCall, 'DELETE', "data"); $data = json_decode($content, true); $this->assertTrue(is_array($data), 'Should return json encoded array'); $this->assertTrue($data['success']); $this->assertFalse($test->exists()); // should return an error, instance no longer exists $content = $this->curl($deletionCall, 'DELETE', "data"); $data = json_decode($content, true); $this->assertTrue(is_array($data), 'Should return json encoded array'); $this->assertFalse($data['success']); }
/** * Test user insertion with special chars */ public function testAddUtf8User() { $this->assertTrue($this->userService->loginAvailable($this->testUserUtf8Data[PROPERTY_USER_LOGIN])); $tmclass = new core_kernel_classes_Class(CLASS_TAO_USER); $this->testUserUtf8 = $tmclass->createInstance(); $this->assertNotNull($this->testUserUtf8); $this->assertTrue($this->testUserUtf8->exists()); $result = $this->userService->bindProperties($this->testUserUtf8, $this->testUserUtf8Data); $this->assertNotNull($result); $this->assertNotEquals($result, false); $this->assertFalse($this->userService->loginAvailable($this->testUserUtf8Data[PROPERTY_USER_LOGIN])); //check inserted data $this->testUserUtf8 = $this->getUserByLogin($this->testUserUtf8Data[PROPERTY_USER_LOGIN]); $this->assertInstanceOf('core_kernel_classes_Resource', $this->testUserUtf8); foreach ($this->testUserUtf8Data as $prop => $value) { try { $p = new core_kernel_classes_Property($prop); $v = $this->testUserUtf8->getUniquePropertyValue($p); $v = $v instanceof core_kernel_classes_Literal ? $v->literal : $v->getUri(); $this->assertEquals($value, $v); } catch (common_Exception $ce) { $this->fail($ce); } } }
/** * Will make the Global Manager include the Management Role of the extension * to install (if it exists). * * @access public * @author Jerome Bogaerts <*****@*****.**> * @return void * @since 2.4 */ public function installManagementRole() { // Try to get a Management Role described by the extension itself. // (this information comes actually from the Manifest of the extension) $roleUri = $this->extension->getManifest()->getManagementRoleUri(); if (!empty($roleUri)) { $role = new core_kernel_classes_Resource($roleUri); $roleService = tao_models_classes_RoleService::singleton(); if (!$role->exists()) { // Management role does not exist yet, so we create it $roleClass = new core_kernel_classes_Class(CLASS_MANAGEMENTROLE); $roleLabel = $this->extension->getId() . ' Manager'; $role = $roleClass->createInstance($roleLabel, $roleLabel . ' Role', $role->getUri()); $roleService->includeRole($role, new core_kernel_classes_Resource(INSTANCE_ROLE_BACKOFFICE)); } // Take the Global Manager role and make it include // the Management role of the currently installed extension. if ($role->getUri() !== INSTANCE_ROLE_GLOBALMANAGER) { $globalManagerRole = new core_kernel_classes_Resource(INSTANCE_ROLE_GLOBALMANAGER); $roleService->includeRole($globalManagerRole, $role); } common_Logger::d("Management Role " . $role->getUri() . " created for extension '" . $this->extension->getId() . "'."); } else { // There is no Management role described by the Extension Manifest. common_Logger::i("No management role for extension '" . $this->extension->getId() . "'."); } }
/** * Test the existence of language definition resources in the knowledge base * regarding what we found in the tao/locales directory. * * @author Jerome Bogaerts, <*****@*****.**> */ public function testLanguagesExistence() { // Check for lang.rdf in /tao locales and query the KB to see if it exists or not. $languageClass = new core_kernel_classes_Class(CLASS_LANGUAGES); $taoLocalesDir = ROOT_PATH . '/tao/locales'; $expectedUriPrefix = 'http://www.tao.lu/Ontologies/TAO.rdf#Lang'; if (false !== ($locales = scandir($taoLocalesDir))) { foreach ($locales as $l) { $localePath = $taoLocalesDir . '/' . $l; if ($l[0] !== '.' && is_dir($localePath) && is_readable($localePath)) { $langPath = $localePath . '/lang.rdf'; if (file_exists($langPath)) { $lgResource = new core_kernel_classes_Resource($expectedUriPrefix . $l); $this->assertTrue($lgResource->exists(), '$lgResource Resource does not exist (' . $expectedUriPrefix . $l . ').'); // Check for this language in Ontology. $kbLangs = $lgResource->getPropertyValues(new core_kernel_classes_Property(RDF_VALUE)); if (is_array($kbLangs)) { $this->assertEquals(count($kbLangs), 1, "Number of languages retrieved for language '{$l}' is '" . count($kbLangs) . "'."); // Check if the language has the correct URI. if ($kbLangs[0] instanceof core_kernel_classes_Resource) { $this->assertTrue($kbLangs[0]->getUri() == $expectedUriPrefix . $l, "Malformed URI scheme for language resource '{$l}'."); } } else { $this->fail('the $kbLangs variable should be an array. "' . gettype($kbLangs) . '" found instead.'); } } } } } }
/** * Resolve the given TAO Item URI in the path to * the related QTI-XML file. * * @param string $url The URI of the TAO Item to resolve. * @return string The path to the related QTI-XML file. * @throws ResolutionException If an error occurs during the resolution of $url. */ public function resolve($url) { $taoItem = new core_kernel_classes_Resource($url); if ($taoItem->exists() === false) { $msg = "The QTI Item with URI '{$url}' cannot be found."; throw new ResolutionException($msg); } // The item is retrieved from the database. // We can try to reach the QTI-XML file by detecting // where it is supposed to be located. return QtiFile::getQtiFilePath(new core_kernel_classes_Resource($url)); }
/** * * @param unknown $params */ public function __invoke($params) { if (count($params) != 2) { return new \common_report_Report(\common_report_Report::TYPE_ERROR, __('Usage: %s DELIVERY_URI OUTPUT_FILE', __CLASS__)); } $deliveryUri = array_shift($params); $delivery = new \core_kernel_classes_Resource($deliveryUri); if (!$delivery->exists()) { return new \common_report_Report(\common_report_Report::TYPE_ERROR, __('Delivery \'%s\' not found', $deliveryUri)); } $file = array_shift($params); \common_ext_ExtensionsManager::singleton()->getExtensionById('taoDeliveryRdf'); $tmpFile = Assembler::exportCompiledDelivery($delivery); \tao_helpers_File::move($tmpFile, $file); return new \common_report_Report(\common_report_Report::TYPE_SUCCESS, __('Exported %1$s to %2$s', $delivery->getLabel(), $file)); }
/** * Resolve the given TAO Item URI in the path to * the related QTI-XML file. * * @param string $url The URI of the TAO Item to resolve. * @return string The path to the related QTI-XML file. * @throws ResolutionException If an error occurs during the resolution of $url. */ public function resolve($url) { $taoItem = new core_kernel_classes_Resource($url); if ($taoItem->exists() === false) { $msg = "The QTI Item with URI '{$url}' cannot be found."; throw new ResolutionException($msg); } // The item is retrieved from the database. // We can try to reach the QTI-XML file by detecting // where it is supposed to be located. // strip xinclude, we don't need that at the moment. $raw = $this->service->getXmlByRdfItem($this->getResource($url)); $tmpfile = sys_get_temp_dir() . '/' . md5($url) . '.xml'; $raw = preg_replace("/<xi:include(?:.*)>/u", '', $raw); file_put_contents($tmpfile, $raw); return $tmpfile; }
public function __invoke($params) { // load constants... \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest')->load(); if (empty($params[0]) === true) { return new \common_report_Report(\common_report_Report::TYPE_ERROR, 'Test URI not provided as parameter 1.'); } if (empty($params[1]) === true) { return new \common_report_Report(\common_report_Report::TYPE_ERROR, 'AssessmentItemRefIdentifier not provided as parameter 2.'); } $testResource = new \core_kernel_classes_Resource($params[0]); if ($testResource->exists() === false) { return new \common_report_Report(\common_report_Report::TYPE_ERROR, 'No RDFS Resource found for URI ' . $params[0] . '.'); } $qtiService = \taoQtiTest_models_classes_QtiTestService::singleton(); $testDoc = $qtiService->getDoc($testResource); $test = $testDoc->getDocumentComponent(); $assessmentItemRef = $test->getComponentByIdentifier($params[1]); if (!$assessmentItemRef) { return new \common_report_Report(\common_report_Report::TYPE_ERROR, 'No QTI assessmentItemRef with identifier ' . $params[1] . ' found in the QTI Test definition.'); } $input = file_get_contents('php://stdin'); if (empty($input) === true) { return new \common_report_Report(\common_report_Report::TYPE_ERROR, 'No QTI-XML input provided in stdin.'); } else { $dom = new \DOMDocument('1.0', 'UTF-8'); if (@$dom->loadXML($input)) { $element = $dom->documentElement; $marshallerFactory = new MarshallerFactory(); $marshaller = $marshallerFactory->createMarshaller($element); $component = $marshaller->unmarshall($element); if (!$component instanceof BranchRule) { return new \common_report_Report(\common_report_Report::TYPE_ERROR, 'No QTI branchRule component found in stdin.'); } $assessmentItemRef->setBranchRules(new BranchRuleCollection(array($component))); $qtiService->getQtiTestFile($testResource)->update($testDoc->saveToString()); } else { return new \common_report_Report(\common_report_Report::TYPE_ERROR, 'Invalid QTI-XML input provided in stdin.'); } } return new \common_report_Report(\common_report_Report::TYPE_SUCCESS, "BranchRule found in stdin successfully appended to assessmentItemRef '" . $params[1] . "' part of QTI Test with URI '" . $params[0] . "'."); }
/** * Generate a delivery from test uri * Test uri has to be set and existing */ public function generate() { try { if (!$this->hasRequestParameter(self::REST_DELIVERY_TEST_ID)) { throw new \common_exception_MissingParameter(self::REST_DELIVERY_TEST_ID, $this->getRequestURI()); } $test = new \core_kernel_classes_Resource($this->getRequestParameter(self::REST_DELIVERY_TEST_ID)); if (!$test->exists()) { throw new \common_exception_NotFound('Unable to find a test associated to the given uri.'); } $label = 'Delivery of ' . $test->getLabel(); $deliveryClass = new \core_kernel_classes_Class(CLASS_COMPILEDDELIVERY); /** @var \common_report_Report $report */ $report = SimpleDeliveryFactory::create($deliveryClass, $test, $label); if ($report->getType() == \common_report_Report::TYPE_ERROR) { \common_Logger::i('Unable to generate delivery execution ' . 'into taoDeliveryRdf::RestDelivery for test uri ' . $test->getUri()); throw new \common_Exception('Unable to generate delivery execution.'); } $delivery = $report->getData(); $this->returnSuccess(array('delivery' => $delivery->getUri())); } catch (\Exception $e) { $this->returnFailure($e); } }
/** * Short description of method attachResource * * @access public * @author Jerome Bogaerts, <*****@*****.**> * @param core_kernel_classes_Property $targetProperty * @param core_kernel_classes_Resource $targetResource * @param string $value * @return mixed */ public function attachResource(core_kernel_classes_Property $targetProperty, core_kernel_classes_Resource $targetResource, $value) { // We have to check if the resource identified by value exists in the Ontology. $resource = new core_kernel_classes_Resource($value); if ($resource->exists()) { // Is the range correct ? $targetPropertyRanges = $targetProperty->getPropertyValuesCollection(new core_kernel_classes_Property(RDFS_RANGE)); $rangeCompliance = true; // If $targetPropertyRange->count = 0, we consider that the resouce // may be attached because $rangeCompliance = true. foreach ($targetPropertyRanges->getIterator() as $range) { // Check all classes in target property's range. if ($resource->hasType(new core_kernel_classes_Class($range))) { $rangeCompliance = false; break; } } if (true == $rangeCompliance) { $targetResource->setPropertyValue($targetProperty, $resource->getUri()); } } }
/** * test deleteTest * @depends testInstanceCreate * @param \core_kernel_classes_Resource $testInstance * @return void */ public function testDeleteTest($testInstance) { $this->assertTrue($testInstance->exists()); $this->wftService->deleteTest($testInstance); $this->assertFalse($testInstance->exists()); }
die(1); } require_once $rawStart; if (!file_exists($csvfile)) { echo 'Csv file not found at "' . $csvfile . '"' . PHP_EOL; die(1); } if (is_null($groupUri)) { $label = 'Group ' . uniqid(); $groupClass = new \core_kernel_classes_Class(TAO_GROUP_CLASS); $group = $groupClass->createInstanceWithProperties(array(RDFS_LABEL => $label)); echo 'Group "' . $label . '" created.' . PHP_EOL; $groupUri = $group->getUri(); } else { $group = new core_kernel_classes_Resource($groupUri); if (!$group->exists()) { echo 'Group "' . $groupUri . '" not found.' . PHP_EOL; die(1); } } $persistence = \common_persistence_Manager::getPersistence('default'); try { $schemaManager = $persistence->getDriver()->getSchemaManager(); $schema = $schemaManager->createSchema(); if (!$schema->hastable('redis')) { $fromSchema = clone $schema; $tableResults = $schema->createtable('redis'); $tableResults->addOption('engine', 'MyISAM'); $tableResults->addColumn('subject', 'string', ['length' => 255]); $tableResults->addColumn('predicate', 'string', ['length' => 255]); $tableResults->addColumn('object', 'string', ['length' => 255]);
/** * Test correct response */ public function testGenerate() { $testUri = $this->initDeliveryGeneration(); $data = $this->curlDeliveryGenerate($testUri); $this->assertTrue(is_array($data)); $this->assertTrue(isset($data['success'])); $this->assertTrue($data['success']); $this->assertTrue(isset($data['data']['delivery'])); $delivery = new \core_kernel_classes_Resource($data['data']['delivery']); $this->assertTrue($delivery->exists()); $this->removeDeliveryTest($delivery, $testUri); }
/** * Short description of method performTransition * * @access public * @author Somsack Sipasseuth, <*****@*****.**> * @param Resource processExecution * @param Resource activityExecution * @return mixed */ public function performTransition(core_kernel_classes_Resource $processExecution, core_kernel_classes_Resource $activityExecution) { $returnValue = null; $session = PHPSession::singleton(); $session->setAttribute("activityExecutionUri", $activityExecution->getUri()); //check if the transition is possible, e.g. process is not finished if ($this->isFinished($processExecution)) { return false; } //init the services $activityDefinitionService = wfEngine_models_classes_ActivityService::singleton(); $connectorService = wfEngine_models_classes_ConnectorService::singleton(); $userService = wfEngine_models_classes_UserService::singleton(); $notificationService = wfEngine_models_classes_NotificationService::singleton(); $currentUser = $userService->getCurrentUser(); //set the activity execution of the current user as finished: if ($activityExecution->exists()) { $this->activityExecutionService->finish($activityExecution); } else { throw new Exception("cannot find the activity execution of the current activity {$activityBeforeTransition->getUri()} in perform transition"); } $activityBeforeTransition = $this->activityExecutionService->getExecutionOf($activityExecution); $nextConnector = $activityDefinitionService->getUniqueNextConnector($activityBeforeTransition); if (wfEngine_models_classes_ActivityCardinalityService::singleton()->isCardinality($nextConnector)) { $nextConnector = wfEngine_models_classes_ActivityCardinalityService::singleton()->getDestination($nextConnector); } $newActivities = array(); if (!is_null($nextConnector)) { $newActivities = $this->getNewActivities($processExecution, $activityExecution, $nextConnector); } else { //final activity: $this->finish($processExecution); return array(); } if ($newActivities === false) { //means that the process must be paused before transition: transition condition not fullfilled $this->pause($processExecution); return false; } // The actual transition starts here: $newActivityExecutions = array(); if (!is_null($nextConnector)) { //trigger the forward transition: $newActivityExecutions = $this->activityExecutionService->moveForward($activityExecution, $nextConnector, $newActivities, $processExecution); //trigger the notifications $notificationService->trigger($nextConnector, $activityExecution, $processExecution); } //transition done from here: now get the following activities: //if the connector is not a parallel one, let the user continue in his current branch and prevent the pause: $uniqueNextActivityExecution = null; if (!is_null($nextConnector)) { if ($connectorService->getType($nextConnector)->getUri() != INSTANCE_TYPEOFCONNECTORS_PARALLEL) { if (count($newActivityExecutions) == 1) { //TODO: could do a double check here: if($newActivities[0] is one of the activty found in the current tokens): if ($this->activityExecutionService->checkAcl(reset($newActivityExecutions), $currentUser, $processExecution)) { $uniqueNextActivityExecution = reset($newActivityExecutions); } } } } $setPause = true; $authorizedActivityExecutions = array(); if (!count($newActivities) || $activityDefinitionService->isFinal($activityBeforeTransition)) { //there is no following activity so the process ends here: $this->finish($processExecution); return array(); } elseif (!is_null($uniqueNextActivityExecution)) { //we are certain that the next activity would be for the user so return it: $authorizedActivityExecutions[$uniqueNextActivityExecution->getUri()] = $uniqueNextActivityExecution; $setPause = false; } else { foreach ($newActivityExecutions as $activityExecutionAfterTransition) { //check if the current user is allowed to execute the activity if ($this->activityExecutionService->checkAcl($activityExecutionAfterTransition, $currentUser, $processExecution)) { $authorizedActivityExecutions[$activityExecutionAfterTransition->getUri()] = $activityExecutionAfterTransition; $setPause = false; } else { continue; } } } $returnValue = array(); //finish actions on the authorized acitivty definitions foreach ($authorizedActivityExecutions as $uri => $activityExecutionAfterTransition) { // Last but not least ... is the next activity a machine activity ? // if yes, we perform the transition. /* * @todo to be tested */ $activityAfterTransition = $this->activityExecutionService->getExecutionOf($activityExecutionAfterTransition); if ($activityDefinitionService->isHidden($activityAfterTransition)) { //required to create an activity execution here with: $currentUser = $userService->getCurrentUser(); if (is_null($currentUser)) { throw new wfEngine_models_classes_ProcessExecutionException("No current user found!"); } $activityExecutionResource = $this->initCurrentActivityExecution($processExecution, $activityExecutionAfterTransition, $currentUser, true); //force execution of the ghost actiivty //service not executed? use curl request? if (!is_null($activityExecutionResource)) { $followingActivityExecutions = $this->performTransition($processExecution, $activityExecutionResource); if (is_array($followingActivityExecutions)) { foreach ($followingActivityExecutions as $followingActivityExec) { $returnValue[$followingActivityExec->getUri()] = $followingActivityExec; } } } else { throw new wfEngine_models_classes_ProcessExecutionException('the activity execution cannot be created for the hidden activity'); } } else { $returnValue[$uri] = $activityExecutionAfterTransition; } } if ($setPause) { $this->pause($processExecution); } else { if (!$this->isFinished($processExecution)) { $this->resume($processExecution); } } return $returnValue; }
public function testUserHasRoles() { $prefix = LOCAL_NAMESPACE . '#'; $baseRole = new core_kernel_classes_Resource($prefix . 'baseRole'); $subRole1 = new core_kernel_classes_Resource($prefix . 'subRole1'); $subRole2 = new core_kernel_classes_Resource($prefix . 'subRole2'); $subRole3 = new core_kernel_classes_Resource($prefix . 'subRole3'); $subRole11 = new core_kernel_classes_Resource($prefix . 'subRole11'); $subRole12 = new core_kernel_classes_Resource($prefix . 'subRole12'); $subRole13 = new core_kernel_classes_Resource($prefix . 'subRole13'); $allRolesOf13 = array($baseRole, $subRole1, $subRole11, $subRole12, $subRole13); $this->assertTrue($baseRole->exists()); $this->assertTrue($subRole1->exists()); $user = $this->service->addUser('user', 'password', $baseRole); $this->assertTrue($this->service->userHasRoles($user, $baseRole)); $this->assertFalse($this->service->userHasRoles($user, array($baseRole, $subRole1))); $user->delete(); $user = $this->service->addUser('user', 'password', $subRole1); $this->assertTrue($this->service->userHasRoles($user, $baseRole)); $this->assertTrue($this->service->userHasRoles($user, $subRole1)); $this->assertFalse($this->service->userHasRoles($user, $subRole2)); $this->assertTrue($this->service->userHasRoles($user, array($baseRole, $subRole1))); $this->assertFalse($this->service->userHasRoles($user, array($baseRole, $subRole1, $subRole2))); $user->delete(); $user = $this->service->addUser('user', 'password', $subRole13); $this->assertTrue($this->service->userHasRoles($user, $subRole13)); $this->assertTrue($this->service->userHasRoles($user, $baseRole)); $this->assertTrue($this->service->userHasRoles($user, $allRolesOf13)); $user->delete(); }
/** * Short description of method setTestItems * * @access public * @author Joel Bout, <*****@*****.**> * @param * Resource test * @param * array items * @return boolean */ public function setTestItems(core_kernel_classes_Resource $test, $items) { $returnValue = (bool) false; $authoringService = wfAuthoring_models_classes_ProcessService::singleton(); // get the current process: $process = $test->getUniquePropertyValue(new core_kernel_classes_Property(TEST_TESTCONTENT_PROP)); // get formal param associated to the 3 required service input parameters: $itemUriParam = new core_kernel_classes_Resource(INSTANCE_FORMALPARAM_ITEMURI); // delete all related activities: $activities = $authoringService->getAllActivities($process); foreach ($activities as $activity) { if (!$authoringService->deleteActivity($activity)) { throw new common_exception_Error('Unable to delete Activity ' . $activity->getUri()); } } // create the list of activities and interactive services and items plus their appropriate property values: $previousActivity = null; $connectorService = wfAuthoring_models_classes_ConnectorService::singleton(); foreach ($items as $item) { if (!$item instanceof core_kernel_classes_Resource) { throw new common_Exception("An item provided to " . __FUNCTION__ . " is not a resource but " . gettype($item)); } // create an activity $activity = null; $activity = $authoringService->createActivity($process, "item: {$item->getLabel()}"); // set property value visible to true $activity->editPropertyValues(new core_kernel_classes_Property(PROPERTY_ACTIVITIES_ISHIDDEN), GENERIS_FALSE); // set ACL mode to role user restricted with role=subject $extManager = common_ext_ExtensionsManager::singleton(); $activity->editPropertyValues(new core_kernel_classes_Property(PROPERTY_ACTIVITIES_ACL_MODE), INSTANCE_ACL_ROLE_RESTRICTED_USER_DELIVERY); $activity->editPropertyValues(new core_kernel_classes_Property(PROPERTY_ACTIVITIES_RESTRICTED_ROLE), INSTANCE_ROLE_DELIVERY); // get the item runner service definition: must exists! $itemRunnerServiceDefinition = new core_kernel_classes_Resource(INSTANCE_ITEMCONTAINER_SERVICE); if (!$itemRunnerServiceDefinition->exists()) { throw new common_exception_InconsistentData('required service definition item runner does not exists'); } // create a call of service and associate the service definition to it: $interactiveService = $authoringService->createInteractiveService($activity); $interactiveService->setPropertyValue(new core_kernel_classes_Property(PROPERTY_CALLOFSERVICES_SERVICEDEFINITION), $itemRunnerServiceDefinition->getUri()); $authoringService->setActualParameter($interactiveService, $itemUriParam, $item->getUri(), PROPERTY_CALLOFSERVICES_ACTUALPARAMETERIN); // constant: we know it! if (!is_null($previousActivity)) { $connectorService->createSequential($previousActivity, $activity); } else { // set the property value as initial $activity->editPropertyValues(new core_kernel_classes_Property(PROPERTY_ACTIVITIES_ISINITIAL), GENERIS_TRUE); } $previousActivity = $activity; } $returnValue = true; return (bool) $returnValue; }
/** * Removes a language from the Ontology and all triples with the related * tag. Will use command line parameters for logic. * * @access protected * @author Joel Bout, <*****@*****.**> * @return void */ protected function removeLanguageFromOntology() { $this->outVerbose("Removing RDF language description '" . $this->options['language'] . "' from ontology..."); $taoNS = 'http://www.tao.lu/Ontologies/TAO.rdf#'; $expectedDescriptionUri = $taoNS . 'Lang' . $this->options['language']; $lgResource = new core_kernel_classes_Resource($expectedDescriptionUri); if (true === $lgResource->exists()) { $lgResource->delete(); $this->outVerbose("RDF language description '" . $this->options['language'] . "' successfully removed."); } else { $this->outVerbose("RDF language description '" . $this->options['language'] . "' not found but considered removed."); } }
/** * Recompile deliveries */ private function compileAction() { $deliveryIds = array_slice($this->params, 1); $deliveryClass = new \core_kernel_classes_Class('http://www.tao.lu/Ontologies/TAODelivery.rdf#AssembledDelivery'); $this->report = new Report(Report::TYPE_INFO, 'Recompile deliveries:'); foreach ($deliveryIds as $deliveryId) { $delivery = new \core_kernel_classes_Resource($deliveryId); if (!$delivery->exists()) { $this->report->add(new Report(Report::TYPE_ERROR, "Delivery {$deliveryId} does not exists")); continue; } else { if (!$delivery->isInstanceOf($deliveryClass)) { $this->report->add(new Report(Report::TYPE_ERROR, "{$deliveryId} is not delivery resource")); continue; } } try { $newDelivery = $this->compileDelivery($delivery); } catch (\common_Exception $e) { $this->report->add(new Report(Report::TYPE_ERROR, $e->getMessage())); } $this->report->add(new Report(Report::TYPE_SUCCESS, "{$deliveryId} successfully compiled. New Id: {$newDelivery->getUri()}")); } }
/** * @param array $properties * @return array */ protected function propertiesToArray($properties) { $result = []; foreach ($properties as $uri => $item) { $resource = new \core_kernel_classes_Resource($uri); if ($resource->exists() && isset($item[0])) { $result[$resource->getLabel()] = (string) $item[0]; } } return $result; }
<?php /** * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; under version 2 * of the License (non-upgradable). * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Copyright (c) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); * * */ require_once dirname(__FILE__) . '/../includes/raw_start.php'; $dbWrapper = core_kernel_classes_DbWrapper::singleton(); $statement = $dbWrapper->query('SELECT DISTINCT "subject" FROM "statements" WHERE "predicate" in (\'' . RDFS_LABEL . '\',\'' . RDFS_COMMENT . '\')'); while ($r = $statement->fetch()) { $subject = new core_kernel_classes_Resource($r['subject']); if (!$subject->exists() && !$subject->isClass()) { echo $subject->getUri() . ' has corpses' . PHP_EOL; } }
/** * (non-PHPdoc) * * @see \oat\tao\model\media\MediaBrowser::getFileInfo */ public function getFileInfo($link) { // get the media link from the resource $resource = new \core_kernel_classes_Resource(\tao_helpers_Uri::decode($link)); if ($resource->exists()) { $fileLink = $resource->getUniquePropertyValue(new \core_kernel_classes_Property(MEDIA_LINK)); $fileLink = $fileLink instanceof \core_kernel_classes_Resource ? $fileLink->getUri() : (string) $fileLink; $file = null; $fileManagement = FileManager::getFileManagementModel(); $filePath = $fileManagement->retrieveFile($fileLink); $mime = (string) $resource->getUniquePropertyValue(new \core_kernel_classes_Property(MEDIA_MIME_TYPE)); if (file_exists($filePath)) { // add the alt text to file array $altArray = $resource->getPropertyValues(new \core_kernel_classes_Property(MEDIA_ALT_TEXT)); $alt = $resource->getLabel(); if (count($altArray) > 0) { $alt = $altArray[0]; } $file = array('name' => $resource->getLabel(), 'uri' => 'taomedia://mediamanager/' . \tao_helpers_Uri::encode($link), 'mime' => $mime, 'filePath' => basename($filePath), 'size' => filesize($filePath), 'alt' => $alt); return $file; } else { throw new \tao_models_classes_FileNotFoundException($link); } } else { throw new \tao_models_classes_FileNotFoundException($link); } }