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; }
/** * @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 = RevisionService::commit($resource, $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()))); }
public function sendSelfMsg() { $message = new Message(); $message->setTo(\common_session_SessionManager::getSession()->getUser()); $message->setBody('<h1>Tao Dev Message send on the ' . \tao_helpers_Date::displayeDate(time()) . '</h1>'); $success = MessagingService::singleton()->send($message); return $this->returnJson(array('success' => $success, 'message' => __('Send a message'))); }
protected static function getDateFormatter() { if (is_null(self::$service)) { $ext = common_ext_ExtensionsManager::singleton()->getExtensionById('tao'); $service = $ext->getConfig(self::CONFIG_KEY); self::$service = is_object($service) && $service instanceof Formatter ? $service : new EuropeanFormatter(); } return self::$service; }
/** * Compute the expiration time for the sandbox version * * @return string */ public static function getSandboxExpiration() { $datetime = new \DateTime(); $d = new \DateTime($datetime->format('Y-m-d')); $weekday = $d->format('w'); $weekNumber = $d->format('W'); $diff = $weekNumber % 2 ? 7 : 6 - $weekday; $d->modify(sprintf('+ %d day', $diff)); return \tao_helpers_Date::displayInterval($d, \tao_helpers_Date::FORMAT_INTERVAL_LONG); }
static function buildFromDeliveryExecution(\taoDelivery_models_classes_execution_DeliveryExecution $deliveryExecution) { $data = array(); $data[self::ID] = $deliveryExecution->getIdentifier(); $data[self::LABEL] = $deliveryExecution->getLabel(); $data[self::LAUNCH_URL] = _url('runDeliveryExecution', 'DeliveryServer', null, array('deliveryExecution' => $deliveryExecution->getIdentifier())); $data[self::DESCRIPTION] = array(__("Started at %s", \tao_helpers_Date::displayeDate($deliveryExecution->getStartTime()))); $data[self::AUTHORIZED] = true; return $data; }
/** * * @param unknown $params */ public function __invoke($params) { if (count($params) < 1) { return new \common_report_Report(\common_report_Report::TYPE_ERROR, __('Usage: %s ASSEMBLY_FILE [ASSEMBLY_FILE_2] [ASSEMBLY_FILE_3] ...', __CLASS__)); } \common_ext_ExtensionsManager::singleton()->getExtensionById('taoDeliveryRdf'); $deliveryClass = DeliveryAssemblyService::singleton()->getRootClass()->createSubClass('Import ' . \tao_helpers_Date::displayeDate(time())); $importer = new Assembler(); $report = new \common_report_Report(\common_report_Report::TYPE_INFO, __('Importing %1$s files into \'%2$s\'', count($params), $deliveryClass->getLabel())); while (!empty($params)) { $file = array_shift($params); $report->add($importer->importDelivery($deliveryClass, $file)); } return $report; }
/** * Rendering of the XHTML implementation of the Calendar Widget. * * @author Bertrand Chevrier, <*****@*****.**> * @return The XHTML stream of the Calendar Widget. */ public function render() { $returnValue = $this->renderLabel(); $uniqueId = uniqid('calendar_'); $elementId = tao_helpers_Display::TextCleaner($this->getDescription()) . '_' . $uniqueId; if (!isset($this->attributes['size'])) { $this->attributes['size'] = 20; } $returnValue .= "<input class='datepicker-input' type='text' name='{$this->name}' id='{$elementId}' "; $returnValue .= $this->renderAttributes(); if (!empty($this->value)) { $timeStamp = is_numeric($this->getRawValue()) ? $this->getRawValue() : $this->getEvaluatedValue(); $returnValue .= ' value="' . _dh(tao_helpers_Date::displayeDate($timeStamp, tao_helpers_Date::FORMAT_DATEPICKER)) . '"'; } $returnValue .= ' />'; $returnValue .= "<script type=\"text/javascript\">\n\t\t\trequire(['jquery','jqueryui','jquery.timePicker'], function(\$){\n\t\t\t\t\$(\"#{$elementId}\").datetimepicker({\n dateFormat: 'yy-mm-dd',\n beforeShow: function (textbox, instance) {\n \$(textbox).parent().append(instance.dpDiv);\n }\n\t\t\t\t});\n \n\t\t\t});</script>"; return (string) $returnValue; }
/** * prepare a data set as an associative array, service intended to populate gui controller * * @param string $filter 'lastSubmitted', 'firstSubmitted' */ public function getItemVariableDataFromDeliveryResult(core_kernel_classes_Resource $deliveryResult, $filter) { $undefinedStr = __('unknown'); //some data may have not been submitted $itemResults = $this->getItemResultsFromDeliveryResult($deliveryResult); $variablesByItem = array(); foreach ($itemResults as $itemResult) { try { common_Logger::d("Retrieving related Item for itemResult " . $itemResult->getUri() . ""); $relatedItem = $this->getItemFromItemResult($itemResult); } catch (common_Exception $e) { common_Logger::w("The itemResult " . $itemResult->getUri() . " is not linked to a valid item. (deleted item ?)"); $relatedItem = null; } if (get_class($relatedItem) == "core_kernel_classes_Literal") { $itemIdentifier = $relatedItem->__toString(); $itemLabel = $relatedItem->__toString(); $itemModel = $undefinedStr; } elseif (get_class($relatedItem) == "core_kernel_classes_Resource") { $itemIdentifier = $relatedItem->getUri(); $itemLabel = $relatedItem->getLabel(); try { common_Logger::d("Retrieving related Item model for item " . $relatedItem->getUri() . ""); $itemModel = $relatedItem->getUniquePropertyValue(new core_kernel_classes_Property(TAO_ITEM_MODEL_PROPERTY)); $variablesByItem[$itemIdentifier]['itemModel'] = $itemModel->getLabel(); } catch (common_Exception $e) { //a resource but unknown $variablesByItem[$itemIdentifier]['itemModel'] = 'unknown'; } } else { $itemIdentifier = $undefinedStr; $itemLabel = $undefinedStr; $variablesByItem[$itemIdentifier]['itemModel'] = $undefinedStr; } foreach ($this->getVariablesFromItemResult($itemResult) as $variable) { //retrieve the type of the variable $class = current($variable->getTypes()); $type = $class->getUri(); //common properties to all variables $properties = array(PROPERTY_IDENTIFIER, PROPERTY_VARIABLE_BASETYPE, PROPERTY_VARIABLE_CARDINALITY, PROPERTY_VARIABLE_EPOCH); //specific property Response Variable if ($type == TAO_RESULT_RESPONSE) { $properties[] = PROPERTY_RESPONSE_VARIABLE_CORRECTRESPONSE; } $baseTypes = $variable->getPropertyValues(new core_kernel_classes_Property(PROPERTY_VARIABLE_BASETYPE)); $baseType = current($baseTypes); if ($baseType != "file") { $properties[] = RDF_VALUE; $variableDescription = $variable->getPropertiesValues($properties); $variableDescription[RDF_VALUE] = array(base64_decode(current($variableDescription[RDF_VALUE]))); } else { $variableDescription = $variable->getPropertiesValues($properties); } try { common_Logger::d("Retrieving related Item for itemResult " . $itemResult->getUri() . ""); $relatedItem = $this->getItemFromVariable($variable); } catch (common_Exception $e) { common_Logger::w("The variable " . $variable->getUri() . " is not linked to a valid item. (deleted item ?)"); $relatedItem = null; } if (get_class($relatedItem) == "core_kernel_classes_Literal") { $itemIdentifier = $relatedItem->__toString(); $itemLabel = $relatedItem->__toString(); $variablesByItem[$itemIdentifier]['itemModel'] = $undefinedStr; } elseif (get_class($relatedItem) == "core_kernel_classes_Resource") { $itemIdentifier = $relatedItem->getUri(); $itemLabel = $relatedItem->getLabel(); try { $itemModel = $relatedItem->getUniquePropertyValue(new core_kernel_classes_Property(TAO_ITEM_MODEL_PROPERTY)); $variablesByItem[$itemIdentifier]['itemModel'] = $itemModel->getLabel(); } catch (common_Exception $e) { //a resource but unknown $variablesByItem[$itemIdentifier]['itemModel'] = $undefinedStr; } } else { $itemIdentifier = $undefinedStr; $itemLabel = $undefinedStr; $variablesByItem[$itemIdentifier]['itemModel'] = $undefinedStr; } $variableIdentifier = current($variableDescription[PROPERTY_IDENTIFIER])->__toString(); $epoch = current($variableDescription[PROPERTY_VARIABLE_EPOCH])->__toString(); $variableDescription["uri"] = $variable->getUri(); $variableDescription["epoch"] = array(tao_helpers_Date::displayeDate(tao_helpers_Date::getTimeStamp($epoch), tao_helpers_Date::FORMAT_VERBOSE)); if (isset($variableDescription[PROPERTY_RESPONSE_VARIABLE_CORRECTRESPONSE])) { $correctResponse = current($variableDescription[PROPERTY_RESPONSE_VARIABLE_CORRECTRESPONSE]); } else { $correctResponse = false; } if ($correctResponse and get_class($correctResponse) == 'core_kernel_classes_Resource') { if ($correctResponse->getUri() == GENERIS_TRUE) { $variableDescription["isCorrect"] = "correct"; } else { if ($correctResponse->getUri() == GENERIS_FALSE) { $variableDescription["isCorrect"] = "incorrect"; } else { //an unknown core_kernel_classes_Resource $variableDescription["isCorrect"] = "unscored"; } } } else { $variableDescription["isCorrect"] = "unscored"; } $variablesByItem[$itemIdentifier]['sortedVars'][$type][$variableIdentifier][$epoch] = $variableDescription; $variablesByItem[$itemIdentifier]['label'] = $itemLabel; } } //sort by epoch and filter foreach ($variablesByItem as $itemIdentifier => $itemVariables) { foreach ($itemVariables['sortedVars'] as $variableType => $variables) { foreach ($variables as $variableIdentifier => $observation) { uksort($variablesByItem[$itemIdentifier]['sortedVars'][$variableType][$variableIdentifier], "self::sortTimeStamps"); //print_r($observation); switch ($filter) { case "lastSubmitted": $variablesByItem[$itemIdentifier]['sortedVars'][$variableType][$variableIdentifier] = array(array_pop($variablesByItem[$itemIdentifier]['sortedVars'][$variableType][$variableIdentifier])); break; case "firstSubmitted": $variablesByItem[$itemIdentifier]['sortedVars'][$variableType][$variableIdentifier] = array(array_shift($variablesByItem[$itemIdentifier]['sortedVars'][$variableType][$variableIdentifier])); break; } } } } return $variablesByItem; }
/** * get all result delivery execution to display */ public function getResults() { $page = $this->getRequestParameter('page'); $limit = $this->getRequestParameter('rows'); $order = $this->getRequestParameter('sortby'); $sord = $this->getRequestParameter('sortorder'); $start = $limit * $page - $limit; $gau = array('order' => $order, 'orderdir' => strtoupper($sord), 'offset' => $start, 'limit' => $limit, 'recursive' => true); $delivery = new \core_kernel_classes_Resource(tao_helpers_Uri::decode($this->getRequestParameter('classUri'))); try { $implementation = $this->getResultStorage($delivery); $this->getClassService()->setImplementation($implementation); $data = array(); $readOnly = array(); $user = \common_session_SessionManager::getSession()->getUser(); $rights = array('view' => !AclProxy::hasAccess($user, 'oat\\taoOutcomeUi\\controller\\Results', 'viewResult', array()), 'delete' => !AclProxy::hasAccess($user, 'oat\\taoOutcomeUi\\controller\\Results', 'delete', array())); $results = $this->getClassService()->getImplementation()->getResultByDelivery(array($delivery->getUri()), $gau); $counti = $this->getClassService()->getImplementation()->countResultByDelivery(array($delivery->getUri())); foreach ($results as $res) { $deliveryExecution = \taoDelivery_models_classes_execution_ServiceProxy::singleton()->getDeliveryExecution($res['deliveryResultIdentifier']); $testTaker = new core_kernel_classes_Resource($res['testTakerIdentifier']); try { $startTime = \tao_helpers_Date::displayeDate($deliveryExecution->getStartTime()); } catch (\common_exception_NotFound $e) { \common_Logger::w($e->getMessage()); $startTime = ''; } $data[] = array('id' => $deliveryExecution->getIdentifier(), 'ttaker' => _dh($testTaker->getLabel()), 'time' => $startTime); $readOnly[$deliveryExecution->getIdentifier()] = $rights; } $this->returnJson(array('data' => $data, 'page' => floor($start / $limit) + 1, 'total' => ceil($counti / $limit), 'records' => count($data), 'readonly' => $readOnly)); } catch (\common_exception_Error $e) { $this->returnJson(array('error' => $e->getMessage())); } }
/** * @param $options * @return null|number timestamp */ private function getPeriodEnd(array $options) { $periodEnd = null; if (!empty($options['periodEnd'])) { $periodEnd = new DateTime($options['periodEnd']); $periodEnd->setTime(23, 59, 59); $periodEnd = DateHelper::getTimeStamp($periodEnd->getTimestamp()); } return $periodEnd; }
/** * Adjusts a list of delivery executions: add information, format the result * * @param DeliveryExecution[] $deliveryExecutions * @param array $options * @return array * @throws \oat\oatbox\service\ServiceNotFoundException */ private static function adjustDeliveryExecutions($deliveryExecutions, $options) { // paginate, then format the data return DataTableHelper::paginate($deliveryExecutions, $options, function ($deliveryExecutions) { $testSessionConnectivityStatusService = ServiceManager::getServiceManager()->get(TestSessionConnectivityStatusService::SERVICE_ID); $executions = []; foreach ($deliveryExecutions as $cachedData) { $state = ['status' => $cachedData[DeliveryMonitoringService::COLUMN_STATUS], 'progress' => $cachedData[DeliveryMonitoringService::COLUMN_CURRENT_ASSESSMENT_ITEM]]; $testTaker = []; $extraFields = []; $user = UserHelper::getUser($cachedData[DeliveryMonitoringService::TEST_TAKER]); if ($user) { /* @var $user User */ $testTaker['id'] = $cachedData[DeliveryMonitoringService::TEST_TAKER]; $testTaker['lastName'] = _dh($cachedData[DeliveryMonitoringService::TEST_TAKER_LAST_NAME]); $testTaker['firstName'] = _dh($cachedData[DeliveryMonitoringService::TEST_TAKER_FIRST_NAME]); $userExtraFields = self::_getUserExtraFields(); foreach ($userExtraFields as $field) { $extraFields[$field['id']] = isset($cachedData[$field['id']]) ? _dh($cachedData[$field['id']]) : ''; } } $rawConnectivity = isset($cachedData[DeliveryMonitoringService::CONNECTIVITY]) ? $cachedData[DeliveryMonitoringService::CONNECTIVITY] : false; $online = $testSessionConnectivityStatusService->isOnline($cachedData[DeliveryMonitoringService::DELIVERY_EXECUTION_ID], $rawConnectivity); $executions[] = array('id' => $cachedData[DeliveryMonitoringService::DELIVERY_EXECUTION_ID], 'delivery' => array('uri' => $cachedData[DeliveryMonitoringService::DELIVERY_ID], 'label' => _dh($cachedData[DeliveryMonitoringService::DELIVERY_NAME])), 'date' => DateHelper::displayeDate($cachedData[DeliveryMonitoringService::COLUMN_START_TIME]), 'timer' => ['remaining' => $cachedData[DeliveryMonitoringService::COLUMN_REMAINING_TIME], 'extraTime' => floatval($cachedData[DeliveryMonitoringService::COLUMN_EXTRA_TIME]), 'consumedExtraTime' => floatval($cachedData[DeliveryMonitoringService::COLUMN_CONSUMED_EXTRA_TIME])], 'testTaker' => $testTaker, 'extraFields' => $extraFields, 'state' => $state, 'online' => $online); } return $executions; }); }
/** * Compare two deliveryExecution by their start timestamp. * CAUTION: getStartTime() is not cached at this moment, so it request the DB on each call * @param DeliveryExecution $a * @param DeliveryExecution $b * @return int */ public function cmpDeliveryExecution($a, $b) { return DateHelper::getTimeStamp($b->getStartTime()) - DateHelper::getTimeStamp($a->getStartTime()); }
/** * Gets the list of assessment reports related to a test site * * @param $testCenter * @param array [$options] * @return array */ public static function getReports($testCenter, $options = array()) { $periodStart = null; $periodEnd = null; if (isset($options['periodStart'])) { $periodStart = new DateTime($options['periodStart']); $periodStart->setTime(0, 0, 0); $periodStart = DateHelper::getTimeStamp($periodStart->getTimestamp()); } if (isset($options['periodEnd'])) { $periodEnd = new DateTime($options['periodEnd']); $periodEnd->setTime(23, 59, 59); $periodEnd = DateHelper::getTimeStamp($periodEnd->getTimestamp()); } $deliveryService = ServiceManager::getServiceManager()->get(DeliveryService::CONFIG_ID); $deliveries = EligibilityService::singleton()->getEligibleDeliveries($testCenter); $filteredExecutions = array(); foreach ($deliveries as $delivery) { if ($delivery->exists()) { $deliveryExecutions = $deliveryService->getDeliveryExecutions($delivery->getUri()); foreach ($deliveryExecutions as $deliveryExecution) { $startTime = $deliveryExecution->getStartTime(); $finishTime = $deliveryExecution->getFinishTime(); if ($finishTime && $periodStart && $periodStart > DateHelper::getTimeStamp($finishTime)) { continue; } if (!$finishTime && $periodStart && $periodEnd && (DateHelper::getTimeStamp($startTime) > $periodEnd || DateHelper::getTimeStamp($startTime) < $periodStart)) { continue; } if ($startTime && $periodEnd && $periodEnd < DateHelper::getTimeStamp($startTime)) { continue; } $filteredExecutions[] = $deliveryExecution; } } } $deliveryExecutionStateService = ServiceManager::getServiceManager()->get(DeliveryExecutionStateService::SERVICE_ID); return DataTableHelper::paginate($filteredExecutions, $options, function ($deliveryExecutions) use($deliveryExecutionStateService) { $reports = []; foreach ($deliveryExecutions as $deliveryExecution) { /* @var $deliveryExecution DeliveryExecution */ $startTime = $deliveryExecution->getStartTime(); $finishTime = $deliveryExecution->getFinishTime(); $userId = $deliveryExecution->getUserIdentifier(); $user = UserHelper::getUser($userId); $authorizationData = self::getDeliveryLog()->get($deliveryExecution->getIdentifier(), 'TEST_AUTHORISE'); $proctor = empty($authorizationData) ? '' : UserHelper::getUser($authorizationData[0][DeliveryLog::DATA]['proctorUri']); $procActions = self::getProctorActions($deliveryExecution); $reports[] = array('id' => $deliveryExecution->getIdentifier(), 'delivery' => $deliveryExecution->getDelivery()->getLabel(), 'testtaker' => $user ? UserHelper::getUserName($user, true) : '', 'proctor' => $proctor ? UserHelper::getUserName($proctor, true) : '', 'status' => $deliveryExecutionStateService->getState($deliveryExecution), 'start' => $startTime ? DateHelper::displayeDate($startTime) : '', 'end' => $finishTime ? DateHelper::displayeDate($finishTime) : '', 'pause' => $procActions['pause'], 'resume' => $procActions['resume'], 'irregularities' => $procActions['irregularities']); } return $reports; }); }
public function getQtiResultXml($deliveryId, $resultId) { $delivery = new \core_kernel_classes_Resource($deliveryId); $resultService = $this->getServiceLocator()->get(ResultServerService::SERVICE_ID); $resultServer = $resultService->getResultStorage($deliveryId); $crudService = new CrudResultsService(); $dom = new \DOMDocument('1.0', 'UTF-8'); $dom->formatOutput = true; $itemResults = $crudService->format($resultServer, $resultId, CrudResultsService::GROUP_BY_ITEM); $testResults = $crudService->format($resultServer, $resultId, CrudResultsService::GROUP_BY_TEST); $assessmentResultElt = $dom->createElementNS(self::QTI_NS, 'assessmentResult'); $dom->appendChild($assessmentResultElt); /** Context */ $contextElt = $dom->createElementNS(self::QTI_NS, 'context'); $contextElt->setAttribute('sourcedId', \tao_helpers_Uri::getUniqueId($resultServer->getTestTaker($resultId))); $assessmentResultElt->appendChild($contextElt); /** Test Result */ foreach ($testResults as $testResultIdentifier => $testResult) { $identifierParts = explode('.', $testResultIdentifier); $testIdentifier = array_pop($identifierParts); $testResultElement = $dom->createElementNS(self::QTI_NS, 'testResult'); $testResultElement->setAttribute('identifier', $testIdentifier); $testResultElement->setAttribute('datestamp', \tao_helpers_Date::displayeDate($testResult[0]['epoch'], \tao_helpers_Date::FORMAT_ISO8601)); /** Item Variable */ foreach ($testResult as $itemVariable) { $isResponseVariable = $itemVariable['type']->getUri() === 'http://www.tao.lu/Ontologies/TAOResult.rdf#ResponseVariable'; $testVariableElement = $dom->createElementNS(self::QTI_NS, $isResponseVariable ? 'responseVariable' : 'outcomeVariable'); $testVariableElement->setAttribute('identifier', $itemVariable['identifier']); $testVariableElement->setAttribute('cardinality', $itemVariable['cardinality']); $testVariableElement->setAttribute('baseType', $itemVariable['basetype']); $valueElement = $this->createCDATANode($dom, 'value', trim($itemVariable['value'])); if ($isResponseVariable) { $candidateResponseElement = $dom->createElementNS(self::QTI_NS, 'candidateResponse'); $candidateResponseElement->appendChild($valueElement); $testVariableElement->appendChild($candidateResponseElement); } else { $testVariableElement->appendChild($valueElement); } $testResultElement->appendChild($testVariableElement); } $assessmentResultElt->appendChild($testResultElement); } /** Item Result */ foreach ($itemResults as $itemResultIdentifier => $itemResult) { // Retrieve identifier. $identifierParts = explode('.', $itemResultIdentifier); $occurenceNumber = array_pop($identifierParts); $refIdentifier = array_pop($identifierParts); $itemElement = $dom->createElementNS(self::QTI_NS, 'itemResult'); $itemElement->setAttribute('identifier', $refIdentifier); $itemElement->setAttribute('datestamp', \tao_helpers_Date::displayeDate($itemResult[0]['epoch'], \tao_helpers_Date::FORMAT_ISO8601)); $itemElement->setAttribute('sessionStatus', 'final'); /** Item variables */ foreach ($itemResult as $key => $itemVariable) { $isResponseVariable = $itemVariable['type']->getUri() === 'http://www.tao.lu/Ontologies/TAOResult.rdf#ResponseVariable'; if ($itemVariable['identifier'] == 'comment') { /** Comment */ $itemVariableElement = $dom->createElementNS(self::QTI_NS, 'candidateComment', $itemVariable['value']); } else { /** Item variable */ $itemVariableElement = $dom->createElementNS(self::QTI_NS, $isResponseVariable ? 'responseVariable' : 'outcomeVariable'); $itemVariableElement->setAttribute('identifier', $itemVariable['identifier']); $itemVariableElement->setAttribute('cardinality', $itemVariable['cardinality']); $itemVariableElement->setAttribute('baseType', $itemVariable['basetype']); /** Split multiple response */ $itemVariable['value'] = trim($itemVariable['value'], '[]'); if ($itemVariable['cardinality'] !== Cardinality::getNameByConstant(Cardinality::SINGLE)) { $values = explode(';', $itemVariable['value']); $returnValue = []; foreach ($values as $value) { $returnValue[] = $this->createCDATANode($dom, 'value', $value); } } else { $returnValue = $this->createCDATANode($dom, 'value', $itemVariable['value']); } /** Get response parent element */ if ($isResponseVariable) { /** Response variable */ $responseElement = $dom->createElementNS(self::QTI_NS, 'candidateResponse'); } else { /** Outcome variable */ $responseElement = $itemVariableElement; } /** Write a response node foreach answer */ if (is_array($returnValue)) { foreach ($returnValue as $valueElement) { $responseElement->appendChild($valueElement); } } else { $responseElement->appendChild($returnValue); } if ($isResponseVariable) { $itemVariableElement->appendChild($responseElement); } } $itemElement->appendChild($itemVariableElement); } $assessmentResultElt->appendChild($itemElement); } return $dom->saveXML(); }
/** * Short description of method prepare * * @access public * @author Joel Bout, <*****@*****.**> * @param array resources results * @param array columns variables * @return mixed */ public function prepare($resources, $columns) { $resultsService = taoResults_models_classes_ResultsService::singleton(); foreach ($resources as $result) { $itemresults = $resultsService->getVariables($result, new core_kernel_classes_Class(TAO_RESULT_VARIABLE), false); $cellData = array(); foreach ($itemresults as $itemResultUri => $vars) { //cache the item information pertaining to a given itemResult (stable over time) if (common_cache_FileCache::singleton()->has('itemResultItemCache' . $itemResultUri)) { $itemUri = common_cache_FileCache::singleton()->get('itemResultItemCache' . $itemResultUri); $item = new core_kernel_classes_Resource($itemUri); } else { $item = $resultsService->getItemFromItemResult(new core_kernel_classes_Resource($itemResultUri)); common_cache_FileCache::singleton()->put($item->getUri(), 'itemResultItemCache' . $itemResultUri); } if (get_class($item) == "core_kernel_classes_Resource") { $contextIdentifier = (string) $item->getUri(); } else { $contextIdentifier = (string) $item->__toString(); } foreach ($vars as $var) { //cache the variable data if (common_cache_FileCache::singleton()->has('variableDataCache' . $var->getUri())) { $varData = common_cache_FileCache::singleton()->get('variableDataCache' . $var->getUri()); } else { $varData = $resultsService->getVariableData($var); common_cache_FileCache::singleton()->put($varData, 'variableDataCache' . $var->getUri()); } if (is_array($varData["value"])) { $varData["value"] = json_encode($varData["value"]); } $variableIdentifier = (string) $varData["identifier"]; foreach ($columns as $column) { if ($variableIdentifier == $column->getIdentifier() and $contextIdentifier == $column->getContextIdentifier()) { $value = (string) $varData["value"]; $epoch = $varData["epoch"]; $readableTime = ""; if ($epoch != "") { $readableTime = "@" . tao_helpers_Date::displayeDate(tao_helpers_Date::getTimeStamp($epoch), tao_helpers_Date::FORMAT_VERBOSE); } $this->cache[$varData["type"]->getUri()][$result->getUri()][$contextIdentifier . $variableIdentifier][(string) $epoch] = array($value, $readableTime); } } } } } }