/**
  * 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;
     }
 }
Beispiel #2
0
 /**
  * (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);
 }
 /**
  * Short description of method getPreviousSteps
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource step
  * @return array
  */
 public function getPreviousSteps(core_kernel_classes_Resource $step)
 {
     $returnValue = array();
     $stepClass = new core_kernel_classes_Class(CLASS_STEP);
     $returnValue = $stepClass->searchInstances(array(PROPERTY_STEP_NEXT => $step), array('like' => false, 'recursive' => true));
     return (array) $returnValue;
 }
 /**
  * Get items of a specific model
  * @param string|core_kernel_classes_Resource $itemModel - the item model URI
  * @return core_kernel_classes_Resource[] the found items
  */
 public function getAllByModel($itemModel)
 {
     if (!empty($itemModel)) {
         $uri = $itemModel instanceof core_kernel_classes_Resource ? $itemModel->getUri() : $itemModel;
         return $this->itemClass->searchInstances(array($this->itemModelProperty->getUri() => $uri), array('recursive' => true));
     }
     return array();
 }
 public function findParallelFromActivityBackward(core_kernel_classes_Resource $activity)
 {
     $returnValue = null;
     //put the activity being searched in an array to prevent searching from it again in case of back connection
     $this->checkedActivities[] = $activity->getUri();
     $connectorClass = new core_kernel_classes_Class(CLASS_CONNECTORS);
     $cardinalityClass = new core_kernel_classes_Class(CLASS_ACTIVITYCARDINALITY);
     $activityCardinalities = $cardinalityClass->searchInstances(array(PROPERTY_STEP_NEXT => $activity->getUri()), array('like' => false));
     //note: count()>1 only
     $nextActivities = array_merge(array($activity->getUri()), array_keys($activityCardinalities));
     $previousConnectors = $connectorClass->searchInstances(array(PROPERTY_STEP_NEXT => $nextActivities), array('like' => false));
     //note: count()>1 only
     foreach ($previousConnectors as $connector) {
         if (in_array($connector->getUri(), array_keys($this->checkedConnectors))) {
             continue;
         } else {
             $this->checkedConnectors[$connector->getUri()] = $connector;
         }
         //get the type of the connector:
         $connectorType = $connector->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_CONNECTORS_TYPE));
         if ($connectorType instanceof core_kernel_classes_Resource) {
             switch ($connectorType->getUri()) {
                 case INSTANCE_TYPEOFCONNECTORS_PARALLEL:
                     //parallel connector found:
                     if ($this->jump == 0) {
                         return $returnValue = $connector;
                     } else {
                         $this->jump--;
                     }
                     break;
                 case INSTANCE_TYPEOFCONNECTORS_JOIN:
                     //increment the class attribute $this->jump
                     $this->jump++;
             }
         }
         //if the wanted parallel connector has not be found (i.e. no value returned so far):
         //get the previousActivityCollection and recursively execute the same function ON ONLY ONE of the previous branches (there would be several branches only in the case of a join, otherwise it should be one anyway:
         $previousActivity = $connector->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_CONNECTORS_ACTIVITYREFERENCE));
         //Note: the use of the property activity reference allow to jump to the "main" (in case of a join connector and successive conditionnal connectors) directly
         //if the previousActivity happens to have already been checked, jump it
         if (in_array($previousActivity->getUri(), $this->checkedActivities)) {
             continue;
         } else {
             $parallelConnector = $this->findParallelFromActivityBackward($previousActivity);
             if ($parallelConnector instanceof core_kernel_classes_Resource) {
                 //found it:
                 if ($this->jump != 0) {
                     throw new Exception('parallel connector returned while the "jump value" is not null (' . $this->jump . ')');
                 }
                 return $returnValue = $parallelConnector;
             }
         }
     }
     return $returnValue;
     //null
 }
 /**
  * (non-PHPdoc)
  * @see taoDelivery_models_classes_execution_Service::getUserExecutions()
  */
 public function getUserExecutions(core_kernel_classes_Resource $compiled, $userUri)
 {
     $executionClass = new core_kernel_classes_Class(CLASS_DELVIERYEXECUTION);
     $instances = $executionClass->searchInstances(array(PROPERTY_DELVIERYEXECUTION_SUBJECT => $userUri, PROPERTY_DELVIERYEXECUTION_DELIVERY => $compiled->getUri()), array('like' => false));
     $deliveryExecutions = array();
     foreach ($instances as $resource) {
         $deliveryExecutions[] = new taoDelivery_models_classes_execution_OntologyDeliveryExecution($resource->getUri());
     }
     return $deliveryExecutions;
 }
Beispiel #7
0
 /**
  * returns a list of active FileSources
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @return array
  * @deprecated
  */
 public static function getFileSources()
 {
     $classRepository = new core_kernel_classes_Class(CLASS_GENERIS_VERSIONEDREPOSITORY);
     $resources = $classRepository->searchInstances(array(PROPERTY_GENERIS_VERSIONEDREPOSITORY_ENABLED => GENERIS_TRUE), array('like' => false));
     $fileSystems = array();
     foreach ($resources as $resource) {
         $fileSystems[] = new core_kernel_fileSystem_FileSystem($resource);
     }
     return $fileSystems;
 }
 /**
  * Short description of method getServiceDefinition
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  string url
  * @return core_kernel_classes_Resource
  */
 public static function getServiceDefinition($url)
 {
     $returnValue = null;
     $serviceClass = new core_kernel_classes_Class(CLASS_SUPPORTSERVICES);
     $services = $serviceClass->searchInstances(array(PROPERTY_SUPPORTSERVICES_URL => $url), array('like' => false, 'recursive' => 1000));
     if (count($services)) {
         $service = array_pop($services);
         if ($service instanceof core_kernel_classes_Resource) {
             $returnValue = $service;
         }
     }
     return $returnValue;
 }
Beispiel #9
0
 /**
  * Helper function to find the OauthConsumer RDF Resource
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  string consumer_key
  * @return core_kernel_classes_Resource
  */
 public function findOauthConsumerResource($consumer_key)
 {
     $returnValue = null;
     $class = new core_kernel_classes_Class(CLASS_OAUTH_CONSUMER);
     $instances = $class->searchInstances(array(PROPERTY_OAUTH_KEY => $consumer_key), array('like' => false, 'recursive' => true));
     if (count($instances) == 0) {
         throw new tao_models_classes_oauth_Exception('No Credentials for consumer key ' . $consumer_key);
     }
     if (count($instances) > 1) {
         throw new tao_models_classes_oauth_Exception('Multiple Credentials for consumer key ' . $consumer_key);
     }
     $returnValue = current($instances);
     return $returnValue;
 }
 /**
  * 
  * @param string $currentVersion
  * @return string $versionUpdatedTo
  */
 public function update($initialVersion)
 {
     $currentVersion = $initialVersion;
     //migrate from 2.6 to 2.6.1
     if ($currentVersion == '2.6') {
         $file = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'indexation_2_6_1.rdf';
         $adapter = new tao_helpers_data_GenerisAdapterRdf();
         if ($adapter->import($file)) {
             $currentVersion = '2.6.1';
         } else {
             common_Logger::w('Import failed for ' . $file);
         }
     }
     if ($currentVersion == '2.6.1') {
         // double check
         $index = new core_kernel_classes_Resource('http://www.tao.lu/Ontologies/TAOItem.rdf#ItemContentIndex');
         $default = $index->getPropertyValues(new core_kernel_classes_Property('http://www.tao.lu/Ontologies/TAO.rdf#IndexDefaultSearch'));
         if (count($default) == 0) {
             //no default search set, import
             $file = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'indexation_2_6_2.rdf';
             $adapter = new tao_helpers_data_GenerisAdapterRdf();
             if ($adapter->import($file)) {
                 $currentVersion = '2.6.2';
             } else {
                 common_Logger::w('Import failed for ' . $file);
             }
         } else {
             common_Logger::w('Defautl Search already set');
             $currentVersion = '2.6.2';
         }
     }
     if ($currentVersion == '2.6.2') {
         OntologyUpdater::correctModelId(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'indexation_2_6_1.rdf');
         OntologyUpdater::correctModelId(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'indexation_2_6_2.rdf');
         $currentVersion = '2.6.3';
     }
     if ($currentVersion == '2.6.3') {
         // update user roles
         $class = new core_kernel_classes_Class(CLASS_TAO_USER);
         $itemManagers = $class->searchInstances(array(PROPERTY_USER_ROLES => 'http://www.tao.lu/Ontologies/TAOItem.rdf#ItemsManagerRole'), array('recursive' => true, 'like' => false));
         foreach ($itemManagers as $user) {
             $user->setPropertyValue(new core_kernel_classes_Property(PROPERTY_USER_ROLES), ItemAuthorRole::INSTANCE_URI);
         }
         $currentVersion = '2.6.4';
     }
     return $currentVersion;
 }
 public function lookup(array $metadataValues)
 {
     $lookup = false;
     foreach ($metadataValues as $metadataValue) {
         $path = $metadataValue->getPath();
         $expectedPath = array(RDFS_LABEL);
         if ($path === $expectedPath) {
             // Check for such a value in database...
             $prop = new \core_kernel_classes_Property(RDFS_LABEL);
             $class = new \core_kernel_classes_Class(RDFS_CLASS);
             $instances = $class->searchInstances(array($prop->getUri() => $metadataValue->getValue()), array('like' => false, 'recursive' => true));
             if (count($instances) > 0) {
                 $lookup = new \core_kernel_classes_Class(reset($instances));
                 break;
             }
         }
     }
     return $lookup;
 }
 public function run()
 {
     common_ext_ExtensionsManager::singleton()->getExtensionById('taoTests');
     common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest');
     $ds = DIRECTORY_SEPARATOR;
     // 1. Find all the tests that have the QTI Test Model.
     $testClass = new core_kernel_classes_Class(TAO_TEST_CLASS);
     $qtiTests = $testClass->searchInstances(array(PROPERTY_TEST_TESTMODEL => INSTANCE_TEST_MODEL_QTI), array('recursive' => true, 'like' => false));
     // 2. Find the test definition file for each test.
     $testContentProp = new core_kernel_classes_Property(TEST_TESTCONTENT_PROP);
     foreach ($qtiTests as $qtiTest) {
         $testContentResource = $qtiTest->getOnePropertyValue($testContentProp);
         $testContent = new core_kernel_file_File($testContentResource);
         $qtiTestFilePath = $testContent->getAbsolutePath();
         $this->out("test.xml file found at '{$qtiTestFilePath}'.");
         // 2.1. Create a directory using the current file name.
         $pathinfo = pathinfo($qtiTestFilePath);
         $targetDirPath = $pathinfo['dirname'] . $ds . $pathinfo['filename'];
         if (!@mkdir($targetDirPath)) {
             $this->err("Unable to create QTI Test Content directory at location '{$targetDirPath}'.");
         } else {
             $this->out("QTI Test Content directory created at location '{$targetDirPath}'.");
         }
         // 2.2 Copy test.xml into the newly created directory.
         $qtiTestFileCopyDest = $targetDirPath . $ds . 'tao-qtitest-testdefinition.xml';
         if (!@copy($qtiTestFilePath, $qtiTestFileCopyDest)) {
             $this->err("Unable to copy test.xml file from '{$qtiTestFilePath}' to '{$qtiTestFileCopyDest}'.");
         } else {
             $this->out("test.xml file copied from '{$qtiTestFilePath}' to '{$qtiTestFileCopyDest}'.");
         }
         // 2.3 Update metadata in Knowledge Base.
         $newFileResource = $testContent->getFileSystem()->createFile('', basename($targetDirPath));
         $this->out("New File Resource in ontology refers to '" . $newFileResource->getAbsolutePath() . "'.");
         $qtiTest->removePropertyValues($testContentProp);
         $qtiTest->setPropertyValue($testContentProp, $newFileResource);
         $testContentResource->delete(true);
         if (!@unlink($qtiTestFilePath)) {
             $this->err("Unable to remove old test.xml file located at '{$qtiTestFilePath}'.");
         } else {
             $this->out("Old test.xml file located at '{$qtiTestFilePath}' removed from file system.");
         }
     }
 }
 /**
  * Returns an resource representing the incoming link
  * 
  * @throws common_exception_Error
  * @return core_kernel_classes_Resource
  */
 public function getLtiLinkResource()
 {
     if (is_null($this->ltiLink)) {
         $class = new core_kernel_classes_Class(CLASS_LTI_INCOMINGLINK);
         $consumer = taoLti_models_classes_LtiService::singleton()->getLtiConsumerResource($this->getLaunchData());
         // search for existing resource
         $instances = $class->searchInstances(array(PROPERTY_LTI_LINK_ID => $this->getLaunchData()->getResourceLinkID(), PROPERTY_LTI_LINK_CONSUMER => $consumer), array('like' => false, 'recursive' => false));
         if (count($instances) > 1) {
             throw new common_exception_Error('Multiple resources for link ' . $this->getLaunchData()->getResourceLinkID());
         }
         if (count($instances) == 1) {
             // use existing link
             $this->ltiLink = current($instances);
         } else {
             // spawn new link
             $this->ltiLink = $class->createInstanceWithProperties(array(PROPERTY_LTI_LINK_ID => $this->getLaunchData()->getResourceLinkID(), PROPERTY_LTI_LINK_CONSUMER => $consumer));
         }
     }
     return $this->ltiLink;
 }
 /**
  * Get resumable (active) deliveries.
  * @param User $user User instance. If not given then all deliveries will be returned regardless of user URI.
  * @return type
  */
 public function getResumableDeliveries($user = null)
 {
     $deliveryExecutionService = taoDelivery_models_classes_execution_ServiceProxy::singleton();
     if ($user === null) {
         $executionClass = new core_kernel_classes_Class(CLASS_DELVIERYEXECUTION);
         $resources = $executionClass->searchInstances(array(PROPERTY_DELVIERYEXECUTION_STATUS => INSTANCE_DELIVERYEXEC_ACTIVE), array('like' => false));
         $started = array_map(function ($resource) use($deliveryExecutionService) {
             return $deliveryExecutionService->getDeliveryExecution($resource);
         }, $resources);
     } else {
         $started = $deliveryExecutionService->getActiveDeliveryExecutions($user->getIdentifier());
     }
     $resumable = array();
     foreach ($started as $deliveryExecution) {
         $delivery = $deliveryExecution->getDelivery();
         if ($delivery->exists()) {
             $resumable[] = $deliveryExecution;
         }
     }
     return $resumable;
 }
 /**
  * Get common user uri associated to Lti user id
  *
  * @param $id string Identifier of LTI user
  * @param $key string Oauth LTI consumer key
  * @return array|null
  * @throws \common_Exception
  * @throws \tao_models_classes_oauth_Exception
  */
 public function getUserId($id, $key)
 {
     $class = new \core_kernel_classes_Class(CLASS_LTI_USER);
     $dataStore = new \tao_models_classes_oauth_DataStore();
     try {
         /** @var \core_kernel_classes_Resource $consumerResource */
         $consumerResource = $dataStore->findOauthConsumerResource($key);
     } catch (\tao_models_classes_oauth_Exception $e) {
         throw new \common_exception_NotFound($e->getMessage());
     }
     $instances = $class->searchInstances(array(PROPERTY_USER_LTIKEY => $id, PROPERTY_USER_LTICONSUMER => $consumerResource), array('like' => false));
     if (count($instances) > 1) {
         throw new \common_Exception('Multiple user accounts found for user key: ' . $id);
     }
     /** @var \core_kernel_classes_Resource $ltiUser */
     $ltiUser = count($instances) == 1 ? current($instances) : null;
     if (!$ltiUser) {
         return null;
     }
     return array('id' => $ltiUser->getUri());
 }
 public function guard(array $metadataValues)
 {
     $guard = false;
     // Search for a metadataValue with path:
     // http://www.imsglobal.org/xsd/imsmd_v1p2#lom
     // http://www.imsglobal.org/xsd/imsmd_v1p2#general
     // http://www.imsglobal.org/xsd/imsmd_v1p2#identifier
     foreach ($metadataValues as $metadataValue) {
         $path = $metadataValue->getPath();
         $expectedPath = array('http://www.imsglobal.org/xsd/imsmd_v1p2#lom', 'http://www.imsglobal.org/xsd/imsmd_v1p2#general', 'http://www.imsglobal.org/xsd/imsmd_v1p2#identifier');
         if ($path === $expectedPath) {
             // Check for such a value in database...
             $prop = new \core_kernel_classes_Property('http://www.imsglobal.org/xsd/imsmd_v1p2#identifier');
             $class = new \core_kernel_classes_Class(TAO_ITEM_CLASS);
             $instances = $class->searchInstances(array($prop->getUri() => $metadataValue->getValue()), array('like' => false, 'recursive' => true));
             if (count($instances) > 0) {
                 //var_dump($instances);
                 $guard = reset($instances);
                 break;
             }
         }
     }
     return $guard;
 }
 /**
  * Short description of method evaluateXPO
  *
  * @access protected
  * @author firstname and lastname of author, <*****@*****.**>
  * @return mixed
  */
 protected function evaluateXPO()
 {
     common_Logger::d('XPO TYPE', array('Generis Term evaluateXPO'));
     $classTerm = new core_kernel_classes_Class(CLASS_TERM_X_PREDICATE_OBJECT);
     $obj = $this->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_TERM_XPO_OBJECT));
     $pred = $this->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_TERM_XPO_PREDICATE));
     if ($obj instanceof core_kernel_classes_Literal) {
         $objValue = $obj->literal;
     }
     if ($obj instanceof core_kernel_classes_Resource) {
         $objValue = $pred->getUri();
     }
     $returnValue = new core_kernel_classes_ContainerCollection(new common_Object(__METHOD__));
     $terms = $classTerm->searchInstances(array($pred->getUri() => $objValue), array('like' => false));
     foreach ($terms as $term) {
         $returnValue->add($term);
     }
     return $returnValue;
 }
Beispiel #18
0
 /**
  * Delete a group or a group class
  * @return void
  */
 public function delete()
 {
     if (!tao_helpers_Request::isAjax()) {
         throw new Exception("wrong request mode");
     } else {
         $deleted = false;
         if ($this->getRequestParameter('uri')) {
             $role = $this->getCurrentInstance();
             if (!in_array($role->getUri(), $this->forbidden)) {
                 //check if no user is using this role:
                 $userClass = new core_kernel_classes_Class(CLASS_GENERIS_USER);
                 $options = array('recursive' => true, 'like' => false);
                 $filters = array(PROPERTY_USER_ROLES => $role->getUri());
                 $users = $userClass->searchInstances($filters, array());
                 if (empty($users)) {
                     //delete role here:
                     $deleted = $this->service->removeRole($role);
                 } else {
                     //set message error
                     throw new Exception(__('This role is still given to one or more users. Please remove the role to these users first.'));
                 }
             } else {
                 throw new Exception($role->getLabel() . ' could not be deleted');
             }
         }
         echo json_encode(array('deleted' => $deleted));
     }
 }
Beispiel #19
0
 /**
  * Short description of method disable
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @return boolean
  */
 public function disable()
 {
     $returnValue = (bool) false;
     $classVersionedFiles = new core_kernel_classes_Class(CLASS_GENERIS_FILE);
     $files = $classVersionedFiles->searchInstances(array(PROPERTY_FILE_FILESYSTEM => $this), array('like' => false));
     $rootFile = $this->getRootFile();
     $used = false;
     foreach ($files as $file) {
         if (is_null($rootFile) || $file->getUri() != $rootFile->getUri()) {
             $used = true;
             break;
         }
     }
     if (!$used) {
         $this->editPropertyValues(new core_kernel_classes_Property(PROPERTY_GENERIS_VERSIONEDREPOSITORY_ENABLED), GENERIS_FALSE);
         common_Logger::i("The remote versioning repository " . $this->getUri() . " has been disabled");
         $returnValue = true;
         core_kernel_fileSystem_Cache::flushCache();
     } else {
         common_Logger::w("The remote versioning repository " . $this->getUri() . " could not be disabled, because it is in use by " . $file->getUri());
     }
     return (bool) $returnValue;
 }
 /**
  * Implementation of old 'taoResults' results to 'taoOutcomeRds' results.
  */
 private static function resultsMigration()
 {
     $outcomeRds = call_user_func(array('oat\\taoOutcomeRds\\model\\RdsResultStorage', 'singleton'));
     $deliveryResultClass = new \core_kernel_classes_Class(self::DELIVERYRESULTCLASSURI);
     $itemResultClass = new \core_kernel_classes_Class(self::ITEMRESULTCLASSURI);
     $variableClass = new \core_kernel_classes_Class(self::VARIABLECLASSURI);
     // Retrieve all Delivery Results. Batch by 1.
     $batch = 1;
     $offset = 0;
     $limit = $batch;
     $deliveryResults = $deliveryResultClass->getInstances(false, array('offset' => $offset, 'limit' => $limit));
     while (count($deliveryResults) > 0) {
         common_Logger::i("- Migrating Delivery Results from offset {$offset} to limit {$limit}...");
         foreach ($deliveryResults as $deliveryResultUri => $deliveryResult) {
             $properties = array(self::DELIVERYIDENTIFIERPROPERTYURI, self::RESULTOFSUBJECTPROPERTYURI, self::RESULTOFDELIVERYPROPERTYURI);
             $deliveryResultValues = $deliveryResult->getPropertiesValues($properties);
             $noIdentifier = empty($deliveryResultValues[self::DELIVERYIDENTIFIERPROPERTYURI]);
             $noSubject = empty($deliveryResultValues[self::RESULTOFSUBJECTPROPERTYURI]);
             $noDelivery = empty($deliveryResultValues[self::RESULTOFDELIVERYPROPERTYURI]);
             if ($noIdentifier === false && $noSubject === false && $noDelivery === false) {
                 $newResultIdentifier = current($deliveryResultValues[self::DELIVERYIDENTIFIERPROPERTYURI])->getUri();
                 $newResultSubject = current($deliveryResultValues[self::RESULTOFSUBJECTPROPERTYURI])->getUri();
                 $newResultDelivery = current($deliveryResultValues[self::RESULTOFDELIVERYPROPERTYURI])->getUri();
                 common_Logger::i("-- Migrating Delivery Result with Identifier '{$newResultIdentifier}'...");
                 // We have a Delivery Result to migrate.
                 $outcomeRds->storeRelatedDelivery($newResultIdentifier, $newResultDelivery);
                 $outcomeRds->storeRelatedTestTaker($newResultIdentifier, $newResultSubject);
                 // Retrieve all Item Results related to DeliveryResult.
                 $itemResultsPropertyFilters = array(self::RELATEDDELIVERYRESULTURI => $deliveryResultUri);
                 $itemResultsOptions = array('recursive' => false, 'like' => false);
                 $itemResults = $itemResultClass->searchInstances($itemResultsPropertyFilters, $itemResultsOptions);
                 foreach ($itemResults as $itemResultUri => $itemResult) {
                     $itemResultProperties = array(self::ITEMIDENTIFIERPROPERTYURI, self::RELATEDITEMPROPERTYURI, self::RELATEDTESTPROPERTYURI);
                     $itemResultValues = $itemResult->getPropertiesValues($itemResultProperties);
                     $noIdentifier = empty($itemResultValues[self::ITEMIDENTIFIERPROPERTYURI]);
                     $noRelatedItem = empty($itemResultValues[self::RELATEDITEMPROPERTYURI]);
                     $noRelatedTest = empty($itemResultValues[self::RELATEDTESTPROPERTYURI]);
                     if ($noIdentifier === false && $noRelatedItem === false && $noRelatedTest === false) {
                         $newItemResultIdentifier = current($itemResultValues[self::ITEMIDENTIFIERPROPERTYURI]);
                         $newItemResultRelatedItem = current($itemResultValues[self::RELATEDITEMPROPERTYURI])->getUri();
                         $newItemResultRelatedTest = current($itemResultValues[self::RELATEDTESTPROPERTYURI])->getUri();
                         common_Logger::i("--- Migrating Item Result with Identifier '{$newItemResultIdentifier}'...");
                         // Get all Variables related to this Item Result.
                         $variablePropertyFilters = array(self::RELATEDITEMRESULTPROPERTYURI => $itemResultUri);
                         $variableOptions = array('recursive' => true, 'like' => false);
                         $variables = $variableClass->searchInstances($variablePropertyFilters, $variableOptions);
                         foreach ($variables as $variableUri => $variable) {
                             $newVariable = self::createVariableObject($variable);
                             if ($newVariable !== false) {
                                 $outcomeRds->storeItemVariable($newResultIdentifier, $newItemResultRelatedTest, $newItemResultRelatedItem, $newVariable, $newItemResultIdentifier);
                             }
                         }
                     } else {
                         common_Logger::i("Skipping Item Result Result with URI '{$itemResultUri}'. Malformed Item Result.");
                     }
                 }
                 // Now let's find test Variables.
                 $variablePropertyFilters = array(self::RELATEDDELIVERYRESULTURI => $deliveryResultUri);
                 $variableOptions = array('recursive' => true, 'like' => false);
                 $variables = $variableClass->searchInstances($variablePropertyFilters, $variableOptions);
                 // If we can infer the related test...
                 if (isset($newItemResultRelatedTest) === true) {
                     foreach ($variables as $variableUri => $variable) {
                         $newVariable = self::createVariableObject($variable);
                         if ($newVariable !== false) {
                             $outcomeRds->storeTestVariable($newResultIdentifier, $newItemResultRelatedTest, $newVariable, $newResultIdentifier);
                         }
                     }
                 }
             } else {
                 common_Logger::i("Skipping Delivery Result with URI '{$deliveryResultUri}'. Malformed Delivery Result.");
             }
         }
         // Retrieve next batch of Delivery Results.
         $limit += $batch;
         $offset += $batch;
         $deliveryResults = $deliveryResultClass->getInstances(false, array('offset' => $offset, 'limit' => $limit));
     }
 }
 /**
  * Short description of method checkNoIsolatedActivity
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @return boolean
  */
 public function checkNoIsolatedActivity()
 {
     $returnValue = (bool) false;
     $returnValue = true;
     //need to be initiated as true
     $this->isolatedActivities = array();
     $connectorsClass = new core_kernel_classes_Class(CLASS_CONNECTORS);
     $process = $this->process;
     foreach ($this->authoringService->getActivitiesByProcess($process) as $activity) {
         if (!$this->activityService->isInitial($activity)) {
             //should have a previous activity:
             $connectors = $connectorsClass->searchInstances(array(PROPERTY_STEP_NEXT => $activity->getUri()), array('like' => false, 'recursive' => 0));
             if (empty($connectors)) {
                 $returnValue = false;
                 $this->isolatedActivities[$activity->getUri()] = $activity;
             }
         }
     }
     return (bool) $returnValue;
 }
 /**
  * Short description of method getProcessExecutionsByDefinition
  *
  * @access public
  * @author Somsack Sipasseuth, <*****@*****.**>
  * @param  Resource processDefinition
  * @return array
  */
 public function getProcessExecutionsByDefinition(core_kernel_classes_Resource $processDefinition)
 {
     $returnValue = array();
     if (!is_null($processDefinition)) {
         $processInstancesClass = new core_kernel_classes_Class(CLASS_PROCESSINSTANCES);
         $returnValue = $processInstancesClass->searchInstances(array(PROPERTY_PROCESSINSTANCES_EXECUTIONOF => $processDefinition->getUri()));
     }
     return (array) $returnValue;
 }
 /**
  * Get JSON monitoring data
  */
 public function monitorProcess()
 {
     $returnValue = array();
     $filters = null;
     //get the filter
     if ($this->hasRequestParameter('filter')) {
         $filter = $this->getRequestParameter('filter');
         $filter = $filter == 'null' || empty($filter) ? null : $filter;
         if (is_array($filter)) {
             foreach ($filter as $propertyUri => $propertyValues) {
                 foreach ($propertyValues as $i => $propertyValue) {
                     $propertyDecoded = tao_helpers_Uri::decode($propertyValue);
                     if (common_Utils::isUri($propertyDecoded)) {
                         $filters[tao_helpers_Uri::decode($propertyUri)][$i] = $propertyDecoded;
                     }
                 }
             }
         }
     }
     //get the processes uris
     $processesUri = $this->hasRequestParameter('processesUri') ? $this->getRequestParameter('processesUri') : null;
     $processInstancesClass = new core_kernel_classes_Class(CLASS_PROCESSINSTANCES);
     if (!is_null($filters)) {
         $processExecutions = $processInstancesClass->searchInstances($filters, array('recursive' => true));
     } else {
         if (!is_null($processesUri)) {
             foreach ($processesUri as $processUri) {
                 $processExecutions[$processUri] = new core_kernel_classes_resource($processUri);
             }
         } else {
             $processExecutions = $processInstancesClass->getInstances();
         }
     }
     $processMonitoringGrid = new wfEngine_helpers_Monitoring_ProcessMonitoringGrid(array_keys($processExecutions), $this->processMonitoringGridOptions);
     $data = $processMonitoringGrid->toArray();
     echo json_encode($data);
 }
Beispiel #24
0
 /**
  * get the users who have the role in parameter
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  core_kernel_classes_Resource role
  * @return array
  */
 public function getUsers(core_kernel_classes_Resource $role)
 {
     $returnValue = array();
     $filters = array(PROPERTY_USER_ROLES => $role->getUri());
     $options = array('like' => false, 'recursive' => true);
     $userClass = new core_kernel_classes_Class(CLASS_GENERIS_USER);
     $results = $userClass->searchInstances($filters, $options);
     $returnValue = array_keys($results);
     return (array) $returnValue;
 }
 public static function getExtensionAccess($extId)
 {
     try {
         $returnValue = self::getCacheImplementation()->get(self::CACHE_PREFIX_EXTENSION . $extId);
     } catch (common_cache_Exception $e) {
         $returnValue = array();
         $aclExtUri = funcAcl_models_classes_AccessService::singleton()->makeEMAUri($extId);
         $roleClass = new core_kernel_classes_Class(CLASS_ROLE);
         $roles = $roleClass->searchInstances(array(funcAcl_models_classes_AccessService::PROPERTY_ACL_GRANTACCESS => $aclExtUri), array('recursive' => true, 'like' => false));
         foreach ($roles as $grantedRole) {
             $returnValue[] = $grantedRole->getUri();
         }
         self::getCacheImplementation()->put($returnValue, self::CACHE_PREFIX_EXTENSION . $extId);
     }
     return $returnValue;
 }
 public static function deleteProcesses()
 {
     $returnValue = false;
     $classProcess = new core_kernel_classes_Class(CLASS_PROCESS);
     $processAuthoringService = wfAuthoring_models_classes_ProcessService::singleton();
     self::$processes = array_merge(self::$processes, $classProcess->searchInstances(array(PROPERTY_IS_SAMPLE => GENERIS_TRUE), array('like' => false, 'recursive' => false)));
     foreach (self::$processes as $processUri => $process) {
         if ($process instanceof core_kernel_classes_Resource && $process->exists()) {
             $returnValue = $processAuthoringService->deleteProcess($process);
         }
         unset(self::$processes[$processUri]);
     }
     return $returnValue;
 }
 /**
  * 
  * @param core_kernel_classes_Resource $deliveryResult
  * @param unknown $callId
  * @param unknown $test
  * @param unknown $item
  * @throws common_exception_Error
  * @return Ambigous <mixed, core_kernel_classes_Resource>
  */
 public function getItemResult(core_kernel_classes_Resource $deliveryResult, $callId, $test, $item)
 {
     //check first from the local cache
     if (isset($this->cacheItemResult[$callId])) {
         return $this->cacheItemResult[$callId];
     }
     $itemResultsClass = new core_kernel_classes_Class(ITEM_RESULT);
     $itemResults = $itemResultsClass->searchInstances(array(PROPERTY_IDENTIFIER => $callId), array("like" => false));
     if (count($itemResults) > 1) {
         throw new common_exception_Error('More then 1 itemResult for the corresponding Id ' . $deliveryResultIdentifier);
     } elseif (count($itemResults) == 1) {
         $returnValue = array_shift($itemResults);
         common_Logger::d('found Item Result after search for ' . $callId);
     } else {
         $returnValue = $itemResultsClass->createInstanceWithProperties(array(RDFS_LABEL => $callId, PROPERTY_IDENTIFIER => $callId, PROPERTY_RELATED_ITEM => $item, PROPERTY_RELATED_TEST => $test, PROPERTY_RELATED_DELIVERY_RESULT => $deliveryResult->getUri()));
     }
     $this->cacheItemResult[$callId] = $returnValue;
     return $returnValue;
 }
 /**
  * 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));
 }
 /**
  * Short description of method getAllUsers
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @param  array options
  * @return array
  */
 public function getAllUsers($options = array())
 {
     $returnValue = array();
     $userClass = new core_kernel_classes_Class(CLASS_TAO_USER);
     $options = array_merge(array('recursive' => true, 'like' => true), $options);
     $filters = array(PROPERTY_USER_LOGIN => '*');
     $returnValue = $userClass->searchInstances($filters, $options);
     return (array) $returnValue;
 }
 /**
  * Short description of method setRelatedDeliveries
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource campaign
  * @param  array deliveries
  * @return boolean
  */
 public function setRelatedDeliveries(core_kernel_classes_Resource $campaign, $deliveries = array())
 {
     $returnValue = (bool) false;
     if (!is_null($campaign)) {
         //the property of the DELIVERIES that will be modified
         $campaignProp = new core_kernel_classes_Property(TAO_DELIVERY_CAMPAIGN_PROP);
         //a way to remove the campaign property value of the delivery that are used to be associated to THIS campaign
         $deliveryClass = new core_kernel_classes_Class(TAO_DELIVERY_CLASS);
         $oldDeliveries = $deliveryClass->searchInstances(array(TAO_DELIVERY_CAMPAIGN_PROP => $campaign->getUri()), array('like' => false, 'recursive' => 0));
         foreach ($oldDeliveries as $oldRelatedDelivery) {
             //find a way to remove the property value associated to THIS campaign ONLY
             $remove = $oldRelatedDelivery->removePropertyValues($campaignProp, array('pattern' => $campaign->getUri()));
         }
         //assign the current compaign to the selected deliveries
         $done = 0;
         foreach ($deliveries as $delivery) {
             //the delivery instance to be modified
             $deliveryInstance = new core_kernel_classes_Resource($delivery);
             //remove the property value associated to another delivery in case ONE delivery can ONLY be associated to ONE campaign
             //if so, then change the widget from comboBox to treeView in the delivery property definition
             // $deliveryInstance->removePropertyValues($campaignProp);
             //now, truly assigning the campaign uri to the affected deliveries
             if ($deliveryInstance->setPropertyValue($campaignProp, $campaign->getUri())) {
                 $done++;
             }
         }
         if ($done == count($deliveries)) {
             $returnValue = true;
         }
     }
     return (bool) $returnValue;
 }