public function get($uri) { $returnData = array(); $deliveryExecution = \taoDelivery_models_classes_execution_ServiceProxy::singleton()->getDeliveryExecution($uri); $delivery = $deliveryExecution->getDelivery(); $implementation = $this->getImplementationClass($delivery); foreach ($implementation->getRelatedItemCallIds($uri) as $callId) { $results = $implementation->getVariables($callId); $resource = array(); foreach ($results as $result) { $result = array_pop($result); if (isset($result->variable)) { $resource['value'] = $result->variable->getValue(); $resource['identifier'] = $result->variable->getIdentifier(); if (get_class($result->variable) === CLASS_RESPONSE_VARIABLE) { $type = "http://www.tao.lu/Ontologies/TAOResult.rdf#ResponseVariable"; } else { $type = "http://www.tao.lu/Ontologies/TAOResult.rdf#OutcomeVariable"; } $resource['type'] = new \core_kernel_classes_Class($type); $resource['epoch'] = $result->variable->getEpoch(); $resource['cardinality'] = $result->variable->getCardinality(); $resource['basetype'] = $result->variable->getBaseType(); } $returnData[$uri][] = $resource; } } return $returnData; }
/** * @param $params * @return Report */ public function __invoke($params) { $deliveryMonitoringService = $this->getServiceLocator()->get(DeliveryMonitoringService::CONFIG_ID); $deliveryClass = new \core_kernel_classes_Class('http://www.tao.lu/Ontologies/TAODelivery.rdf#AssembledDelivery'); $deliveries = $deliveryClass->getInstances(true); $deliveryExecutionService = \taoDelivery_models_classes_execution_ServiceProxy::singleton(); $this->report = new Report(Report::TYPE_INFO, 'Updating of delivery monitoring cache...'); foreach ($deliveries as $delivery) { if ($delivery->exists()) { $deliveryExecutions = $deliveryExecutionService->getExecutionsByDelivery($delivery); foreach ($deliveryExecutions as $deliveryExecution) { $data = $deliveryMonitoringService->getData($deliveryExecution, true); if ($deliveryMonitoringService->save($data)) { $this->report->add(new Report(Report::TYPE_SUCCESS, "Delivery execution {$deliveryExecution->getUri()} successfully updated.")); } else { $errors = $data->getErrors(); $errorsStr = " " . PHP_EOL; array_walk($errors, function ($val, $key) use(&$errorsStr) { $errorsStr .= " {$key} - {$val}" . PHP_EOL; }); $this->report->add(new Report(Report::TYPE_ERROR, "Delivery execution {$deliveryExecution->getUri()} was not updated. {$errorsStr}")); } } } } return $this->report; }
private function getIrregularities($delivery, $from = '', $to = '') { $export = array(array(__('date'), __('author'), __('test taker'), __('category'), __('subcategory'), __('comment'))); $deliveryLog = ServiceManager::getServiceManager()->get(DeliveryLog::SERVICE_ID); $service = ResultsService::singleton(); $implementation = $service->getReadableImplementation($delivery); $service->setImplementation($implementation); $results = $service->getImplementation()->getResultByDelivery(array($delivery->getUri())); foreach ($results as $res) { $deliveryExecution = \taoDelivery_models_classes_execution_ServiceProxy::singleton()->getDeliveryExecution($res['deliveryResultIdentifier']); $logs = $deliveryLog->get($deliveryExecution->getIdentifier(), 'TEST_IRREGULARITY'); foreach ($logs as $data) { $exportable = array(); if ((empty($from) || $data['created_at'] > $from) && (empty($to) || $data['created_at'] < $to)) { $testTaker = new \core_kernel_classes_Resource($res['testTakerIdentifier']); $author = new \core_kernel_classes_Resource($data['created_by']); $exportable[] = \tao_helpers_Date::displayeDate($data['created_at']); $exportable[] = $author->getLabel(); $exportable[] = $testTaker->getLabel(); $exportable[] = $data['data']['reason']['reasons']['category']; $exportable[] = isset($data['data']['reason']['reasons']['subCategory']) ? $data['data']['reason']['reasons']['subCategory'] : ''; $exportable[] = $data['data']['reason']['comment']; $export[] = $exportable; } } } return $export; }
public function isDeliveryExecutionAllowed(core_kernel_classes_Resource $delivery, User $user) { $userUri = $user->getIdentifier(); if (is_null($delivery)) { common_Logger::w("Attempt to start the compiled delivery " . $delivery->getUri() . " related to no delivery"); return false; } //first check the user is assigned if (!taoDelivery_models_classes_AssignmentService::singleton()->isUserAssigned($delivery, $user)) { common_Logger::w("User " . $userUri . " attempts to start the compiled delivery " . $delivery->getUri() . " he was not assigned to."); return false; } $settings = $this->getDeliverySettings($delivery); //check Tokens $usedTokens = count(taoDelivery_models_classes_execution_ServiceProxy::singleton()->getUserExecutions($delivery, $userUri)); if ($settings[TAO_DELIVERY_MAXEXEC_PROP] != 0 and $usedTokens >= $settings[TAO_DELIVERY_MAXEXEC_PROP]) { common_Logger::d("Attempt to start the compiled delivery " . $delivery->getUri() . "without tokens"); return false; } //check time $startDate = date_create('@' . $settings[TAO_DELIVERY_START_PROP]); $endDate = date_create('@' . $settings[TAO_DELIVERY_END_PROP]); if (!$this->areWeInRange($startDate, $endDate)) { common_Logger::d("Attempt to start the compiled delivery " . $delivery->getUri() . " at the wrong date"); return false; } return true; }
/** * * @param string $currentVersion * @return string $versionUpdatedTo */ public function update($initialVersion) { $currentVersion = $initialVersion; //migrate from 2.6 to 2.6.1 if ($currentVersion == '2.6') { //data upgrade OntologyUpdater::syncModels(); $currentVersion = '2.6.1'; } if ($currentVersion == '2.6.1') { $ext = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoDelivery'); $className = $ext->getConfig(\taoDelivery_models_classes_execution_ServiceProxy::CONFIG_KEY); if (is_string($className)) { $impl = null; switch ($className) { case 'taoDelivery_models_classes_execution_OntologyService': $impl = new \taoDelivery_models_classes_execution_OntologyService(); break; case 'taoDelivery_models_classes_execution_KeyValueService': $impl = new \taoDelivery_models_classes_execution_KeyValueService(array(\taoDelivery_models_classes_execution_KeyValueService::OPTION_PERSISTENCE => 'deliveryExecution')); break; default: \common_Logger::w('Unable to migrate custom execution service'); } if (!is_null($impl)) { $proxy = \taoDelivery_models_classes_execution_ServiceProxy::singleton(); $proxy->setImplementation($impl); $currentVersion = '2.6.2'; } } } return $currentVersion; }
/** * @param array $params * @return Report */ public function __invoke($params) { $this->params = $params; $this->report = new Report(Report::TYPE_INFO, 'Termination expired paused executions...'); common_Logger::d('Termination expired paused execution started at ' . date(DATE_RFC3339)); \common_ext_ExtensionsManager::singleton()->getExtensionById('taoDeliveryRdf'); \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest'); $deliveryExecutionService = \taoDelivery_models_classes_execution_ServiceProxy::singleton(); $count = 0; $testSessionService = ServiceManager::getServiceManager()->get(TestSessionService::SERVICE_ID); /** @var DeliveryMonitoringService $deliveryMonitoringService */ $deliveryMonitoringService = ServiceManager::getServiceManager()->get(DeliveryMonitoringService::CONFIG_ID); $deliveryExecutionsData = $deliveryMonitoringService->find([DeliveryMonitoringService::STATUS => [DeliveryExecution::STATE_ACTIVE, DeliveryExecution::STATE_PAUSED]]); foreach ($deliveryExecutionsData as $deliveryExecutionData) { $data = $deliveryExecutionData->get(); $deliveryExecution = $deliveryExecutionService->getDeliveryExecution($data[DeliveryMonitoringService::DELIVERY_EXECUTION_ID]); if ($testSessionService->isExpired($deliveryExecution)) { try { $this->terminateExecution($deliveryExecution); $count++; } catch (\Exception $e) { $this->addReport(Report::TYPE_ERROR, $e->getMessage()); } } } $msg = $count > 0 ? "{$count} executions has been terminated." : "Expired executions not found."; $this->addReport(Report::TYPE_INFO, $msg); common_Logger::d('Termination expired paused execution finished at ' . date(DATE_RFC3339)); return $this->report; }
/** * @return DeliveryExecution */ public function getDeliveryExecution() { if (is_null($this->deliveryExecution)) { $this->deliveryExecution = \taoDelivery_models_classes_execution_ServiceProxy::singleton()->getDeliveryExecution($this->deliveryExecutionId); } return $this->deliveryExecution; }
protected function getDescription() { $propMaxExec = $this->delivery->getOnePropertyValue(new core_kernel_classes_Property(TAO_DELIVERY_MAXEXEC_PROP)); $maxExecs = is_null($propMaxExec) ? 0 : $propMaxExec->literal; $user = \common_session_SessionManager::getSession()->getUser(); $countExecs = count(\taoDelivery_models_classes_execution_ServiceProxy::singleton()->getUserExecutions($this->delivery, $user->getIdentifier())); return $this->buildDescriptionFromData($this->startTime, $this->endTime, $countExecs, $maxExecs); }
public function get($uri, $groupBy = self::GROUP_BY_DELIVERY) { $returnData = array(); $deliveryExecution = \taoDelivery_models_classes_execution_ServiceProxy::singleton()->getDeliveryExecution($uri); $delivery = $deliveryExecution->getDelivery(); $resultService = $this->getServiceLocator()->get(ResultServerService::SERVICE_ID); $implementation = $resultService->getResultStorage($delivery->getUri()); return $this->format($implementation, $uri); }
public function run() { taoUpdate_helpers_ExtensionConfigUpdater::update('taoQtiTest', ROOT_PATH . 'taoQtiTest/includes/config.php'); taoUpdate_helpers_ExtensionConfigUpdater::update('taoItems', ROOT_PATH . 'taoItems/includes/config.php'); taoUpdate_helpers_ExtensionConfigUpdater::update('tao', ROOT_PATH . 'tao/includes/config.php'); taoQtiTest_models_classes_QtiTestService::singleton()->setQtiTestAcceptableLatency('PT5S'); taoDelivery_models_classes_execution_ServiceProxy::singleton()->setImplementation('taoDelivery_models_classes_execution_OntologyService'); $resultServer = new core_kernel_classes_Resource('http://www.tao.lu/Ontologies/TAOResult.rdf#taoResultServer'); taoResultServer_models_classes_ResultServerAuthoringService::singleton()->setDefaultResultServer($resultServer); }
protected function getDescription() { $deliveryProps = $this->delivery->getPropertiesValues(array(new core_kernel_classes_Property(TAO_DELIVERY_MAXEXEC_PROP), new core_kernel_classes_Property(TAO_DELIVERY_START_PROP), new core_kernel_classes_Property(TAO_DELIVERY_END_PROP))); $propMaxExec = current($deliveryProps[TAO_DELIVERY_MAXEXEC_PROP]); $propStartExec = current($deliveryProps[TAO_DELIVERY_START_PROP]); $propEndExec = current($deliveryProps[TAO_DELIVERY_END_PROP]); $startTime = (!is_object($propStartExec) or $propStartExec == "") ? null : $propStartExec->literal; $endTime = (!is_object($propEndExec) or $propEndExec == "") ? null : $propEndExec->literal; $maxExecs = (!is_object($propMaxExec) or $propMaxExec == "") ? 0 : $propMaxExec->literal; $countExecs = count(\taoDelivery_models_classes_execution_ServiceProxy::singleton()->getUserExecutions($this->delivery, $this->getUserId())); return $this->buildDescriptionFromData($startTime, $endTime, $countExecs, $maxExecs); }
public static function testStateChange(QtiTestChangeEvent $event) { /** @var DeliveryMonitoringService $service */ $service = ServiceManager::getServiceManager()->get(DeliveryMonitoringService::CONFIG_ID); $deliveryExecution = \taoDelivery_models_classes_execution_ServiceProxy::singleton()->getDeliveryExecution($event->getServiceCallId()); $data = $service->getData($deliveryExecution, false); $data->setTestSession($event->getSession()); $data->updateData([DeliveryMonitoringService::STATUS, DeliveryMonitoringService::CURRENT_ASSESSMENT_ITEM, DeliveryMonitoringService::START_TIME, DeliveryMonitoringService::END_TIME, DeliveryMonitoringService::REMAINING_TIME, DeliveryMonitoringService::EXTRA_TIME]); $success = $service->save($data); if (!$success) { \common_Logger::w('monitor cache for teststate could not be updated'); } }
/** * 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 $user) { $deliveryExecutionService = taoDelivery_models_classes_execution_ServiceProxy::singleton(); $started = array_merge($deliveryExecutionService->getActiveDeliveryExecutions($user->getIdentifier()), $deliveryExecutionService->getPausedDeliveryExecutions($user->getIdentifier())); $resumable = array(); foreach ($started as $deliveryExecution) { $delivery = $deliveryExecution->getDelivery(); if ($delivery->exists()) { $resumable[] = $deliveryExecution; } } return $resumable; }
/** * Returns an array of taoDelivery_models_classes_execution_DeliveryExecution * * @param core_kernel_classes_Resource $delivery * @param core_kernel_classes_Resource $link * @param string $userId * @return array */ public function getLinkedDeliveryExecutions(core_kernel_classes_Resource $delivery, core_kernel_classes_Resource $link, $userId) { $class = new core_kernel_classes_Class(CLASS_LTI_DELIVERYEXECUTION_LINK); $links = $class->searchInstances(array(PROPERTY_LTI_DEL_EXEC_LINK_USER => $userId, PROPERTY_LTI_DEL_EXEC_LINK_LINK => $link), array('like' => false)); $returnValue = array(); foreach ($links as $link) { $execId = $link->getUniquePropertyValue(new \core_kernel_classes_Property(PROPERTY_LTI_DEL_EXEC_LINK_EXEC_ID)); $deliveryExecution = \taoDelivery_models_classes_execution_ServiceProxy::singleton()->getDeliveryExecution($execId); if ($delivery->equals($deliveryExecution->getDelivery())) { $returnValue[] = $deliveryExecution; } } return $returnValue; }
/** * 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 $user) { $deliveryExecutionService = \taoDelivery_models_classes_execution_ServiceProxy::singleton(); $userUri = $user->getIdentifier(); $started = array_merge($deliveryExecutionService->getActiveDeliveryExecutions($userUri), $deliveryExecutionService->getPausedDeliveryExecutions($userUri), $deliveryExecutionService->getDeliveryExecutionsByStatus($userUri, DeliveryExecution::STATE_AWAITING), $deliveryExecutionService->getDeliveryExecutionsByStatus($userUri, DeliveryExecution::STATE_AUTHORIZED)); $eligibilityService = EligibilityService::singleton(); $resumable = array(); foreach ($started as $deliveryExecution) { $delivery = $deliveryExecution->getDelivery(); if ($delivery->exists() && $eligibilityService->isDeliveryEligible($delivery, $user)) { $resumable[] = $deliveryExecution; } } return $resumable; }
/** * Edit a delivery instance * * @access public * @author CRP Henri Tudor - TAO Team - {@link http://www.tao.lu} * @return void */ public function editDelivery() { $clazz = $this->getCurrentClass(); $delivery = $this->getCurrentInstance(); $formContainer = new taoDelivery_actions_form_Delivery($clazz, $delivery); $myForm = $formContainer->getForm(); $myForm->evaluate(); if ($myForm->isSubmited()) { if ($myForm->isValid()) { $propertyValues = $myForm->getValues(); // then save the property values as usual $binder = new tao_models_classes_dataBinding_GenerisFormDataBinder($delivery); $delivery = $binder->bind($propertyValues); $this->setData("selectNode", tao_helpers_Uri::encode($delivery->getUri())); $this->setData('message', __('Delivery saved')); $this->setData('reload', true); } } $this->setData('label', $delivery->getLabel()); // history $this->setData('date', taoDelivery_models_classes_DeliveryAssemblyService::singleton()->getCompilationDate($delivery)); if (taoDelivery_models_classes_execution_ServiceProxy::singleton()->implementsMonitoring()) { $execs = taoDelivery_models_classes_execution_ServiceProxy::singleton()->getExecutionsByDelivery($delivery); $this->setData('exec', count($execs)); } // define the groups related to the current delivery $property = new core_kernel_classes_Property(PROPERTY_GROUP_DELVIERY); $tree = tao_helpers_form_GenerisTreeForm::buildReverseTree($delivery, $property); $tree->setTitle(__('Assigned to')); $tree->setTemplate(Template::getTemplate('widgets/assignGroup.tpl')); $this->setData('groupTree', $tree->render()); // testtaker brick $this->setData('assemblyUri', $delivery->getUri()); // define the subjects excluded from the current delivery $property = new core_kernel_classes_Property(TAO_DELIVERY_EXCLUDEDSUBJECTS_PROP); $excluded = $delivery->getPropertyValues($property); $this->setData('ttexcluded', count($excluded)); $users = taoDelivery_models_classes_AssignmentService::singleton()->getAssignedUsers($delivery); $assigned = array_diff(array_unique($users), $excluded); $this->setData('ttassigned', count($assigned)); $this->setData('formTitle', __('Properties')); $this->setData('myForm', $myForm->render()); if (common_ext_ExtensionsManager::singleton()->isEnabled('taoCampaign')) { $this->setData('campaign', taoCampaign_helpers_Campaign::renderCampaignTree($delivery)); } $this->setView('Delivery/editDelivery.tpl'); }
/** * @param array $sessions List of session ids * @param array $options The following option is handled: * - periodStart: a date/time string. * - periodEnd: a date/time string. * - detailed: whether to retrieve detailed or brief report. Defaults to false (brief). * - sortBy: column name string. * - sortOrder: order direction (asc|desc) string. * @return array */ public function getSessionsHistory(array $sessions, $options) { $history = []; $periodStart = $this->getPeriodStart($options); $periodEnd = $this->getPeriodEnd($options); $deliveryLog = $this->getServiceManager()->get(DeliveryLog::SERVICE_ID); //empty array means that all events (except listed in self::$eventsToExclude) will be represented in the report $eventsToInclude = $options['detailed'] ? [] : self::$briefEvents; foreach ($sessions as $sessionUri) { $deliveryExecution = \taoDelivery_models_classes_execution_ServiceProxy::singleton()->getDeliveryExecution($sessionUri); $logs = $deliveryLog->get($deliveryExecution->getIdentifier()); $exportable = []; foreach ($logs as $data) { $eventId = isset($data['data']['type']) ? $data['data']['type'] : $data[DeliveryLog::EVENT_ID]; $eventName = strtolower(explode('.', $eventId)[0]); if (!empty($eventsToInclude) && !in_array($eventName, $eventsToInclude) || in_array($eventName, self::$eventsToExclude)) { continue; } $author = $this->getAuthor($data); $details = $this->getEventDetails($data); $context = $this->getEventContext($data); $role = $this->getUserRole($author); $exportable['timestamp'] = isset($data['data']['timestamp']) ? $data['data']['timestamp'] : $data['created_at']; if ($periodStart && $exportable['timestamp'] < $periodStart || $periodEnd && $exportable['timestamp'] > $periodEnd) { continue; } $exportable['date'] = DateHelper::displayeDate($exportable['timestamp']); $exportable['role'] = $role; $exportable['actor'] = _dh($author->getLabel()); $exportable['event'] = $eventId; $exportable['details'] = $details; $exportable['context'] = $context; $history[] = $exportable; } } $this->sortHistory($history, $options); return $history; }
/** * Delete a result or a result class * @throws Exception * @return string json {'deleted' : true} */ public function delete() { if (!tao_helpers_Request::isAjax()) { throw new Exception("wrong request mode"); } $deliveryExecutionUri = tao_helpers_Uri::decode($this->getRequestParameter('uri')); $de = \taoDelivery_models_classes_execution_ServiceProxy::singleton()->getDeliveryExecution($deliveryExecutionUri); try { $implementation = $this->getResultStorage($de->getDelivery()); $this->getClassService()->setImplementation($implementation); $deleted = $this->getClassService()->deleteResult($deliveryExecutionUri); $this->returnJson(array('deleted' => $deleted)); } catch (\common_exception_Error $e) { $this->returnJson(array('error' => $e->getMessage())); } }
/** * Find delivery monitoring data. * * Examples: * Find by delivery execution id: * ------------------------------ * ```php * $deliveryMonitoringService->find([ * ['delivery_execution_id' => 'http://sample/first.rdf#i1450191587554175'] * ]); * ``` * * Find by two fields with `AND` operator * -------------------------------------- * ```php * $deliveryMonitoringService->find([ * ['status' => 'active'], * ['start_time' => '>1450428401'], * ]); * ``` * * Find by two fields with `OR` operator * ------------------------------------- * ```php * $deliveryMonitoringService->find([ * ['status' => 'active'], * 'OR', * ['start_time' => '>1450428401'], * ]); * ``` * * * Combined condition * ------------------ * ```php * $deliveryMonitoringService->find([ * ['status' => 'finished'], * 'AND', * [['error_code' => '0'], 'OR', ['error_code' => '1']], * ]); * ``` * supports also the following syntax * ```php * $deliveryMonitoringService->find([ * ['status' => 'finished'], * 'AND', * [['error_code' => ['0', '1']], * ]); * ``` * * @param array $criteria - criteria to find data. * The comparison operator is determined based on the first few * characters in the given value. It recognizes the following operators * if they appear as the leading characters in the given value: * <ul> * <li><code><</code>: the column must be less than the given value.</li> * <li><code>></code>: the column must be greater than the given value.</li> * <li><code><=</code>: the column must be less than or equal to the given value.</li> * <li><code>>=</code>: the column must be greater than or equal to the given value.</li> * <li><code><></code>: the column must not be the same as the given value.</li> * <li><code>=</code>: the column must be equal to the given value.</li> * <li>none of the above: the column must be equal to the given value.</li> * </ul> * @param array $options * <ul> * <li>string `$options['order']='id ASC'`</li> * <li>integer `$options['limit']=null`</li> * <li>integer `$options['offset']=0`</li> * <li>integer `$options['asArray']=false` whether data should be returned as multidimensional or as array of `DeliveryMonitoringData` instances</li> * </ul> * @param boolean $together - whether the secondary data should be fetched together with primary. * @return DeliveryMonitoringData[] */ public function find(array $criteria = [], array $options = [], $together = false) { $result = []; $this->joins = []; $defaultOptions = ['order' => static::COLUMN_ID . " ASC", 'offset' => 0, 'asArray' => false]; $options = array_merge($defaultOptions, $options); $whereClause = 'WHERE '; $parameters = []; $options['order'] = $this->prepareOrderStmt($options['order']); $selectClause = "SELECT DISTINCT t.* "; $fromClause = "FROM " . self::TABLE_NAME . " t "; $whereClause .= $this->prepareCondition($criteria, $parameters, $selectClause); $sql = $selectClause . $fromClause . PHP_EOL . implode(PHP_EOL, $this->joins) . PHP_EOL . $whereClause . PHP_EOL; if ($options['order']['primary']) { $sql .= "ORDER BY " . $options['order']['primary']; } if (isset($options['limit'])) { $sql = $this->getPersistence()->getPlatForm()->limitStatement($sql, $options['limit'], $options['offset']); } $stmt = $this->getPersistence()->query($sql, $parameters); $data = $stmt->fetchAll(\PDO::FETCH_ASSOC); if ($together) { foreach ($data as &$row) { $row = array_merge($row, $this->getKvData($row[static::COLUMN_ID])); } unset($row); if ($data) { $data = $this->orderResult($data, $options['order']); } } if ($options['asArray']) { $result = $data; } else { foreach ($data as $row) { $deliveryExecution = \taoDelivery_models_classes_execution_ServiceProxy::singleton()->getDeliveryExecution($row[self::COLUMN_DELIVERY_EXECUTION_ID]); $monitoringData = new DeliveryMonitoringData($deliveryExecution, false); $result[] = $monitoringData; } } return $result; }
protected function getDeliverySettings(core_kernel_classes_Resource $delivery, User $user) { $deliveryProps = $delivery->getPropertiesValues(array(new core_kernel_classes_Property(TAO_DELIVERY_MAXEXEC_PROP), new core_kernel_classes_Property(TAO_DELIVERY_START_PROP), new core_kernel_classes_Property(TAO_DELIVERY_END_PROP))); $propMaxExec = current($deliveryProps[TAO_DELIVERY_MAXEXEC_PROP]); $propStartExec = current($deliveryProps[TAO_DELIVERY_START_PROP]); $propEndExec = current($deliveryProps[TAO_DELIVERY_END_PROP]); $executions = taoDelivery_models_classes_execution_ServiceProxy::singleton()->getUserExecutions($delivery, $user->getIdentifier()); $allowed = $this->service->isDeliveryExecutionAllowed($delivery, $user); return array("compiledDelivery" => $delivery, "settingsDelivery" => array(TAO_DELIVERY_MAXEXEC_PROP => (!is_object($propMaxExec) or $propMaxExec == "") ? 0 : $propMaxExec->literal, TAO_DELIVERY_START_PROP => (!is_object($propStartExec) or $propStartExec == "") ? null : $propStartExec->literal, TAO_DELIVERY_END_PROP => (!is_object($propEndExec) or $propEndExec == "") ? null : $propEndExec->literal, "TAO_DELIVERY_USED_TOKENS" => count($executions), "TAO_DELIVERY_TAKABLE" => $allowed)); }
/** * Get info on the current Result and display it */ public function viewResult() { $result = $this->getCurrentInstance(); $de = \taoDelivery_models_classes_execution_ServiceProxy::singleton()->getDeliveryExecution($result->getUri()); try { $implementation = $this->getClassService()->getReadableImplementation($de->getDelivery()); $this->getClassService()->setImplementation($implementation); $testTaker = $this->getClassService()->getTestTakerData($de); if (is_object($testTaker) and get_class($testTaker) == 'core_kernel_classes_Literal' or is_null($testTaker)) { //the test taker is unknown $this->setData('userLogin', $testTaker); $this->setData('userLabel', $testTaker); $this->setData('userFirstName', $testTaker); $this->setData('userLastName', $testTaker); $this->setData('userEmail', $testTaker); } else { $login = count($testTaker[PROPERTY_USER_LOGIN]) > 0 ? current($testTaker[PROPERTY_USER_LOGIN])->literal : ""; $label = count($testTaker[RDFS_LABEL]) > 0 ? current($testTaker[RDFS_LABEL])->literal : ""; $firstName = count($testTaker[PROPERTY_USER_FIRSTNAME]) > 0 ? current($testTaker[PROPERTY_USER_FIRSTNAME])->literal : ""; $userLastName = count($testTaker[PROPERTY_USER_LASTNAME]) > 0 ? current($testTaker[PROPERTY_USER_LASTNAME])->literal : ""; $userEmail = count($testTaker[PROPERTY_USER_MAIL]) > 0 ? current($testTaker[PROPERTY_USER_MAIL])->literal : ""; $this->setData('userLogin', $login); $this->setData('userLabel', $label); $this->setData('userFirstName', $firstName); $this->setData('userLastName', $userLastName); $this->setData('userEmail', $userEmail); } $filter = $this->hasRequestParameter("filter") ? $this->getRequestParameter("filter") : "lastSubmitted"; $stats = $this->getClassService()->getItemVariableDataStatsFromDeliveryResult($de, $filter); $this->setData('nbResponses', $stats["nbResponses"]); $this->setData('nbCorrectResponses', $stats["nbCorrectResponses"]); $this->setData('nbIncorrectResponses', $stats["nbIncorrectResponses"]); $this->setData('nbUnscoredResponses', $stats["nbUnscoredResponses"]); $this->setData('deliveryResultLabel', $result->getLabel()); $this->setData('variables', $stats["data"]); //retireve variables not related to item executions $deliveryVariables = $this->getClassService()->getVariableDataFromDeliveryResult($de); $this->setData('deliveryVariables', $deliveryVariables); $this->setData('uri', $this->getRequestParameter("uri")); $this->setData('classUri', $this->getRequestParameter("classUri")); $this->setData('filter', $filter); $this->setView('viewResult.tpl'); } catch (\common_exception_Error $e) { $this->setData('type', 'error'); $this->setData('error', $e->getMessage()); $this->setView('index.tpl'); return; } }
/** * returns a data set containing results data using and using an associative array * with basic statistics related to a delivery class. * * @author Patrick Plichart, <*****@*****.**> * @param core_kernel_classes_Class deliveryClass the current class selection * @return array an assocaitive array containing global statistics and per variable statistics */ public function extractDeliveryDataSet($deliveryClass) { $deliveryDataSet = array("nbExecutions" => 0, "nbMaxExpectedExecutions" => 0, "nbMaxExecutions" => 0, "statisticsPerVariable" => array(), "statistics" => array()); $deliveryResults = $this->getImplementation()->getAllTestTakerIds(); if (count($deliveryResults) == 0) { throw new common_Exception(__('The class you have selected contains no results to be analysed, please select a different class')); } $deliveryDataSet["nbExecutions"] = count($deliveryResults); $statisticsGroupedPerVariable = array(); $statisticsGrouped = array("sum" => 0, "#" => 0); foreach ($deliveryResults as $deliveryResult) { $de = \taoDelivery_models_classes_execution_ServiceProxy::singleton()->getDeliveryExecution($deliveryResult["deliveryResultIdentifier"]); $testTaker = $this->getTestTaker($de); if (get_class($testTaker) == 'core_kernel_classes_Literal') { $testTakerIdentifier = $testTaker->__toString(); $testTakerLabel = $testTaker->__toString(); } else { $testTakerIdentifier = $testTaker->getUri(); $testTakerLabel = $testTaker->getLabel(); } $statisticsGrouped["distinctTestTaker"][$testTakerIdentifier] = $testTakerLabel; $scoreVariables = $this->getVariables($de); try { $relatedDelivery = $this->getDelivery($de); $deliveryDataSet["deliveries"][$relatedDelivery->getUri()] = $relatedDelivery->getLabel(); } catch (Exception $e) { $deliveryDataSet["deliveries"]["undefined"] = "Unknown Delivery"; } foreach ($scoreVariables as $variable) { $variableData = (array) array_shift($variable); $activityIdentifier = ""; $activityNaturalId = ""; if (isset($variableData["item"])) { $item = new \core_kernel_classes_Resource($variableData["item"]); $activityIdentifier = $item->getUri(); $activityNaturalId = $item->getLabel(); } $variableIdentifier = $activityIdentifier . $variableData["variable"]->getIdentifier(); if (!isset($statisticsGroupedPerVariable[$variableIdentifier])) { $statisticsGroupedPerVariable[$variableIdentifier] = array("sum" => 0, "#" => 0); } // we should parametrize if we consider multiple executions of the same test taker or not, here all executions are considered $statisticsGroupedPerVariable[$variableIdentifier]["data"][] = $variableData["variable"]->getValue(); $statisticsGroupedPerVariable[$variableIdentifier]["sum"] += $variableData["variable"]->getValue(); $statisticsGroupedPerVariable[$variableIdentifier]["#"] += 1; $statisticsGroupedPerVariable[$variableIdentifier]["naturalid"] = $activityNaturalId . " (" . $variableData["variable"]->getIdentifier() . ")"; $statisticsGrouped["data"][] = $variableData["variable"]->getValue(); $statisticsGrouped["sum"] += $variableData["variable"]->getValue(); $statisticsGrouped["#"] += 1; } } // compute basic statistics $statisticsGrouped["avg"] = $statisticsGrouped["sum"] / $statisticsGrouped["#"]; // number of different type of variables collected $statisticsGrouped["numberVariables"] = sizeOf($statisticsGroupedPerVariable); // compute the deciles scores for the complete delivery $statisticsGrouped = $this->computeQuantiles($statisticsGrouped, 10); // computing average, std and distribution for every single variable foreach ($statisticsGroupedPerVariable as $variableIdentifier => $data) { ksort($statisticsGroupedPerVariable[$variableIdentifier]["data"]); // compute the total populationa verage score for this variable $statisticsGroupedPerVariable[$variableIdentifier]["avg"] = $statisticsGroupedPerVariable[$variableIdentifier]["sum"] / $statisticsGroupedPerVariable[$variableIdentifier]["#"]; $statisticsGroupedPerVariable[$variableIdentifier] = $this->computeQuantiles($statisticsGroupedPerVariable[$variableIdentifier], 10); } ksort($statisticsGrouped["data"]); natsort($statisticsGrouped["distinctTestTaker"]); $deliveryDataSet["statistics"] = $statisticsGrouped; $deliveryDataSet["statisticsPerVariable"] = $statisticsGroupedPerVariable; return $deliveryDataSet; }
protected function verifyToken(core_kernel_classes_Resource $delivery, User $user) { $propMaxExec = $delivery->getOnePropertyValue(new \core_kernel_classes_Property(TAO_DELIVERY_MAXEXEC_PROP)); $maxExec = is_null($propMaxExec) ? 0 : $propMaxExec->literal; //check Tokens $usedTokens = count(\taoDelivery_models_classes_execution_ServiceProxy::singleton()->getUserExecutions($delivery, $user->getIdentifier())); if ($maxExec != 0 && $usedTokens >= $maxExec) { \common_Logger::d("Attempt to start the compiled delivery " . $delivery->getUri() . "without tokens"); return false; } return true; }
public static function getDeliveryExecutionById($deliveryExecutionId) { return \taoDelivery_models_classes_execution_ServiceProxy::singleton()->getDeliveryExecution($deliveryExecutionId); }
/** * * @param string $currentVersion * @return string $versionUpdatedTo */ public function update($initialVersion) { $currentVersion = $initialVersion; //migrate from 2.6 to 2.6.1 if ($currentVersion == '2.6') { //data upgrade OntologyUpdater::syncModels(); $currentVersion = '2.6.1'; } if ($currentVersion == '2.6.1') { $ext = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoDelivery'); $className = $ext->getConfig(\taoDelivery_models_classes_execution_ServiceProxy::CONFIG_KEY); if (is_string($className)) { $impl = null; switch ($className) { case 'taoDelivery_models_classes_execution_OntologyService': $impl = new \taoDelivery_models_classes_execution_OntologyService(); break; case 'taoDelivery_models_classes_execution_KeyValueService': $impl = new \taoDelivery_models_classes_execution_KeyValueService(array(\taoDelivery_models_classes_execution_KeyValueService::OPTION_PERSISTENCE => 'deliveryExecution')); break; default: \common_Logger::w('Unable to migrate custom execution service'); } if (!is_null($impl)) { $proxy = \taoDelivery_models_classes_execution_ServiceProxy::singleton(); $proxy->setImplementation($impl); $currentVersion = '2.6.2'; } } } if ($currentVersion == '2.6.2') { $currentVersion = '2.6.3'; } if ($currentVersion == '2.6.3') { //data upgrade OntologyUpdater::syncModels(); $currentVersion = '2.7.0'; } if ($currentVersion == '2.7.0') { EntryPointService::getRegistry()->registerEntryPoint(new \taoDelivery_models_classes_entrypoint_FrontOfficeEntryPoint()); $currentVersion = '2.7.1'; } if ($currentVersion == '2.7.1' || $currentVersion == '2.8') { $currentVersion = '2.9'; } if ($currentVersion == '2.9') { OntologyUpdater::syncModels(); //grant access to anonymous user $anonymousRole = new \core_kernel_classes_Resource(INSTANCE_ROLE_ANONYMOUS); $accessService = \funcAcl_models_classes_AccessService::singleton(); $accessService->grantActionAccess($anonymousRole, 'taoDelivery', 'DeliveryServer', 'guest'); $currentVersion = '2.9.1'; } if ($currentVersion == '2.9.1') { OntologyUpdater::syncModels(); $currentVersion = '2.9.2'; } if ($currentVersion == '2.9.2') { //$assignmentService = new \taoDelivery_models_classes_AssignmentService(); //$this->getServiceManager()->register('taoDelivery/assignment', $assignmentService); $currentVersion = '2.9.3'; } if ($currentVersion == '2.9.3') { try { $currentConfig = $this->getServiceManager()->get(\taoDelivery_models_classes_DeliveryServerService::CONFIG_ID); if (is_array($currentConfig)) { $deliveryServerService = new \taoDelivery_models_classes_DeliveryServerService($currentConfig); } else { $deliveryServerService = new \taoDelivery_models_classes_DeliveryServerService(); } } catch (ServiceNotFoundException $e) { $deliveryServerService = new \taoDelivery_models_classes_DeliveryServerService(); } $this->getServiceManager()->register(\taoDelivery_models_classes_DeliveryServerService::CONFIG_ID, $deliveryServerService); $currentVersion = '2.9.4'; } $this->setVersion($currentVersion); if ($this->isVersion('2.9.4')) { OntologyUpdater::syncModels(); $this->setVersion('3.0.0'); } if ($this->isBetween('3.0.0', '3.1.0')) { $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoDelivery'); $config = $extension->getConfig('deliveryServer'); $config->setOption('deliveryContainer', 'oat\\taoDelivery\\helper\\container\\DeliveryServiceContainer'); $extension->setConfig('deliveryServer', $config); $this->setVersion('3.1.0'); } $this->skip('3.1.0', '3.2.0'); if ($this->isVersion('3.2.0')) { // set the test runner controller $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoDelivery'); $config = $extension->getConfig('testRunner'); $config['serviceController'] = 'Runner'; $config['serviceExtension'] = 'taoQtiTest'; $extension->setConfig('testRunner', $config); $this->setVersion('3.3.0'); } $this->skip('3.3.0', '3.5.0'); }
/** * Function returns extended delivery data (e.g. groups, number of executions etc.) * @param \core_kernel_classes_Resource $delivery * @return void */ private function getFullDeliveryData(\core_kernel_classes_Resource $delivery) { $result = array(); if (\taoDelivery_models_classes_execution_ServiceProxy::singleton()->implementsMonitoring()) { $execs = \taoDelivery_models_classes_execution_ServiceProxy::singleton()->getExecutionsByDelivery($delivery); $result['executions'] = count($execs); } $result['published'] = $this->service->getCompilationDate($delivery); //groups $groups = array_keys($this->getServiceManager()->get('taoDeliverySchedule/DeliveryGroupsService')->getGroups($delivery)); $result['groups'] = \tao_helpers_Uri::encodeArray($groups); //Test takers $result = $result + DeliveryTestTakersService::singleton()->getDeliveryTestTakers($delivery); //Max. number of executions $deliveryMaxexecProperty = new \core_kernel_classes_Property(TAO_DELIVERY_MAXEXEC_PROP); $result['maxexec'] = (string) $delivery->getOnePropertyValue($deliveryMaxexecProperty); //Result server $resultServerProp = new \core_kernel_classes_Property(TAO_DELIVERY_RESULTSERVER_PROP); $result['resultserver'] = $delivery->getOnePropertyValue($resultServerProp)->getUri(); $result['resultserver'] = \tao_helpers_Uri::encode($result['resultserver']); $result['repeatedDeliveries'] = $this->getServiceManager()->get(RepeatedDeliveryService::CONFIG_ID)->getRepeatedDeliveriesData($delivery); return $result; }
/** * Whether test session is online * @param string $sessionId test session identifier * @return bool */ public function isOnline($sessionId) { \common_Logger::w('Using of `oat\\taoProctoring\\model\\implementation\\TestSessionConnectivityStatusService::isOnline()` method which may give inaccurate result.'); $deliveryExecution = \taoDelivery_models_classes_execution_ServiceProxy::singleton()->getDeliveryExecution($sessionId); return $deliveryExecution->getState()->getUri() === DeliveryExecution::STATE_ACTIVE; }
/** * Pause delivery execution if test session was paused. * @param TestExecutionPausedEvent $event */ public static function catchSessionPause(TestExecutionPausedEvent $event) { $deliveryExecution = \taoDelivery_models_classes_execution_ServiceProxy::singleton()->getDeliveryExecution($event->getTestExecutionId()); $deliveryExecution->setState(ProctoredDeliveryExecution::STATE_PAUSED); }
/** * Gets the active or paused executions of a delivery * * @param $deliveryId * @param $testCenterId * @param array $options * @return DeliveryExecution[] * @deprecated */ public function getCurrentDeliveryExecutions($deliveryId, $testCenterId, $options = array()) { $returnedDeliveryExecutions = array(); $group = $this->findGroup($deliveryId, $testCenterId); $users = GroupsService::singleton()->getUsers($group); $delivery = $this->getResource($deliveryId); foreach ($users as $user) { $returnedDeliveryExecutions[] = ExecutionServiceProxy::singleton()->getUserExecutions($delivery, $user->getUri()); } if (count($returnedDeliveryExecutions)) { return call_user_func_array('array_merge', $returnedDeliveryExecutions); } return []; }
/** * @param AssessmentTestSession $session * @return \taoDelivery_models_classes_execution_DeliveryExecution */ private function getDeliveryExecution(AssessmentTestSession $session) { return $this->deliveryExecutionService->getDeliveryExecution($session->getSessionId()); }