Skip to content

Commit

Permalink
use different cache for watermark print (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
bloep authored Aug 27, 2019
1 parent 522f5d6 commit 91a05c7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/TemplateFiller/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function setData($d)
$maxRowsVar = '';
}

$cachedTemplateKey = $this->templateCache->getCacheTemplateKey(basename($this->path), $maxRows);
$cachedTemplateKey = $this->templateCache->getCacheTemplateKey(basename($this->path), $maxRows, $this->probeausdruck);

if ($cachedTemplateKey && $this->templateCache->exists($cachedTemplateKey) && !$this->templateCache->isInvalid($cachedTemplateKey, $this->path)) {
$this->templateParser = $this->templateCache->loadFromCache($cachedTemplateKey);
Expand Down
12 changes: 6 additions & 6 deletions src/PhpSpreadsheet/TemplateFiller/TemplateCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@ public static function setCache(CacheInterface $cacheClass)
self::$cacheClass = $cacheClass;
}

public function getCacheTemplateKey($filename, $maxRows)
public function getCacheTemplateKey($filename, $maxRows, $probeausdruck = false)
{
$meta = $this->getTemplateMeta();
if (self::$cacheClass && isset($meta[$filename])) {
$fileCache = $meta[$filename];
$breakPoints = $fileCache['breakpoints'];

if ($breakPoints[TemplateParser::ONEPAGER] >= $maxRows) {
return self::getCacheKey($filename, TemplateParser::ONEPAGER, 0);
return self::getCacheKey($filename, TemplateParser::ONEPAGER, 0, $probeausdruck);
}

if (!isset($breakPoints[TemplateParser::TWOPAGER]) && !isset($breakPoints[TemplateParser::MULTIPAGER])) {
throw new Exception('Table is too large for the given template and twopager doesn\'t exists');
}

if (isset($breakPoints[TemplateParser::TWOPAGER]) && $breakPoints[TemplateParser::TWOPAGER] >= $maxRows) {
return self::getCacheKey($filename, TemplateParser::TWOPAGER, 0);
return self::getCacheKey($filename, TemplateParser::TWOPAGER, 0, $probeausdruck);
}

if (!isset($breakPoints[TemplateParser::MULTIPAGER])) {
Expand All @@ -52,7 +52,7 @@ public function getCacheTemplateKey($filename, $maxRows)
$neededRows = $maxRows - ($breakPoints[TemplateParser::NAME_STARTPAGE] + $breakPoints[TemplateParser::NAME_ENDPAGE]);
}
$additionalPages = max(0, ceil($neededRows / $breakPoints[TemplateParser::MULTIPAGER]));
return self::getCacheKey($filename, TemplateParser::MULTIPAGER, $additionalPages);
return self::getCacheKey($filename, TemplateParser::MULTIPAGER, $additionalPages, $probeausdruck);
}
return null;
}
Expand Down Expand Up @@ -93,9 +93,9 @@ private function getTemplateMeta()
return null;
}

public static function getCacheKey($filename, $type, $additionalPages = 0)
public static function getCacheKey($filename, $type, $additionalPages = 0, $probeausdruck = false)
{
return $filename.'_'.$type.'_'.$additionalPages;
return $filename.'_'.$type.'_'.($probeausdruck ? 'probe_' : '').$additionalPages;
}

public function loadFromCache($cachedTemplateKey)
Expand Down
6 changes: 5 additions & 1 deletion src/PhpSpreadsheet/TemplateFiller/TemplateParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ class TemplateParser
/** @var array */
private $headerFooter = [];

/** @var boolean */
private $probeausdruck = false;

public function __construct($path)
{
$this->path = $path;
Expand Down Expand Up @@ -466,7 +469,7 @@ public function getPreparedSpreadsheet()

public function getCacheKey()
{
return TemplateCache::getCacheKey(basename($this->path), self::getTypeNameByIndex($this->selectedIndex), $this->additionalPages);
return TemplateCache::getCacheKey(basename($this->path), self::getTypeNameByIndex($this->selectedIndex), $this->additionalPages, $this->probeausdruck);
}

public function getPath()
Expand Down Expand Up @@ -500,6 +503,7 @@ public function setLogo($path, $header, $position = HeaderFooter::IMAGE_HEADER_L
}

public function setProbeausdruck($path) {
$this->probeausdruck = true;
$drawing = new HeaderFooterDrawing();
$drawing->setName('Logo');
$drawing->setPath($path);
Expand Down

0 comments on commit 91a05c7

Please sign in to comment.