public function setReverseValues() { if (!tao_helpers_Request::isAjax()) { throw new common_exception_IsAjaxAction(__FUNCTION__); } $values = tao_helpers_form_GenerisTreeForm::getSelectedInstancesFromPost(); $resource = new core_kernel_classes_Resource($this->getRequestParameter('resourceUri')); $property = new core_kernel_classes_Property($this->getRequestParameter('propertyUri')); $currentValues = array(); foreach ($property->getDomain() as $domain) { $instances = $domain->searchInstances(array($property->getUri() => $resource), array('recursive' => true, 'like' => false)); $currentValues = array_merge($currentValues, array_keys($instances)); } $toAdd = array_diff($values, $currentValues); $toRemove = array_diff($currentValues, $values); $success = true; foreach ($toAdd as $uri) { $subject = new core_kernel_classes_Resource($uri); $success = $success && $subject->setPropertyValue($property, $resource); } foreach ($toRemove as $uri) { $subject = new core_kernel_classes_Resource($uri); $success = $success && $subject->removePropertyValue($property, $resource); } echo json_encode(array('saved' => $success)); }
/** * 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); }
/** * Displays the three action box for the test center */ public function testCenter() { $testCenters = TestCenterHelper::getTestCenters(); $testCenter = $this->getCurrentTestCenter(); $data = array('testCenter' => $testCenter->getUri(), 'title' => sprintf($this->convert('Test site %s'), $testCenter->getLabel()), 'list' => TestCenterHelper::getTestCenterActions($testCenter)); if (\tao_helpers_Request::isAjax()) { $this->returnJson($data); } else { $this->composeView('testcenters-testcenter', $data, array(BreadcrumbsHelper::testCenters(), BreadcrumbsHelper::testCenter($testCenter, $testCenters))); } }
/** * view and item * @return void */ public function viewItem() { if (!tao_helpers_Request::isAjax()) { throw new Exception("wrong request mode"); } $itemClass = $this->getCurrentClass(); $item = $this->getCurrentInstance(); $lang = null; if ($this->hasRequestParameter('target_lang')) { $lang = $this->getRequestParameter('target_lang'); } $hiddenProperties = array(taoItems_models_classes_ItemsService::PROPERTY_ITEM_CONTENT); $properties = array(); foreach ($this->service->getClazzProperties($itemClass) as $property) { if (in_array($property->getUri(), $hiddenProperties)) { continue; } $range = $property->getRange(); if (is_null($lang)) { $propValues = $item->getPropertyValues($property); } else { $propContainer = $item->getPropertyValuesByLg($property, $lang); $propValues = $propContainer->getIterator(); } foreach ($propValues as $propValue) { $value = ''; if ($range->getUri() == RDFS_LITERAL) { $value = (string) $propValue; } else { $resource = new core_kernel_classes_Resource($propValue); $value = $resource->getLabel(); } $properties[] = array('name' => $property->getLabel(), 'value' => $value); } } $previewData = $this->initPreview($item, $itemClass); if (count($previewData) == 0) { $this->setData('preview', false); $this->setData('previewMsg', __('Not yet available')); } else { $this->setData('preview', true); $this->setData('instanceUri', tao_helpers_Uri::encode($item->getUri(), false)); foreach ($previewData as $key => $value) { $this->setData($key, $value); } } $this->setData('uri', tao_helpers_Uri::encode($item->getUri())); $this->setData('classUri', tao_helpers_Uri::encode($itemClass->getUri())); $this->setData('label', $item->getLabel()); $this->setData('itemProperties', $properties); $this->setView('view.tpl'); }
/** * Delete a result or a result class * @return void */ public function delete() { if (!tao_helpers_Request::isAjax()) { throw new Exception("wrong request mode"); } $deleted = false; if ($this->getRequestParameter('uri')) { $deleted = $this->service->deleteResult($this->getCurrentInstance()); } else { $deleted = $this->service->deleteResultClass($this->getCurrentClass()); } echo json_encode(array('deleted' => $deleted)); }
public function deliveriesByProctor() { $deliveryData = array(); if (\common_ext_ExtensionsManager::singleton()->isInstalled('ltiDeliveryProvider')) { /** @var DeliveryService $service */ $service = $this->getServiceManager()->get(DeliveryService::CONFIG_ID); $deliveries = $service->getAccessibleDeliveries(); if (!empty($deliveries)) { try { $dataStore = new \tao_models_classes_oauth_DataStore(); $test_consumer = $dataStore->lookup_consumer('proctoring_key'); } catch (\tao_models_classes_oauth_Exception $e) { $secret = uniqid('proctoring_'); \taoLti_models_classes_ConsumerService::singleton()->getRootClass()->createInstanceWithProperties(array(RDFS_LABEL => 'proctoring', PROPERTY_OAUTH_KEY => 'proctoring_key', PROPERTY_OAUTH_SECRET => $secret)); $test_consumer = new \OAuthConsumer('proctoring_key', $secret); } $session = \common_session_SessionManager::getSession(); $ltiData = array('lti_message_type' => 'basic-lti-launch-request', 'lti_version' => 'LTI-1p0', 'resource_link_id' => rand(0, 9999999), 'resource_link_title' => 'Launch Title', 'resource_link_label' => 'Launch label', 'context_title' => 'Launch Title', 'context_label' => 'Launch label', 'user_id' => $session->getUserUri(), 'roles' => 'Learner', 'lis_person_name_full' => $session->getUserLabel(), 'tool_consumer_info_product_family_code' => PRODUCT_NAME, 'tool_consumer_info_version' => TAO_VERSION, 'custom_skip_thankyou' => 'true', 'launch_presentation_return_url' => _url('logout', 'Main', 'tao')); $hmac_method = new \OAuthSignatureMethod_HMAC_SHA1(); $test_token = new \OAuthToken($test_consumer, ''); foreach ($deliveries as $delivery) { $launchUrl = LTIDeliveryTool::singleton()->getLaunchUrl(array('delivery' => $delivery->getUri())); $acc_req = \OAuthRequest::from_consumer_and_token($test_consumer, $test_token, 'GET', $launchUrl, $ltiData); $acc_req->sign_request($hmac_method, $test_consumer, $test_token); $deliveryData[] = array('id' => $delivery->getUri(), 'label' => $delivery->getLabel(), 'url' => $acc_req->to_url(), 'text' => __('Test')); } } } $this->setData('title', __('Available Deliveries')); if (\tao_helpers_Request::isAjax()) { $this->returnJson(array('list' => $deliveryData)); } else { try { $testCenter = $this->getCurrentTestCenter(); $this->composeView('diagnostic-deliveries', array('list' => $deliveryData), array(BreadcrumbsHelper::testCenters(), BreadcrumbsHelper::testCenter($testCenter, TestCenterHelper::getTestCenters()), BreadcrumbsHelper::diagnostics($testCenter, array(BreadcrumbsHelper::deliveries($testCenter))), BreadcrumbsHelper::deliveriesByProctor($testCenter))); } catch (\common_Exception $e) { $this->composeView('diagnostic-deliveries', array('list' => $deliveryData), array(BreadcrumbsHelper::testCenters())); } } }
/** * save the related items from the checkbox tree or from the sequence box * @return void */ public function saveItems() { if (!tao_helpers_Request::isAjax()) { throw new Exception("wrong request mode"); } $saved = false; $candidates = tao_helpers_form_GenerisTreeForm::getSelectedInstancesFromPost(); foreach ($this->getRequestParameters() as $key => $value) { if (preg_match("/^instance_/", $key)) { $candidates[] = tao_helpers_Uri::decode($value); } } $items = array(); foreach ($candidates as $uri) { $item = new core_kernel_classes_Resource($uri); $itemModel = $item->getOnePropertyValue(new core_kernel_classes_Property(TAO_ITEM_MODEL_PROPERTY)); $supported = false; if (!is_null($itemModel)) { foreach ($itemModel->getPropertyValues(new core_kernel_classes_Property(TAO_ITEM_MODELTARGET_PROPERTY)) as $targeturi) { if ($targeturi == TAO_ITEM_ONLINE_TARGET) { $supported = true; break; } } } if ($supported) { array_push($items, $item); } else { throw new common_Exception($item->getLabel() . ' cannot be added to a test'); } } if ($this->service->setTestItems($this->getCurrentInstance(), $items)) { $saved = true; } $this->returnJson(array('saved' => $saved)); }
/** * Get the data to populate the tree of deliveries * @return void */ public function getDeliveries() { if (!tao_helpers_Request::isAjax()) { throw new Exception("wrong request mode"); } $options = array('chunk' => false); if ($this->hasRequestParameter('classUri')) { $clazz = $this->getCurrentClass(); $options['chunk'] = true; } else { $clazz = new core_kernel_classes_Class(TAO_DELIVERY_CLASS); } if ($this->hasRequestParameter('selected')) { $selected = $this->getRequestParameter('selected'); if (!is_array($selected)) { $selected = array($selected); } $options['browse'] = $selected; } echo json_encode($this->service->toTree($clazz, $options)); }
/** * Remove the list element in parameter * @return void */ public function removeListElement() { if (!tao_helpers_Request::isAjax()) { throw new Exception("wrong request mode"); } $deleted = false; if ($this->hasRequestParameter('uri')) { $deleted = $this->service->removeListElement(new core_kernel_classes_Resource(tao_helpers_Uri::decode($this->getRequestParameter('uri')))); } echo json_encode(array('deleted' => $deleted)); }
/** * Print an error report into the response. * After you have called this method, you must prevent other actions to be processed and must close the response. * @param string $message * @param int $code */ protected function notifyError($message, $code = 0) { $ctx = array('success' => false, 'state' => $this->getTestSession()->getState(), 'message' => $message, 'code' => $code); $this->setData('assessmentTestContext', $ctx); if (\tao_helpers_Request::isAjax()) { $this->returnJson($ctx); } }
/** * action used to check if a login can be used * @return void */ public function checkLogin() { if (!tao_helpers_Request::isAjax()) { throw new Exception("wrong request mode"); } $data = array('available' => false); if ($this->hasRequestParameter('login')) { $data['available'] = $this->userService->loginAvailable($this->getRequestParameter('login')); } $this->returnJson($data); }
/** * Generic class deletion action * * @throws Exception * @requiresRight id WRITE */ public function deleteClass() { if (!tao_helpers_Request::isAjax() || !$this->hasRequestParameter('id')) { throw new Exception("wrong request mode"); } $clazz = new core_kernel_classes_Class($this->getRequestParameter('id')); if ($this->getRootClass()->equals($clazz)) { $success = false; $msg = __('You cannot delete the root node'); } else { $label = $clazz->getLabel(); $success = $this->getClassService()->deleteClass($clazz); $msg = $success ? __('%s has been deleted', $label) : __('Unable to delete %s', $label); } return $this->returnJson(array('deleted' => $success, 'msg' => $msg)); }
public function saveTheme() { if (!\tao_helpers_Request::isAjax()) { throw new \common_exception_IsAjaxAction(__FUNCTION__); } $data = array(); if ($this->hasRequestParameter('logo')) { $data = $this->getRequestParameter('logo'); if (isset($data['logo'])) { $logoFile = $this->getPlatformService()->storeFile($data['logo']['uploaded_file'], $data['logo']['name']); $data['logo'] = $logoFile; } } $dataArray = array(); if ($this->hasRequestParameter('css')) { $css = $this->getRequestParameter('css'); $formatedArray = array(); foreach ($css as $key => $array) { $properties = explode('-', $key, 2); if (isset($properties[1])) { $value = $array['value']; $pos = strpos($value, ' !important'); if ($pos !== false) { $value = substr($value, 0, $pos); } $dataArray[$key] = $value; $property = $properties[1]; $formatedArray[$array['selector']][$property] = $array['value']; } } $this->getPlatformService()->generateCss($formatedArray, 'platformtheme.css'); $data['css-file'] = 'platformtheme.css'; } $data = array_merge($data, $dataArray); $previousConf = $this->getPlatformService()->retrieveThemingConfig(); $previousArray = $previousConf->getArrayCopy(); $missingConf = array_diff_key($previousArray, $data); $data = array_merge($data, $missingConf); $newConfig = new PlatformThemingConfig($data); $newConfig['login_message'] = $this->getRequestParameter('login_msg'); $newConfig['login_field'] = $this->getRequestParameter('login_field'); $newConfig['password_field'] = $this->getRequestParameter('password_field'); $newConfig['copyright_notice'] = $this->getRequestParameter('copyright_notice'); $newConfig['stable'] = $this->getRequestParameter('stable') == 'true' ? true : false; $this->getPlatformService()->syncThemingConfig($newConfig); $return['success'] = true; $return['message'] = __('Your theme has been saved'); $this->returnJson($return); }
public function getUsers() { if (!tao_helpers_Request::isAjax()) { throw new Exception("wrong request mode"); } else { $userService = tao_models_classes_UserService::singleton(); echo json_encode($userService->toTree(new core_kernel_classes_Class(CLASS_TAO_USER), array())); } }
/** * Function to return an user readable error * Does not work with ajax Requests yet * * @param string $description error to show * @param boolean $returnLink whenever or not to add a return link */ protected function returnError($description, $returnLink = true) { if (tao_helpers_Request::isAjax()) { common_Logger::w('Called ' . __FUNCTION__ . ' in an unsupported AJAX context'); throw new common_Exception($description); } else { $this->setData('message', $description); $this->setData('returnLink', $returnLink); $this->setView('error/user_error.tpl', 'tao'); } }
/** * Render the add index sub form. * @throws Exception * @return void */ public function addPropertyIndex() { if (!tao_helpers_Request::isAjax()) { throw new Exception("wrong request mode"); } if (!$this->hasRequestParameter('uri')) { throw new Exception("wrong request Parameter"); } $uri = $this->getRequestParameter('uri'); $clazz = $this->getCurrentClass(); $index = 1; if ($this->hasRequestParameter('index')) { $index = $this->getRequestParameter('index'); } $propertyIndex = 1; if ($this->hasRequestParameter('propertyIndex')) { $propertyIndex = $this->getRequestParameter('propertyIndex'); } //create and attach the new index property to the property $property = new core_kernel_classes_Property(tao_helpers_Uri::decode($uri)); $class = new \core_kernel_classes_Class("http://www.tao.lu/Ontologies/TAO.rdf#Index"); //get property range to select a default tokenizer /** @var core_kernel_classes_Class $range */ $range = $property->getRange(); //range is empty select item content $tokenizer = null; if (is_null($range)) { $tokenizer = new core_kernel_classes_Resource('http://www.tao.lu/Ontologies/TAO.rdf#RawValueTokenizer'); } else { $tokenizer = $range->getUri() === RDFS_LITERAL ? new core_kernel_classes_Resource('http://www.tao.lu/Ontologies/TAO.rdf#RawValueTokenizer') : new core_kernel_classes_Resource('http://www.tao.lu/Ontologies/TAO.rdf#LabelTokenizer'); } $indexClass = new core_kernel_classes_Class('http://www.tao.lu/Ontologies/TAO.rdf#Index'); $i = 0; $indexIdentifierBackup = preg_replace('/[^a-z_0-9]/', '_', strtolower($property->getLabel())); $indexIdentifierBackup = ltrim(trim($indexIdentifierBackup, '_'), '0..9'); $indexIdentifier = $indexIdentifierBackup; do { if ($i !== 0) { $indexIdentifier = $indexIdentifierBackup . '_' . $i; } $resources = $indexClass->searchInstances(array(INDEX_PROPERTY_IDENTIFIER => $indexIdentifier), array('like' => false)); $count = count($resources); $i++; } while ($count !== 0); $indexProperty = $class->createInstanceWithProperties(array(RDFS_LABEL => preg_replace('/_/', ' ', ucfirst($indexIdentifier)), INDEX_PROPERTY_IDENTIFIER => $indexIdentifier, INDEX_PROPERTY_TOKENIZER => $tokenizer, INDEX_PROPERTY_FUZZY_MATCHING => GENERIS_TRUE, INDEX_PROPERTY_DEFAULT_SEARCH => GENERIS_FALSE)); $property->setPropertyValue(new core_kernel_classes_Property(INDEX_PROPERTY), $indexProperty); //generate form $indexFormContainer = new tao_actions_form_IndexProperty($clazz, $indexProperty, array('index' => $index, 'propertyindex' => $propertyIndex)); $myForm = $indexFormContainer->getForm(); $form = trim(preg_replace('/\\s+/', ' ', $myForm->renderElements())); echo json_encode(array('form' => $form)); }
private function dispatchError(Exception $e, $httpStatus, $message = '', $trace = '') { // Set relevant HTTP header. header(HTTPToolkit::statusCodeHeader($httpStatus)); if (tao_helpers_Request::isAjax()) { new common_AjaxResponse(array("success" => false, "type" => 'Exception', "data" => array('ExceptionType' => get_class($e)), "message" => $message)); } else { require_once Template::getTemplate("error/error{$httpStatus}.tpl", 'tao'); } }
/** * delete a test or a test class * called via ajax * @return void * @throws Exception * @requiresRight id WRITE */ public function delete() { if (!tao_helpers_Request::isAjax()) { throw new Exception("wrong request mode"); } $deleted = false; if ($this->getRequestParameter('uri')) { $instance = $this->getCurrentInstance(); $lockManager = LockManager::getImplementation(); $userId = common_session_SessionManager::getSession()->getUser()->getIdentifier(); if ($lockManager->isLocked($instance)) { $lockManager->releaseLock($instance, $userId); } $deleted = $this->service->deleteTest($instance); } else { return $this->forward('deleteClass', null, null, array('id' => $this->getRequestParameter('id'))); } echo json_encode(array('deleted' => $deleted)); }
/** * Render the add property sub form. * @throws Exception * @return void */ public function removeClassProperty() { $success = false; if (!tao_helpers_Request::isAjax()) { throw new Exception("wrong request mode"); } $class = new core_kernel_classes_Class($this->getRequestParameter('classUri')); $property = new core_kernel_classes_Property($this->getRequestParameter('uri')); //delete property mode foreach ($class->getProperties() as $classProperty) { if ($classProperty->equals($property)) { //delete property and the existing values of this property if ($property->delete(true)) { $success = true; break; } } } if ($success) { return $this->returnJson(array('success' => true)); } else { $this->returnError(__('Unable to remove the property.')); } }
/** * Duplicate a process instance * * @access public * @author CRP Henri Tudor - TAO Team - {@link http://www.tao.lu} * @return void */ public function cloneProcess() { if (!tao_helpers_Request::isAjax()) { throw new Exception("wrong request mode"); } $clone = $this->service->cloneProcess($this->getCurrentInstance(), $this->getCurrentClass()); if (!is_null($clone)) { echo json_encode(array('label' => $clone->getLabel(), 'uri' => tao_helpers_Uri::encode($clone->getUri()))); } }
/** * simplified Version of TaoModule function * * @return void */ public function sasGetOntologyData() { if (!tao_helpers_Request::isAjax()) { throw new common_exception_IsAjaxAction(__FUNCTION__); } $showInstances = $this->hasRequestParameter('hideInstances') ? !(bool) $this->getRequestParameter('hideInstances') : true; $hideNode = $this->hasRequestParameter('classUri'); $clazz = $this->hasRequestParameter('classUri') ? $this->getCurrentClass() : $this->getRootClass(); if ($this->hasRequestParameter('offset')) { $options['offset'] = $this->getRequestParameter('offset'); } $limit = $this->hasRequestParameter('limit') ? $this->getRequestParameter('limit') : 0; $offset = $this->hasRequestParameter('offset') ? $this->getRequestParameter('offset') : 0; $factory = new GenerisTreeFactory($showInstances, array($clazz->getUri()), $limit, $offset); $tree = $factory->buildTree($clazz); $returnValue = $hideNode ? $tree['children'] : $tree; echo json_encode($returnValue); }
public function addActionAccess() { if (!tao_helpers_Request::isAjax()) { throw new Exception("wrong request mode"); } else { $role = $this->getRequestParameter('role'); $uri = $this->getRequestParameter('uri'); $actionService = funcAcl_models_classes_ActionAccessService::singleton(); $actionService->add($role, $uri); echo json_encode(array('uri' => $uri)); } }
/** * Duplicate a resultServer instance * @return void * @throws Exception */ public function cloneResultServer() { if (!tao_helpers_Request::isAjax()) { throw new Exception("wrong request mode"); } $resultServer = $this->getCurrentResultServer(); $clazz = $this->getCurrentClass(); $clone = $this->service->createInstance($clazz); if (!is_null($clone)) { foreach ($clazz->getProperties() as $property) { foreach ($resultServer->getPropertyValues($property) as $propertyValue) { $clone->setPropertyValue($property, $propertyValue); } } $clone->setLabel($resultServer->getLabel() . "'"); echo json_encode(array('label' => $clone->getLabel(), 'uri' => tao_helpers_Uri::encode($clone->getUri()))); } }
public function saveExcluded() { if (!tao_helpers_Request::isAjax()) { throw new common_exception_IsAjaxAction(__FUNCTION__); } if (!$this->hasRequestParameter('excluded')) { throw new common_exception_MissingParameter('excluded'); } $jsonArray = json_decode($_POST['excluded']); if (!is_array($jsonArray)) { throw new common_Exception('parameter "excluded" should be a json encoded array'); } $assembly = $this->getCurrentInstance(); $success = $assembly->editPropertyValues(new core_kernel_classes_Property(TAO_DELIVERY_EXCLUDEDSUBJECTS_PROP), $jsonArray); echo json_encode(array('saved' => $success)); }
/** * Check if the system is ready */ public function isReady() { if (tao_helpers_Request::isAjax()) { // the default ajax response is successful style rastafarai $ajaxResponse = new common_AjaxResponse(); } else { throw new common_exception_IsAjaxAction(__CLASS__ . '::' . __METHOD__ . '()'); } }
/** * delete a test or a test class * called via ajax * @return void * @throws Exception * @requiresRight id WRITE */ public function delete() { if (!tao_helpers_Request::isAjax()) { throw new Exception("wrong request mode"); } $deleted = false; if ($this->getRequestParameter('uri')) { $deleted = $this->service->deleteTest($this->getCurrentInstance()); } else { return $this->forward('deleteClass', null, null, array('id' => $this->getRequestParameter('id'))); } echo json_encode(array('deleted' => $deleted)); }