Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 13 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| TextReaderLegacyDetection | |
0.00% |
0 / 13 |
|
0.00% |
0 / 4 |
90 | |
0.00% |
0 / 1 |
| isTextReaderWithImage | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| isLegacyTextReader | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| isPagesContainsImages | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| pageContentHasImage | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| 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) 2022-2023 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\pciSamples\model\LegacyPciHelper; |
| 24 | |
| 25 | use oat\taoQtiItem\model\qti\interaction\Interaction; |
| 26 | use oat\taoQtiItem\model\qti\interaction\PortableCustomInteraction; |
| 27 | |
| 28 | class TextReaderLegacyDetection |
| 29 | { |
| 30 | private const IMAGE_ATTRIBUTE_SUBSTRING = '<img'; |
| 31 | private const TEXT_READER_TYPE_IDENTIFIER = 'textReaderInteraction'; |
| 32 | |
| 33 | public function isTextReaderWithImage(Interaction $interaction): bool |
| 34 | { |
| 35 | $interactionProperties = $interaction->getProperties(); |
| 36 | return $this->isLegacyTextReader($interaction) && |
| 37 | isset($interactionProperties['pages']) && |
| 38 | $this->isPagesContainsImages($interactionProperties['pages']); |
| 39 | } |
| 40 | |
| 41 | public function isLegacyTextReader(Interaction $interaction): bool |
| 42 | { |
| 43 | return $interaction instanceof PortableCustomInteraction && |
| 44 | $interaction->getTypeIdentifier() === static::TEXT_READER_TYPE_IDENTIFIER; |
| 45 | } |
| 46 | |
| 47 | private function isPagesContainsImages(array $pages): bool |
| 48 | { |
| 49 | foreach ($pages as $page) { |
| 50 | if ($this->pageContentHasImage($page['content'])) { |
| 51 | return true; |
| 52 | } |
| 53 | } |
| 54 | return false; |
| 55 | } |
| 56 | |
| 57 | private function pageContentHasImage(array $content): bool |
| 58 | { |
| 59 | return !empty(array_filter($content, function ($var) { |
| 60 | return false !== strrpos($var, self::IMAGE_ATTRIBUTE_SUBSTRING); |
| 61 | })); |
| 62 | } |
| 63 | } |