Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| ExporterAction | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
42 | |
0.00% |
0 / 1 |
| __invoke | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
42 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2015 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | namespace oat\taoQtiItem\model\flyExporter; |
| 24 | |
| 25 | use oat\oatbox\action\Action; |
| 26 | use oat\oatbox\service\ConfigurableService; |
| 27 | use oat\taoQtiItem\model\flyExporter\simpleExporter\SimpleExporter; |
| 28 | |
| 29 | /** |
| 30 | * Command line entry to generate item export |
| 31 | * |
| 32 | * Class ExporterAction |
| 33 | * @package oat\taoQtiItem\model\simpleExporter |
| 34 | */ |
| 35 | class ExporterAction extends ConfigurableService implements Action |
| 36 | { |
| 37 | /** |
| 38 | * Call to launch export method of exporter |
| 39 | * |
| 40 | * php index.php 'oat\taoQtiItem\model\flyExporter\ExporterAction' $uri |
| 41 | * |
| 42 | * @param $params $params[0] is optional uri parameter |
| 43 | * @return \common_report_Report |
| 44 | */ |
| 45 | public function __invoke($params) |
| 46 | { |
| 47 | try { |
| 48 | \common_ext_ExtensionsManager::singleton()->getExtensionById('taoItems'); |
| 49 | |
| 50 | /** @var SimpleExporter $exporterService */ |
| 51 | $exporterService = $this->getServiceManager()->get(SimpleExporter::SERVICE_ID); |
| 52 | |
| 53 | $uri = isset($params[0]) ? $params[0] : null; |
| 54 | if (!is_null($uri)) { |
| 55 | $class = new \core_kernel_classes_Class($uri); |
| 56 | if ($class->exists()) { |
| 57 | $items = $class->getInstances(true); |
| 58 | } else { |
| 59 | throw new \Exception("Exporter needs a valid class uri."); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | $filename = $exporterService->export(isset($items) ? $items : $uri); |
| 64 | return new \common_report_Report( |
| 65 | \common_report_Report::TYPE_SUCCESS, |
| 66 | "\nExport end.\nCSV export is located at: " . $filename . "\n" |
| 67 | ); |
| 68 | } catch (\Exception $e) { |
| 69 | \common_Logger::w('Error during item metadata export: ' . $e->getMessage()); |
| 70 | return new \common_report_Report(\common_report_Report::TYPE_ERROR, "\n" . $e->getMessage() . "\n"); |
| 71 | } |
| 72 | } |
| 73 | } |