Jak przeniesc dane z jedneko pliku php do drugiego?

PHP to skryptowy język wykonywany po stronie serwera. Forum przeznaczone na pytania dot. programowania obiektowego, wzorców projektowych itp.
Awatar użytkownika
Scorpinus11
Posty: 2
Rejestracja: 10 lut 2014, 10:49

Jak przeniesc dane z jedneko pliku php do drugiego?

Post autor: Scorpinus11 » 11 lut 2014, 10:40

Witam. Mam pewien problem. Ot potrzebuje przeniesc dane z jednego pliku php do drugiego tak aby powstal jeden spojny. pierwszy plik to:RgHmiReportGenerator, drugi: RgRefSheetProductGenerator. HMI wyglda tak:
<?php
require_once 'classes/processors/RgProductProcessor.php';

class RgHmiReportGenerator extends RgProductProcessor
{
private $product;
private $orderNum;
private $productSku;
private $productId;
private $tempPdfFilePath;
private $tempHtmlFilePath;

public function __construct()
{

}

public function load($product, $productId)
{
if ($product == null)
{
throw new Exception("Product is NOT set. Loading product failed.");
}

if ($productId == null)
{
throw new Exception("Product ID is empty. Loading product failed.");
}

$this->product = $product;
$this->productSku = $this->product->getSku();
$this->productId = $productId;
$this->tempPdfFilePath = $_SERVER['DOCUMENT_ROOT'] . '/render_cache/pdf_hmi_report_' . $this->productId . '.pdf';
$this->tempHtmlFilePath = $_SERVER['DOCUMENT_ROOT'] . '/render_cache/html_hmi_report_'.$this->productId.'.html';
//$this->tempHtmlFilePath = $_SERVER['DOCUMENT_ROOT'] . '/render_cache/html_hmi_report.html';
$this->setImgPath();
}

public function process()
{
$htmlForPdf = $this->setHtml();
if($htmlForPdf == null)
{
throw new Exception("HTML rendering failed.");
}

$this->createTempHtmlFile($htmlForPdf);
$this->createTempPdfFile();

$html = $this->setHtml(true);
echo $html;
}

private function setImgPath()
{
$render_processor = new RgProductRenderProcessor();
$render_processor->load($this->product);
$render_processor->setFilename($this->productSku . '.jpg');
$render_processor->setImageWidth(250);
$render_processor->setImageHeight(250);
$render_processor->process();
$this->imgPath = $render_processor->toImage();
$render_processor->clean();
}

private function setHtml($isPrintButton)
{
ob_start();
// $cssPath = 'http://regaldev.localhost/skin/frontend ... erence.css';
$cssPath = 'http://' . $_SERVER['HTTP_HOST'] . '/skin/frontend/regal/regaltheme/css/reference.css';?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Model Boards List</title>
<link rel="stylesheet" type="text/css" href="<?php echo $cssPath; ?>" media="all" />
<style type="text/css">
div
{
padding: 10px;
}
table, th, td
{
font-size: 15px;
border: 1px solid grey;
border-collapse:collapse;
text-align: center;
vertical-align: middle;
padding: 5px;
}
</style>
</head>
<body>
<div>
<?php if($isPrintButton == true): ?>
<div>
<a href="<?php echo 'http://' . $_SERVER['HTTP_HOST'] . '/render_cache/pdf_hmi_report_' . $this->productId . '.pdf'; ?>">
<b>Print this page</b>
</a>
</div>
<?php endif; ?>
<div>
<img src="<?php echo $this->imgPath; ?>" alt="contoured" class="furniture" />
<p>Base Model: <b><?php echo $this->productSku; ?></b></p>
</div>
<div>
<p>Materials</p>
<table>
<tr>
<th>Material Type</th>
<th>Material Name</th>
</tr>
<?php $this->printProductMaterials(); ?>
</table>
</div>
<div>
<p>Product dimensions</p>
<table>
<?php $this->printProductDimensions(); ?>
</table>
</div>
<div>
<p>Boards</p>
<table>
<tr>
<?php $this->printBoardsTableHead();?>
</tr>
<?php $this->printBoardsTableRows(); ?>
</table>
</div>
<div>
<p>Extras:<p>
<?php $this->printExtrasNames();?>
</div>
</div>
</body>
</html>
<?php

return ob_get_clean();
}

private function printProductMaterials()
{
$materials = $this->product->getMaterials();
if($materials == null)
{
throw new Exception("Product's materials are not set.");
}

foreach ($materials as $type => $name)
{
echo '<tr>';
echo '<td>'.$type.'</td>';
echo '<td>'.$name.'</td>';
echo '</tr>';
}
}

private function printProductDimensions()
{
$productDimensions = $this->getProductDimensions();
if($productDimensions == null)
{
throw new Exception("Product's dimensions are not set.");
}

foreach ($productDimensions as $property => $valueInCentimetres)
{
$valueInMillimetres = $valueInCentimetres * 10;
echo '<tr>';
echo '<td>'.ucfirst($property).'</td>';
echo '<td>'.$valueInMillimetres.' mm</td>';
echo '</tr>';
}
}

private function getProductDimensions()
{
$geomParams = $this->product->getGeomParams();
if($geomParams == null)
{
throw new Exception("Product's geomParams are not set.");
}

foreach($geomParams as $dimention => $value)
{
switch($dimention)
{
case $dimention == 'width':
$productDimensions[$dimention]= $value;
break;

case $dimention == 'height':
$productDimensions[$dimention]= $value;
break;

case $dimention == 'depth':
$productDimensions[$dimention]= $value;
break;

default:
continue;
break;
}
}
$orderedProductDimensions = $this->setDimensionsOrder($productDimensions, 'height', 'depth');

return $orderedProductDimensions;
}

private function setDimensionsOrder($productDimensions, $key1, $key2)
{
if (!array_key_exists($key1, $productDimensions) || !array_key_exists($key2, $productDimensions) || $key1 == $key2)
{
return $productDimensions;
}

$swapped = array();

foreach($productDimensions as $key => $val)
{
if($key == $key1)
{
$swapped[$key2] = $productDimensions[$key2];
}
elseif($key == $key2)
{
$swapped[$key1] = $productDimensions[$key1];
}
else
{
$swapped[$key] = $val;
}
}

$productDimensions = $swapped;

return $productDimensions;
}

private function printBoardsTableHead()
{
$tableHeadValues = array(
'Board Name',
'Amount',
'Size A',
'Size B',
'Edge Front',
'Edge Back',
'Edge 3',
'Edge 4',
'Sand Surface',
'Oil Surface',
);

foreach ($tableHeadValues as $v)
{
echo '<th>'.$v.'</th>';
}
}

private function printBoardsTableRows()
{
$boardsArray = $this->product->getBoards();
if($boardsArray == null)
{
throw new Exception("Product has NO boards.");
}

foreach ($boardsArray as $boards)
{
$count = count($boards);
foreach ($boards as $board)
{
$this->printTableRow($board, $count);
break;
}
}
}

private function printTableRow($board, $count)
{
echo '<tr>';
$this->printBoardName($board);
$this->printBoardAmount($count);
$this->printBoardSizeA($board);
$this->printBoardSizeB($board);
$this->printBoardProperties($board);
echo '</tr>';
}

private function printBoardAmount($count)
{
echo '<td>'.$count.'</td>';
}
private function printBoardName($board)
{
$boardName = $board->getName();
echo '<td>'.$boardName.'</td>';
}

private function printBoardSizeA($board)
{
$sizeA = round($board->getDimensions()->getSizeA() * 10);
echo '<td>'.$sizeA.'</td>';
}

private function printBoardSizeB($board)
{
$sizeB = round($board->getDimensions()->getSizeB() * 10);
echo '<td>'.$sizeB.'</td>';
}

private function printBoardProperties($board)
{
$priceRules = $board->getPriceRules();
if($priceRules == null)
{
throw new Exception('Price rules are not set.');

}

$boardProperties = array(
'edge_front',
'edge_back',
'edge_3',
'edge_4',
'oil_surfaces',
'sand_surfaces',
);

foreach ($boardProperties as $boardProperty)
{
if(isset($priceRules[$boardProperty]))
{
echo '<td>ABS_2</td>';
}
else
{
echo '<td>&nbsp</td>';
}
}
}

private function printExtrasNames()
{
$extras = $this->product->getExtras();
if($extras)
{
foreach ($extras as $extra)
{
echo '<p> - '.$extra->getName().'</p>';
}
}
else
{
echo 'This product has NO extras.';
}
}

private function createTempHtmlFile($html)
{
if(!$handle = fopen($this->tempHtmlFilePath, 'w'))
{
throw new Exception("Cannot create ($this->tempHtmlFilePath)");
}
else
{
fwrite($handle, '');
fclose($handle);
}

if(is_writable($this->tempHtmlFilePath))
{
if(!$handle = fopen($this->tempHtmlFilePath, 'w'))
{
throw new Exception("Cannot open file ($this->tempHtmlFilePath)");
}

if(fwrite($handle, $html) === false)
{
throw new Exception("Cannot write to file ($this->tempHtmlFilePath)");
}

fclose($handle);
}
else
{
throw new Exception("The file $this->tempHtmlFilePath is not writable");
}
}

private function createTempPdfFile()
{
//http://code.google.com/p/wkhtmltopdf/
exec('wkhtmltopdf -s A4 ' . $_SERVER['HTTP_HOST'].'/render_cache/html_hmi_report_'.$this->productId.'.html' . ' '. $this->tempPdfFilePath);
}
}


natomiast Sheet jest taki:
<?php
require_once 'classes/processors/RgProductProcessor.php';

class RgRefSheetProductGenerator extends RgProductProcessor
{

private $orderNum;
private $orderData = array();
private $products = array();
private $items = array();
private $translator;
private $content;
private $printButton = false;


public function __construct()
{
$this->translator = RgApp::getTranslatorFactory()->createTranslator('mage');
}

public function load($orderNum)
{
$this->orderNum = $orderNum;
}

public function process()
{
$orderReader = RgApp::getReaderFactory()->createReader('mage-order');
$orderReader->load($this->orderNum);
$this->setOrderData($orderReader);
$this->setProducts();
$this->setHtml();
}

private function setOrderData($orderReader)
{
//Date setting
$orderDate = explode(' ', $orderReader->read('createdAt'));
$orderDateEnd = strtotime('+14 days', strtotime($orderDate[0]));
$orderDateEnd = date('Y-m-j', $orderDateEnd);

$this->orderData = array(
'billingAddress' => $orderReader->read('billingAddress')->format('html'),
'shippingAddress' => $orderReader->read('shippingAddress')->format('html'),
'paymentMethod' => $orderReader->read('payment')->getMethodInstance()->getTitle(),
'orderDate' => $orderDate[0],
'orderDateEnd' => $orderDateEnd,
'customerName' => $orderReader->read('customerName'),
'customerEmail' => $orderReader->read('customerEmail'),
'grandTotalPrice' => $orderReader->read('grandTotal'),
);
}

private function setProducts()
{
$orderReader = RgApp::getReaderFactory()->createReader('mage-order');
$orderReader->load($this->orderNum);
$items = $orderReader->read('allItems');

foreach ($items as $item)
{
$magentoId = $item['product_id'];

$reader = RgApp::getReaderFactory()->createReader('mage-product');
$reader->load('id', $magentoId);

$this->items[$magentoId]['sku'] = $reader->read('sku');
$this->items[$magentoId]['price'] = $reader->read('price');
$itemData = $item->getData();
$this->items[$magentoId]['quantity'] = $itemData['qty_ordered'];
$productData = RgApp::getProductDataFactory()->createProductData();
$productData->load($reader);

if ($productData->isConfigured())
{
$sku = $productData->getBaseModelCode();
$productRules = RgApp::loadProductRules($sku);

$extrasAssembler = RgApp::getProductAssemblerFactory()->createExtrasAssembler();
$extraReader = RgApp::getReaderFactory()->createReader('mage-product');
$extrasAssembler->load($productData, $extraReader, $productRules);
$extras = $extrasAssembler->produceExtras();

$boardAssembler = RgApp::getProductAssemblerFactory()->createBoardAssembler();
$boardAssembler->load($productData, $productRules, $extras);
$boards = $boardAssembler->produceBoards();
$productParams = $boardAssembler->getProductParams();
$productMaterials = $boardAssembler->getProductMaterials();

$product = RgApp::getProductFactory()->createProduct($sku);
$product->load($productParams, $boards, $extras);
$product->setMaterials($productMaterials);

$volumeCalculator = RgApp::getProcessorFactory()->createProcessor('volume');
$volumeCalculator->load($product);
$volumeCalculator->process();

$weightCalculator = RgApp::getProcessorFactory()->createProcessor('weight');
$weightCalculator->load($product);
$weightCalculator->process();

$shippingCalculator = RgApp::getProcessorFactory()->createProcessor('shipping');
$shippingCalculator->load($product);
$shippingCalculator->process($volumeCalculator);

$packagingCalculator = RgApp::getProcessorFactory()->createProcessor('packaging');
$packagingCalculator->load($product);
$packagingCalculator->process($weightCalculator);

$processingPrices = RgApp::getReaderFactory()->createReader('yml');
$processingPrices->load(RgApp::getPriceFormulasDirectory(), 'processing_prices');

$priceCalculator = RgApp::getProcessorFactory()->createProcessor('price');
$priceCalculator->load($packagingCalculator, $shippingCalculator, $processingPrices);
$priceCalculator->process($product);

$priceReport = RgApp::getProcessorFactory()->createProcessor('priceReport');
$priceReport->load($product, $processingPrices);
$priceReport->process($weightCalculator, $priceCalculator, $volumeCalculator);

$render_image = RgApp::renderProduct($product, $magentoId, array('250','250'), array(255,255,255));

$widgets = $productData->getProductGeomParamsValues()->getValues();

$this->items[$magentoId]['modelCode'] = $sku;

$this->products[$magentoId]['model'] = $product;
$this->products[$magentoId]['corners'] = $widgets['corners'];
$this->products[$magentoId]['qty'] = $itemData['qty_ordered'];
$this->products[$magentoId]['price'] = $item->getOriginalPrice();
$this->products[$magentoId]['totalPrice'] = $this->products[$magentoId]['qty'] * $this->products[$magentoId]['price'];
$this->products[$magentoId]['weight'] = $weightCalculator->getProductWeight();
$this->products[$magentoId]['volume'] = $volumeCalculator->getProductVolume();
$this->products[$magentoId]['image'] = $render_image;
$this->products[$magentoId]['totalReport'] = $priceReport->getTotalTable();
$this->products[$magentoId]['materialConsumption'] = $this->getMaterialConsumption($product);
}
}

$this->orderData['limit'] = count($this->products);

}

public function setPrintButton($flag)
{
$this->printButton = $flag;
}

private function getExtrasArray($extras)
{
$modExtras = array();

foreach ($extras as $extraCat => $extra)
{
$catIds = $extra->getCategoryIds();
$catId = isset($catIds[1]) ? (int) $catIds[1] : (int) $catIds[0];
$reader = RgApp::getReaderFactory()->createReader('mage-catalog');
$reader->load($catId);
$catName = $reader->read('name');
$modExtras[$catName] = $extra;
}

return $modExtras;
}

private function getMaterialConsumption($product)
{
$boards = $product->getBoards();
$matConsumption = array();

foreach ($boards as $boardSets)
{
foreach ($boardSets as $board)
{
$matType = $board->getMaterialType();
$boardDimensions = $board->getDimensions();
$matConsumption[$matType] += ($boardDimensions->getSizeA() * $boardDimensions->getSizeB())/10000;

$counter = 0;
foreach($board->getEdges() as $edge)
{
if($edge->isConsumptional() && preg_match('/edge/', $edge->getMatType()))
{
//front and back edge
if($counter == 0 || $counter == 2)
{
$matConsumption['edges'][$edge->getMatType()] += $boardDimensions->getSizeA();
}
else
{
$matConsumption['edges'][$edge->getMatType()] += $boardDimensions->getSizeB();
}
}
$counter++;
}
}
}

return $matConsumption;
}

private function setHtml()
{
$baseUrl = 'http://' . $_SERVER['HTTP_HOST'];
$skinPath = $baseUrl. '/skin/frontend/regal/regaltheme/';
$cssPath = $baseUrl . '/skin/frontend/regal/regaltheme/css/';

ob_start();
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Reference List</title>
<link rel="stylesheet" type="text/css" href="<?php echo $cssPath . 'reference.css'; ?>" media="all" />
<style type="text/css">
.print-wrap{
position: fixed;
top:0;left:0;
width: 100%;
height: 25px;
opacity: 0.8;
background: #FDFBB2;
padding: 10px 0px 0px 0px;
border-bottom: 1px solid #696969;
}
.printpage{
float: right;
margin-right: 15px;
color:#EE7626;
}
</style>
</head>
<body>
<?php if($this->printButton): ?>
<div class="print-wrap">
<a class="printpage" href="<?php echo $baseUrl . '/render_cache/reference_sheet_' . $this->orderNum . '.pdf' ?>"><b>Print this page</b></a>
</div>
<?php endif; ?>
<!-- Page 1 -->
<?php $counter = 1; ?>
<?php foreach ($this->products as $product): ?>
<?php // if ($product['isProductConfigured']): ?>
<?php $geomParams = $product['model']->getGeomParams(); ?>
<?php $materials = $product['model']->getMaterials(); ?>
<?php $matConsumption = $product['materialConsumption']; ?>
<?php $oldExtras = $product['model']->getExtras(); ?>
<?php $extras = $this->getExtrasArray($oldExtras); ?>
<div class="a4-format">
<div class="sheet-logo">
<img src="<?php echo $skinPath . 'images/logo_black_white.jpg' ?>" alt="regal" />
</div>
<div class="sheet-order-info">
<h3><b>Auftagsnummer:</b> <?php echo $this->orderNum; ?></h3>
<h3><b>Auftragsdatum:</b> <?php echo $this->orderData['orderDate']; ?></h3>
<h3><b>Name:</b> <?php echo $this->orderData['customerName']; ?></h3>
<h3><b>Email:</b> <?php echo $this->orderData['customerEmail']; ?></h3>
<div style="float: left;width: 300px; margin-right: 20px">
<h4>Billing Address:<br /><hr /></h4> <?php echo $this->orderData['billingAddress']; ?>
</div>
<div style="float: left;width: 300px;">
<h4>Shipping Address:<br /><hr /></h4> <?php echo $this->orderData['shippingAddress']; ?>
</div>
<br style="clear: both" />
<h4>Bezahlart: <?php echo $this->orderData['paymentMethod']; ?></h4>
<br />
<table class="styled">
<thead>
<th>Model</th>
<th>Artikel-Nr.</th>
<th>Preis</th>
<th>Menge</th>
<th>Zwischensumme</th>
</thead>
<tbody>
<?php foreach ($this->items as $item): ?>
<?php $productSku[] = $item['sku']; ?>
<tr>
<td><?php echo isset($item['modelCode']) ? $item['modelCode'] : ''; ?></td>
<td><?php echo $item['sku']; ?></td>
<td><?php echo number_format($item['price'], 2);?></td>
<td><?php echo $item['quantity']; ?></td>
<td><?php echo number_format($item['quantity'] * $item['price'], 2); ?></td>
</tr>
<?php endforeach; ?>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&euro;<?php echo number_format($this->orderData['grandTotalPrice'], 2); ?></td>
</tr>
</tbody>
</table>
</div>
<br />
<div>
<?php echo $product['totalReport']; ?>
</div>
</div>
<!-- Part 2 -->
<div class="a4-format">
<div class="sheet-order-info">
<h3><b>Auftagsnummer:</b> <?php echo $this->orderNum; ?></h3>
<h3><b>Produktionsauftrag für : <?php echo $counter; ?> von <?php echo $this->orderData['limit']; ?> Artikel</b></h3>
</div>
<table class="no-style">
<thead>
<th class="first">Model</th>
<th>Artikel-Nr.</th>
<th>Menge</th>
<th>Gewicht</th>
<th>Volumen</th>
</thead>
<tbody>
<tr>
<td class="first"><?php echo $product['model']->getSku(); ?></td>
<td><?php echo $productSku[$counter-1]; ?></td>
<td><?php echo $product['qty']; ?></td>
<td><?php echo $product['weight']; ?> kg</td>
<td><?php echo $product['volume']; ?> m<sup>3</sup></td>
</tr>
</tbody>
</table><br />
<b>Konfiguration:</b><br />
<div class="model_images">
<img src="<?php echo $baseUrl . $product['image']; ?>" /><br /><br />
<img src="<?php echo $skinPath . 'images/dimensions-pics/' . $product['model']->getSku() . '/correct.png' ?>" />
</div>
<div class="clear-fix"></div>
<br />
<b>Abmessungen (Außenmaße) in cm: </b>
<div style="width: 230px;">
<ul class="products-details">
<?php if (isset($geomParams['width'])): ?>
<li>Breite: <span class="right-pos"><?php echo $geomParams['width']; ?> cm </span</li>
<?php endif; ?>
<?php if (isset($geomParams['height'])): ?>
<li>Höhe: <span class="right-pos"><?php echo $geomParams['height']; ?> cm </span></li>
<?php endif; ?>
<?php if (isset($geomParams['depth'])): ?>
<li>Tiefe: <span class="right-pos"><?php echo $geomParams['depth']; ?> cm </span></li>
<?php endif; ?>
<li>&nbsp;</li>
<?php if (isset($geomParams['shelves'])): ?>
<li><b>Anzahl Regalböden:</b> <span class="right-pos"><?php echo $geomParams['shelves']; ?></span></li>
<li>&nbsp;</li>
<?php endif; ?>
<?php if (isset($geomParams['lower_height'])): ?>
<li><b>Sockelleiste:</b></li>
<li>Tiefe: <span class="right-pos"><?php echo isset($geomParams['lower_depth']) ? $geomParams['lower_depth'] : 0; ?> cm </span></li>
<li>Höhe: <span class="right-pos"><?php echo $geomParams['lower_height']; ?> cm </span></li>
<li>&nbsp;</li>
<?php endif; ?>
</ul>
</div>
<div>
<ul class="product-materials" style="width: 550px">
<?php foreach ($product['corners'] as $cornerName => $corner): ?>
<?php if ($corner['type'] != 0): ?>
<?php $cornerTitle = str_replace('_', ' ', uc_words($cornerName)) ?>
<?php $cornerName = str_replace('_', '-', $cornerName) ?>
<li><b><?php echo $cornerTitle; ?>: </b></li>
<li>
<span class="left-position">
<b>
<?php if ($corner['type'] == 1): ?>
<img src="<?php echo $skinPath . 'images/table-edges/big/'. $cornerName .'45-degrees.png'; ?>" width="80" />
<?php else: ?>
<img src="<?php echo $skinPath . 'images/table-edges/big/'. $cornerName .'90-degrees.png'; ?>" width="80"/>
<?php endif; ?>
</b>
</span>
<span class="right-position">
X-Scale: <?php echo $corner['x']; ?> cm<br />
Y-Scale: <?php echo $corner['y']; ?> cm
</span><br class="clear-fix" />
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
</div>
<h3><b>Materials:</b></h3>
<ul class="product-materials">
<?php foreach ($materials as $materialType => $material): ?>
<?php $materialData = RgApp::loadMaterial($material); ?>
<li>
<span class="left-position"><b><?php echo $this->translator->translate($materialType . '_material') ?>:</b></span>
<span class="right-position">
Sku: <?php echo $materialData->getSku(); ?><br />
Thickness: <?php echo $materialData->getThickness()*10; ?> mm<br />
<?php if (isset($matConsumption[$materialType])): ?>
Material Consumption: <?php echo $matConsumption[$materialType]; ?> m<sup>2</sup> <br />
<?php endif; ?>
<?php if (isset($matConsumption['edges'][$materialType])): ?>
Edge Lenght: <?php echo $matConsumption['edges'][$materialType]; ?> cm<br />
<?php endif; ?>
<?php echo $material . ' - ' . $materialData->getBsText(); ?> <br />
Wholesaler: <?php echo $materialData->getWholesaler(); ?><br />
</span>
<br class="clear-fix" />
</li>
<?php endforeach; ?>
</ul>
<div class="clear-fix"></div>
<h3><b>Ausstattung:</b></h3>
<ul class="product-ausstattung">
<?php if (count($extras) > 0): ?>
<?php foreach ($extras as $extraCat => $extra):?>
<li>
<span class="rposition"><b><?php echo ucwords(strtolower($extraCat . ': ')); ?></b></span>
<span style="float: left;"><?php echo ucwords(strtolower($extra->getName())); ?></span>
<span style="float: left;">&nbsp;&nbsp;Wholesaler:&nbsp;&nbsp;<?php echo ucwords(strtolower($extra->getWholesaler())); ?></span>
<br class="clear-fix"/>
</li>
<?php endforeach; ?>
<?php else: ?>
<li><span class="rposition"><b><?php echo 'No ausstattung'; ?></b></span><br class="clear-fix"/></li>
<?php endif; ?>
</ul>
</div>
<?php $counter++; ?>
<?php // endif; ?>
<?php endforeach; ?>
</body>
</html>
<?php
$this->content = ob_get_contents();
ob_end_clean();
}

public function getContent()
{
return $this->content;
}

}

<<?php
require_once 'classes/processors/RgProductProcessor.php';

class RgHmiReportGenerator extends RgProductProcessor
{
private $product;
private $orderNum;
private $productSku;
private $productId;
private $tempPdfFilePath;
private $tempHtmlFilePath;

public function __construct()
{

}

public function load($product, $productId)
{
if ($product == null)
{
throw new Exception("Product is NOT set. Loading product failed.");
}

if ($productId == null)
{
throw new Exception("Product ID is empty. Loading product failed.");
}

$this->product = $product;
$this->productSku = $this->product->getSku();
$this->productId = $productId;
$this->tempPdfFilePath = $_SERVER['DOCUMENT_ROOT'] . '/render_cache/pdf_hmi_report_' . $this->productId . '.pdf';
$this->tempHtmlFilePath = $_SERVER['DOCUMENT_ROOT'] . '/render_cache/html_hmi_report_'.$this->productId.'.html';
//$this->tempHtmlFilePath = $_SERVER['DOCUMENT_ROOT'] . '/render_cache/html_hmi_report.html';
$this->setImgPath();
}

public function process()
{
$htmlForPdf = $this->setHtml();
if($htmlForPdf == null)
{
throw new Exception("HTML rendering failed.");
}

$this->createTempHtmlFile($htmlForPdf);
$this->createTempPdfFile();

$html = $this->setHtml(true);
echo $html;
}

private function setImgPath()
{
$render_processor = new RgProductRenderProcessor();
$render_processor->load($this->product);
$render_processor->setFilename($this->productSku . '.jpg');
$render_processor->setImageWidth(250);
$render_processor->setImageHeight(250);
$render_processor->process();
$this->imgPath = $render_processor->toImage();
$render_processor->clean();
}

private function setHtml($isPrintButton)
{
ob_start();
// $cssPath = 'http://regaldev.localhost/skin/frontend ... erence.css';
$cssPath = 'http://' . $_SERVER['HTTP_HOST'] . '/skin/frontend/regal/regaltheme/css/reference.css';?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Model Boards List</title>
<link rel="stylesheet" type="text/css" href="<?php echo $cssPath; ?>" media="all" />
<style type="text/css">
div
{
padding: 10px;
}
table, th, td
{
font-size: 15px;
border: 1px solid grey;
border-collapse:collapse;
text-align: center;
vertical-align: middle;
padding: 5px;
}
</style>
</head>
<body>
<div>
<?php if($isPrintButton == true): ?>
<div>
<a href="<?php echo 'http://' . $_SERVER['HTTP_HOST'] . '/render_cache/pdf_hmi_report_' . $this->productId . '.pdf'; ?>">
<b>Print this page</b>
</a>
</div>
<?php endif; ?>
<div>
<img src="<?php echo $this->imgPath; ?>" alt="contoured" class="furniture" />
<p>Base Model: <b><?php echo $this->productSku; ?></b></p>
</div>
<div>
<p>Materials</p>
<table>
<tr>
<th>Material Type</th>
<th>Material Name</th>
</tr>
<?php $this->printProductMaterials(); ?>
</table>
</div>
<div>
<p>Product dimensions</p>
<table>
<?php $this->printProductDimensions(); ?>
</table>
</div>
<div>
<p>Boards</p>
<table>
<tr>
<?php $this->printBoardsTableHead();?>
</tr>
<?php $this->printBoardsTableRows(); ?>
</table>
</div>
<div>
<p>Extras:<p>
<?php $this->printExtrasNames();?>
</div>
</div>
</body>
</html>
<?php

return ob_get_clean();
}

private function printProductMaterials()
{
$materials = $this->product->getMaterials();
if($materials == null)
{
throw new Exception("Product's materials are not set.");
}

foreach ($materials as $type => $name)
{
echo '<tr>';
echo '<td>'.$type.'</td>';
echo '<td>'.$name.'</td>';
echo '</tr>';
}
}

private function printProductDimensions()
{
$productDimensions = $this->getProductDimensions();
if($productDimensions == null)
{
throw new Exception("Product's dimensions are not set.");
}

foreach ($productDimensions as $property => $valueInCentimetres)
{
$valueInMillimetres = $valueInCentimetres * 10;
echo '<tr>';
echo '<td>'.ucfirst($property).'</td>';
echo '<td>'.$valueInMillimetres.' mm</td>';
echo '</tr>';
}
}

private function getProductDimensions()
{
$geomParams = $this->product->getGeomParams();
if($geomParams == null)
{
throw new Exception("Product's geomParams are not set.");
}

foreach($geomParams as $dimention => $value)
{
switch($dimention)
{
case $dimention == 'width':
$productDimensions[$dimention]= $value;
break;

case $dimention == 'height':
$productDimensions[$dimention]= $value;
break;

case $dimention == 'depth':
$productDimensions[$dimention]= $value;
break;

default:
continue;
break;
}
}
$orderedProductDimensions = $this->setDimensionsOrder($productDimensions, 'height', 'depth');

return $orderedProductDimensions;
}

private function setDimensionsOrder($productDimensions, $key1, $key2)
{
if (!array_key_exists($key1, $productDimensions) || !array_key_exists($key2, $productDimensions) || $key1 == $key2)
{
return $productDimensions;
}

$swapped = array();

foreach($productDimensions as $key => $val)
{
if($key == $key1)
{
$swapped[$key2] = $productDimensions[$key2];
}
elseif($key == $key2)
{
$swapped[$key1] = $productDimensions[$key1];
}
else
{
$swapped[$key] = $val;
}
}

$productDimensions = $swapped;

return $productDimensions;
}

private function printBoardsTableHead()
{
$tableHeadValues = array(
'Board Name',
'Amount',
'Size A',
'Size B',
'Edge Front',
'Edge Back',
'Edge 3',
'Edge 4',
'Sand Surface',
'Oil Surface',
);

foreach ($tableHeadValues as $v)
{
echo '<th>'.$v.'</th>';
}
}

private function printBoardsTableRows()
{
$boardsArray = $this->product->getBoards();
if($boardsArray == null)
{
throw new Exception("Product has NO boards.");
}

foreach ($boardsArray as $boards)
{
$count = count($boards);
foreach ($boards as $board)
{
$this->printTableRow($board, $count);
break;
}
}
}

private function printTableRow($board, $count)
{
echo '<tr>';
$this->printBoardName($board);
$this->printBoardAmount($count);
$this->printBoardSizeA($board);
$this->printBoardSizeB($board);
$this->printBoardProperties($board);
echo '</tr>';
}

private function printBoardAmount($count)
{
echo '<td>'.$count.'</td>';
}
private function printBoardName($board)
{
$boardName = $board->getName();
echo '<td>'.$boardName.'</td>';
}

private function printBoardSizeA($board)
{
$sizeA = round($board->getDimensions()->getSizeA() * 10);
echo '<td>'.$sizeA.'</td>';
}

private function printBoardSizeB($board)
{
$sizeB = round($board->getDimensions()->getSizeB() * 10);
echo '<td>'.$sizeB.'</td>';
}

private function printBoardProperties($board)
{
$priceRules = $board->getPriceRules();
if($priceRules == null)
{
throw new Exception('Price rules are not set.');

}

$boardProperties = array(
'edge_front',
'edge_back',
'edge_3',
'edge_4',
'oil_surfaces',
'sand_surfaces',
);

foreach ($boardProperties as $boardProperty)
{
if(isset($priceRules[$boardProperty]))
{
echo '<td>ABS_2</td>';
}
else
{
echo '<td>&nbsp</td>';
}
}
}

private function printExtrasNames()
{
$extras = $this->product->getExtras();
if($extras)
{
foreach ($extras as $extra)
{
echo '<p> - '.$extra->getName().'</p>';
}
}
else
{
echo 'This product has NO extras.';
}
}

private function createTempHtmlFile($html)
{
if(!$handle = fopen($this->tempHtmlFilePath, 'w'))
{
throw new Exception("Cannot create ($this->tempHtmlFilePath)");
}
else
{
fwrite($handle, '');
fclose($handle);
}

if(is_writable($this->tempHtmlFilePath))
{
if(!$handle = fopen($this->tempHtmlFilePath, 'w'))
{
throw new Exception("Cannot open file ($this->tempHtmlFilePath)");
}

if(fwrite($handle, $html) === false)
{
throw new Exception("Cannot write to file ($this->tempHtmlFilePath)");
}

fclose($handle);
}
else
{
throw new Exception("The file $this->tempHtmlFilePath is not writable");
}
}

private function createTempPdfFile()
{
//http://code.google.com/p/wkhtmltopdf/
exec('wkhtmltopdf -s A4 ' . $_SERVER['HTTP_HOST'].'/render_cache/html_hmi_report_'.$this->productId.'.html' . ' '. $this->tempPdfFilePath);
}
}


Moje pytanie chce przeniesc dane tzn img obiektu wybranego oraz trzy tabele z hmi do sheet. Funkcja class oraZ require once wykorzystane czy mozna je w jakis sposob polaczyc i usunac zbedne dane?

ODPOWIEDZ