00001 <?php
00002 require_once 
TM_PATH . 'constants.php';
00003 require_once 
TM_PATH . 'juelich/JuelichGlobals.php';
00004 require_once 
TM_PATH . 'juelich/data/
JuelichDataProduct.php';
00005 require_once 
TM_PATH . 'juelich/lib/
JuelichFunction.php';
00006 
00015 define('TPL_L', 1);
00019 define('TPL_D', 2);
00020 
00026 class JuelichRendererProduct {
00027 
00035   function 
renderShortList($mId) {
00036     $data    =& 
getDataInstance();
00037     
$db      =& 
getDbReaderInstance();
00038     $l10n    = $data->getAppData('l10n');
00039     $func    = 
new JuelichFunction;
00040     $dProd   = 
new JuelichDataProduct;
00041     $rP      = 
new RendererProduct_(
TPL_L, $l10n, $func);
00042     $rA      = 
new RendererAccessory_(
TPL_L, $l10n, $func);
00043     $rV      = 
new RendererVariant_($l10n, $func);
00044     $content = '';
00045 
00046     $firstProduct = 
true;
00047     $name         = '';
00048     $oldName      = '';
00049     $products     = array();
00050     $dProd->getProducts($mId, $products);
00051 
00052     foreach ($products as $p) {
00053       $name = $p['product']['p_name'];
00054       
if ($rV->isVariant($name, $oldName)) {
00055         
if ($firstProduct) {
00056           $content .= $rV->getStart();
00057           $firstProduct = 
false;
00058         }
00059         $content .= $rV->getText($p['product']);
00060       }
00061       
else {
00062         $firstProduct = 
true;
00063         $content .= $rP->getText($p)
00064           . $rA->getText($p['access']);
00065       }
00066       $oldName = $name;
00067     }
00068     
return $content;
00069   }
00070 
00078   function 
renderProductDetail($
id) {
00079     $l10n = 
getDataInstance()->getAppData('l10n');
00080     $dProd= 
new JuelichDataProduct;
00081     $func = 
new JuelichFunction;
00082     $rP   = 
new RendererProduct_(
TPL_D, $l10n, $func);
00083     $row  = array();
00084     $dProd->getDetailProduct($
id, $row);
00085     
return $rP->getText($row);
00086   }
00087 
00095   function 
renderAccessDetail($
id) {
00096     $l10n = 
getDataInstance()->getAppData('l10n');
00097     $dProd= 
new JuelichDataProduct;
00098     $func = 
new JuelichFunction;
00099     $rA   = 
new RendererAccessory_(
TPL_D, $l10n, $func);
00100     $row  = array();
00101     $dProd->getDetailAccess($
id, $row);
00102     
return $rA->getText($row);
00103   }
00104 
00105 }
00106 
00111 class RendererProduct_ {
00112   var 
$tplType = '';            
00113   var 
$pList   = '';            
00114   var 
$pDetail = '';            
00115   var 
$func;                    
00117   function 
RendererProduct_($type, $l10n, &$func) {
00118       $this->tplType = $type;
00119       
$db            =& 
getDbReaderInstance();
00120       $tplName       = 'product-produkt-normal';
00121       $this->pList   = 
$db->getTemplateContent($tplName, $l10n);
00122       $tplName       = 'product-produkt-detail-normal';
00123       $this->pDetail = 
$db->getTemplateContent($tplName, 0);
00124       $this->func    = 
$func;
00125     }
00126     
00134   function 
getText(&$row) {
00135     $pData = array();
00136     $dData = '';
00137     $dData = $this->func->getModuleDataValues($row['detail'],
00138                                               $row['product']['produkt_id']);
00139     
00140     
switch ($this->tplType) {
00141     
case TPL_L:
00142       $pTpl  = $this->pList;
00143       $pData = $this->func->getProductDataValues($row['product']);
00144       $cTmp  = sprintf($pTpl,
00145                        $pData['imageLink'],
00146                        $pData['name'],
00147                        $dData,
00148                        $pData['text'],
00149                        $pData['detailLink'],
00150                        $pData['price']
00151                        );
00152       
if (!empty($row['depend'])) {
00153         $cTmp .= $this->
getDependOutputList($row['depend']);
00154       }
00155       
return $cTmp;
00156     
case TPL_D:
00157       $pTpl      = $this->pDetail;
00158       $pData     = $this->func->getProductDataDetailValues($row['product']);
00159       $nameExtra = '';
00160       $data      =& 
getDataInstance();
00161       
00162       
if ($data->getAppData('dependDetail')) {
00163         $l10n      = $data->getAppData('l10n');
00164         $nameExtra = $data->getAppData('module')->depend['scndName'][$l10n]
00165           . $row['detail']['prim_p_name'];
00166       }
00167       
00168       
return sprintf($pTpl,
00169                      $pData['image'],
00170                      $pData['name'] . $nameExtra,
00171                      $dData,
00172                      $pData['text'],
00173                      $pData['price']
00174                      );
00175     
default:
00176       
return '';
00177     }
00178   }
00179 
00188   function 
getDependOutputList(&$dpData) {
00189     
$db      =& 
getDbReaderInstance();
00190     $data    =& 
getDataInstance();
00191     $content = '';
00192     $modData = $data->getAppData('module')->depend;
00193     $l10n    = $data->getAppData('l10n');
00194       
00195     $content = 
$db->getTemplateContent($modData['tplStart'], $l10n);
00196     $tplRow  = 
$db->getTemplateContent($modData['tplRow'], 0);
00197     $pId = array_shift($dpData);
00198     foreach ($dpData as $row) {
00199       $yes = 
true;
00200       $dId = $row['produkt_id'];
00201       
if ($modData['constraint']) {
00202         $yes = $data->getAppData('module')->isSecondary($pId, $dId);
00203       }
00204       
if ($yes) {
00205         $href = 
'~'
00206           . $modData['name'][$l10n]
00207           . 
'/' 
00208           . $pId
00209           . 
'/'
00210           . $dId
00211           . 
'/'
00212           . $this->func->getValue(
F_U2P, $row['p_name'])
00213           . '.html';
00214         $content .= sprintf($tplRow,
00215                             $href,
00216                             $row['p_name'],
00217                             $this->func->getValue(
F_FP, $row['p_preis'])
00218                             );
00219       }
00220     }
00221     
return $content;
00222   }
00223     
00224 }
00225   
00230 class RendererAccessory_ {
00231   var 
$zLStart = '';            
00232   var 
$zLRow   = '';            
00233   var 
$zDetail = '';            
00234   var 
$type    = '';            
00235   var 
$func;                    
00237   function 
RendererAccessory_($type, $l10n, &$func) {
00238     
$db =& 
getDbReaderInstance();
00239     $this->zLStart = 
$db->getTemplateContent('product-zubehoer-normal-start',
00240                                              $l10n);
00241     $this->zLRow   = 
$db->getTemplateContent('product-zubehoer-normal', 0);
00242     $tplName       = 'product-produkt-detail-normal';
00243     $this->zDetail = 
$db->getTemplateContent($tplName, 0);
00244     $this->type    = 
$type;
00245     $this->func    = 
$func;
00246   }
00247   
00255   function 
getText(&$data) {
00256     
$s = count($data);
00257     
if (
$s == 0) {
00258       
return '';
00259     }
00260     $text = '';
00261     
switch ($this->type) {
00262     
case TPL_L:
00263       $text = $this->zLStart;
00264       foreach ($data as $d) {
00265         $aData = $this->func->getAccessDataValues($d);
00266         $text .= sprintf($this->zLRow,
00267                          $aData['detailLink'],
00268                          $aData['name'],
00269                          $aData['price']
00270                          );
00271       }
00272       
break;
00273     
case TPL_D:
00274       $zData = $this->func->getAccessDataDetailValues($data);
00275       $text = sprintf($this->zDetail,
00276                       $zData['image'],
00277                       $zData['name'],
00278                       '',
00279                       $zData['text'],
00280                       $zData['price']
00281                       );
00282       
break;
00283     
default:
00284       
break;
00285     }
00286     
return $text;
00287   }
00288 
00289 }
00290 
00295 class RendererVariant_ {
00296   var 
$vStart = '';             
00297   var 
$vNormal = '';            
00298   var 
$func;                    
00300   function 
RendererVariant_($l10n, &$func) {
00301     
$db =& 
getDbReaderInstance();
00302     $this->vStart = 
$db->getTemplateContent('product-variant-start',
00303                                             $l10n);
00304     $this->vNormal = 
$db->getTemplateContent('product-variant', 0);
00305     $this->func = 
$func;
00306   }
00307     
00316   function 
isVariant($name, $oldName) {
00317     $data =& 
getDataInstance();
00318     
if (!$data->getAppData('module')->variants ) {
00319       
return false;
00320     }
00321     $pattern = $data->getAppData('module')->variantPattern;
00322     preg_match($pattern, $name, $match);
00323     preg_match($pattern, $oldName, $match_zuvor);
00324     
return sizeof($match) > 1 &&
00325       
sizeof($match_zuvor) > 1 &&
00326       $match[1] == $match_zuvor[1] &&
00327       $match[1] != '' &&
00328       $match_zuvor[1] != '';
00329   }
00330 
00336   function 
getStart() {
00337     
return $this->vStart;
00338   }
00339 
00347   function 
getText(&$pData) {
00348     $linkData = array($pData['produkt_id'], $pData['p_name']);
00349     
return sprintf($this->vNormal,
00350                    $this->func->getValue(
F_LD, $linkData),
00351                    $pData['p_name'],
00352                    $this->func->getValue(
F_FP, $pData['p_preis'])
00353                    );
00354   }
00355 
00356 }
00357 
00358 ?>