assessmentUri = $uri; $testData = $this->getAssessmentData(); $finalData = []; foreach ($testData as $data) { $item = new \core_kernel_classes_Resource($data[self::ITEM_URI]); unset($data[self::ITEM_URI]); $itemData = $this->getItemExporter()->getDataByItem($item); foreach ($itemData as &$column) { $column = array_merge($column, $data); } $finalData[] = $itemData; } $headers = array_merge($this->getItemExporter()->getHeaders(), $this->getHeaders()); return $this->getItemExporter()->save($headers, $finalData); } /** * Fetch assessment item data * * @return array */ protected function getAssessmentData() { $xml = \taoQtiTest_models_classes_QtiTestService::singleton()->getDoc($this->getResource($this->assessmentUri)); $testPartCollection = $xml->getDocumentComponent()->getComponentsByClassName(self::TEST_PART); $assessmentItemData = []; /** @var TestPart $testPart */ foreach ($testPartCollection as $testPart) { $sectionCollection = $testPart->getAssessmentSections(); /** @var AssessmentSection $section */ foreach ($sectionCollection as $section) { $itemCollection = $section->getComponentsByClassName(self::TEST_ITEM); $order = 1; /** @var AssessmentItemRef $item */ foreach ($itemCollection as $item) { $assessmentItemData[$item->getIdentifier()] = [ self::ITEM_URI => $item->getHref(), self::TEST_PART => $testPart->getIdentifier(), self::TEST_SECTION => $section->getIdentifier(), self::ITEM_SHUFFLE => is_null($section->getOrdering()) ? 0 : (int)$section->getOrdering()->getShuffle(), self::ITEM_ORDER => $order, ]; $order++; } } } return $assessmentItemData; } /** * Get headers of additional data for assessment items * * @return array */ protected function getHeaders() { return [self::TEST_PART, self::TEST_SECTION, self::ITEM_SHUFFLE, self::ITEM_ORDER]; } /** * Get item exporter service * * @return SimpleExporter */ protected function getItemExporter() { if (!$this->itemExporter) { $this->itemExporter = $this->getServiceLocator()->get(SimpleExporter::SERVICE_ID); } if ($this->hasOption(self::OPTION_FILE_NAME)) { $this->itemExporter->setOption(ItemExporter::OPTION_FILE_LOCATION, $this->getOption(self::OPTION_FILE_NAME)); } return $this->itemExporter; } }