/**
  *
  * @param array callOptions an array of parameters sent to the results storage configuration
  * @param mixed $resultServer
  * @param string uri or resource
  */
 public function __construct($resultServer, $additionalStorages = array())
 {
     $this->implementations = array();
     if (is_object($resultServer) and get_class($resultServer) == 'core_kernel_classes_Resource') {
         $this->resultServer = $resultServer;
     } else {
         if (common_Utils::isUri($resultServer)) {
             $this->resultServer = new core_kernel_classes_Resource($resultServer);
         }
     }
     // the static storages
     if ($this->resultServer->getUri() != TAO_VOID_RESULT_SERVER) {
         $resultServerModels = $this->resultServer->getPropertyValues(new core_kernel_classes_Property(TAO_RESULTSERVER_MODEL_PROP));
         if (!isset($resultServerModels) or count($resultServerModels) == 0) {
             throw new common_Exception("The result server is not correctly configured (Resource definition)");
         }
         foreach ($resultServerModels as $resultServerModelUri) {
             $resultServerModel = new core_kernel_classes_Resource($resultServerModelUri);
             $this->addImplementation($resultServerModel->getUniquePropertyValue(new core_kernel_classes_Property(TAO_RESULTSERVER_MODEL_IMPL_PROP))->literal);
         }
     }
     if (!is_null($additionalStorages)) {
         // the dynamic storages
         foreach ($additionalStorages as $additionalStorage) {
             $this->addImplementation($additionalStorage["implementation"], $additionalStorage["parameters"]);
         }
     }
     common_Logger::i("Result Server Initialized using defintion:" . $this->resultServer->getUri());
     // sets the details required depending on the type of storage
 }
Ejemplo n.º 2
0
 /**
  * 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.');
                     }
                 }
             }
         }
     }
 }
 /**
  * Get tokens as string[] extracted from a QTI file
  * XML inside qti.xml is parsed and all text is tokenized
  *
  * @param \core_kernel_classes_Resource $resource
  * @return array
  */
 public function getStrings(\core_kernel_classes_Resource $resource)
 {
     try {
         $ontologyFiles = $resource->getPropertyValues($this->getProperty(TAO_ITEM_CONTENT_PROPERTY));
         if (empty($ontologyFiles)) {
             return [];
         }
     } catch (\core_kernel_classes_EmptyProperty $e) {
         return [];
     }
     $file = $this->getFileReferenceSerializer()->unserializeDirectory(reset($ontologyFiles))->getFile(Service::QTI_ITEM_FILE);
     if (!$file->exists()) {
         return [];
     }
     $content = $file->read();
     if (empty($content)) {
         return [];
     }
     $dom = new \DOMDocument();
     $dom->loadXML($content);
     $xpath = new \DOMXPath($dom);
     $textNodes = $xpath->query('//text()');
     unset($xpath);
     $contentStrings = array();
     foreach ($textNodes as $textNode) {
         if (ctype_space($textNode->wholeText) === false) {
             $contentStrings[] = trim($textNode->wholeText);
         }
     }
     return $contentStrings;
 }
 /**
  * Short description of method getNextSteps
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource step
  * @return array
  */
 public function getNextSteps(core_kernel_classes_Resource $step)
 {
     $returnValue = array();
     $nextStepProp = new core_kernel_classes_Property(PROPERTY_STEP_NEXT);
     foreach ($step->getPropertyValues($nextStepProp) as $stepUri) {
         $returnValue[] = new core_kernel_classes_Resource($stepUri);
     }
     return (array) $returnValue;
 }
 /**
  * Short description of method add
  *
  * @access public
  * @author Jehan Bihin, <*****@*****.**>
  * @param  string roleUri
  * @param  string accessUri
  * @return mixed
  */
 public function add($roleUri, $accessUri)
 {
     $module = new core_kernel_classes_Resource($accessUri);
     $role = new core_kernel_classes_Resource($roleUri);
     $moduleAccessProperty = new core_kernel_classes_Property(PROPERTY_ACL_GRANTACCESS);
     $values = $role->getPropertyValues($moduleAccessProperty);
     if (!in_array($module->getUri(), $values)) {
         $role->setPropertyValue($moduleAccessProperty, $module->getUri());
         funcAcl_helpers_Cache::cacheModule($module);
     } else {
         common_Logger::w('Tried to add role ' . $role->getUri() . ' again to controller ' . $accessUri);
     }
 }
Ejemplo n.º 6
0
 /**
  * Generates a form to define the values of a specific property for a resource
  * 
  * @param core_kernel_classes_Resource $resource
  * @param core_kernel_classes_Property $property
  * @return tao_helpers_form_GenerisTreeForm
  */
 public static function buildTree(core_kernel_classes_Resource $resource, core_kernel_classes_Property $property)
 {
     $tree = new self($resource, $property);
     $range = $property->getRange();
     $tree->setData('rootNode', $range->getUri());
     $tree->setData('dataUrl', _url('getData', 'GenerisTree', 'tao'));
     $tree->setData('saveUrl', _url('setValues', 'GenerisTree', 'tao'));
     $values = $resource->getPropertyValues($property);
     $tree->setData('values', $values);
     $openNodeUris = tao_models_classes_GenerisTreeFactory::getNodesToOpen($values, $range);
     $tree->setData('openNodes', $openNodeUris);
     return $tree;
 }
 /**
  * 
  * @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;
 }
 /**
  * Short description of method add
  *
  * @access public
  * @author Jehan Bihin, <*****@*****.**>
  * @param  string roleUri
  * @param  string accessUri
  * @return mixed
  */
 public function add($roleUri, $accessUri)
 {
     $uri = explode('#', $accessUri);
     list($type, $ext, $mod, $act) = explode('_', $uri[1]);
     $role = new core_kernel_classes_Resource($roleUri);
     $module = new core_kernel_classes_Resource($this->makeEMAUri($ext, $mod));
     $actionAccessProperty = new core_kernel_classes_Property(PROPERTY_ACL_GRANTACCESS);
     $moduleAccessProperty = new core_kernel_classes_Property(PROPERTY_ACL_GRANTACCESS);
     $values = $role->getPropertyValues($actionAccessProperty);
     if (!in_array($accessUri, $values)) {
         $role->setPropertyValue($actionAccessProperty, $accessUri);
         $controllerClassName = funcAcl_helpers_Map::getControllerFromUri($module->getUri());
         funcAcl_helpers_Cache::flushControllerAccess($controllerClassName);
     } else {
         common_Logger::w('Tried to regrant access for role ' . $role->getUri() . ' to action ' . $accessUri);
     }
 }
Ejemplo n.º 9
0
 public static function getToolService(core_kernel_classes_Resource $tool)
 {
     $services = $tool->getPropertyValues(new core_kernel_classes_Property(PROPERTY_LTITOOL_SERVICE));
     if (count($services) > 0) {
         if (count($services) > 1) {
             throw new common_exception_Error('Conflicting services for tool ' . $tool->getLabel());
         }
         $serviceName = (string) current($services);
         if (class_exists($serviceName) && is_subclass_of($serviceName, __CLASS__)) {
             return call_user_func(array($serviceName, 'singleton'));
         } else {
             throw new common_exception_Error('Tool service ' . $serviceName . ' not found, or not compatible for tool ' . $tool->getLabel());
         }
     } else {
         common_Logger::w('No implementation for ' . $tool->getLabel());
     }
 }
 /**
  * Get test takers assigned to the delivery.
  * @param \core_kernel_classes_Resource $delivery
  * @return array list of assigned and excluded test takers.
  * Example:
  * <pre>
  * array(
  *   'ttassigned' => array(
  *     array(
  *       'uri' => 'http://sample/first.rdf#i14298035456775118',
  *       'label' => 'test taker 1',
  *       'firstname' => 'test',    
  *       'lastname' => 'taker'    
  *     ),
  *     ...   
  *   )
  *   'ttexcluded' => array(
  *     array(
  *       'uri' => 'http://sample/first.rdf#i14303206619279661',
  *       'label' => 'test taker 2',
  *       'firstname' => 'test',    
  *       'lastname' => 'taker'    
  *     ),
  *     ...   
  *   )
  * )
  * </pre>
  */
 public function getDeliveryTestTakers(\core_kernel_classes_Resource $delivery)
 {
     $result = array('ttexcluded' => array(), 'ttassigned' => array());
     // excluded test takers
     $excludedSubjProperty = new \core_kernel_classes_Property(TAO_DELIVERY_EXCLUDEDSUBJECTS_PROP);
     $excluded = $delivery->getPropertyValues($excludedSubjProperty);
     foreach ($excluded as $testTaker) {
         $result['ttexcluded'][] = $this->getTestTakerData(new \core_kernel_classes_Resource($testTaker));
     }
     // assigned test takers
     $users = ServiceManager::getServiceManager()->get(AssignmentService::CONFIG_ID)->getAssignedUsers($delivery->getUri());
     $assigned = array_values(array_diff(array_unique($users), $excluded));
     foreach ($assigned as $testTaker) {
         $result['ttassigned'][] = $this->getTestTakerData(new \core_kernel_classes_Resource($testTaker));
     }
     return $result;
 }
 public function testSetStatement()
 {
     $true = new core_kernel_classes_Resource(GENERIS_TRUE, __METHOD__);
     $predicate = RDFS_SEEALSO;
     $property = new core_kernel_classes_Property($predicate, __METHOD__);
     $this->assertTrue($this->object->setStatement($true->getUri(), $predicate, 'test', DEFAULT_LANG), "setStatement should be able to set a value.");
     $values = $true->getPropertyValues($property);
     $this->assertTrue(count($values) > 0);
     $tripleFound = false;
     foreach ($values as $value) {
         if (!common_Utils::isUri($value) && $value == 'test') {
             $tripleFound = true;
             break;
         }
     }
     $this->assertTrue($tripleFound, "A property value for property " . $property->getUri() . " should be found for resource " . $true->getUri());
     $this->object->removeStatement($true->getUri(), $predicate, 'test', DEFAULT_LANG);
 }
 /**
  * Short description of method cloneInstance
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param
  *            Resource instance
  * @param
  *            Class clazz
  * @return core_kernel_classes_Resource
  */
 public function cloneInstance(core_kernel_classes_Resource $instance, core_kernel_classes_Class $clazz = null)
 {
     $returnValue = null;
     // call the parent create instance to prevent useless process test to be created:
     $label = $instance->getLabel();
     $cloneLabel = "{$label} bis";
     $clone = parent::createInstance($clazz, $cloneLabel);
     if (!is_null($clone)) {
         $noCloningProperties = array(TEST_TESTCONTENT_PROP, RDF_TYPE);
         foreach ($clazz->getProperties(true) as $property) {
             if (!in_array($property->getUri(), $noCloningProperties)) {
                 // allow clone of every property value but the deliverycontent, which is a process:
                 foreach ($instance->getPropertyValues($property) as $propertyValue) {
                     $clone->setPropertyValue($property, $propertyValue);
                 }
             }
         }
         // Fix label
         if (preg_match("/bis/", $label)) {
             $cloneNumber = (int) preg_replace("/^(.?)*bis/", "", $label);
             $cloneNumber++;
             $cloneLabel = preg_replace("/bis(.?)*\$/", "", $label) . "bis {$cloneNumber}";
         }
         $clone->setLabel($cloneLabel);
         // clone the process:
         $propInstanceContent = new core_kernel_classes_Property(TEST_TESTCONTENT_PROP);
         try {
             $process = $instance->getUniquePropertyValue($propInstanceContent);
         } catch (Exception $e) {
         }
         if (!is_null($process)) {
             $processCloner = new wfAuthoring_models_classes_ProcessCloner();
             $processClone = $processCloner->cloneProcess($process);
             $clone->editPropertyValues($propInstanceContent, $processClone->getUri());
         } else {
             throw new Exception("the test process cannot be found");
         }
         $this->onChangeTestLabel($clone);
         $returnValue = $clone;
     }
     return $returnValue;
 }
 /**
  * export a compiled delivery into an archive
  * 
  * @param core_kernel_classes_Resource $compiledDelivery
  * @throws Exception
  * @return string
  */
 public static function exportCompiledDelivery(core_kernel_classes_Resource $compiledDelivery)
 {
     $fileName = tao_helpers_Display::textCleaner($compiledDelivery->getLabel()) . '.zip';
     $path = tao_helpers_File::concat(array(tao_helpers_Export::getExportPath(), $fileName));
     if (!tao_helpers_File::securityCheck($path, true)) {
         throw new Exception('Unauthorized file name');
     }
     $zipArchive = new ZipArchive();
     if ($zipArchive->open($path, ZipArchive::CREATE) !== true) {
         throw new Exception('Unable to create archive at ' . $path);
     }
     $taoDeliveryVersion = common_ext_ExtensionsManager::singleton()->getInstalledVersion('taoDelivery');
     $data = array('dir' => array(), 'label' => $compiledDelivery->getLabel(), 'version' => $taoDeliveryVersion);
     $directories = $compiledDelivery->getPropertyValues(new core_kernel_classes_Property(PROPERTY_COMPILEDDELIVERY_DIRECTORY));
     foreach ($directories as $id) {
         $directory = tao_models_classes_service_FileStorage::singleton()->getDirectoryById($id);
         tao_helpers_File::addFilesToZip($zipArchive, $directory->getPath(), $directory->getRelativePath());
         $data['dir'][$id] = $directory->getRelativePath();
     }
     $runtime = $compiledDelivery->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_COMPILEDDELIVERY_RUNTIME));
     $serviceCall = tao_models_classes_service_ServiceCall::fromResource($runtime);
     $data['runtime'] = base64_encode($serviceCall->serializeToString());
     $rdfExporter = new tao_models_classes_export_RdfExporter();
     $rdfdata = $rdfExporter->getRdfString(array($compiledDelivery));
     if (!$zipArchive->addFromString('delivery.rdf', $rdfdata)) {
         throw common_Exception('Unable to add metadata to exported delivery assembly');
     }
     $data['meta'] = 'delivery.rdf';
     $content = json_encode($data);
     //'<?php return '.common_Utils::toPHPVariableString($data).";";
     if (!$zipArchive->addFromString(self::MANIFEST_FILE, $content)) {
         $zipArchive->close();
         unlink($path);
         throw common_Exception('Unable to add manifest to exported delivery assembly');
     }
     $zipArchive->close();
     return $path;
 }
 /**
  * Short description of method remove
  *
  * @access public
  * @author Jehan Bihin, <*****@*****.**>
  * @param  string roleUri
  * @param  string accessUri
  * @return mixed
  */
 public function remove($roleUri, $accessUri)
 {
     $uri = explode('#', $accessUri);
     list($type, $extId) = explode('_', $uri[1]);
     // Remove the access to the extension for this role.
     $extManager = common_ext_ExtensionsManager::singleton();
     $extension = $extManager->getExtensionById($extId);
     $role = new core_kernel_classes_Resource($roleUri);
     $role->removePropertyValues(new core_kernel_classes_Property(PROPERTY_ACL_GRANTACCESS), array('pattern' => $accessUri));
     funcAcl_helpers_Cache::flushExtensionAccess($extId);
     // also remove access to all the controllers
     $moduleAccessProperty = new core_kernel_classes_Property(PROPERTY_ACL_GRANTACCESS);
     $moduleAccessService = funcAcl_models_classes_ModuleAccessService::singleton();
     $grantedModules = $role->getPropertyValues($moduleAccessProperty);
     foreach ($grantedModules as $gM) {
         $gM = new core_kernel_classes_Resource($gM);
         $uri = explode('#', $gM->getUri());
         list($type, $ext) = explode('_', $uri[1]);
         if ($extId == $ext) {
             $moduleAccessService->remove($role->getUri(), $gM->getUri());
         }
     }
 }
 /**
  * Short description of method getRelatedCampaigns
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource delivery
  * @return array
  */
 public function getRelatedCampaigns(core_kernel_classes_Resource $delivery)
 {
     $returnValue = array();
     $campaigns = $delivery->getPropertyValues(new core_kernel_classes_Property(TAO_DELIVERY_CAMPAIGN_PROP));
     if (count($campaigns) > 0) {
         $campaignSubClasses = array();
         foreach ($this->getRootClass()->getSubClasses(true) as $campaignSubClass) {
             $campaignSubClasses[] = $campaignSubClass->getUri();
         }
         foreach ($campaigns as $campaignUri) {
             $clazz = $this->getClass(new core_kernel_classes_Resource($campaignUri));
             if (!is_null($clazz)) {
                 if (in_array($clazz->getUri(), $campaignSubClasses)) {
                     $returnValue[] = $clazz->getUri();
                 }
             }
             $returnValue[] = $campaignUri;
         }
     }
     return (array) $returnValue;
 }
 /**
  * Short description of method linkClonedStep
  *
  * @access protected
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource original
  * @return mixed
  */
 protected function linkClonedStep(core_kernel_classes_Resource $original)
 {
     $nextProp = new core_kernel_classes_Property(PROPERTY_STEP_NEXT);
     $arr = $this->mapClonedResources(array($original), false);
     $clone = current($arr);
     $resources = array();
     foreach ($original->getPropertyValues($nextProp) as $uri) {
         $resources[] = new core_kernel_classes_Resource($uri);
     }
     $mappedValues = $this->mapClonedResources($resources, true);
     $clone->editPropertyValues($nextProp, $mappedValues);
 }
 private function getItemFile(core_kernel_classes_Resource $item, $type, $countryCode, $langCode, core_kernel_classes_Resource $user = null)
 {
     $returnValue = null;
     if (!isset($this->properties[TranslationProcessHelper::getPropertyName($type, $countryCode, $langCode)])) {
         $this->fail("The item property does not exist for the item {$item->getLabel()} ({$item->getUri()}) : {$type}, {$countryCode}, {$langCode} ");
         return $returnValue;
     }
     $file = null;
     if (in_array(strtolower($type), array('xliff_working', 'vff_working'))) {
         if (is_null($user)) {
             $this->fail('no user given');
             return $returnValue;
         }
         $values = $item->getPropertyValues($this->properties[TranslationProcessHelper::getPropertyName($type, $countryCode, $langCode)]);
         foreach ($values as $uri) {
             if (common_Utils::isUri($uri)) {
                 $aFile = new core_kernel_versioning_File($uri);
                 $assignedUser = $aFile->getUniquePropertyValue($this->userProperty);
                 if ($assignedUser->getUri() == $user->getUri()) {
                     $file = $aFile;
                     break;
                 }
             }
         }
     } else {
         $values = $item->getPropertyValues($this->properties[TranslationProcessHelper::getPropertyName($type, $countryCode, $langCode)]);
         $this->assertEqual(count($values), 1);
         $file = new core_kernel_versioning_File(reset($values));
     }
     if (!is_null($file) && $file->isVersioned()) {
         $returnValue = $file;
     } else {
         $this->fail("Cannot get the versioned {$type} file in {$countryCode}_{$langCode} for the item {$item->getLabel()} ({$item->getUri()})");
     }
     return $returnValue;
 }
 /**
  * Returns the activityExecutions of a ProcessInstance
  * in order of execution
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource process
  * @return array
  */
 public static function getActivityExecutions(core_kernel_classes_Resource $process)
 {
     $returnValue = array();
     $prop = new core_kernel_classes_Property(PROPERTY_PROCESSINSTANCES_ACTIVITYEXECUTIONS);
     $activities = $process->getPropertyValues($prop);
     $nextmap = array();
     $previous = new core_kernel_classes_Property(PROPERTY_ACTIVITY_EXECUTION_PREVIOUS);
     $ordered = array();
     foreach ($activities as $activity) {
         $activityRessource = new core_kernel_classes_Resource($activity);
         $predecessor = $activityRessource->getOnePropertyValue($previous);
         if (is_null($predecessor)) {
             $currenturi = $activity;
             $returnValue[] = new core_kernel_classes_Resource($activity);
         } else {
             $nextmap[$predecessor->getUri()] = $activity;
         }
     }
     while (!empty($nextmap)) {
         $nexturi = $nextmap[$currenturi];
         $returnValue[] = new core_kernel_classes_Resource($nexturi);
         unset($nextmap[$currenturi]);
         $currenturi = $nexturi;
     }
     return (array) $returnValue;
 }
 /**
  * To build the audit trail of a process execution.
  * Return the list of all activity executions, ordered by creation time,
  * with their row data.
  *
  * @access public
  * @author Somsack Sipasseuth, <*****@*****.**>
  * @param  Resource processExecution
  * @param  boolean withData
  * @return array
  */
 public function getExecutionHistory(core_kernel_classes_Resource $processExecution, $withData = false)
 {
     $returnValue = array();
     $previousProperty = new core_kernel_classes_Property(PROPERTY_ACTIVITY_EXECUTION_PREVIOUS);
     $followingProperty = new core_kernel_classes_Property(PROPERTY_ACTIVITY_EXECUTION_FOLLOWING);
     $recoveryService = wfEngine_models_classes_RecoveryService::singleton();
     $currentActivityExecutions = $this->getCurrentActivityExecutions($processExecution);
     $creationTime = array();
     $unorderedActivityExecutions = array();
     $allActivityExecutions = $processExecution->getPropertyValues($this->processInstancesActivityExecutionsProp);
     $count = count($allActivityExecutions);
     for ($i = 0; $i < $count; $i++) {
         $uri = $allActivityExecutions[$i];
         if (common_Utils::isUri($uri)) {
             $activityExecution = new core_kernel_classes_Resource($uri);
             $createdOn = (string) $activityExecution->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_ACTIVITY_EXECUTION_TIME_CREATED));
             if ($withData) {
                 $previousArray = array();
                 $followingArray = array();
                 $previous = $activityExecution->getPropertyValues($previousProperty);
                 $countPrevious = count($previous);
                 for ($j = 0; $j < $countPrevious; $j++) {
                     if (common_Utils::isUri($previous[$j])) {
                         $prevousActivityExecution = new core_kernel_classes_Resource($previous[$j]);
                         $previousArray[] = $prevousActivityExecution->getUri();
                     }
                 }
                 $following = $activityExecution->getPropertyValues($followingProperty);
                 $countFollowing = count($following);
                 for ($k = 0; $k < $countFollowing; $k++) {
                     if (common_Utils::isUri($following[$k])) {
                         $followingActivityExecution = new core_kernel_classes_Resource($following[$k]);
                         $followingArray[] = $followingActivityExecution->getUri();
                     }
                 }
                 $unorderedActivityExecutions[$uri] = array('activityExecution' => $activityExecution, 'executionOf' => $this->activityExecutionService->getExecutionOf($activityExecution), 'createdOn' => date('d-m-Y G:i:s', $createdOn), 'current' => array_key_exists($activityExecution->getUri(), $currentActivityExecutions), 'status' => $this->activityExecutionService->getStatus($activityExecution), 'ACLmode' => $this->activityExecutionService->getAclMode($activityExecution), 'restrictedRole' => $this->activityExecutionService->getRestrictedRole($activityExecution), 'restrictedUser' => $this->activityExecutionService->getRestrictedUser($activityExecution), 'user' => $this->activityExecutionService->getActivityExecutionUser($activityExecution), 'previous' => $previousArray, 'following' => $followingArray, 'nonce' => $this->activityExecutionService->getNonce($activityExecution), 'context' => $recoveryService->getContext($activityExecution, ''), 'variables' => $this->activityExecutionService->getVariables($activityExecution));
             } else {
                 $unorderedActivityExecutions[$uri] = $activityExecution->getUri();
             }
             $creationTime[$uri] = $createdOn;
         }
     }
     asort($creationTime);
     foreach ($creationTime as $uri => $time) {
         $returnValue[] = $unorderedActivityExecutions[$uri];
     }
     return (array) $returnValue;
 }
 /**
  * Short description of method getFollowing
  *
  * @access public
  * @author Somsack Sipasseuth, <*****@*****.**>
  * @param  Resource activityExecution
  * @return array
  */
 public function getFollowing(core_kernel_classes_Resource $activityExecution)
 {
     $returnValue = array();
     $following = $activityExecution->getPropertyValues($this->activityExecutionFollowingProperty);
     $countFollowing = count($following);
     for ($k = 0; $k < $countFollowing; $k++) {
         if (common_Utils::isUri($following[$k])) {
             $returnValue[$following[$k]] = new core_kernel_classes_Resource($following[$k]);
         }
     }
     return (array) $returnValue;
 }
 /**
  * Check if a user is excluded from a delivery
  * @param core_kernel_classes_Resource $delivery
  * @param string $userUri the URI of the user to check
  * @return boolean true if excluded
  */
 private function isUserExcluded(core_kernel_classes_Resource $delivery, User $user)
 {
     $excludedUsers = $delivery->getPropertyValues(new core_kernel_classes_Property(TAO_DELIVERY_EXCLUDEDSUBJECTS_PROP));
     return in_array($user->getIdentifier(), $excludedUsers);
 }
 /**
  * Short description of method getItemFolder
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource item
  * @param  string lang
  * @return string
  */
 public function getItemFolder(core_kernel_classes_Resource $item, $lang = '')
 {
     $returnValue = (string) '';
     if ($lang === '') {
         $files = $item->getPropertyValues(new core_kernel_classes_Property(TAO_ITEM_CONTENT_PROPERTY));
     } else {
         $files = $item->getPropertyValuesByLg(new core_kernel_classes_Property(TAO_ITEM_CONTENT_PROPERTY), $lang)->toArray();
     }
     if (count($files) == 0) {
         // no content found assign default
         $returnValue = $this->getDefaultItemFolder($item, $lang);
     } else {
         if (count($files) > 1) {
             throw new common_Exception(__METHOD__ . ': Item ' . $item->getUri() . ' has multiple.');
         }
         $content = new core_kernel_file_File(current($files));
         $returnValue = dirname($content->getAbsolutePath()) . DIRECTORY_SEPARATOR;
     }
     return (string) $returnValue;
 }
 /**
  * Retrieves information about the variable, including or not the related item $getItem (slower)
  * 
  * @access public
  * @author Patrick Plichart, <*****@*****.**>
  * @param  Resource variable
  * @param  bool getItem retireve associated item reference
  * @return array simple associative
  */
 public function getVariableData(core_kernel_classes_Resource $variable, $getItem = false)
 {
     $returnValue = array();
     $baseTypes = $variable->getPropertyValues(new core_kernel_classes_Property(PROPERTY_VARIABLE_BASETYPE));
     $baseType = current($baseTypes);
     if ($baseType != "file") {
         $propValues = $variable->getPropertiesValues(array(PROPERTY_IDENTIFIER, PROPERTY_VARIABLE_EPOCH, RDF_VALUE, PROPERTY_VARIABLE_CARDINALITY, PROPERTY_VARIABLE_BASETYPE));
         $returnValue["value"] = (string) base64_decode(current($propValues[RDF_VALUE]));
     } else {
         $propValues = $variable->getPropertiesValues(array(PROPERTY_IDENTIFIER, PROPERTY_VARIABLE_EPOCH, PROPERTY_VARIABLE_CARDINALITY, PROPERTY_VARIABLE_BASETYPE));
         $returnValue["value"] = "";
     }
     $returnValue["identifier"] = current($propValues[PROPERTY_IDENTIFIER])->__toString();
     $class = current($variable->getTypes());
     $returnValue["type"] = $class;
     $returnValue["epoch"] = current($propValues[PROPERTY_VARIABLE_EPOCH])->__toString();
     if (count($propValues[PROPERTY_VARIABLE_CARDINALITY]) > 0) {
         $returnValue["cardinality"] = current($propValues[PROPERTY_VARIABLE_CARDINALITY])->__toString();
     }
     if (count($propValues[PROPERTY_VARIABLE_BASETYPE]) > 0) {
         $returnValue["basetype"] = current($propValues[PROPERTY_VARIABLE_BASETYPE])->__toString();
     }
     if ($getItem) {
         $returnValue["item"] = $this->getItemFromVariable($variable);
     }
     return (array) $returnValue;
 }
Ejemplo n.º 24
0
 /**
  *
  * @param string $currentVersion
  * @return string $versionUpdatedTo
  */
 public function update($initialVersion)
 {
     //migrate from 2.6 to 2.6.1
     if ($this->isVersion('2.6')) {
         $file = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'indexation_2_6_1.rdf';
         $adapter = new tao_helpers_data_GenerisAdapterRdf();
         if ($adapter->import($file)) {
             ${$this}->setVerion('2.6.1');
         } else {
             common_Logger::w('Import failed for ' . $file);
         }
     }
     if ($this->isVersion('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)) {
                 $this->setVerion('2.6.2');
             } else {
                 common_Logger::w('Import failed for ' . $file);
             }
         } else {
             common_Logger::w('Defautl Search already set');
             ${$this}->setVerion('2.6.2');
         }
     }
     if ($this->isVersion('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');
         $this->setVerion('2.6.3');
     }
     if ($this->isVersion('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);
         }
         $this->setVerion('2.6.4');
     }
     if ($this->isBetween('2.6.4', '2.8')) {
         $this->setVersion('2.8');
     }
     // fix itemModelLabelProp
     if ($this->isVersion('2.8')) {
         $fakeProperty = new core_kernel_classes_Property('itemModelLabel');
         $iterator = new core_kernel_classes_ResourceIterator(array(taoItems_models_classes_ItemsService::singleton()->getRootClass()));
         foreach ($iterator as $resource) {
             $resource->removePropertyValues($fakeProperty);
         }
         $this->setVersion('2.8.1');
     }
     $this->skip('2.8.1', '2.14.0');
     if ($this->isVersion('2.14.0')) {
         OntologyUpdater::syncModels();
         AclProxy::applyRule(new AccessRule('grant', 'http://www.tao.lu/Ontologies/TAOItem.rdf#AbstractItemAuthor', 'taoItems_actions_ItemContent'));
         $this->setVersion('2.15.0');
     }
     $this->skip('2.15.0', '2.22.3');
     if ($this->isVersion('2.22.3')) {
         OntologyUpdater::syncModels();
         $categoryService = new CategoryService();
         $categoryService->setServiceManager($this->getServiceManager());
         $this->getServiceManager()->register(CategoryService::SERVICE_ID, $categoryService);
         $this->setVersion('2.23.0');
     }
     if ($this->isVersion('2.23.0')) {
         OntologyUpdater::syncModels();
         $this->setVersion('2.24.0');
     }
     $this->skip('2.24.0', '2.24.1');
 }
Ejemplo n.º 25
0
 /**
  * Short description of method getPropertyValuesByLg
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource resource
  * @param  Property property
  * @param  string lg
  * @return \core_kernel_classes_ContainerCollection
  */
 public function getPropertyValuesByLg(\core_kernel_classes_Resource $resource, \core_kernel_classes_Property $property, $lg)
 {
     $returnValue = null;
     $options = array('lg' => $lg);
     $returnValue = new \core_kernel_classes_ContainerCollection($resource);
     foreach ($resource->getPropertyValues($property, $options) as $value) {
         $returnValue->add(\common_Utils::toResource($value));
     }
     return $returnValue;
 }
 /**
  * Returns the items flysystem directory
  *
  * @param core_kernel_classes_Resource $item
  * @param string $language
  * @return \oat\oatbox\filesystem\Directory
  * @throws Exception
  * @throws common_Exception
  * @throws core_kernel_persistence_Exception
  */
 public function getItemDirectory(core_kernel_classes_Resource $item, $language = '')
 {
     // Get file by language
     if ($language === '') {
         $files = $item->getPropertyValues($this->itemContentProperty);
     } else {
         $files = $item->getPropertyValuesByLg($this->itemContentProperty, $language)->toArray();
     }
     // If multiple files then throw exception
     if (count($files) > 1) {
         common_Logger::i(print_r($files, true));
         throw new common_Exception(__METHOD__ . ': Item ' . $item->getUri() . ' has multiple.');
     }
     // If there is one file then return directory
     if (count($files) == 1) {
         $file = reset($files);
         $file = is_object($file) && $file instanceof core_kernel_classes_Resource ? $file->getUri() : (string) $file;
         return $this->getFileReferenceSerializer()->unserializeDirectory($file);
     }
     // Otherwise there is no file, create one and return directory
     $model = $this->getItemModel($item);
     if (is_null($model)) {
         throw new common_Exception('Call to ' . __FUNCTION__ . ' for item without model');
     }
     // File does not exist, let's create it
     $actualLang = empty($language) ? $this->getSessionLg() : $language;
     $filePath = tao_helpers_Uri::getUniqueId($item->getUri()) . DIRECTORY_SEPARATOR . 'itemContent' . DIRECTORY_SEPARATOR . $actualLang;
     // Create item directory
     $itemDirectory = $this->getDefaultItemDirectory()->getDirectory($filePath);
     // Set uri file value as serial to item persistence
     $serial = $this->getFileReferenceSerializer()->serialize($itemDirectory);
     $item->setPropertyValueByLg($this->itemContentProperty, $serial, $actualLang);
     // Store file into persistence, purpose of serializer ?
     $dataFile = (string) $model->getOnePropertyValue($this->getProperty(TAO_ITEM_MODEL_DATAFILE_PROPERTY));
     $this->getFileReferenceSerializer()->serialize($itemDirectory->getFile($dataFile));
     return $itemDirectory;
 }
 /**
  * Short description of method cloneInstance
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource instance
  * @param  Class clazz
  * @return core_kernel_classes_Resource
  */
 public function cloneInstance(core_kernel_classes_Resource $instance, core_kernel_classes_Class $clazz = null)
 {
     $returnValue = null;
     //call the parent create instance to prevent useless process test to be created:
     $label = $instance->getLabel();
     $cloneLabel = "{$label} bis";
     $clone = parent::createInstance($clazz, $cloneLabel);
     if (!is_null($clone)) {
         $noCloningProperties = array(TEST_TESTCONTENT_PROP, RDF_TYPE);
         foreach ($clazz->getProperties(true) as $property) {
             if (!in_array($property->getUri(), $noCloningProperties)) {
                 //allow clone of every property value but the deliverycontent, which is a process:
                 foreach ($instance->getPropertyValues($property) as $propertyValue) {
                     $clone->setPropertyValue($property, $propertyValue);
                 }
             }
         }
         //Fix label
         if (preg_match("/bis/", $label)) {
             $cloneNumber = (int) preg_replace("/^(.?)*bis/", "", $label);
             $cloneNumber++;
             $cloneLabel = preg_replace("/bis(.?)*\$/", "", $label) . "bis {$cloneNumber}";
         }
         $clone->setLabel($cloneLabel);
         $impl = $this->getTestModelImplementation($this->getTestModel($instance));
         $impl->cloneContent($instance, $clone);
         $this->onChangeTestLabel($clone);
         $returnValue = $clone;
     }
     return $returnValue;
 }
 /**
  * Returns the ActivityCardinality that links the specified steps
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource source
  * @param  Resource destination
  * @return core_kernel_classes_Resource
  */
 public function getCardinalityResource(core_kernel_classes_Resource $source, core_kernel_classes_Resource $destination)
 {
     $returnValue = null;
     // @TODO consider other properties in case of chained connectors
     $propNextStep = new core_kernel_classes_Property(PROPERTY_STEP_NEXT);
     $candidates = $source->getPropertyValues($propNextStep);
     foreach ($candidates as $candidate) {
         if ($this->isCardinality($candidate)) {
             $candDest = $candidate->getUniquePropertyValue($propNextStep);
             if ($candDest->getUri() == $destination->getUri()) {
                 $returnValue = $candidate;
                 break;
             }
         }
     }
     return $returnValue;
 }
 /**
  * (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);
     }
 }
 public function getAssembliesByGroup(core_kernel_classes_Resource $group)
 {
     $returnValue = array();
     foreach ($group->getPropertyValues(new core_kernel_classes_Property(PROPERTY_GROUP_DELVIERY)) as $groupUri) {
         $returnValue[] = new core_kernel_classes_Resource($groupUri);
     }
     return $returnValue;
 }