本文整理汇总了PHP中core_kernel_classes_Class类的典型用法代码示例。如果您正苦于以下问题:PHP core_kernel_classes_Class类的具体用法?PHP core_kernel_classes_Class怎么用?PHP core_kernel_classes_Class使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了core_kernel_classes_Class类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
parent::setUp();
TaoPhpUnitTestRunner::initTest();
$class = new core_kernel_classes_Class(CLASS_OAUTH_CONSUMER);
$this->credentials = $class->createInstanceWithProperties(array(RDFS_LABEL => 'test_credentials', PROPERTY_OAUTH_KEY => 'testcase_12345', PROPERTY_OAUTH_SECRET => 'secret_12345'));
}
示例2: setUp
/**
* tests initialization
*/
public function setUp()
{
TaoPhpUnitTestRunner::initTest();
$oauthClass = new core_kernel_classes_Class(CLASS_OAUTH_CONSUMER);
$resource = $oauthClass->createInstanceWithProperties(array(PROPERTY_OAUTH_KEY => 'test_key', PROPERTY_OAUTH_SECRET => md5(rand())));
$this->oauthCustomer = new tao_models_classes_oauth_Credentials($resource);
}
示例3: migrateDeliveryToTemplate
/**
*
* @author Lionel Lecaque, lionel@taotesting.com
*/
private function migrateDeliveryToTemplate()
{
$deliveryClass = new core_kernel_classes_Class(TAO_DELIVERY_CLASS);
foreach ($deliveryClass->getInstances(true) as $delivery) {
self::switchType($delivery, CLASS_DELIVERY_TEMPLATE);
}
}
示例4: getData
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);
}
示例5: createItem
/**
* create a new QTI item
*
* @requiresRight id WRITE
*/
public function createItem()
{
if (!\tao_helpers_Request::isAjax()) {
throw new \Exception("wrong request mode");
}
$clazz = new \core_kernel_classes_Resource($this->getRequestParameter('id'));
if ($clazz->isClass()) {
$clazz = new \core_kernel_classes_Class($clazz);
} else {
foreach ($clazz->getTypes() as $type) {
// determine class from selected instance
$clazz = $type;
break;
}
}
$service = \taoItems_models_classes_ItemsService::singleton();
$label = $service->createUniqueLabel($clazz);
$item = $service->createInstance($clazz, $label);
if (!is_null($item)) {
$service->setItemModel($item, new \core_kernel_classes_Resource(ItemModel::MODEL_URI));
$response = array('label' => $item->getLabel(), 'uri' => $item->getUri());
} else {
$response = false;
}
$this->returnJson($response);
}
示例6: setUp
/**
* initialize a test method
*/
public function setUp()
{
TaoPhpUnitTestRunner::initTest();
$activityExecutionClass = new core_kernel_classes_Class(CLASS_ACTIVITY_EXECUTION);
$this->activityExecution = $activityExecutionClass->createInstance('test');
$this->service = wfEngine_models_classes_RecoveryService::singleton();
}
示例7: mapLTIRole2TaoRole
/**
* Maps a fuly qualified or abbreviated lti role
* to an existing tao role
*
* @param string $role
* @throws common_Exception
* @throws common_exception_Error
* @return core_kernel_classes_Resource the tao role or null
*/
public static function mapLTIRole2TaoRole($role)
{
$taoRole = null;
if (filter_var($role, FILTER_VALIDATE_URL)) {
// url found
$taoRole = new core_kernel_classes_Resource($role);
} else {
// if not fully qualified prepend LIS context role NS
if (strtolower(substr($role, 0, 4)) !== 'urn:') {
$role = self::LIS_CONTEXT_ROLE_NAMESPACE . $role;
}
list($prefix, $nid, $nss) = explode(':', $role, 3);
if ($nid != 'lti') {
common_Logger::w('Non LTI URN ' . $role . ' passed via LTI');
}
$urn = 'urn:' . strtolower($nid) . ':' . $nss;
// search for fitting role
$class = new core_kernel_classes_Class(CLASS_LTI_ROLES);
$cand = $class->searchInstances(array(PROPERTY_LTI_ROLES_URN => $urn));
if (count($cand) > 1) {
throw new common_exception_Error('Multiple instances share the URN ' . $urn);
}
if (count($cand) == 1) {
$taoRole = current($cand);
} else {
common_Logger::w('Unknown LTI role with urn: ' . $urn);
}
}
if (!is_null($taoRole) && $taoRole->exists()) {
return $taoRole->getUri();
} else {
return null;
}
}
示例8: __invoke
/**
* @param $params
* @return Report
*/
public function __invoke($params)
{
$deliveryMonitoringService = $this->getServiceLocator()->get(DeliveryMonitoringService::CONFIG_ID);
$deliveryClass = new \core_kernel_classes_Class('http://www.tao.lu/Ontologies/TAODelivery.rdf#AssembledDelivery');
$deliveries = $deliveryClass->getInstances(true);
$deliveryExecutionService = \taoDelivery_models_classes_execution_ServiceProxy::singleton();
$this->report = new Report(Report::TYPE_INFO, 'Updating of delivery monitoring cache...');
foreach ($deliveries as $delivery) {
if ($delivery->exists()) {
$deliveryExecutions = $deliveryExecutionService->getExecutionsByDelivery($delivery);
foreach ($deliveryExecutions as $deliveryExecution) {
$data = $deliveryMonitoringService->getData($deliveryExecution, true);
if ($deliveryMonitoringService->save($data)) {
$this->report->add(new Report(Report::TYPE_SUCCESS, "Delivery execution {$deliveryExecution->getUri()} successfully updated."));
} else {
$errors = $data->getErrors();
$errorsStr = " " . PHP_EOL;
array_walk($errors, function ($val, $key) use(&$errorsStr) {
$errorsStr .= " {$key} - {$val}" . PHP_EOL;
});
$this->report->add(new Report(Report::TYPE_ERROR, "Delivery execution {$deliveryExecution->getUri()} was not updated. {$errorsStr}"));
}
}
}
}
return $this->report;
}
示例9: setUp
/**
* tests initialization
*/
public function setUp()
{
TaoTestRunner::initTest();
$resultsService = taoResults_models_classes_ResultsService::singleton();
$this->resultsService = $resultsService;
$this->statsService = taoResults_models_classes_StatisticsService::singleton();
$this->reportService = taoResults_models_classes_ReportService::singleton();
//create an activity execution
$activityExecutionClass = new core_kernel_classes_Class(CLASS_ACTIVITY_EXECUTION);
//create an activity definition
$activityDefinitionClass = new core_kernel_classes_Class(CLASS_ACTIVITIES);
$this->activityExecution = $activityExecutionClass->createInstance("MyActivityExecution");
//links the activity execution to the activity definition
$this->activityDefinition = $activityDefinitionClass->createInstance("MyActivityDefinition");
$this->activityExecution->setPropertyValue(new core_kernel_classes_Property(PROPERTY_ACTIVITY_EXECUTION_ACTIVITY), $this->activityDefinition->getUri());
//links the call of service to the activity execution
$interactiveServiceClass = new core_kernel_classes_Class(CLASS_CALLOFSERVICES);
$this->interactiveService = $interactiveServiceClass->createInstance("MyInteractiveServiceCall");
$this->activityDefinition->setPropertyValue(new core_kernel_classes_Property(PROPERTY_ACTIVITIES_INTERACTIVESERVICES), $this->interactiveService->getUri());
$this->interactiveService->setPropertyValue(new core_kernel_classes_Property(PROPERTY_CALLOFSERVICES_SERVICEDEFINITION), "#interactiveServiceDefinition");
$deliveryResult = new core_kernel_classes_Resource("#MyDeliveryResult");
$variableIDentifier = "GRADE";
$value = 0.4;
//create a small delivery
$this->subClass = $this->resultsService->createSubClass(new core_kernel_classes_Class(TAO_DELIVERY_RESULT), "UnitTestingGenClass");
$this->delivery = $this->subClass->createInstance("UnitTestingGenDelivery");
$this->delivery->setPropertyValue(new core_kernel_classes_Property(PROPERTY_RESULT_OF_DELIVERY), "#unitTestResultOfDelivery");
$this->delivery->setPropertyValue(new core_kernel_classes_Property(PROPERTY_RESULT_OF_SUBJECT), "#unitTestResultOfSubject");
$this->delivery->setPropertyValue(new core_kernel_classes_Property(PROPERTY_RESULT_OF_PROCESS), "#unitTestResultOfProcess");
//stores a grade in this delivery
$this->grade = $this->resultsService->storeGrade($this->delivery, $this->activityExecution, $variableIDentifier, $value);
$this->response = $this->resultsService->storeResponse($this->delivery, $this->activityExecution, $variableIDentifier, $value);
}
示例10: create
/**
* Creates a new delivery
*
* @param core_kernel_classes_Class $deliveryClass
* @param core_kernel_classes_Resource $test
* @param array $properties Array of properties of delivery
* @return common_report_Report
*/
public static function create(\core_kernel_classes_Class $deliveryClass, \core_kernel_classes_Resource $test, $properties = array())
{
\common_Logger::i('Creating delivery with ' . $test->getLabel() . ' under ' . $deliveryClass->getLabel());
$storage = new TrackedStorage();
$testCompilerClass = \taoTests_models_classes_TestsService::singleton()->getCompilerClass($test);
$compiler = new $testCompilerClass($test, $storage);
$report = $compiler->compile();
if ($report->getType() == \common_report_Report::TYPE_SUCCESS) {
//$tz = new \DateTimeZone(\common_session_SessionManager::getSession()->getTimeZone());
$tz = new \DateTimeZone('UTC');
if (!empty($properties[TAO_DELIVERY_START_PROP])) {
$dt = new \DateTime($properties[TAO_DELIVERY_START_PROP], $tz);
$properties[TAO_DELIVERY_START_PROP] = (string) $dt->getTimestamp();
}
if (!empty($properties[TAO_DELIVERY_END_PROP])) {
$dt = new \DateTime($properties[TAO_DELIVERY_END_PROP], $tz);
$properties[TAO_DELIVERY_END_PROP] = (string) $dt->getTimestamp();
}
$serviceCall = $report->getData();
$properties[PROPERTY_COMPILEDDELIVERY_DIRECTORY] = $storage->getSpawnedDirectoryIds();
$compilationInstance = DeliveryAssemblyService::singleton()->createAssemblyFromServiceCall($deliveryClass, $serviceCall, $properties);
$report->setData($compilationInstance);
}
return $report;
}
示例11: migrateCompiledDeliveryToAssembly
/**
*
* @author Lionel Lecaque, lionel@taotesting.com
*/
private function migrateCompiledDeliveryToAssembly()
{
$compiledDeliveryClass = new core_kernel_classes_Class(self::OLD_COMPILED_DELIVERY);
$props = array(self::OLD_PROPERTY_COMPILEDDELIVERY_DELIVERY => PROPERTY_COMPILEDDELIVERY_DELIVERY, self::OLD_PROPERTY_COMPILEDDELIVERY_TIME => PROPERTY_COMPILEDDELIVERY_TIME, self::OLD_PROPERTY_COMPILEDDELIVERY_RUNTIME => PROPERTY_COMPILEDDELIVERY_RUNTIME, self::OLD_PROPERTY_COMPILEDDELIVERY_DIRECTORY => PROPERTY_COMPILEDDELIVERY_DIRECTORY);
foreach ($compiledDeliveryClass->getInstances(true) as $compiledDelivery) {
taoUpdate_scripts_update_UpdateDeliveryModel::switchType($compiledDelivery, TAO_DELIVERY_CLASS);
$values = $compiledDelivery->getPropertiesValues(array_keys($props));
foreach ($values as $prop => $val) {
//compiled time was not always set in 2.5 so I set a 0 will appear as 1970 in UI
if ($prop == self::OLD_PROPERTY_COMPILEDDELIVERY_TIME && empty($val)) {
if (isset($props[$prop])) {
$compiledDelivery->setPropertyValue(new core_kernel_classes_Property($props[$prop]), '0');
}
}
if (!empty($val) && $prop != self::OLD_PROPERTY_COMPILEDDELIVERY_DIRECTORY) {
if (isset($props[$prop])) {
$compiledDelivery->removePropertyValues(new core_kernel_classes_Property($prop));
$compiledDelivery->setPropertiesValues(array($props[$prop] => $val));
} else {
$this->info('could not found property ' . $prop);
}
//copy property value from templace to assembly
if ($prop == self::OLD_PROPERTY_COMPILEDDELIVERY_DELIVERY) {
if (isset($val[0]) && $val[0] instanceof core_kernel_classes_Resource) {
$this->copyPropertyValuesFromTemplateToAssembly($val[0], $compiledDelivery);
}
}
}
}
}
}
示例12: importDelivery
public static function importDelivery(core_kernel_classes_Class $deliveryClass, $archiveFile)
{
$folder = tao_helpers_File::createTempDir();
$zip = new ZipArchive();
if ($zip->open($archiveFile) === true) {
if ($zip->extractTo($folder)) {
$returnValue = $folder;
}
$zip->close();
}
$manifestPath = $folder . self::MANIFEST_FILE;
if (!file_exists($manifestPath)) {
return common_report_Report::createFailure(__('Manifest not found in assembly'));
}
$manifest = json_decode(file_get_contents($manifestPath), true);
$label = $manifest['label'];
$serviceCall = tao_models_classes_service_ServiceCall::fromString(base64_decode($manifest['runtime']));
$dirs = $manifest['dir'];
$resultServer = taoResultServer_models_classes_ResultServerAuthoringService::singleton()->getDefaultResultServer();
try {
foreach ($dirs as $id => $relPath) {
tao_models_classes_service_FileStorage::singleton()->import($id, $folder . $relPath);
}
$delivery = $deliveryClass->createInstanceWithProperties(array(RDFS_LABEL => $label, PROPERTY_COMPILEDDELIVERY_DIRECTORY => array_keys($dirs), PROPERTY_COMPILEDDELIVERY_TIME => time(), PROPERTY_COMPILEDDELIVERY_RUNTIME => $serviceCall->toOntology(), TAO_DELIVERY_RESULTSERVER_PROP => $resultServer));
$report = common_report_Report::createSuccess(__('Delivery "%s" successfully imported', $label), $delivery);
} catch (Exception $e) {
if (isset($delivery) && $delivery instanceof core_kernel_classes_Resource) {
$delivery->delete();
}
$report = common_report_Report::createFailure(__('Unkown error during impoort'));
}
return $report;
}
示例13: authenticate
/**
* (non-PHPdoc)
* @see common_user_auth_Adapter::authenticate()
*/
public function authenticate()
{
$userClass = new core_kernel_classes_Class(CLASS_GENERIS_USER);
$filters = array(PROPERTY_USER_LOGIN => $this->username);
$options = array('like' => false, 'recursive' => true);
$users = $userClass->searchInstances($filters, $options);
if (count($users) > 1) {
// Multiple users matching
throw new common_exception_InconsistentData("Multiple Users found with the same login '" . $this->username . "'.");
}
if (empty($users)) {
// fake code execution to prevent timing attacks
$label = new core_kernel_classes_Property(RDFS_LABEL);
$hash = $label->getUniquePropertyValue($label);
if (!core_kernel_users_Service::getPasswordHash()->verify($this->password, $hash)) {
throw new core_kernel_users_InvalidLoginException();
}
// should never happen, added for integrity
throw new core_kernel_users_InvalidLoginException();
}
$userResource = current($users);
$hash = $userResource->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_USER_PASSWORD));
if (!core_kernel_users_Service::getPasswordHash()->verify($this->password, $hash)) {
throw new core_kernel_users_InvalidLoginException();
}
return new core_kernel_users_GenerisUser($userResource);
}
示例14: import
/**
* 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;
}
}
示例15: initElements
public function initElements()
{
$class = $this->data['class'];
if (!$class instanceof \core_kernel_classes_Class) {
throw new \common_Exception('missing class in simple delivery creation form');
}
$classUriElt = \tao_helpers_form_FormFactory::getElement('classUri', 'Hidden');
$classUriElt->setValue($class->getUri());
$this->form->addElement($classUriElt);
//create the element to select the import format
$formatElt = \tao_helpers_form_FormFactory::getElement('test', 'Combobox');
$formatElt->setDescription(__('Select the test you want to publish to the test-takers'));
$testClass = new \core_kernel_classes_Class(TAO_TEST_CLASS);
$options = array();
$testService = \taoTests_models_classes_TestsService::singleton();
foreach ($testClass->getInstances(true) as $test) {
try {
$testItems = $testService->getTestItems($test);
//Filter tests which has no items
if (!empty($testItems)) {
$options[$test->getUri()] = $test->getLabel();
}
} catch (\Exception $e) {
\common_Logger::w('Unable to load items for test ' . $test->getUri());
}
}
if (empty($options)) {
throw new NoTestsException();
}
$formatElt->setOptions($options);
$formatElt->addValidator(\tao_helpers_form_FormFactory::getValidator('NotEmpty'));
$this->form->addElement($formatElt);
}