-
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 #24 from oat-sa/feature/no-binaryStreamAccess-abst…
…raction Feature/no binary stream access abstraction
- Loading branch information
Showing
5 changed files
with
94 additions
and
119 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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; | ||
|
@@ -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 | ||
|
@@ -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; | ||
} | ||
|
||
/** | ||
|
@@ -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. | ||
* | ||
|
@@ -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
65
src/qtism/runtime/storage/binary/QtiBinaryStreamAccessFsFile.php
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -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 | ||
|
@@ -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; | ||
|
||
/** | ||
|
@@ -88,6 +89,6 @@ protected function getRetrievalStream($sessionId) | |
*/ | ||
protected function createBinaryStreamAccess(IStream $stream) | ||
{ | ||
return new QtiBinaryStreamAccessFsFile($stream); | ||
return new QtiBinaryStreamAccess($stream, new FileSystemFileManager()); | ||
} | ||
} |
Oops, something went wrong.