/**
  *
  * @param unknown $userId
  * @param core_kernel_classes_Resource $assembly
  * @return taoDelivery_models_classes_execution_KVDeliveryExecution
  */
 public static function spawn(common_persistence_KeyValuePersistence $persistence, $userId, core_kernel_classes_Resource $assembly)
 {
     $identifier = self::DELIVERY_EXECUTION_PREFIX . common_Utils::getNewUri();
     $de = new self($persistence, $identifier, array(RDFS_LABEL => $assembly->getLabel(), PROPERTY_DELVIERYEXECUTION_DELIVERY => $assembly->getUri(), PROPERTY_DELVIERYEXECUTION_SUBJECT => $userId, PROPERTY_DELVIERYEXECUTION_START => time(), PROPERTY_DELVIERYEXECUTION_STATUS => INSTANCE_DELIVERYEXEC_ACTIVE));
     $de->save();
     return $de;
 }
Ejemplo n.º 2
0
 /**
  * Search results
  * The search is paginated and initiated by the datatable component.
  */
 public function search()
 {
     $params = $this->getRequestParameter('params');
     $query = $params['query'];
     $class = new core_kernel_classes_Class($params['rootNode']);
     $rows = $this->hasRequestParameter('rows') ? (int) $this->getRequestParameter('rows') : null;
     $page = $this->hasRequestParameter('page') ? (int) $this->getRequestParameter('page') : 1;
     $startRow = is_null($rows) ? 0 : $rows * ($page - 1);
     try {
         $results = SearchService::getSearchImplementation()->query($query, $class, $startRow, $rows);
         $totalPages = is_null($rows) ? 1 : ceil($results->getTotalCount() / $rows);
         $response = new StdClass();
         if (count($results) > 0) {
             foreach ($results as $uri) {
                 $instance = new core_kernel_classes_Resource($uri);
                 $instanceProperties = array('id' => $instance->getUri(), RDFS_LABEL => $instance->getLabel());
                 $response->data[] = $instanceProperties;
             }
         }
         $response->success = true;
         $response->page = empty($response->data) ? 0 : $page;
         $response->total = $totalPages;
         $response->records = count($results);
         $this->returnJson($response, 200);
     } catch (SyntaxException $e) {
         $this->returnJson(array('success' => false, 'msg' => $e->getUserMessage()));
     }
 }
 /**
  * Creates a new delivery
  * 
  * @param core_kernel_classes_Class $deliveryClass
  * @param core_kernel_classes_Resource $test
  * @param array $properties Array of properties of delivery
  * @return common_report_Report
  */
 public static function create(\core_kernel_classes_Class $deliveryClass, \core_kernel_classes_Resource $test, $properties = array())
 {
     \common_Logger::i('Creating delivery with ' . $test->getLabel() . ' under ' . $deliveryClass->getLabel());
     $storage = new TrackedStorage();
     $testCompilerClass = \taoTests_models_classes_TestsService::singleton()->getCompilerClass($test);
     $compiler = new $testCompilerClass($test, $storage);
     $report = $compiler->compile();
     if ($report->getType() == \common_report_Report::TYPE_SUCCESS) {
         //$tz = new \DateTimeZone(\common_session_SessionManager::getSession()->getTimeZone());
         $tz = new \DateTimeZone('UTC');
         if (!empty($properties[TAO_DELIVERY_START_PROP])) {
             $dt = new \DateTime($properties[TAO_DELIVERY_START_PROP], $tz);
             $properties[TAO_DELIVERY_START_PROP] = (string) $dt->getTimestamp();
         }
         if (!empty($properties[TAO_DELIVERY_END_PROP])) {
             $dt = new \DateTime($properties[TAO_DELIVERY_END_PROP], $tz);
             $properties[TAO_DELIVERY_END_PROP] = (string) $dt->getTimestamp();
         }
         $serviceCall = $report->getData();
         $properties[PROPERTY_COMPILEDDELIVERY_DIRECTORY] = $storage->getSpawnedDirectoryIds();
         $compilationInstance = DeliveryAssemblyService::singleton()->createAssemblyFromServiceCall($deliveryClass, $serviceCall, $properties);
         $report->setData($compilationInstance);
     }
     return $report;
 }
 /**
  * 
  * @author Lionel Lecaque, lionel@taotesting.com
  */
 public function wizard()
 {
     $this->defaultData();
     try {
         $formContainer = new \taoSimpleDelivery_actions_form_WizardForm(array('class' => $this->getCurrentClass()));
         $myForm = $formContainer->getForm();
         if ($myForm->isValid() && $myForm->isSubmited()) {
             $label = $myForm->getValue('label');
             $test = new core_kernel_classes_Resource($myForm->getValue('test'));
             $label = __("Delivery of %s", $test->getLabel());
             $deliveryClass = new core_kernel_classes_Class($myForm->getValue('classUri'));
             $report = taoSimpleDelivery_models_classes_SimpleDeliveryService::singleton()->create($deliveryClass, $test, $label);
             if ($report->getType() == common_report_Report::TYPE_SUCCESS) {
                 $assembly = $report->getdata();
                 $this->setData("selectNode", tao_helpers_Uri::encode($assembly->getUri()));
                 $this->setData('reload', true);
                 $this->setData('message', __('Delivery created'));
                 $this->setData('formTitle', __('Create a new delivery'));
                 $this->setView('form.tpl', 'tao');
             } else {
                 $this->setData('report', $report);
                 $this->setData('title', __('Error'));
                 $this->setView('report.tpl', 'tao');
             }
         } else {
             $this->setData('myForm', $myForm->render());
             $this->setData('formTitle', __('Create a new delivery'));
             $this->setView('form.tpl', 'tao');
         }
     } catch (taoSimpleDelivery_actions_form_NoTestsException $e) {
         $this->setView('wizard_error.tpl');
     }
 }
Ejemplo n.º 5
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());
     }
 }
Ejemplo n.º 6
0
 /**
  * @requiresRight id WRITE
  */
 public function commitResource()
 {
     $resource = new \core_kernel_classes_Resource($this->getRequestParameter('id'));
     // prevent escaping on input
     $message = isset($_POST['message']) ? $_POST['message'] : '';
     $revision = $this->getRevisionService()->commit($resource->getUri(), $message);
     $this->returnJson(array('success' => true, 'id' => $revision->getVersion(), 'modified' => \tao_helpers_Date::displayeDate($revision->getDateCreated()), 'author' => UserHelper::renderHtmlUser($revision->getAuthorId()), 'message' => $revision->getMessage(), 'commitMessage' => __('%s has been committed', $resource->getLabel())));
 }
 /**
  *
  * @param common_persistence_KeyValuePersistence $persistence
  * @param unknown $userId
  * @param core_kernel_classes_Resource $assembly
  * @return DeliveryExecution
  */
 public static function spawn(common_persistence_KeyValuePersistence $persistence, $userId, core_kernel_classes_Resource $assembly)
 {
     $identifier = self::DELIVERY_EXECUTION_PREFIX . common_Utils::getNewUri();
     $params = array(RDFS_LABEL => $assembly->getLabel(), PROPERTY_DELVIERYEXECUTION_DELIVERY => $assembly->getUri(), PROPERTY_DELVIERYEXECUTION_SUBJECT => $userId, PROPERTY_DELVIERYEXECUTION_START => microtime(), PROPERTY_DELVIERYEXECUTION_STATUS => InterfaceDeliveryExecution::STATE_ACTIVE);
     $kvDe = new static($persistence, $identifier, $params);
     $kvDe->save();
     $de = new DeliveryExecution($kvDe);
     return $de;
 }
 /**
  * Creates a new simple delivery
  * 
  * @param core_kernel_classes_Class $deliveryClass
  * @param core_kernel_classes_Resource $test
  * @param string $label
  * @return common_report_Report
  */
 public function create(core_kernel_classes_Class $deliveryClass, core_kernel_classes_Resource $test, $label)
 {
     common_Logger::i('Creating ' . $label . ' with ' . $test->getLabel() . ' under ' . $deliveryClass->getLabel());
     $contentClass = new core_kernel_classes_Class(CLASS_SIMPLE_DELIVERYCONTENT);
     $content = $contentClass->createInstanceWithProperties(array(PROPERTY_DELIVERYCONTENT_TEST => $test->getUri()));
     $report = TemplateAssemblyService::singleton()->createAssemblyByContent($deliveryClass, $content, array(RDFS_LABEL => $label));
     $content->delete();
     return $report;
 }
 /**
  * @deprecated
  * @see taoTests_models_classes_TestModel::getAuthoring()
  */
 public function getAuthoring(core_kernel_classes_Resource $test)
 {
     $process = $test->getUniquePropertyValue(new core_kernel_classes_Property(TEST_TESTCONTENT_PROP));
     $ext = common_ext_ExtensionsManager::singleton()->getExtensionById('taoWfAdvTest');
     $widget = new Renderer($ext->getConstant('DIR_VIEWS') . 'templates' . DIRECTORY_SEPARATOR . 'authoring.tpl');
     $widget->setData('processUri', $process->getUri());
     $widget->setData('label', __('Authoring %s', $test->getLabel()));
     return $widget->render();
 }
 /**
  * Builds a simple Diagram of the Process
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource process
  * @return string
  */
 public static function buildDiagramData(core_kernel_classes_Resource $process)
 {
     $returnValue = (string) '';
     common_Logger::i("Building diagram for " . $process->getLabel());
     $authoringService = wfAuthoring_models_classes_ProcessService::singleton();
     $activityService = wfEngine_models_classes_ActivityService::singleton();
     $connectorService = wfEngine_models_classes_ConnectorService::singleton();
     $activityCardinalityService = wfEngine_models_classes_ActivityCardinalityService::singleton();
     $activities = $authoringService->getActivitiesByProcess($process);
     $todo = array();
     foreach ($activities as $activity) {
         if ($activityService->isInitial($activity)) {
             $todo[] = $activity;
         }
     }
     $currentLevel = 0;
     $diagram = new wfAuthoring_models_classes_ProcessDiagram();
     $done = array();
     while (!empty($todo)) {
         $nextLevel = array();
         $posOnLevel = 0;
         foreach ($todo as $item) {
             $next = array();
             if ($activityService->isActivity($item)) {
                 // add this activity
                 $diagram->addActivity($item, 54 + 200 * $posOnLevel + 10 * $currentLevel, 35 + 80 * $currentLevel);
                 $next = array_merge($next, $activityService->getNextConnectors($item));
                 common_Logger::d('Activity added ' . $item->getUri());
             } elseif ($connectorService->isConnector($item)) {
                 // add this connector
                 $diagram->addConnector($item, 100 + 200 * $posOnLevel + 10 * $currentLevel, 40 + 80 * $currentLevel);
                 $next = array_merge($next, $connectorService->getNextActivities($item));
             } else {
                 common_Logger::w('unexpected ressource in process ' . $item->getUri());
             }
             //replace cardinalities
             foreach ($next as $key => $destination) {
                 if ($activityCardinalityService->isCardinality($destination)) {
                     // not represented on diagram
                     $next[$key] = $activityCardinalityService->getDestination($destination);
                 }
             }
             //add arrows
             foreach ($next as $destination) {
                 $diagram->addArrow($item, $destination);
             }
             $posOnLevel++;
             $nextLevel = array_merge($nextLevel, $next);
         }
         $done = array_merge($done, $todo);
         $todo = array_diff($nextLevel, $done);
         $currentLevel++;
     }
     $returnValue = $diagram->toJSON();
     return (string) $returnValue;
 }
Ejemplo n.º 11
0
 public function getStrings($values)
 {
     $strings = array();
     foreach ($values as $valueUri) {
         if (!empty($valueUri)) {
             $value = new \core_kernel_classes_Resource($valueUri);
             $strings[] = $value->getLabel();
         }
     }
     return $strings;
 }
 /**
  * Manage permissions
  * @requiresRight id GRANT
  */
 public function adminPermissions()
 {
     $resource = new \core_kernel_classes_Resource($this->getRequestParameter('id'));
     $accessRights = AdminService::getUsersPermissions($resource->getUri());
     $this->setData('privileges', PermissionProvider::getRightLabels());
     $users = array();
     $roles = array();
     foreach ($accessRights as $uri => $privileges) {
         $identity = new \core_kernel_classes_Resource($uri);
         if ($identity->isInstanceOf(\tao_models_classes_RoleService::singleton()->getRoleClass())) {
             $roles[$uri] = array('label' => $identity->getLabel(), 'privileges' => $privileges);
         } else {
             $users[$uri] = array('label' => $identity->getLabel(), 'privileges' => $privileges);
         }
     }
     $this->setData('users', $users);
     $this->setData('roles', $roles);
     $this->setData('isClass', $resource->isClass());
     $this->setData('uri', $resource->getUri());
     $this->setData('label', _dh($resource->getLabel()));
     $this->setView('AdminAccessController/index.tpl');
 }
Ejemplo n.º 13
0
 /**
  * @requiresRight id WRITE
  */
 public function index()
 {
     $resource = new \core_kernel_classes_Resource($this->getRequestParameter('id'));
     $revisions = RepositoryProxy::getRevisions($resource->getUri());
     $returnRevision = array();
     foreach ($revisions as $revision) {
         $returnRevision[] = array('id' => $revision->getVersion(), 'modified' => \tao_helpers_Date::displayeDate($revision->getDateCreated()), 'author' => UserHelper::renderHtmlUser($revision->getAuthorId()), 'message' => _dh($revision->getMessage()));
     }
     $this->setData('resourceLabel', _dh($resource->getLabel()));
     $this->setData('id', $resource->getUri());
     $this->setData('revisions', $returnRevision);
     $this->setView('History/index.tpl');
 }
 /**
  * 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;
 }
Ejemplo n.º 15
0
 /**
  * overwrite the parent defaultData, adding the item label to be sent to the view
  */
 protected function defaultData()
 {
     parent::defaultData();
     if ($this->hasRequestParameter('uri')) {
         $uri = $this->getRequestParameter('uri');
         $classUri = $this->getRequestParameter('classUri');
         if (!empty($uri)) {
             $item = new core_kernel_classes_Resource(tao_helpers_Uri::decode($uri));
             $this->setData('label', $item->getLabel());
             $this->setData('authoringUrl', _url('authoring', 'Items', 'taoItems', array('uri' => $uri, 'classUri' => $classUri)));
             $this->setData('previewUrl', $this->getClassService()->getPreviewUrl($item));
         }
     }
 }
Ejemplo n.º 16
0
 /**
  * Short description of method createSPX
  *
  * @access public
  * @author firstname and lastname of author, <*****@*****.**>
  * @param  Resource $subject
  * @param  Property $predicate
  * @return core_kernel_rules_Term
  */
 public static function createSPX(core_kernel_classes_Resource $subject, core_kernel_classes_Property $predicate)
 {
     $returnValue = null;
     $termSPXClass = new core_kernel_classes_Class(CLASS_TERM_SUJET_PREDICATE_X, __METHOD__);
     $label = 'Def Term SPX Label : ' . $subject->getLabel() . ' - ' . $predicate->getLabel();
     $comment = 'Def Term SPX Label : ' . $subject->getUri() . ' ' . $predicate->getUri();
     $SPXResource = core_kernel_classes_ResourceFactory::create($termSPXClass, $label, $comment);
     $returnValue = new core_kernel_rules_Term($SPXResource->getUri());
     $subjectProperty = new core_kernel_classes_Property(PROPERTY_TERM_SPX_SUBJET, __METHOD__);
     $predicateProperty = new core_kernel_classes_Property(PROPERTY_TERM_SPX_PREDICATE, __METHOD__);
     $returnValue->setPropertyValue($subjectProperty, $subject->getUri());
     $returnValue->setPropertyValue($predicateProperty, $predicate->getUri());
     return $returnValue;
 }
Ejemplo n.º 17
0
 /**
  * Short description of method getValue
  *
  * @access public
  * @author Somsack Sipasseuth, <*****@*****.**>
  * @param  string rowId
  * @param  string columnId
  * @param  string data
  * @return mixed
  */
 public function getValue($rowId, $columnId, $data = null)
 {
     $returnValue = null;
     if (!empty($data) && is_string($data) && common_Utils::isUri($data)) {
         $data = new core_kernel_classes_Resource($data);
     }
     if ($data instanceof core_kernel_classes_Resource) {
         $returnValue = $data->getLabel();
     } else {
         $returnValue = $data;
         //return the data, unaltered
     }
     return $returnValue;
 }
 /**
  * Creates a new simple delivery
  * 
  * @param core_kernel_classes_Class $deliveryClass
  * @param core_kernel_classes_Resource $test
  * @param string $label
  * @return common_report_Report
  */
 public static function create(core_kernel_classes_Class $deliveryClass, core_kernel_classes_Resource $test, $label)
 {
     common_Logger::i('Creating ' . $label . ' with ' . $test->getLabel() . ' under ' . $deliveryClass->getLabel());
     $storage = new taoDelivery_models_classes_TrackedStorage();
     $testCompilerClass = taoTests_models_classes_TestsService::singleton()->getCompilerClass($test);
     $compiler = new $testCompilerClass($test, $storage);
     $report = $compiler->compile();
     if ($report->getType() == common_report_Report::TYPE_SUCCESS) {
         $serviceCall = $report->getData();
         $properties = array(RDFS_LABEL => $label, PROPERTY_COMPILEDDELIVERY_DIRECTORY => $storage->getSpawnedDirectoryIds());
         $compilationInstance = taoDelivery_models_classes_DeliveryAssemblyService::singleton()->createAssemblyFromServiceCall($deliveryClass, $serviceCall, $properties);
         $report->setData($compilationInstance);
     }
     return $report;
 }
 /**
  * Short description of method initElements
  *
  * @access protected
  * @author Joel Bout, <*****@*****.**>
  * @return mixed
  */
 protected function initElements()
 {
     $userElement = \tao_helpers_form_FormFactory::getElement('user', 'Hidden');
     $userElement->setValue(\common_session_SessionManager::getSession()->getUserUri());
     $this->form->addElement($userElement);
     $roleOptions = array();
     foreach (\common_session_SessionManager::getSession()->getUserRoles() as $role) {
         $roleResource = new \core_kernel_classes_Resource($role);
         $roleOptions[$role] = $roleResource->getLabel();
     }
     $roleElement = \tao_helpers_form_FormFactory::getElement('rolefilter', 'Checkbox');
     $roleElement->setDescription(__('Keep roles'));
     $roleElement->setOptions($roleOptions);
     $roleElement->setValues(array_keys($roleOptions));
     $this->form->addElement($roleElement);
 }
 /**
  * Short description of method createOperation
  *
  * @access public
  * @author firstname and lastname of author, <*****@*****.**>
  * @param  Term term1
  * @param  Term term2
  * @param  Resource operator
  * @return core_kernel_rules_Operation
  */
 public static function createOperation(core_kernel_rules_Term $term1, core_kernel_rules_Term $term2, core_kernel_classes_Resource $operator)
 {
     $returnValue = null;
     $operationClass = new core_kernel_classes_Class(CLASS_OPERATION, __METHOD__);
     $label = 'Def Operation Label ' . $term1->getLabel() . ' ' . $operator->getLabel() . ' ' . $term2->getLabel();
     $comment = 'Def Operation Comment ' . $term1->getUri() . ' ' . $operator->getUri() . ' ' . $term2->getUri();
     $operatorProperty = new core_kernel_classes_Property(PROPERTY_OPERATION_OPERATOR, __METHOD__);
     $firstOperand = new core_kernel_classes_Property(PROPERTY_OPERATION_FIRST_OP, __METHOD__);
     $secondOperand = new core_kernel_classes_Property(PROPERTY_OPERATION_SECND_OP, __METHOD__);
     $termOperationInstance = core_kernel_classes_ResourceFactory::create($operationClass, $label, $comment);
     $returnValue = new core_kernel_rules_Operation($termOperationInstance->getUri());
     $returnValue->debug = __METHOD__;
     $returnValue->setPropertyValue($operatorProperty, $operator->getUri());
     $returnValue->setPropertyValue($firstOperand, $term1->getUri());
     $returnValue->setPropertyValue($secondOperand, $term2->getUri());
     return $returnValue;
 }
 /**
  * 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;
 }
Ejemplo n.º 22
0
 /**
  * Render the tree and the list to select and order the test related items 
  * @return void
  */
 public function selectItems()
 {
     $this->setData('uri', $this->getRequestParameter('uri'));
     $this->setData('classUri', $this->getRequestParameter('classUri'));
     $test = $this->getCurrentInstance();
     $allItems = array();
     foreach ($this->service->getAllItems() as $itemUri => $itemLabel) {
         $allItems['item_' . tao_helpers_Uri::encode($itemUri)] = $itemLabel;
     }
     $this->setData('allItems', json_encode($allItems));
     $relatedItems = tao_helpers_Uri::encodeArray($this->service->getTestItems($test, true), tao_helpers_Uri::ENCODE_ARRAY_VALUES);
     $this->setData('relatedItems', json_encode($relatedItems));
     $itemSequence = array();
     foreach ($relatedItems as $index => $itemUri) {
         $item = new core_kernel_classes_Resource($itemUri);
         $itemSequence[$index] = array('uri' => tao_helpers_Uri::encode($itemUri), 'label' => $item->getLabel());
     }
     $this->setData('itemSequence', $itemSequence);
     $this->setView('items.tpl');
 }
 /**
  * Short description of method getValue
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  string rowId
  * @param  string columnId
  * @param  string data
  * @return mixed
  */
 public function getValue($rowId, $columnId, $data = null)
 {
     $returnValue = null;
     if (isset($this->data[$rowId])) {
         //return values:
         if (isset($this->data[$rowId][$columnId])) {
             $returnValue = $this->data[$rowId][$columnId];
         }
     } else {
         if (common_Utils::isUri($rowId)) {
             $excludedProperties = is_array($this->options) && isset($this->options['excludedProperties']) ? $this->options['excludedProperties'] : array();
             $processExecutionService = wfEngine_models_classes_ProcessExecutionService::singleton();
             $processInstance = new core_kernel_classes_Resource($rowId);
             $this->data[$rowId] = array();
             if (!in_array(RDFS_LABEL, $excludedProperties)) {
                 $this->data[$rowId][RDFS_LABEL] = $processInstance->getLabel();
             }
             if (!in_array(PROPERTY_PROCESSINSTANCES_STATUS, $excludedProperties)) {
                 $status = $processExecutionService->getStatus($processInstance);
                 $this->data[$rowId][PROPERTY_PROCESSINSTANCES_STATUS] = is_null($status) ? 'n/a' : $status->getLabel();
             }
             if (!in_array(PROPERTY_PROCESSINSTANCES_EXECUTIONOF, $excludedProperties)) {
                 $executionOf = $processExecutionService->getExecutionOf($processInstance);
                 $this->data[$rowId][PROPERTY_PROCESSINSTANCES_EXECUTIONOF] = is_null($executionOf) ? 'n/a' : $executionOf->getLabel();
             }
             if (!in_array(PROPERTY_PROCESSINSTANCES_TIME_STARTED, $excludedProperties)) {
                 $time = (string) $processInstance->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_PROCESSINSTANCES_TIME_STARTED));
                 $this->data[$rowId][PROPERTY_PROCESSINSTANCES_TIME_STARTED] = !empty($time) ? date('d-m-Y G:i:s', $time) : 'n/a';
             }
             //				if(!in_array(PROPERTY_PROCESSINSTANCES_CURRENTACTIVITYEXECUTIONS, $excludedProperties)){
             //					$currentActivityExecutions = $processExecutionService->getCurrentActivityExecutions($processInstance);
             //					$this->data[$rowId][PROPERTY_PROCESSINSTANCES_CURRENTACTIVITYEXECUTIONS] = new wfAuthoring_helpers_Monitoring_ActivityMonitoringGrid(array_keys($currentActivityExecutions));
             //				}
             if (isset($this->data[$rowId][$columnId])) {
                 $returnValue = $this->data[$rowId][$columnId];
             }
         }
     }
     return $returnValue;
 }
 public function run()
 {
     //set_time_limit(200);
     helpers_TimeOutHelper::setTimeOutLimit(helpers_TimeOutHelper::LONG);
     $processExecutionService = wfEngine_models_classes_ProcessExecutionService::singleton();
     $activityExecutionService = wfEngine_models_classes_ActivityExecutionService::singleton();
     $processDefinitionUri = $this->getRequestParameter('processDefinition');
     $processDefinition = new core_kernel_classes_Resource($processDefinitionUri);
     if (!$this->hasRequestParameter('serviceCallId')) {
         throw new common_exception_Error('No serviceCallId on service call');
     }
     $serviceService = tao_models_classes_service_StateStorage::singleton();
     $userUri = common_session_SessionManager::getSession()->getUserUri();
     $processExecutionUri = is_null($userUri) ? null : $serviceService->get($userUri, $this->getRequestParameter('serviceCallId'));
     if (is_null($processExecutionUri)) {
         $processExecName = $processDefinition->getLabel();
         $processExecComment = 'Created in Processes server on ' . date(DATE_ISO8601);
         if (isset($_REQUEST['processVariables']) && !empty($_REQUEST['processVariables'])) {
             $processVariables = json_decode($_REQUEST['processVariables'], true);
             $processVariables = is_array($processVariables) ? $processVariables : array();
         } else {
             // none provided
             $processVariables = array();
         }
         $newProcessExecution = $processExecutionService->createProcessExecution($processDefinition, $processExecName, $processExecComment, $processVariables);
         $processExecutionUri = $newProcessExecution->getUri();
         $serviceService->set($userUri, $this->getRequestParameter('serviceCallId'), $processExecutionUri);
     }
     $processExecution = new core_kernel_classes_Resource($processExecutionUri);
     //create nonce to initial activity executions:
     foreach ($processExecutionService->getCurrentActivityExecutions($processExecution) as $initialActivityExecution) {
         $activityExecutionService->createNonce($initialActivityExecution);
     }
     helpers_TimeOutHelper::reset();
     $param = array('processUri' => urlencode($processExecution->getUri()), 'standalone' => 'true');
     $this->redirect(tao_helpers_Uri::url('index', null, null, $param));
 }
Ejemplo n.º 25
0
 /**
  * (non-PHPdoc)
  * @see tao_actions_form_Instance::initElements()
  */
 protected function initElements()
 {
     parent::initElements();
     $elementId = tao_helpers_Uri::encode(TAO_ITEM_MODEL_PROPERTY);
     $ele = $this->form->getElement($elementId);
     $ele->feed();
     $modelUri = $ele->getEvaluatedValue();
     if (empty($modelUri)) {
         // remove deprecated models
         $statusProperty = new core_kernel_classes_Property(TAO_ITEM_MODEL_STATUS_PROPERTY);
         $options = array();
         foreach ($ele->getOptions() as $optUri => $optLabel) {
             $model = new core_kernel_classes_Resource(tao_helpers_Uri::decode($optUri));
             $status = $model->getOnePropertyValue($statusProperty);
             if (!is_null($status) && $status->getUri() != TAO_ITEM_MODEL_STATUS_DEPRECATED) {
                 $options[$optUri] = $optLabel;
             }
         }
         $ele->setOptions($options);
         if (count($options) === 1) {
             reset($options);
             $ele->setValue(key($options));
         }
     } else {
         // replace radio with hidden element
         $this->form->removeElement($elementId);
         $itemModelElt = tao_helpers_form_FormFactory::getElement($elementId, 'Hidden');
         $itemModelElt->setValue($modelUri);
         $this->form->addElement($itemModelElt);
         // display model label
         $model = new core_kernel_classes_Resource($modelUri);
         $itemModelLabelElt = tao_helpers_form_FormFactory::getElement('itemModelLabel', 'Label');
         $itemModelLabelElt->setDescription(__('Item Model'));
         $itemModelLabelElt->setValue($model->getLabel());
         $this->form->addElement($itemModelLabelElt);
     }
 }
 /**
  * Edit a media instance with a new file and/or a new language
  * @param $fileTmp
  * @param $instanceUri
  * @param $language
  * @return bool $instanceUri or false on error
  */
 public function editMediaInstance($fileTmp, $instanceUri, $language)
 {
     $instance = new \core_kernel_classes_Resource($instanceUri);
     $link = $instance->getUniquePropertyValue(new \core_kernel_classes_Property(MEDIA_LINK));
     $link = $link instanceof \core_kernel_classes_Resource ? $link->getUri() : (string) $link;
     $fileManager = FileManager::getFileManagementModel();
     $fileManager->deleteFile($link);
     $link = $fileManager->storeFile($fileTmp, $instance->getLabel());
     if ($link !== false) {
         //get the file MD5
         $md5 = md5_file($fileTmp);
         /** @var $instance  \core_kernel_classes_Resource */
         if (!is_null($instance) && $instance instanceof \core_kernel_classes_Resource) {
             $instance->editPropertyValues(new \core_kernel_classes_Property(MEDIA_LINK), $link);
             $instance->editPropertyValues(new \core_kernel_classes_Property(MEDIA_LANGUAGE), $language);
             $instance->editPropertyValues(new \core_kernel_classes_Property(MEDIA_MD5), $md5);
         }
         if (common_ext_ExtensionsManager::singleton()->isEnabled('taoRevision')) {
             \common_Logger::i('Auto generating revision');
             RevisionService::commit($instance, __('Imported new file'));
         }
     }
     return $link !== false ? true : false;
 }
 /**
  * Generate a delivery from test uri
  * Test uri has to be set and existing
  */
 public function generate()
 {
     try {
         if (!$this->hasRequestParameter(self::REST_DELIVERY_TEST_ID)) {
             throw new \common_exception_MissingParameter(self::REST_DELIVERY_TEST_ID, $this->getRequestURI());
         }
         $test = new \core_kernel_classes_Resource($this->getRequestParameter(self::REST_DELIVERY_TEST_ID));
         if (!$test->exists()) {
             throw new \common_exception_NotFound('Unable to find a test associated to the given uri.');
         }
         $label = 'Delivery of ' . $test->getLabel();
         $deliveryClass = new \core_kernel_classes_Class(CLASS_COMPILEDDELIVERY);
         /** @var \common_report_Report $report */
         $report = SimpleDeliveryFactory::create($deliveryClass, $test, $label);
         if ($report->getType() == \common_report_Report::TYPE_ERROR) {
             \common_Logger::i('Unable to generate delivery execution ' . 'into taoDeliveryRdf::RestDelivery for test uri ' . $test->getUri());
             throw new \common_Exception('Unable to generate delivery execution.');
         }
         $delivery = $report->getData();
         $this->returnSuccess(array('delivery' => $delivery->getUri()));
     } catch (\Exception $e) {
         $this->returnFailure($e);
     }
 }
Ejemplo n.º 28
0
 /**
  * Search results
  * The search is pagintaed and initiated by the datatable component.
  */
 public function search()
 {
     $params = $this->getRequestParameter('params');
     $query = $params['query'];
     $class = new core_kernel_classes_Class($params['rootNode']);
     try {
         $results = SearchService::getSearchImplementation()->query($query, $class);
         $response = new StdClass();
         if (count($results) > 0) {
             foreach ($results as $uri) {
                 $instance = new core_kernel_classes_Resource($uri);
                 $instanceProperties = array('id' => $instance->getUri(), RDFS_LABEL => $instance->getLabel());
                 $response->data[] = $instanceProperties;
             }
         }
         $response->success = true;
         $response->page = 1;
         $response->total = 1;
         $response->records = count($results);
         $this->returnJson($response, 200);
     } catch (SyntaxException $e) {
         $this->returnJson(array('success' => false, 'msg' => $e->getUserMessage()));
     }
 }
 /**
  * (non-PHPdoc)
  * @see core_kernel_classes_Resource::getLabel()
  */
 public function getLabel()
 {
     return parent::getLabel();
 }
 /**
  * Gets the section map for navigation between test parts, sections and items.
  *
  * @param AssessmentTestSession $session
  * @return array A navigator map (parts, sections, items so on)
  */
 private static function getNavigatorMap(AssessmentTestSession $session)
 {
     // get jumps
     $jumps = $session->getPossibleJumps();
     // no jumps, notify linear-mode
     if (!$jumps->count()) {
         return NavigationMode::LINEAR;
     }
     $jumpsMapInfo = self::getJumpsMap($session, $jumps);
     $jumpsMap = $jumpsMapInfo['map'];
     $numberItemsFlagged = $jumpsMapInfo['flagged'];
     // the active test-part identifier
     $activePart = $session->getCurrentTestPart()->getIdentifier();
     // the active section identifier
     $activeSection = $session->getCurrentAssessmentSection()->getIdentifier();
     $route = $session->getRoute();
     $activeItem = $session->getCurrentAssessmentItemRef()->getIdentifier();
     if (isset($jumpsMap[$activePart][$activeSection][$activeItem])) {
         $jumpsMap[$activePart][$activeSection][$activeItem]['active'] = true;
     }
     // current position
     $oldPosition = $route->getPosition();
     $route->setPosition($oldPosition);
     // get config for the sequence number option
     $config = common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest')->getConfig('testRunner');
     $forceTitles = !empty($config['test-taker-review-force-title']);
     $uniqueTitle = isset($config['test-taker-review-item-title']) ? $config['test-taker-review-item-title'] : '%d';
     $returnValue = array();
     $testParts = array();
     $testPartIdx = 0;
     $numberItemsPart = 0;
     $numberItemsSection = 0;
     $numberCompletedPart = 0;
     $numberCompletedSection = 0;
     $numberPresentedPart = 0;
     $numberPresentedSection = 0;
     $numberFlaggedPart = 0;
     $numberFlaggedSection = 0;
     $itemPositionPart = 0;
     $itemPositionSection = 0;
     $itemPosition = $session->getRoute()->getPosition();
     foreach ($jumps as $jump) {
         $testPart = $jump->getTarget()->getTestPart();
         $id = $testPart->getIdentifier();
         if (isset($testParts[$id])) {
             continue;
         }
         $sections = array();
         if ($testPart->getNavigationMode() == NavigationMode::NONLINEAR) {
             $firstPositionPart = PHP_INT_MAX;
             foreach ($testPart->getAssessmentSections() as $sectionId => $section) {
                 $completed = 0;
                 $presented = 0;
                 $flagged = 0;
                 $items = array();
                 $firstPositionSection = PHP_INT_MAX;
                 $positionInSection = 0;
                 foreach ($section->getSectionParts() as $itemId => $item) {
                     if (isset($jumpsMap[$id][$sectionId][$itemId])) {
                         $jumpInfo = $jumpsMap[$id][$sectionId][$itemId];
                         $resItem = new \core_kernel_classes_Resource(strstr($item->getHref(), '|', true));
                         if ($jumpInfo['answered']) {
                             ++$completed;
                         }
                         if ($jumpInfo['viewed']) {
                             ++$presented;
                         }
                         if ($jumpInfo['flagged']) {
                             ++$flagged;
                         }
                         if ($forceTitles) {
                             $label = sprintf($uniqueTitle, ++$positionInSection);
                         } else {
                             $label = $resItem->getLabel();
                         }
                         $items[] = array_merge(array('id' => $itemId, 'label' => $label), $jumpInfo);
                         $firstPositionPart = min($firstPositionPart, $jumpInfo['position']);
                         $firstPositionSection = min($firstPositionSection, $jumpInfo['position']);
                     }
                 }
                 $sectionData = array('id' => $sectionId, 'active' => $sectionId === $activeSection, 'label' => $section->getTitle(), 'answered' => $completed, 'items' => $items);
                 $sections[] = $sectionData;
                 if ($sectionData['active']) {
                     $numberItemsSection = count($items);
                     $itemPositionSection = $itemPosition - $firstPositionSection;
                     $numberCompletedSection = $completed;
                     $numberPresentedSection = $presented;
                     $numberFlaggedSection = $flagged;
                 }
                 if ($id === $activePart) {
                     $numberItemsPart += count($items);
                     $numberCompletedPart += $completed;
                     $numberPresentedPart += $presented;
                     $numberFlaggedPart += $flagged;
                 }
             }
             if ($id === $activePart) {
                 $itemPositionPart = $itemPosition - $firstPositionPart;
             }
         }
         $data = array('id' => $id, 'sections' => $sections, 'active' => $id === $activePart, 'label' => __('Part %d', ++$testPartIdx));
         if (empty($sections)) {
             $item = current(current($jumpsMap[$id]));
             $data['position'] = $item['position'];
             $data['itemId'] = key(current($jumpsMap[$id]));
         }
         $returnValue[] = $data;
         $testParts[$id] = false;
     }
     return array('map' => $returnValue, 'numberItemsFlagged' => $numberItemsFlagged, 'numberItemsPart' => $numberItemsPart, 'numberItemsSection' => $numberItemsSection, 'numberCompletedPart' => $numberCompletedPart, 'numberCompletedSection' => $numberCompletedSection, 'numberPresentedPart' => $numberPresentedPart, 'numberPresentedSection' => $numberPresentedSection, 'numberFlaggedPart' => $numberFlaggedPart, 'numberFlaggedSection' => $numberFlaggedSection, 'itemPositionPart' => $itemPositionPart, 'itemPositionSection' => $itemPositionSection);
 }