diff --git a/lam/lib/pdfstruct.inc b/lam/lib/pdfstruct.inc index 69270f2e..c9bff0e8 100644 --- a/lam/lib/pdfstruct.inc +++ b/lam/lib/pdfstruct.inc @@ -542,6 +542,28 @@ class PDFStructure { private $sections = array(); + /** + * Returns an array representation of the structure. + * + * @return array export data + */ + public function export() { + $data = array(); + $data['title'] = $this->title; + $data['foldingMarks'] = $this->foldingMarks; + $data['logo'] = $this->logo; + $data['sections'] = array(); + foreach($this->sections as $section) { + $type = ($section instanceof PDFTextSection) ? 'text' : 'entry'; + $sectionData = $section->export(); + $data['sections'][] = array( + 'type' => $type, + 'data' => $sectionData + ); + } + return $data; + } + /** * Returns the logo file path. * @@ -634,6 +656,15 @@ class PDFTextSection { $this->text = $text; } + /** + * Exports the section. + * + * @return string text + */ + public function export() { + return $this->getText(); + } + /** * Returns the text. * @@ -664,6 +695,21 @@ class PDFEntrySection { $this->title = $title; } + /** + * Exports the section. + * + * @return array export data + */ + public function export() { + $data = array(); + $data['title'] = $this->title; + $data['entries'] = array(); + foreach($this->getEntries() as $entry) { + $data['entries'][] = $entry->getKey(); + } + return $data; + } + /** * Returns if the title is an attribute value. * diff --git a/lam/tests/lib/pdfstructTest.php b/lam/tests/lib/pdfstructTest.php index 0f0d73ae..d290d751 100644 --- a/lam/tests/lib/pdfstructTest.php +++ b/lam/tests/lib/pdfstructTest.php @@ -1,4 +1,6 @@ export(); + + $this->assertEquals('sometext', $data); + } + +} + +/** + * Tests PDFEntrySection + */ +class PDFEntrySectionTest extends TestCase { + + public function testExport() { + $section = new PDFEntrySection('mytitle'); + $section->setEntries(array(new PDFSectionEntry('key1'), new PDFSectionEntry('key2'))); + + $data = $section->export(); + + $expected = array( + 'title' => 'mytitle', + 'entries' => array('key1', 'key2') + ); + + $this->assertEquals($expected, $data); + } + +} + +/** + * Tests PDFStructure + */ +class PDFStructureTest extends TestCase { + + public function testExport() { + $structure = new PDFStructure(); + $structure->setFoldingMarks(PDFStructure::FOLDING_STANDARD); + $structure->setLogo('somelogo'); + $structure->setTitle('mytitle'); + $entrySection = new PDFEntrySection('sometitle'); + $entrySection->setEntries(array(new PDFSectionEntry('key1'))); + $structure->setSections(array( + new PDFTextSection('sometext'), + $entrySection + )); + + $data = $structure->export(); + + $expected = array( + 'title' => 'mytitle', + 'foldingMarks' => PDFStructure::FOLDING_STANDARD, + 'logo' => 'somelogo', + 'sections' => array( + array( + 'type' => 'text', + 'data' => 'sometext' + ), + array( + 'type' => 'entry', + 'data' => array( + 'title' => 'sometitle', + 'entries' => array('key1') + ) + ) + ) + ); + + $this->assertEquals($expected, $data); + } + +} + ?> \ No newline at end of file