Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 20 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
| Tooltip | |
0.00% |
0 / 20 |
|
0.00% |
0 / 8 |
110 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getUsedAttributes | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getSerial | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getContent | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setContent | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| getTemplateQtiVariables | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| toArray | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| getBody | |
0.00% |
0 / 1 |
|
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) 2017 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | /** |
| 23 | * @author Christophe Noël <christophe@taotesting.com> |
| 24 | */ |
| 25 | |
| 26 | namespace oat\taoQtiItem\model\qti; |
| 27 | |
| 28 | use oat\taoQtiItem\model\qti\container\ContainerTooltip; |
| 29 | use oat\taoQtiItem\model\qti\container\FlowContainer; |
| 30 | |
| 31 | class Tooltip extends Element implements FlowContainer |
| 32 | { |
| 33 | protected static $qtiTagName = '_tooltip'; |
| 34 | protected $content = ''; |
| 35 | protected $body = null; |
| 36 | |
| 37 | public function __construct($attributes, Item $relatedItem = null, $serial = '') |
| 38 | { |
| 39 | parent::__construct($attributes, $relatedItem, $serial); |
| 40 | $this->body = new ContainerTooltip(); |
| 41 | } |
| 42 | |
| 43 | public function getUsedAttributes() |
| 44 | { |
| 45 | return []; |
| 46 | } |
| 47 | |
| 48 | public function getSerial() |
| 49 | { |
| 50 | return '_' . parent::getSerial(); |
| 51 | } |
| 52 | |
| 53 | public function getContent() |
| 54 | { |
| 55 | return $this->content; |
| 56 | } |
| 57 | |
| 58 | public function setContent($content) |
| 59 | { |
| 60 | if (empty($content)) { |
| 61 | $content = strval($content); |
| 62 | } |
| 63 | if (is_string($content)) { |
| 64 | $this->content = $content; |
| 65 | } else { |
| 66 | throw new InvalidArgumentException('a Tooltip content can only be text'); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Add tooltip id & content to template variables |
| 72 | */ |
| 73 | protected function getTemplateQtiVariables() |
| 74 | { |
| 75 | // this is necessary because the QTI template gets a serialized string for attributes and cannot address a |
| 76 | // specific attribute |
| 77 | $tooltipId = $this->getAttributeValue('aria-describedby'); |
| 78 | |
| 79 | $variables = parent::getTemplateQtiVariables(); |
| 80 | $variables['tooltipId'] = $tooltipId; |
| 81 | $variables['content'] = (string) $this->getContent(); |
| 82 | return $variables; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Add tooltip content to element serialization |
| 87 | */ |
| 88 | public function toArray($filterVariableContent = false, &$filtered = []) |
| 89 | { |
| 90 | $returnValue = parent::toArray($filterVariableContent, $filtered); |
| 91 | $returnValue['content'] = (string) $this->getContent(); |
| 92 | return $returnValue; |
| 93 | } |
| 94 | |
| 95 | public function getBody() |
| 96 | { |
| 97 | return $this->body; |
| 98 | } |
| 99 | } |