Skip to content

Commit

Permalink
Feedbacks from @Progi1984
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed Dec 13, 2023
1 parent 0e5dd85 commit 9bd6f4a
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 43 deletions.
1 change: 1 addition & 0 deletions docs/changes/1.1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

## Improvements
- Slide : Raised max value for identifier rand call - [@Scheissy](https://github.com/Scheissy) in [#777](https://github.com/PHPOffice/PHPPresentation/pull/777)
- Document Properties : Support for Revision & Status [@devX2712](https://github.com/devX2712) in [#788](https://github.com/PHPOffice/PHPPresentation/pull/787)

## Bugfixes

Expand Down
35 changes: 15 additions & 20 deletions src/PhpPresentation/DocumentProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,18 @@ class DocumentProperties
private $company;

/**
* revision
* Revision.
*
* @var string
*/
private $revision;

/**
* Status.
*
* @var string
*/
private $status;

/**
* Custom Properties.
Expand All @@ -116,14 +123,7 @@ class DocumentProperties
private $customProperties = [];

/**
* status
*
* @var string
*/
private $status;

/**
* Create a new \PhpOffice\PhpPresentation\DocumentProperties
* Create a new \PhpOffice\PhpPresentation\DocumentProperties.
*/
public function __construct()
{
Expand All @@ -139,7 +139,7 @@ public function __construct()
$this->category = '';
$this->company = 'Microsoft Corporation';
$this->revision = '';
$this->status = '';
$this->status = '';
}

/**
Expand Down Expand Up @@ -479,7 +479,7 @@ public function getRevision(): string
}

/**
* Set Revision
* Set Revision.
*/
public function setRevision(string $pValue = ''): self
{
Expand All @@ -489,22 +489,17 @@ public function setRevision(string $pValue = ''): self
}

/**
* Get Status
*
* @return string
* Get Status.
*/
public function getStatus()
public function getStatus(): string
{
return $this->status;
}

/**
* Set Status
*
* @param string $pValue
* @return \PhpOffice\PhpPresentation\DocumentProperties
* Set Status.
*/
public function setStatus($pValue = '')
public function setStatus(string $pValue = ''): self
{
$this->status = $pValue;

Expand Down
8 changes: 4 additions & 4 deletions src/PhpPresentation/Reader/PowerPoint2007.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ protected function loadDocumentProperties(string $sPart): void
'/cp:coreProperties/dcterms:modified' => 'setModified',
'/cp:coreProperties/cp:revision' => 'setRevision',
'/cp:coreProperties/cp:contentStatus' => 'setStatus',
);
];
$oProperties = $this->oPhpPresentation->getDocumentProperties();
foreach ($arrayProperties as $path => $property) {
$oElement = $xmlReader->getElement($path);
Expand Down Expand Up @@ -913,15 +913,15 @@ protected function loadEffect(XMLReader $document, \DOMElement $nodeEffect)
$effect = new \PhpOffice\PhpPresentation\Style\Effect($type);
// load blur radius
if ($node->hasAttribute('blurRad')) {
$effect->setBlurRadius(CommonDrawing::emuToPixels($node->getAttribute('blurRad')));
$effect->setBlurRadius(CommonDrawing::emuToPixels((int) $node->getAttribute('blurRad')));
}
// load distance
if ($node->hasAttribute('dist')) {
$effect->setDistance(CommonDrawing::emuToPixels($node->getAttribute('dist')));
$effect->setDistance(CommonDrawing::emuToPixels((int) $node->getAttribute('dist')));
}
// load direction
if ($node->hasAttribute('dir')) {
$effect->setDirection(CommonDrawing::angleToDegrees($node->getAttribute('dir')));
$effect->setDirection((int) CommonDrawing::angleToDegrees((int) $node->getAttribute('dir')));
}
// load alignment
if ($node->hasAttribute('algn')) {
Expand Down
8 changes: 4 additions & 4 deletions src/PhpPresentation/Style/Effect.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ class Effect implements ComparableInterface
/**
* Hash index
*
* @var string
* @var ?int
*/
private string $hashIndex;
private $hashIndex;

/**
* Create a new \PhpOffice\PhpPresentation\Shape\Effect instance
Expand Down Expand Up @@ -276,7 +276,7 @@ public function getAlpha():int
*
* @return string Hash code
*/
public function getHashCode()
public function getHashCode(): string
{
return md5($this->effectType . $this->blurRadius . $this->distance . $this->direction . $this->alignment . $this->color->getHashCode() . $this->alpha . __CLASS__);
}
Expand All @@ -289,7 +289,7 @@ public function getHashCode()
*
* @return string Hash index
*/
public function getHashIndex()
public function getHashIndex(): ?int
{
return $this->hashIndex;
}
Expand Down
11 changes: 5 additions & 6 deletions src/PhpPresentation/Writer/PowerPoint2007/DocPropsCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,15 @@ public function render(): ZipInterface
$objWriter->writeElement('cp:revision', $this->oPresentation->getDocumentProperties()->getRevision());

// cp:contentStatus
$objWriter->writeElement('cp:contentStatus', $this->oPresentation->getDocumentProperties()->getStatus());

// cp:category
$objWriter->writeElement('cp:category', $this->oPresentation->getDocumentProperties()->getCategory());

if ($this->oPresentation->getPresentationProperties()->isMarkedAsFinal()) {
// cp:contentStatus = Final
$objWriter->writeElement('cp:contentStatus', 'Final');
} else {
$objWriter->writeElement('cp:contentStatus', $this->oPresentation->getDocumentProperties()->getStatus());
}

// cp:category
$objWriter->writeElement('cp:category', $this->oPresentation->getDocumentProperties()->getCategory());

$objWriter->endElement();

$this->oZip->addFromString('docProps/core.xml', $objWriter->getData());
Expand Down
2 changes: 2 additions & 0 deletions tests/PhpPresentation/Tests/DocumentPropertiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public function testGetSet(): void
'keywords' => '',
'category' => '',
'company' => '',
'revision' => '',
'status' => '',
];

foreach ($properties as $key => $val) {
Expand Down
2 changes: 2 additions & 0 deletions tests/PhpPresentation/Tests/Reader/PowerPoint2007Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ public function testLoadFile01(): void
self::assertEquals('Sample 02 Description', $oPhpPresentation->getDocumentProperties()->getDescription());
self::assertEquals('office 2007 openxml libreoffice odt php', $oPhpPresentation->getDocumentProperties()->getKeywords());
self::assertEquals('Sample Category', $oPhpPresentation->getDocumentProperties()->getCategory());
self::assertEquals('', $oPhpPresentation->getDocumentProperties()->getRevision());
self::assertEquals('', $oPhpPresentation->getDocumentProperties()->getStatus());
self::assertIsArray($oPhpPresentation->getDocumentProperties()->getCustomProperties());
self::assertCount(0, $oPhpPresentation->getDocumentProperties()->getCustomProperties());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ class DocPropsCoreTest extends PhpPresentationTestCase
{
protected $writerName = 'PowerPoint2007';

public function testRender(): void
{
$this->assertZipFileExists('docProps/core.xml');
$this->assertZipXmlElementNotExists('docProps/core.xml', '/cp:coreProperties/cp:contentStatus');
$this->assertIsSchemaECMA376Valid();
}

public function testDocumentProperties(): void
{
$expected = 'aAbBcDeE';
Expand All @@ -42,7 +35,9 @@ public function testDocumentProperties(): void
->setDescription($expected)
->setSubject($expected)
->setKeywords($expected)
->setCategory($expected);
->setCategory($expected)
->setRevision($expected)
->setStatus($expected);

$this->assertZipFileExists('docProps/core.xml');
$this->assertZipXmlElementExists('docProps/core.xml', '/cp:coreProperties/dc:creator');
Expand All @@ -57,6 +52,10 @@ public function testDocumentProperties(): void
$this->assertZipXmlElementEquals('docProps/core.xml', '/cp:coreProperties/cp:keywords', $expected);
$this->assertZipXmlElementExists('docProps/core.xml', '/cp:coreProperties/cp:category');
$this->assertZipXmlElementEquals('docProps/core.xml', '/cp:coreProperties/cp:category', $expected);
$this->assertZipXmlElementExists('docProps/core.xml', '/cp:coreProperties/cp:revision');
$this->assertZipXmlElementEquals('docProps/core.xml', '/cp:coreProperties/cp:revision', $expected);
$this->assertZipXmlElementExists('docProps/core.xml', '/cp:coreProperties/cp:contentStatus');
$this->assertZipXmlElementEquals('docProps/core.xml', '/cp:coreProperties/cp:contentStatus', $expected);
$this->assertIsSchemaECMA376Valid();
}

Expand All @@ -73,7 +72,8 @@ public function testMarkAsFinalFalse(): void
{
$this->oPresentation->getPresentationProperties()->markAsFinal(false);

$this->assertZipXmlElementNotExists('docProps/core.xml', '/cp:coreProperties/cp:contentStatus');
$this->assertZipXmlElementExists('docProps/core.xml', '/cp:coreProperties/cp:contentStatus');
$this->assertZipXmlElementEquals('docProps/core.xml', '/cp:coreProperties/cp:contentStatus', '');
$this->assertIsSchemaECMA376Valid();
}
}
12 changes: 12 additions & 0 deletions tests/PhpPresentation/Tests/_includes/PhpPresentationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,18 @@ public function assertZipXmlElementEquals($filePath, $xPath, $value): void
self::assertEquals($nodeList->item(0)->nodeValue, $value);
}

/**
* @param string $filePath
* @param string $xPath
* @param mixed $value
*/
public function assertZipXmlElementNotEquals($filePath, $xPath, $value): void
{
$this->writePresentationFile($this->oPresentation, $this->writerName);
$nodeList = $this->getXmlNodeList($filePath, $xPath);
self::assertNotEquals($nodeList->item(0)->nodeValue, $value);
}

/**
* @param mixed $value
*/
Expand Down

0 comments on commit 9bd6f4a

Please sign in to comment.