/** * @param $item * @param $manifest * @return array * @throws Exception */ private function createZipArchive($item, $manifest = null) { $path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('test_') . '.zip'; $zipArchive = new ZipArchive(); if ($zipArchive->open($path, ZipArchive::CREATE) !== true) { throw new Exception('Unable to create archive at ' . $path); } if ($this->itemService->hasItemModel($item, array(ItemModel::MODEL_URI))) { $exporter = new QTIPackedItemExporter($item, $zipArchive, $manifest); $exporter->export(); $manifest = $exporter->getManifest(); } $this->assertTrue($this->itemService->hasItemModel($item, array(ItemModel::MODEL_URI))); $this->assertNotNull($manifest); $this->assertEquals(ZipArchive::ER_OK, $zipArchive->status, $zipArchive->getStatusString()); $zipArchive->close(); $this->assertTrue(file_exists($path), 'could not find path ' . $path); $this->exportedZips[] = $path; return array($path, $manifest); }
/** * render an item as a Qti zip package * @author christophe GARCIA <*****@*****.**> */ public function export() { try { if ($this->getRequestMethod() != Request::HTTP_GET) { throw new \common_exception_NotImplemented('Only GET method is accepted to export QIT Item.'); } if (!$this->hasRequestParameter('id')) { $this->returnFailure(new \common_exception_MissingParameter('required parameter `id` is missing')); } $id = $this->getRequestParameter('id'); $item = new \core_kernel_classes_Resource($id); $itemService = \taoItems_models_classes_ItemsService::singleton(); if ($itemService->hasItemModel($item, array(ItemModel::MODEL_URI))) { $path = \tao_helpers_Export::getExportFile(); $tmpZip = new \ZipArchive(); $tmpZip->open($path, \ZipArchive::CREATE); $exporter = new QTIPackedItemExporter($item, $tmpZip); $exporter->export(array('apip' => false)); $exporter->getZip()->close(); header('Content-Type: application/zip'); \tao_helpers_Http::returnFile($path, false); return; } else { $this->returnFailure(new \common_exception_NotFound('item can\'t be found')); } } catch (\Exception $e) { $this->returnFailure($e); } }
/** * (non-PHPdoc) * @see tao_models_classes_export_ExportHandler::export() */ public function export($formValues, $destination) { $file = null; if (isset($formValues['filename'])) { $instances = $formValues['instances']; if (count($instances) > 0) { $itemService = taoItems_models_classes_ItemsService::singleton(); $fileName = $formValues['filename'] . '_' . time() . '.zip'; $path = tao_helpers_File::concat(array($destination, $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); } $manifest = null; foreach ($instances as $instance) { $item = new core_kernel_classes_Resource($instance); if ($itemService->hasItemModel($item, array(ItemModel::MODEL_URI))) { $exporter = new QTIPackedItemExporter($item, $zipArchive, $manifest); $exporter->export(); $manifest = $exporter->getManifest(); } } $zipArchive->close(); $file = $path; } } else { common_Logger::w('Missing filename for export using ' . __CLASS__); } return $file; }
public function buildBasePath() { $basePath = parent::buildBasePath(); return 'items/' . $basePath; }