Пример #1
0
 private function questionnaireDefinition2completedResponseSchema($dom)
 {
     $xsl = new DOMDocument();
     if (!$xsl->load(_path(PROJECT_PATH, 'xml', 'csi-qframe-questionnaire-definition-to-completed-response-schema-v1_0.xsl'))) {
         $errors = libxml_get_errors();
         try {
             $logger = Zend_Registry::get('logger');
         } catch (Zend_Exception $e) {
         }
         foreach ($errors as $error) {
             $message = rtrim("XSL XML error on line {$error->line} of {$error->file}: {$error->message}");
             if (isset($logger) && $logger) {
                 $logger->log($message, Zend_Log::ERR);
             }
             error_log($message);
         }
         if (count($errors) > 0) {
             throw new Exception('XSL XML Validation Exception');
         }
     }
     $proc = new XSLTProcessor();
     $proc->importStyleSheet($xsl);
     $result = $proc->transformToXML($dom);
     $files = new FileModel($this);
     $files->store($result, array('filename' => 'completed-response-schema.xsd'));
 }
Пример #2
0
 public function testFetchAllWorksProperly()
 {
     $contents1 = file_get_contents(TEST_PATH . '/fixtures/sample.pdf');
     $contents2 = file_get_contents(TEST_PATH . '/fixtures/sample.doc');
     $files = new FileModel(new QuestionModel(array('questionID' => 1)));
     $ids = array();
     $ids[] = $files->store($contents1);
     $ids[] = $files->store($contents2);
     $this->assertEquals($ids, $files->fetchAll());
 }
Пример #3
0
 /**
  * Helper function for importXML.  Logic specifically for attachments.
  *
  * @param  See importXML.
  */
 private static function importXMLAttachments($attachments, $question, $zip)
 {
     if ($attachments->length) {
         for ($a = 0; $a < $attachments->length; $a++) {
             $attachment = $attachments->item($a);
             $filename = $attachment->getElementsByTagName('filename')->item(0)->nodeValue;
             $mime = $attachment->getElementsByTagName('mime')->item(0)->nodeValue;
             $location = $attachment->getElementsByTagName('location')->item(0)->nodeValue;
             $fileObj = new FileModel($question);
             if (!is_a($zip, 'ZipArchiveModel')) {
                 throw new Exception('XML contains attachment but no zip archive was loaded');
             }
             $content = $zip->getFromName($location);
             if ($content === FALSE) {
                 throw new Exception("Unable to find filename in zip archive: {$location}");
             }
             $fileObj->store($content, array('filename' => $filename, 'mime' => $mime));
         }
     }
 }
Пример #4
0
 public function testKnownGoodZipArchiveEqualsGeneratedZipArchive()
 {
     $this->auth();
     $goodZip = new ZipArchiveModel(null, array('filename' => PROJECT_PATH . "/test/data/zip/test-archive.zip"));
     $xml = file_get_contents(PROJECT_PATH . "/test/data/xml/test1-questionnaire-definition.xml");
     QuestionnaireModel::importXML($xml);
     InstanceModel::importXML($xml, 'Test1 Company');
     $instance = new InstanceModel(array('questionnaireName' => 'Test1 Questionnaire', 'questionnaireVersion' => '3.00', 'revision' => 1, 'instanceName' => 'Test1 Company', 'depth' => 'question'));
     while ($page = $instance->nextPage()) {
         while ($section = $page->nextSection()) {
             while ($question = $section->nextQuestion()) {
                 $fileObj = new FileModel($question);
                 $fileObj->store(file_get_contents(PROJECT_PATH . '/test/data/zip/test-archive-attachment.txt'), array('filename' => 'test-archive-attachment.txt'));
                 break 3;
             }
         }
     }
     $zip = new ZipArchiveModel($instance, array('new' => '1'));
     $zip->addInstanceFullResponsesXMLDocument();
     $zip->addAttachments();
     $zip->close();
     $zip = new ZipArchiveModel($instance, array('filename' => $zip->getZipFileName()));
     $this->assertEquals($goodZip->getInstanceFullResponsesXMLDocument(), $zip->getInstanceFullResponsesXMLDocument());
     $this->assertEquals($goodZip->getFromName('files/4'), $zip->getFromName('files/4'));
     $zip->deleteZipFile();
 }