*/ namespace oat\taoQtiItem\model\qti; use oat\taoQtiItem\model\qti\container\ContainerTooltip; use oat\taoQtiItem\model\qti\container\FlowContainer; class Tooltip extends Element implements FlowContainer { protected static $qtiTagName = '_tooltip'; protected $content = ''; protected $body = null; public function __construct($attributes, Item $relatedItem = null, $serial = '') { parent::__construct($attributes, $relatedItem, $serial); $this->body = new ContainerTooltip(); } public function getUsedAttributes() { return []; } public function getSerial() { return '_' . parent::getSerial(); } public function getContent() { return $this->content; } public function setContent($content) { if (empty($content)) { $content = strval($content); } if (is_string($content)) { $this->content = $content; } else { throw new InvalidArgumentException('a Tooltip content can only be text'); } } /** * Add tooltip id & content to template variables */ protected function getTemplateQtiVariables() { // this is necessary because the QTI template gets a serialized string for attributes and cannot address a specific attribute $tooltipId = $this->getAttributeValue('aria-describedby'); $variables = parent::getTemplateQtiVariables(); $variables['tooltipId'] = $tooltipId; $variables['content'] = (string) $this->getContent(); return $variables; } /** * Add tooltip content to element serialization */ public function toArray($filterVariableContent = false, &$filtered = []) { $returnValue = parent::toArray($filterVariableContent, $filtered); $returnValue['content'] = (string) $this->getContent(); return $returnValue; } public function getBody() { return $this->body; } }