Skip to content

Commit

Permalink
Merge pull request #24 from oat-sa/feature/no-binaryStreamAccess-abst…
Browse files Browse the repository at this point in the history
…raction

Feature/no binary stream access abstraction
  • Loading branch information
Jérôme Bogaerts committed Nov 25, 2015
2 parents f62a42c + 20142d1 commit 0d2d380
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 119 deletions.
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-2015 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
*
* @author Jérôme Bogaerts <[email protected]>
* @license GPLv2
Expand All @@ -23,17 +23,15 @@

namespace qtism\runtime\storage\binary;



use qtism\data\state\ShufflingCollection;

use qtism\runtime\common\TemplateVariable;
use qtism\runtime\tests\AbstractSessionManager;
use qtism\common\datatypes\QtiFile;
use qtism\common\datatypes\QtiScalar;
use qtism\common\datatypes\QtiIdentifier;
use qtism\common\datatypes\QtiInteger;
use qtism\common\collections\IdentifierCollection;
use qtism\common\datatypes\files\FileManager;
use qtism\data\state\Value;
use qtism\data\state\Shuffling;
use qtism\data\state\ShufflingGroup;
Expand Down Expand Up @@ -64,6 +62,7 @@
use qtism\runtime\common\Variable;
use qtism\common\storage\IStream;
use qtism\common\storage\BinaryStreamAccess;
use \Exception;

/**
* The QtiBinaryStreamAccess aims at providing access to QTI data stored
Expand All @@ -72,23 +71,46 @@
* @author Jérôme Bogaerts <[email protected]>
*
*/
abstract class AbstractQtiBinaryStreamAccess extends BinaryStreamAccess
class QtiBinaryStreamAccess extends BinaryStreamAccess
{
const RW_VALUE = 0;

const RW_DEFAULTVALUE = 1;

const RW_CORRECTRESPONSE = 2;

private $fileManager;

/**
* Create a new QtiBinaryStreamAccess object.
*
* @param \qtism\common\storage\IStream $stream The IStream object to be accessed.
* @throws \qtism\common\storage\BinaryStreamAccessException If $stream is not open yet.
*/
public function __construct(IStream $stream)
public function __construct(IStream $stream, FileManager $fileManager)
{
parent::__construct($stream);
$this->setFileManager($fileManager);
}

/**
* Set the FileManager object.
*
* @param \qtism\common\datatypes\files\FileManager $fileManager A FileManager object.
*/
protected function setFileManager(FileManager $fileManager)
{
$this->fileManager = $fileManager;
}

/**
* Get the FileManager object.
*
* @return \qtism\common\datatypes\files\FileManager A FileManager object.
*/
protected function getFileManager()
{
return $this->fileManager;
}

/**
Expand Down Expand Up @@ -605,22 +627,6 @@ public function writeUri($uri)
}
}

/**
* Read a File from the current binary stream.
*
* @throws \qtism\runtime\storage\binary\QtiBinaryStreamAccessException
* @return \qtism\common\datatypes\File A File object
*/
abstract public function readFile();

/**
* Write A file composed by some $binaryContent into the current binary stream.
*
* @param \qtism\common\datatypes\File $file A File object
* @throws \qtism\runtime\storage\binary\QtiBinaryStreamAccessException
*/
abstract public function writeFile(QtiFile $file);

/**
* Read an intOrIdentifier from the current binary stream.
*
Expand Down Expand Up @@ -1060,4 +1066,35 @@ public function writePendingResponses(AssessmentTestSeeker $seeker, PendingRespo
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::PENDING_RESPONSES, $e);
}
}

/**
* Write a QtiFile object in the current binary stream.
*
* @param \qtism\common\datatypes\QtiFile $file
*/
public function writeFile(QtiFile $file)
{
try {
$this->writeString($file->getIdentifier());
} catch (QtiBinaryStreamAccessException $e) {
$msg = "An error occured while reading a QTI File.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::FILE, $e);
}
}

/**
* Read a QtiFile object from the current binary stream.
*
* @return \qtism\common\datatypes\QtiFile
*/
public function readFile()
{
try {
$id = $this->readString();
return $this->getFileManager()->retrieve($id);
} catch (\Exception $e) {
$msg = "An error occured while writing a QTI File.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::FILE, $e);
}
}
}
65 changes: 0 additions & 65 deletions src/qtism/runtime/storage/binary/QtiBinaryStreamAccessFsFile.php

This file was deleted.

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-2015 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
*
* @author Jérôme Bogaerts <[email protected]>
* @license GPLv2
Expand All @@ -27,6 +27,7 @@
use qtism\data\AssessmentTest;
use qtism\runtime\tests\AssessmentTestSession;
use qtism\common\storage\MemoryStream;
use qtism\common\datatypes\files\FileSystemFileManager;
use \RuntimeException;

/**
Expand Down Expand Up @@ -88,6 +89,6 @@ protected function getRetrievalStream($sessionId)
*/
protected function createBinaryStreamAccess(IStream $stream)
{
return new QtiBinaryStreamAccessFsFile($stream);
return new QtiBinaryStreamAccess($stream, new FileSystemFileManager());
}
}
Loading

0 comments on commit 0d2d380

Please sign in to comment.