Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
wazelin committed Jun 3, 2022
2 parents 4509d3a + 8a06eb4 commit ce2c7f7
Show file tree
Hide file tree
Showing 20 changed files with 1,083 additions and 29 deletions.
2 changes: 2 additions & 0 deletions src/qtism/data/content/xhtml/Img.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
*/
class Img extends AtomicInline
{
public const QTI_CLASS_NAME_IMG='img';

/**
* The img's src attribute.
*
Expand Down
81 changes: 81 additions & 0 deletions src/qtism/data/content/xhtml/html5/Figcaption.php
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;
}
}
81 changes: 81 additions & 0 deletions src/qtism/data/content/xhtml/html5/Figure.php
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;
}
}
13 changes: 12 additions & 1 deletion src/qtism/data/storage/xml/marshalling/ContentMarshaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
use qtism\data\content\SimpleInline;
use qtism\data\content\TemplateBlock;
use qtism\data\content\TemplateInline;
use qtism\data\content\xhtml\html5\Figcaption;
use qtism\data\content\xhtml\html5\Figure;
use qtism\data\content\xhtml\lists\Dl;
use qtism\data\content\xhtml\lists\DlElement;
use qtism\data\content\xhtml\lists\Li;
Expand All @@ -64,6 +66,7 @@
use qtism\data\content\xhtml\tables\Tr;
use qtism\data\content\xhtml\text\Blockquote;
use qtism\data\content\xhtml\text\Div;
use qtism\data\content\xhtml\Img;
use qtism\data\ExternalQtiComponent;
use qtism\data\QtiComponent;
use qtism\data\QtiComponentCollection;
Expand Down Expand Up @@ -106,7 +109,7 @@ public function __construct($version)
'graphicGapMatchInteraction',
'hotspotChoice',
'hr',
'img',
Img::QTI_CLASS_NAME_IMG,
'include',
'math',
'mediaInteraction',
Expand Down Expand Up @@ -177,6 +180,8 @@ public function __construct($version)
'modalFeedback',
'feedbackBlock',
'bdo',
Figure::QTI_CLASS_NAME_FIGURE,
Figcaption::QTI_CLASS_NAME_FIGCAPTION
];

/**
Expand Down Expand Up @@ -288,6 +293,10 @@ protected function getChildrenComponents(QtiComponent $component)
return $component->getContent()->getArrayCopy();
} elseif ($component instanceof InfoControl) {
return $component->getContent()->getArrayCopy();
} elseif ($component instanceof Figure) {
return $component->getContent()->getArrayCopy();
} elseif ($component instanceof Figcaption) {
return $component->getContent()->getArrayCopy();
}
}

Expand Down Expand Up @@ -341,6 +350,8 @@ protected function getChildrenElements(DOMElement $element)
return self::getChildElements($element);
} elseif ($localName === 'simpleMatchSet') {
return $this->getChildElementsByTagName($element, 'simpleAssociableChoice');
} elseif ($localName === Figure::QTI_CLASS_NAME_FIGURE) {
return $this->getChildElementsByTagName($element, [Figcaption::QTI_CLASS_NAME_FIGCAPTION, Img::QTI_CLASS_NAME_IMG]);
} elseif ($localName === 'gapImg') {
return $this->getChildElementsByTagName($element, 'object');
} else {
Expand Down
103 changes: 103 additions & 0 deletions src/qtism/data/storage/xml/marshalling/Html5ContentMarshaller.php
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"
];
}
}
Loading

0 comments on commit ce2c7f7

Please sign in to comment.