Skip to content

Commit d8c5703

Browse files
committed
Merge remote-tracking branch
'github_troosan/fix_for_different_even_odd_headers' into develop Conflicts: tests/PhpWord/SettingsTest.php tests/PhpWord/Writer/Word2007/Part/SettingsTest.php
2 parents 7c08dd5 + aef7a0b commit d8c5703

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

src/PhpWord/Settings.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,14 @@ class Settings
145145
* @var bool
146146
*/
147147
private static $outputEscapingEnabled = false;
148-
148+
149+
/**
150+
* Enables different header for odd and even pages.
151+
*
152+
* @var bool
153+
*/
154+
private static $evenAndOddHeaders = false;
155+
149156
/**
150157
* Return the compatibility option used by the XMLWriter
151158
*
@@ -352,6 +359,22 @@ public static function setOutputEscapingEnabled($outputEscapingEnabled)
352359
self::$outputEscapingEnabled = $outputEscapingEnabled;
353360
}
354361

362+
/**
363+
* @return boolean
364+
*/
365+
public static function isEvenAndOddHeaders()
366+
{
367+
return self::$evenAndOddHeaders;
368+
}
369+
370+
/**
371+
* @param boolean $evenAndOddHeaders
372+
*/
373+
public static function setEvenAndOddHeaders($evenAndOddHeaders)
374+
{
375+
self::$evenAndOddHeaders = $evenAndOddHeaders;
376+
}
377+
355378
/**
356379
* Get default font name
357380
*

src/PhpWord/Writer/Word2007/Part/Settings.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ private function getSettings()
105105
'w:defaultTabStop' => array('@attributes' => array('w:val' => '708')),
106106
'w:hyphenationZone' => array('@attributes' => array('w:val' => '425')),
107107
'w:characterSpacingControl' => array('@attributes' => array('w:val' => 'doNotCompress')),
108+
'w:evenAndOddHeaders' => array('@attributes' => array('w:val' => DocumentSettings::isEvenAndOddHeaders() ? 'true': 'false')),
108109
'w:themeFontLang' => array('@attributes' => array('w:val' => 'en-US')),
109110
'w:hideSpellingErrors' => array('@attributes' => array('w:val' => DocumentSettings::isSpellingErrorsHidden() ? 'true' : 'false')),
110111
'w:hideGrammaticalErrors' => array('@attributes' => array('w:val' => DocumentSettings::isGrammaticalErrorsHidden() ? 'true' : 'false')),

tests/PhpWord/SettingsTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,16 @@ public function testSetGetSpellingGrammar()
128128
$this->assertTrue(Settings::isGrammaticalErrorsHidden());
129129
}
130130

131+
/**
132+
* Test set/get even and odd headers
133+
*/
134+
public function testSetGetEvenAndOddHeaders()
135+
{
136+
$this->assertFalse(Settings::isEvenAndOddHeaders());
137+
Settings::setEvenAndOddHeaders(true);
138+
$this->assertTrue(Settings::isEvenAndOddHeaders());
139+
}
140+
131141
/**
132142
* Test load config
133143
*/

tests/PhpWord/Writer/Word2007/Part/SettingsTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,23 @@ public function testSpelling()
104104

105105
$this->assertEquals('true', $element->getAttribute('w:val'));
106106
}
107+
108+
/**
109+
* Test even and odd headers
110+
*/
111+
public function testEvenAndOddHeaders()
112+
{
113+
$phpWord = new PhpWord();
114+
Settings::setEvenAndOddHeaders(true);
115+
116+
$doc = TestHelperDOCX::getDocument($phpWord);
117+
118+
$file = 'word/settings.xml';
119+
120+
$path = '/w:settings/w:evenAndOddHeaders';
121+
$this->assertTrue($doc->elementExists($path, $file));
122+
123+
$element = $doc->getElement($path, $file);
124+
$this->assertEquals('true', $element->getAttribute('w:val'));
125+
}
107126
}

0 commit comments

Comments
 (0)