Beispiel #1
0
 /**
  * Marshall a QTI File datatype into a binary string. The resulting binary string constitution
  * is the following:
  * 
  * * The length of the file name, unsigned short.
  * * The file name, string.
  * * The length of the mime type, unsigned short.
  * * The mime type, string.
  * * The binary content of the file, string.
  * 
  * @param File $file
  * @return string
  */
 public static function qtiFileToString(QtiFile $file)
 {
     $string = '';
     $filename = $file->getFilename();
     $mimetype = $file->getMimeType();
     $filenameLen = strlen($filename);
     $mimetypeLen = strlen($mimetype);
     $string .= pack('S', $filenameLen);
     $string .= $filename;
     $string .= pack('S', $mimetypeLen);
     $string .= $mimetype;
     // Avoid invalid data for serialize
     // (This could make me cry...)
     $string .= $file->getData();
     return $string;
 }
Beispiel #2
0
 /**
  * Marshall a QTI file datatype into its PCI JSON Representation.
  *
  * @param \qtism\common\datatypes\File $file
  * @return array
  */
 protected function marshallFile(QtiFile $file)
 {
     $data = array('base' => array('file' => array('mime' => $file->getMimeType(), 'data' => base64_encode($file->getData()))));
     if ($file->hasFilename() === true) {
         $data['base']['file']['name'] = $file->getFilename();
     }
     return $data;
 }