-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #312 from oat-sa/feature/TR-4179/support-qti-figur…
…e-elm feat: TR-4179 new html5 elements for QTI SDK
- Loading branch information
Showing
20 changed files
with
1,083 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
/** | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; under version 2 | ||
* of the License (non-upgradable). | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Copyright (c) 2022 (original work) Open Assessment Technologies SA; | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace qtism\data\content\xhtml\html5; | ||
|
||
use qtism\data\content\FlowStatic; | ||
use qtism\data\content\FlowTrait; | ||
use qtism\data\content\InlineCollection; | ||
|
||
class Figcaption extends Html5Element implements FlowStatic | ||
{ | ||
use FlowTrait; | ||
|
||
public const QTI_CLASS_NAME_FIGCAPTION = 'figcaption'; | ||
|
||
/** | ||
* The Block components composing the SimpleBlock object. | ||
* | ||
* @var InlineCollection | ||
* @qtism-bean-property | ||
*/ | ||
private $content; | ||
|
||
/** | ||
* Create a new figcaption object. | ||
*/ | ||
public function __construct($title = null, $role = null, $id = null, $class = null, $lang = null, $label = null) | ||
{ | ||
parent::__construct($title, $role, $id, $class, $lang, $label); | ||
$this->setContent(new InlineCollection()); | ||
} | ||
|
||
public function getQtiClassName() | ||
{ | ||
return self::QTI_CLASS_NAME_FIGCAPTION; | ||
} | ||
|
||
public function getComponents() | ||
{ | ||
return $this->getContent(); | ||
} | ||
|
||
/** | ||
* Set the collection of Flow objects composing the Div. | ||
* | ||
* @param InlineCollection $content A collection of Flow objects. | ||
*/ | ||
public function setContent(InlineCollection $content) | ||
{ | ||
$this->content = $content; | ||
} | ||
|
||
/** | ||
* Get the collection of Flow objects composing the Div. | ||
* | ||
* @return InlineCollection | ||
*/ | ||
public function getContent() | ||
{ | ||
return $this->content; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
/** | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; under version 2 | ||
* of the License (non-upgradable). | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Copyright (c) 2022 (original work) Open Assessment Technologies SA; | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace qtism\data\content\xhtml\html5; | ||
|
||
use qtism\data\content\FlowCollection; | ||
use qtism\data\content\FlowStatic; | ||
use qtism\data\content\FlowTrait; | ||
|
||
class Figure extends Html5Element implements FlowStatic | ||
{ | ||
use FlowTrait; | ||
|
||
public const QTI_CLASS_NAME_FIGURE = 'figure'; | ||
|
||
/** | ||
* The Block components composing the SimpleBlock object. | ||
* | ||
* @var FlowCollection | ||
* @qtism-bean-property | ||
*/ | ||
private $content; | ||
|
||
/** | ||
* Create a new figure object. | ||
*/ | ||
public function __construct($title = null, $role = null, $id = null, $class = null, $lang = null, $label = null) | ||
{ | ||
parent::__construct($title, $role, $id, $class, $lang, $label); | ||
$this->setContent(new FlowCollection()); | ||
} | ||
|
||
public function getQtiClassName() | ||
{ | ||
return self::QTI_CLASS_NAME_FIGURE; | ||
} | ||
|
||
public function getComponents() | ||
{ | ||
return $this->getContent(); | ||
} | ||
|
||
/** | ||
* Set the collection of Flow objects composing the Div. | ||
* | ||
* @param FlowCollection $content A collection of Flow objects. | ||
*/ | ||
public function setContent(FlowCollection $content) | ||
{ | ||
$this->content = $content; | ||
} | ||
|
||
/** | ||
* Get the collection of Flow objects composing the Div. | ||
* | ||
* @return FlowCollection | ||
*/ | ||
public function getContent() | ||
{ | ||
return $this->content; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
src/qtism/data/storage/xml/marshalling/Html5ContentMarshaller.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php | ||
|
||
/** | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; under version 2 | ||
* of the License (non-upgradable). | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Copyright (c) 2022 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); | ||
* | ||
* @author Julien Sébire <julien@taotesting.com> | ||
* @license GPLv2 | ||
*/ | ||
|
||
namespace qtism\data\storage\xml\marshalling; | ||
|
||
use DOMElement; | ||
use qtism\common\utils\Version; | ||
use qtism\data\content\FlowCollection; | ||
use qtism\data\content\xhtml\html5\Html5Element; | ||
use qtism\data\QtiComponent; | ||
use qtism\data\QtiComponentCollection; | ||
|
||
/** | ||
* Marshalling/Unmarshalling implementation for generic Html5. | ||
*/ | ||
abstract class Html5ContentMarshaller extends ContentMarshaller | ||
{ | ||
use QtiNamespacePrefixTrait; | ||
use QtiHtml5AttributeTrait; | ||
|
||
public function getExpectedQtiClassName() | ||
{ | ||
return Version::compare($this->getVersion(), '2.2', '>=') ? static::getExpectedQtiClassName() : 'not_existing'; | ||
} | ||
|
||
abstract protected static function getContentCollectionClassName(); | ||
|
||
/** | ||
* @param DOMElement $element | ||
* @param QtiComponentCollection $children | ||
* @return mixed | ||
* @throws UnmarshallingException | ||
*/ | ||
protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentCollection $children) | ||
{ | ||
$fqClass = $this->lookupClass($element); | ||
$component = new $fqClass(); | ||
$collectionClassName = static::getContentCollectionClassName() ?? FlowCollection::class; | ||
|
||
$component->setContent(new $collectionClassName($children->getArrayCopy())); | ||
|
||
if (($xmlBase = self::getXmlBase($element)) !== false) { | ||
$component->setXmlBase($xmlBase); | ||
} | ||
|
||
$this->fillBodyElementAttributes($component, $element); | ||
$this->fillBodyElement($component, $element); | ||
|
||
return $component; | ||
} | ||
|
||
|
||
/** | ||
* @param QtiComponent $component | ||
* @param array $elements | ||
* @return DOMElement | ||
*/ | ||
protected function marshallChildrenKnown(QtiComponent $component, array $elements) | ||
{ | ||
/** @var Html5Element $component */ | ||
$element = $this->getNamespacedElement($component); | ||
|
||
if ($component->hasXmlBase() === true) { | ||
self::setXmlBase($element, $component->getXmlBase()); | ||
} | ||
|
||
foreach ($elements as $e) { | ||
$element->appendChild($e); | ||
} | ||
|
||
$this->fillElement($element, $component); | ||
|
||
return $element; | ||
} | ||
|
||
protected function setLookupClasses() | ||
{ | ||
$this->lookupClasses = [ | ||
"qtism\\data\\content\\xhtml", | ||
"qtism\\data\\content\\xhtml\\html5" | ||
]; | ||
} | ||
} |
Oops, something went wrong.