Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Aug 2, 2016
2 parents ff62a44 + 49ed17f commit f73c989
Show file tree
Hide file tree
Showing 33 changed files with 740 additions and 588 deletions.
46 changes: 46 additions & 0 deletions src/qtism/data/QtiIdentifiableCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

use \InvalidArgumentException;
use \OutOfRangeException;
use \UnexpectedValueException;
use \SplObserver;
use \SplSubject;

Expand Down Expand Up @@ -152,13 +153,58 @@ public function offsetUnset($offset)
if (gettype($offset) === 'string') {
$data = &$this->getDataPlaceHolder();
if (isset($data[$offset])) {
$data[$offset]->detach($this);
unset($data[$offset]);
}
} else {
$msg = "The requested offset must be a non-empty string.";
throw new OutOfRangeException($msg);
}
}

/**
* Replace an $object in the collection by another $replacement $object.
*
* @param mixed $object An object to be replaced.
* @param mixed $replacement An object to be used as a replacement.
* @throws \InvalidArgumentException If $object or $replacement are not compliant with the current collection typing.
* @throws \UnexpectedValueException If $object is not contained in the collection.
*/
public function replace($object, $replacement)
{
$this->checkType($object);
$this->checkType($replacement);

if (($search = array_search($object, $this->dataPlaceHolder, true)) !== false) {

$objectKey = $object->getIdentifier();
$replacementKey = $replacement->getIdentifier();

if ($objectKey === $replacementKey) {
// If they share the same key, just replace.
$this->dataPlaceHolder[$objectKey] = $replacement;
} else {
// Otherwise, we have to insert the $replacement object at the appropriate offset (just before $object),
// and then remove the former $object.
$objectOffset = array_search($objectKey, array_keys($this->dataPlaceHolder));

$this->dataPlaceHolder = array_merge(
array_slice($this->dataPlaceHolder, 0, $objectOffset),
array($replacementKey => $replacement),
array_slice($this->dataPlaceHolder, $objectOffset, null)
);

$this->offsetUnset($objectKey);
}

$replacement->attach($this);
$object->detach($this);

} else {
$msg = "The object you want to replace could not be found.";
throw new UnexpectedValueException($msg);
}
}

/**
* Implementation of SplObserver::update.
Expand Down
41 changes: 2 additions & 39 deletions src/qtism/data/content/AtomicBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* 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) 2013-2014 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
* Copyright (c) 2013-2016 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
*
* @author Jérôme Bogaerts <[email protected]>
* @license GPLv2
Expand All @@ -30,13 +30,7 @@
*/
abstract class AtomicBlock extends BodyElement implements BlockStatic, FlowStatic
{
/**
* The base URI of the AtomicBlock.
*
* @var string
* @qtism-bean-property
*/
private $xmlBase = '';
use FlowTrait;

/**
* The collection of Inline components contained by the AtomicBlock.
Expand Down Expand Up @@ -89,35 +83,4 @@ public function getComponents()
{
return $this->getContent();
}

/**
* Set the base URI of the AtomicBlock.
*
* @param string $xmlBase A URI.
* @throws \InvalidArgumentException if $base is not a valid URI nor an empty string.
*/
public function setXmlBase($xmlBase = '')
{
if (is_string($xmlBase) && (empty($xmlBase) || Format::isUri($xmlBase))) {
$this->xmlBase = $xmlBase;
} else {
$msg = "The 'xmlBase' argument must be an empty string or a valid URI, '" . $xmlBase . "' given";
throw new InvalidArgumentException($msg);
}
}

/**
* Get the base URI of the AtomicBlock.
*
* @return string An empty string or a URI.
*/
public function getXmlBase()
{
return $this->xmlBase;
}

public function hasXmlBase()
{
return $this->getXmlBase() !== '';
}
}
42 changes: 3 additions & 39 deletions src/qtism/data/content/AtomicInline.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* 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) 2013-2014 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
* Copyright (c) 2013-2016 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
*
* @author Jérôme Bogaerts <[email protected]>
* @license GPLv2
Expand All @@ -34,13 +34,8 @@
*/
abstract class AtomicInline extends BodyElement implements FlowStatic, InlineStatic
{
/**
* The base URI of the AtomicInline.
*
* @var string
* @qtism-bean-property
*/
private $xmlBase = '';

use FlowTrait;

/**
* Create a new AtomicInline object.
Expand All @@ -65,35 +60,4 @@ public function getComponents()
{
return new QtiComponentCollection();
}

/**
* Set the base URI of the AtomicInline.
*
* @param string $XmlBase A URI.
* @throws \InvalidArgumentException if $base is not a valid URI nor an empty string.
*/
public function setXmlBase($xmlBase = '')
{
if (is_string($xmlBase) && (empty($xmlBase) || Format::isUri($xmlBase))) {
$this->xmlBase = $xmlBase;
} else {
$msg = "The 'xmlBase' argument must be an empty string or a valid URI, '" . $xmlBase . "' given";
throw new InvalidArgumentException($msg);
}
}

/**
* Get the base URI of the AtomicInline.
*
* @return string An empty string or a URI.
*/
public function getXmlBase()
{
return $this->xmlBase;
}

public function hasXmlBase()
{
return $this->getXmlBase() !== '';
}
}
46 changes: 2 additions & 44 deletions src/qtism/data/content/FeedbackBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* 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) 2013-2014 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
* Copyright (c) 2013-2016 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
*
* @author Jérôme Bogaerts <[email protected]>
* @license GPLv2
Expand All @@ -34,13 +34,7 @@
*/
class FeedbackBlock extends BodyElement implements FlowStatic, BlockStatic, FeedbackElement
{
/**
* The base URI.
*
* @var string
* @qtism-bean-property
*/
private $xmlBase = '';
use FlowTrait;

/**
* The components composing the FeedbackBlock content.
Expand Down Expand Up @@ -218,40 +212,4 @@ public function getQtiClassName()
{
return 'feedbackBlock';
}

/**
* Set the base URI of the TemplateBlock.
*
* @param string $xmlBase A URI.
* @throws \InvalidArgumentException if $base is not a valid URI nor an empty string.
*/
public function setXmlBase($xmlBase = '')
{
if (is_string($xmlBase) && (empty($xmlBase) || Format::isUri($xmlBase))) {
$this->xmlBase = $xmlBase;
} else {
$msg = "The 'base' argument must be an empty string or a valid URI, '" . $xmlBase . "' given";
throw new InvalidArgumentException($msg);
}
}

/**
* Get the base URI of the TemplateBlock.
*
* @return string An empty string or a URI.
*/
public function getXmlBase()
{
return $this->xmlBase;
}

/**
* Whether a value is defined for the base URI of the TemplateBlock.
*
* @return boolean
*/
public function hasXmlBase()
{
return $this->getXmlBase() !== '';
}
}
4 changes: 1 addition & 3 deletions src/qtism/data/content/Flow.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@
* 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) 2013-2014 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
* Copyright (c) 2013-2016 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
*
* @author Jérôme Bogaerts <[email protected]>
* @license GPLv2
*/

namespace qtism\data\content;

use \InvalidArgumentException;

/**
* From IMS QTI:
*
Expand Down
72 changes: 72 additions & 0 deletions src/qtism/data/content/FlowTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?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) 2013-2016 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
*
* @author Jérôme Bogaerts <[email protected]>
* @license GPLv2
*/

namespace qtism\data\content;

use \InvalidArgumentException;
use qtism\common\utils\Format;

/**
* The Flow trait.
*
* @authorJérôme Bogaerts <[email protected]>
* @see \qtism\data\content\Flow
*/
trait FlowTrait
{
private $xmlBase = '';

/**
* setXmlBase method implementation.
*
* @see \qtism\data\content\Flow::setXmlBase()
*/
public function setXmlBase($xmlBase = '')
{
if (is_string($xmlBase) && (empty($xmlBase) || Format::isUri($xmlBase))) {
$this->xmlBase = $xmlBase;
} else {
$msg = "The 'xmlBase' argument must be an empty string or a valid URI, '" . $xmlBase . "' given";
throw new InvalidArgumentException($msg);
}
}

/**
* getXmlBase method implementation.
*
* @see \qtism\data\content\Flow::getXmlBase()
*/
public function getXmlBase()
{
return $this->xmlBase;
}

/**
* hasXmlBase method implementation.
*
* @see \qtism\data\content\Flow::hasXmlBase()
*/
public function hasXmlBase()
{
return $this->getXmlBase() !== '';
}
}
Loading

0 comments on commit f73c989

Please sign in to comment.