Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| ItemsScannerService | |
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
72 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| isPciUsedInItems | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
42 | |||
| getItemResource | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace oat\qtiItemPci\model; |
| 4 | |
| 5 | use oat\taoQtiItem\model\portableElement\exception\PortableElementException; |
| 6 | use oat\taoQtiItem\model\qti\interaction\PortableCustomInteraction; |
| 7 | use oat\taoQtiItem\model\qti\Service as QtiService; |
| 8 | |
| 9 | /** |
| 10 | * Scan items for desire content |
| 11 | * Class ItemsScannerService |
| 12 | * @author Bartlomiej Marszal |
| 13 | */ |
| 14 | class ItemsScannerService |
| 15 | { |
| 16 | /** |
| 17 | * @var QtiService |
| 18 | */ |
| 19 | private $qtiService; |
| 20 | |
| 21 | /** |
| 22 | * ItemsScannerService constructor. |
| 23 | * @param QtiService $qtiServiceSingleton |
| 24 | */ |
| 25 | public function __construct(QtiService $qtiServiceSingleton) |
| 26 | { |
| 27 | $this->qtiService = $qtiServiceSingleton; |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * @param string $requestTypeIndentifier |
| 32 | * @param array $allItems |
| 33 | * @throws \common_Exception |
| 34 | * @throws \common_exception_Error |
| 35 | */ |
| 36 | public function isPciUsedInItems($requestTypeIndentifier, array $allItems) |
| 37 | { |
| 38 | foreach ($allItems as $key => $item) { |
| 39 | if ($this->qtiService->getDataItemByRdfItem($this->getItemResource($key)) !== null) { |
| 40 | $interactions = $this->qtiService |
| 41 | ->getDataItemByRdfItem($this->getItemResource($key)) |
| 42 | ->getInteractions(); |
| 43 | |
| 44 | foreach ($interactions as $interaction) { |
| 45 | if ( |
| 46 | $interaction instanceof PortableCustomInteraction |
| 47 | && $requestTypeIndentifier === $interaction->getTypeIdentifier() |
| 48 | ) { |
| 49 | throw new PortableElementException('Portable element is used in one of items'); |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * @param string|\core_kernel_classes_Container $key |
| 58 | * @return \core_kernel_classes_Resource |
| 59 | * @throws \common_exception_Error |
| 60 | */ |
| 61 | protected function getItemResource($key) |
| 62 | { |
| 63 | return new \core_kernel_classes_Resource($key); |
| 64 | } |
| 65 | } |