refactoring

This commit is contained in:
Roland Gruber 2020-05-07 20:22:41 +02:00
parent 81587a9b00
commit 665ca9daad
4 changed files with 17 additions and 4 deletions

View File

@ -61,7 +61,7 @@ include_once('pdfstruct.inc');
function createModulePDF($accounts, $pdf_structure, $font, $returnAsString = false) { function createModulePDF($accounts, $pdf_structure, $font, $returnAsString = false) {
$account_type = $accounts[0]->get_type(); $account_type = $accounts[0]->get_type();
// Get PDF structure from xml file // Get PDF structure from xml file
$reader = new PDFStructureReader(); $reader = new PDFStructureReader($_SESSION['config']->getName());
$structure = $reader->read($account_type->getId(), $pdf_structure); $structure = $reader->read($account_type->getId(), $pdf_structure);
// get list of PDF keys // get list of PDF keys
$pdfKeys = array(); $pdfKeys = array();

View File

@ -203,7 +203,7 @@ function deletePDFLogo($name, $serverProfileName) {
// check if still in use // check if still in use
$typeManager = new \LAM\TYPES\TypeManager(); $typeManager = new \LAM\TYPES\TypeManager();
$activeTypes = $typeManager->getConfiguredTypes(); $activeTypes = $typeManager->getConfiguredTypes();
$reader = new PDFStructureReader(); $reader = new PDFStructureReader($serverProfileName);
foreach ($activeTypes as $type) { foreach ($activeTypes as $type) {
$structures = getPDFStructures($type->getId(), $serverProfileName); $structures = getPDFStructures($type->getId(), $serverProfileName);
foreach ($structures as $structure) { foreach ($structures as $structure) {
@ -301,6 +301,17 @@ function installPDFTemplates() {
*/ */
class PDFStructureReader { class PDFStructureReader {
private $serverProfileName;
/**
* Constructor.
*
* @param $serverProfileName server profile name
*/
public function __construct($serverProfileName) {
$this->serverProfileName = $serverProfileName;
}
/** /**
* Reads a PDF structure. * Reads a PDF structure.
* *
@ -324,7 +335,7 @@ class PDFStructureReader {
* @return string file name * @return string file name
*/ */
protected function getFileName($typeId, $name) { protected function getFileName($typeId, $name) {
return dirname(__FILE__) . '/../config/pdf/' . $_SESSION['config']->getName() . '/' . $name . '.' . $typeId . '.xml'; return dirname(__FILE__) . '/../config/pdf/' . $this->serverProfileName . '/' . $name . '.' . $typeId . '.xml';
} }
/** /**

View File

@ -105,7 +105,7 @@ if(isset($_GET['abort'])) {
// Load PDF structure from file if it is not defined in session // Load PDF structure from file if it is not defined in session
if(!isset($_SESSION['currentPDFStructure'])) { if(!isset($_SESSION['currentPDFStructure'])) {
// Load structure file to be edit // Load structure file to be edit
$reader = new PDFStructureReader(); $reader = new PDFStructureReader($_SESSION['config']->getName());
try { try {
if(isset($_GET['edit'])) { if(isset($_GET['edit'])) {
$_SESSION['currentPDFStructure'] = $reader->read($type->getId(), $_GET['edit']); $_SESSION['currentPDFStructure'] = $reader->read($type->getId(), $_GET['edit']);

View File

@ -41,6 +41,7 @@ class ReadStructureTest extends TestCase {
*/ */
public function testRead() { public function testRead() {
$reader = $this->getMockBuilder('\LAM\PDF\PDFStructureReader') $reader = $this->getMockBuilder('\LAM\PDF\PDFStructureReader')
->setConstructorArgs(array('test'))
->setMethods(array('getFileName')) ->setMethods(array('getFileName'))
->getMock(); ->getMock();
$reader->method('getFileName')->willReturn($this->getTestFileName('test.xml')); $reader->method('getFileName')->willReturn($this->getTestFileName('test.xml'));
@ -99,6 +100,7 @@ class ReadStructureTest extends TestCase {
fclose($fileHandle); fclose($fileHandle);
// read structure // read structure
$reader = $this->getMockBuilder('\LAM\PDF\PDFStructureReader') $reader = $this->getMockBuilder('\LAM\PDF\PDFStructureReader')
->setConstructorArgs(array('test'))
->setMethods(array('getFileName')) ->setMethods(array('getFileName'))
->getMock(); ->getMock();
$reader->method('getFileName')->willReturn($file); $reader->method('getFileName')->willReturn($file);