Code Coverage  | 
      ||||||||||
Lines  | 
       Functions and Methods  | 
       Classes and Traits  | 
      ||||||||
| Total |         | 
       95.00%  | 
       19 / 20  | 
               | 
       50.00%  | 
       1 / 2  | 
       CRAP |         | 
       0.00%  | 
       0 / 1  | 
      
| NextItemData |         | 
       95.00%  | 
       19 / 20  | 
               | 
       50.00%  | 
       1 / 2  | 
       5 |         | 
       0.00%  | 
       0 / 1  | 
      
| process |         | 
       94.74%  | 
       18 / 19  | 
               | 
       0.00%  | 
       0 / 1  | 
       4.00 | |||
| getRequiredFields |         | 
       100.00%  | 
       1 / 1  | 
               | 
       100.00%  | 
       1 / 1  | 
       1 | |||
| 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) 2017-2022 (original work) Open Assessment Technologies SA ; | 
| 19 | */ | 
| 20 | |
| 21 | namespace oat\taoQtiTest\models\runner\synchronisation\action; | 
| 22 | |
| 23 | use common_Logger; | 
| 24 | use Exception; | 
| 25 | use oat\taoQtiTest\model\Service\ListItemsQuery; | 
| 26 | use oat\taoQtiTest\model\Service\ListItemsService; | 
| 27 | use oat\taoQtiTest\models\runner\synchronisation\TestRunnerAction; | 
| 28 | |
| 29 | class NextItemData extends TestRunnerAction | 
| 30 | { | 
| 31 | /** | 
| 32 | * Get item data by identifier | 
| 33 | * | 
| 34 | * Validate required fields. | 
| 35 | * Get item data by given identifier | 
| 36 | * | 
| 37 | * @return array | 
| 38 | */ | 
| 39 | public function process(): array | 
| 40 | { | 
| 41 | $this->validate(); | 
| 42 | |
| 43 | $itemIdentifiers = $this->hasRequestParameter('itemDefinition') | 
| 44 | ? $this->getRequestParameter('itemDefinition') | 
| 45 | : null; | 
| 46 | |
| 47 | if (!is_array($itemIdentifiers)) { | 
| 48 | $itemIdentifiers = [$itemIdentifiers]; | 
| 49 | } | 
| 50 | |
| 51 | try { | 
| 52 | $query = new ListItemsQuery( | 
| 53 | $this->getServiceContext(), | 
| 54 | $itemIdentifiers | 
| 55 | ); | 
| 56 | |
| 57 | /** @var ListItemsService $listItems */ | 
| 58 | $listItems = $this->getPsrContainer()->get(ListItemsService::class); | 
| 59 | |
| 60 | $response = $listItems($query); | 
| 61 | |
| 62 | return $response->toArray(); | 
| 63 | } catch (Exception $e) { | 
| 64 | common_Logger::e( | 
| 65 | $e->getMessage(), | 
| 66 | ['deliveryExecutionId' => $this->getServiceContext()->getTestExecutionUri()] | 
| 67 | ); | 
| 68 | return $this->getErrorResponse($e); | 
| 69 | } | 
| 70 | } | 
| 71 | |
| 72 | protected function getRequiredFields(): array | 
| 73 | { | 
| 74 | return array_merge(parent::getRequiredFields(), ['itemDefinition']); | 
| 75 | } | 
| 76 | } |