VbzCart/archive/code/files/store.php
About
- Purpose: Classes for displaying different types of catalog display pages
- History:
- 2009-03-07 Transcribed from working code at vbz.net
- To Do:
- should be split up into auto-loadable class files, e.g. vbz.title.php, vbz.dept.php, etc.
- "clsFactory" should be eliminated in favor of static functions for each class
Code - store.php
<php><?php
- PURPOSE: vbz class library
define('kfpHostAcctRoot','/hsphere/local/home/hypertwi/'); define('kfpMediaWiki',kfpHostAcctRoot.'wiki.vbz.net/'); define('kEmbeddedPagePrefix','embed:');
require('datamgr.php'); if (KF_USE_WIKI) {
define(KW_WIKI_ROOT,'http://wiki.vbz.net/'); include('extract.php');
}
define('EN_PGTYPE_NOTFND',-1); // requested item (supp/dept/title) not found define('EN_PGTYPE_HOME',1); // catalog home page define('EN_PGTYPE_SUPP',2); // supplier page define('EN_PGTYPE_DEPT',3); // department page, or possibly title for keyless dept define('EN_PGTYPE_TITLE',4); // title page
$imgSize['th'] = 'thumbnail'; $imgSize['sm'] = 'small'; $imgSize['big'] = 'large'; $imgSize['huge'] = 'huge'; $imgSize['zoom'] = 'detail';
$intCallDepth = 0;
// CALCULATED GLOBALS $fpTools = '/tools'; $fpPages = ; $fwpAbsPages = 'http://'.KS_PAGE_SERVER.$fpPages; $fwpAbsTools = 'http://'.KS_TOOLS_SERVER.$fpTools; $fwpCart = $fwpAbsPages.'/cart/'; $strCurServer = $_ENV['SERVER_NAME'];
// SET UP DEPENDENT VALUES /* if ($strCurServer != KS_TOOLS_SERVER) {
$fpTools = $fwpAbsTools; $fpPages = $fwpAbsPages;
}
- /
$fwpLogo = $fpTools.'/img/logos/v/';
function InitData($iSpec) {
global $objFactory,$objDataMgr;
$objDb = new clsDatabase($iSpec); $objFactory = new clsFactory($objDb); $objDataMgr = new clsDataMgr($objDb,'data_tables','data_procs','v_data_flow','data_log'); return $objDb;
}
class clsFactory {
protected $objDB; private $objPages; private $objSupps; private $objDepts; private $objTitles; private $objTitlesExt; private $objItems; private $objItTyps; private $objImages; private $objStkItems; private $objTopics;
public function __construct($iDB) { $this->objDB = $iDB; }
// generic functions
public function DB() { return $this->objDB; } public function Table($iName) { return new clsDataTable($this->objDB,$iName); } public function Query($iSQL) { return new clsDataQuery($this->objDB,$iSQL); }
// table-specific functions
public function Pages() { if (!is_object($this->objPages)) { $this->objPages = new clsCatPages($this->objDB); } return $this->objPages; } public function Suppliers() { if (!is_object($this->objSupps)) { $this->objSupps = new clsSuppliers($this->objDB); } return $this->objSupps; } public function Depts() { if (!is_object($this->objDepts)) { $this->objDepts = new clsDepts($this->objDB); } return $this->objDepts; } public function Titles() { if (!is_object($this->objTitles)) { $this->objTitles = new clsTitles($this->objDB); } return $this->objTitles; } public function TitlesExt() { if (!is_object($this->objTitlesExt)) { $this->objTitlesExt = new clsTitlesExt($this->objDB); } return $this->objTitlesExt; } public function Items() { if (!is_object($this->objItems)) { $this->objItems = new clsItems($this->objDB); } return $this->objItems; } public function ItTyps() { if (!is_object($this->objItTyps)) { $this->objItTyps = new clsItTyps($this->objDB); } return $this->objItTyps; } public function Images() { if (!is_object($this->objImages)) { $this->objImages = new clsImages($this->objDB); } return $this->objImages; } public function StkItems() { if (!is_object($this->objStkItems)) { $this->objStkItems = new clsStkItems($this->objDB); } return $this->objStkItems; } public function Topics() { if (!is_object($this->objTopics)) { $this->objTopics = new clsTopics($this->objDB); } return $this->objTopics; } public function Table_noID($iName) { return new clsDataTable_noID($objDb,$iName); }
}
class clsList {
public $List;
public function Add($iName, $iValue=NULL) { $objItem = new clsListItem($iName,$iValue); $this->List[] = $objItem; return $objItem; } public function Output($iPfx, $iSep, $iSfx) { if (is_array($this->List)) { foreach ($this->List as $objItem) { if (is_null($objItem->value)) { $out .= $iPfx.$iSep.$objItem->name.$iSfx; } else { $out .= $iPfx.$objItem->name.$iSep.$objItem->value.$iSfx; } } } return $out; }
} class clsListItem {
public $name; public $value;
public function __construct($iName, $iValue=NULL) { $this->name = $iName; $this->value = $iValue; }
}
/* ===================
CLASS: clsPage PURPOSE: Handles display of different page types
- /
class clsPage { // query
protected $strReq; // requested page
// page definition
protected $strAbbr; // page's abbreviation for wiki embedding lookups (if blank, suppress embedding) protected $strName; // short title: {item name} (goes into html title, prefixed with store name) protected $strTitle; // longer, descriptive title: {"item name" by Supplier} (goes at top of page) protected $strSheet; // name of style sheet to use (without the .css) protected $strTitleContext; // context of short title, in HTML: {Supplier: Department:} (goes above title, in small print) protected $strHdrXtra; // any extra stuff (HTML) for the header protected $strSideXtra; // any extra stuff for the sidebar protected $lstTop; // stuff listed at the top of the sidebar
// calculated fields
protected $strCalcTitle; protected $strContText;
// flags set by wiki contents
protected $hideImgs;
/* OLD // query parsing
public $CatNum;
// status
var $enPgType;
/**/
public function __construct() { $this->lstTop = new clsList(); }
public function GetQuery() {
// ACTION: Retrieves request from URL and parses it
$this->strSheet = 'browse'; // default $strReq = $_SERVER['PATH_INFO']; $this->strReq = $strReq;
// $pathinfo = $_SERVER['REQUEST_URI'];
if (strrpos($strReq,'/')+1 < strlen($strReq)) { $strRedir = KWP_CAT_REL.substr($strReq,1).'/'; header('Location: '.$strRedir); exit; // retry with new URL } $this->ParseQuery(); } public function ParseQuery() {
// This is essentially an abstract function // Define any additional parsing of the query (store member vars etc.)
// global $objFactory;
// $strReq = $this->strReq;
// $this->objCatPage = $objFactory->Pages()->GetItem_byKey($strReq);
//print 'REQ='.$strReq.' ABBR='.$this->objCatPage->AB;
}
// DIFFERENT TYPES OF PAGES
protected function DoNotFound() {
// $this->Setup(,'Unknown Title','unknown title in catalog','browse','Tomb of the...');
$this->strAbbr = ; $this->strTitle = 'Unknown Page'; $this->strName = 'unknown title in catalog'; $this->strTitleContext = 'Tomb of the...'; $this->strHdrXtra = ;
$this->strSideXtra = '
- Framework
$this->DoSepBar();print '
'.$txtFooter.' | ';
$fltExecTime = microtime(true)-$fltStart; $dat = getrusage(); $fltUserTime = $dat["ru_utime.tv_usec"]/1000000; $strServer = $_SERVER['SERVER_SOFTWARE']; print $strServer.' .. '; print 'PHP '.phpversion().' .. Generated in '.$fltUserTime.' seconds (script execution '.$fltExecTime.' sec.) .. '; if ($strPageAbbr) { print 'wiki: <a href="'.KWP_WIKI_ROOT.kEmbeddedPagePrefix.$strPageAbbr.'">'.$strPageAbbr.'</a> .. '; } print date('Y-m-d H:i:s');print ' |
$didPage = true; } private function DoWikiContent() {
- WIKI CONTENTS
- $txtPage = GetEmbedPage('cat');
if (KF_USE_WIKI) { $txtWiki = GetWikiPage($this->strAbbr); if ($txtWiki) { if (strpos($txtWiki,'__NOIMG__') != -1) { $txtWiki = str_replace('__NOIMG__',,$txtWiki); $this->hideImgs = true; } } if ($txtWiki) {
// print ''.$txtPage.'
';
'.$txtWiki.' |
} } } protected function DoSidebar() { global $fpTools,$objDataMgr;
// later: these will be pulled from the [stats] table if ($objDataMgr->dtNewest) {
$timeSidebarBuild=$objDataMgr->dtNewest;
} $statsQtyTitlesAvail = 2245; $statsQtyStockPieces = 1395; $statsQtyStockItems = 753; $statsQtyArtists = 136; $statsQtyTopics = 1048;
print '';
?>
|
} private function DoSepBar() { global $fpTools;
print '<img src="'.$fpTools.'/img/bg/hlines/" alt="-----" width="100%">'; } private function ToolbarItem($iURL,$iIcon,$iTitle,$iAlt) { global $fpTools; return '<a href="'.$iURL.'"><img border=0 src="'.$fpTools.'/img/icons/'.$iIcon.'.050pxh.png" title="'.$iTitle.'" alt="'.$iAlt.'"></a>'; } protected function DoToolbar() { global $fpPages,$fwpCart; print $this->ToolbarItem($fpPages.'/','home',KS_STORE_NAME.' home page','home page'); print $this->ToolbarItem($fpPages.'/search/','search','search page','search page'); print $this->ToolbarItem($fwpCart,'cart','shopping cart','shopping cart'); print $this->ToolbarItem(KWP_WIKI.'/help','help','help!','help'); }
// -- HEADER
protected function DoHeader() { global $fpTools, $fwpLogo,$strPageAbbr;;
$strPageAbbr = $this->strAbbr; $this->strCalcTitle = KS_STORE_NAME.' - '.$this->strName; $htmlHead = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'; $htmlHead .= ''.$this->strCalcTitle.' '; if ($this->strSheet) { $htmlHead .= ''; } # remove any quotes from $pageName: $htmlName = str_replace('"','"',$this->strName); if ($htmlName) { $htmlName = ': '.$htmlName; } $htmlHead .= ''; $htmlHead .= ''; print $htmlHead; ?> '; print ''; // === LEFT HEADER: Title === print ''; // === END LEFT HEADER === // === RIGHT HEADER: nav icons === print ''; // === END RIGHT HEADER === ?>
';
print '';
if ($this->strTitleContext) {
print ''.KS_STORE_NAME.': '.$this->strTitleContext.' '; } print ''.$this->strTitle.' | '; $this->DoToolbar(); print ' |
'.$iTitle.'
'; return $this->out; } function StartTable($iTitle) { if ($iTitle) { $this->SectionHdr($iTitle); $this->out .= ''; $this->inTbl++; } } function RowStart($iClass='') { if ($iAttr) { $this->out .= ''; } else { $this->out .= ''; } } function RowStop() { $this->out .= ''; $this->isOdd = !$this->isOdd; } function ColAdd($iText) { if ($this->isOdd) { $cellOpen = ''; } function EndTable() { if ($this->inTbl) { $this->out .= ''; } else { $cellOpen = ' | '; } $this->out .= $cellOpen.$iText.' |
Rangeto
orderstatus'); } $objNoImgSect->RowStart(); $objNoImgSect->ColAdd(''.$objTitle->CatNum.''); $objNoImgSect->ColAdd($objTitle->Name); $objNoImgSect->ColAdd($strPrice); $objNoImgSect->ColAdd('['.$objTitle->Link().'order]'); $qtyInStock = $objTitle->GetValue('qtyInStock'); if ($qtyInStock) { $strStock = ''.$qtyInStock.' in stock'; $objNoImgSect->ColAdd($strStock); if ($objTitle->GetValue('cntInPrint') == 0) { $objNoImgSect->ColAdd('OUT OF PRINT!'); } } else { $objNoImgSect->ColAdd('available, not in stock'); // Debugging: // $objNoImgSect->ColAdd('ID_Title='.$objTitle->ID.' ID_ItTyp='.$objTitle->idItTyp); } $objNoImgSect->RowStop(); } } if ($cntImgs) { $this->SectionHdr($iHdrText); $this->AddText($outImgs); } return $this->out; } function ShowImgUnavail() { $this->out .= '
|
Departments:
'; $objDepts = $this->GetData('ID_Supplier='.$iSuppID,'Name'); $isFirst = true; while ($objDepts->HasData()) { $outDept = $objDepts->DoListing(); if ($outDept) { // only show departments with something in them if ($isOdd) { $cellOpen = ''.$cellOpen.''.$objDepts->Name.''; $isOdd = !$isOdd; $out .= $cellOpen.$outDept.''; } $objDepts->NextRow(); } $out .= ''; } else { $cellOpen = ' | '; } $keyDept = $objDepts->PageKey(); $out .= ' |
Found '.$objTypes->RowCount().' item(s):'); if (KF_CART_ABSOLUTE) { $urlCart = KWP_CART_ABS; } else { $urlCart = KWP_CART_REL; } $objSection->AddText(''); $objSection->AddText(''); } else { $objSection->SectionHdr('This title is currently unavailable'); } return $objSection->out; } public function ListImages($iSize) { global $objFactory; $objImgs = $objFactory->Images()->GetData('(ID_Title='.$this->ID.') AND (Ab_Size="'.$iSize.'")','AttrSort'); return $objImgs; } public function CatNum($iSep='-') { $objDept = $this->Dept(); $objSupp = $objDept->Supplier(); $strDeptKey = $objDept->CatKey; $strOut = $objSupp->CatKey; if ($strDeptKey) { $strOut .= $iSep.$strDeptKey; } $strOut .= $iSep.$this->CatKey; return strtoupper($strOut); } public function Link() { $strRel = $this->CatNum('/'); return ''; } public function LinkName() { return $this->Link().$this->Name.''; } } // extended Title data from v_titles class clsTitlesExt extends clsTitles { public function __construct($iDB,$iTable='v_titles') { parent::__construct($iDB,$iTable); } protected function _newItem() { CallStep('clsTitlesExt._newItem()'); return new clsTitleExt($this); } } // this encapsulates [_titles] instead of [titles] class clsTitleExt extends clsTitle { public $CatNum; public $CatWeb; public $curMinPrice; public $curMaxPrice; public $idItTyp; public $qtyInStock; // action flags public $dontLoadBasic; protected function LoadResults() { CallEnter('clsTitleExt.LoadResults()'); if (!$this->dontLoadBasic) { parent::LoadResults(); } $this->CatNum = $this->GetValue('CatNum'); $this->CatWeb = $this->GetValue('CatWeb'); $this->currMinPrice = $this->GetValue('currMinPrice'); $this->currMaxPrice = $this->GetValue('currMaxPrice'); $this->idItTyp = $this->GetValue('ID_ItTyp'); $this->qtyInStock = $this->GetValue('qtyInStock'); CallExit('clsTitle.LoadResults()'); } public function Link() { $out = ''; return $out; } public function URL() { return KWP_CAT_REL.$this->CatWeb.'/'; } } /* -------------------- *\ TITLE/ITTYP hybrid \* -------------------- */ class clsTitleIttyp extends clsDataItem_noID { public $ID_ItTyp; public $ID_Dept; public $cntForSale; public $cntInPrint; public $cntInStock; public $qtyInStock; public $ItTypNameSng; public $ItTypNamePlr; // object cache private $objIttyp; protected function LoadResults() { CallEnter('clsTitleIttyp.LoadResults()'); $idItTyp = $this->GetValue('ID_ItTyp'); if ($idItTyp != $this->ID_ItTyp) { $this->ID_ItTyp = $this->GetValue('ID_ItTyp'); $this->objIttyp = NULL; } $this->ID_Title = $this->GetValue('ID_Title'); $this->ID_Dept = $this->GetValue('ID_Dept'); $this->cntForSale = $this->GetValue('cntForSale'); $this->cntInPrint = $this->GetValue('cntInPrint'); $this->cntInStock = $this->GetValue('cntInStock'); $this->qtyInStock = $this->GetValue('qtyInStock'); $this->ItTypNameSng = $this->GetValue('ItTypNameSng'); $this->ItTypNamePlr = $this->GetValue('ItTypNamePlr'); if ($this->ID_ItTyp) { } else { echo 'ERROR: ID_ItTyp has no value! data = '; DumpArray($this->Row,TRUE); } CallExit('clsTitleIttyp.LoadResults()'); } public function Ittyp() { global $objFactory; if (is_null($this->objIttyp)) { $this->objIttyp = $objFactory->ItTyps()->GetItem($this->ID_ItTyp); } return $this->objIttyp; } } /* -------------------- *\ ITEM classes \* -------------------- */ class clsItems extends clsDataTable { public function __construct($iDB,$iTable='cat_items') { global $objDataMgr; $objDataMgr->Update('cat_items','clsItems()'); parent::__construct($iDB,$iTable); } protected function _newItem() { CallStep('clsTitles._newItem()'); return new clsItem($this); } } class clsItem extends clsDataItem { // NOTE: "in stock" always refers to stock for sale, not stock which has already been purchased public $CatNum; public $isForSale; public $isInPrint; public $qtyInStock; public $idTitle; public $idItTyp; public $idItOpt; public $ItOptDescr; public $PriceSell; public $PriceList; // object cache private $objTitle; protected function LoadResults() { CallEnter('clsItem.LoadResults()'); $this->ID = $this->GetValue('ID'); $this->CatNum = $this->GetValue('CatNum'); $this->isForSale = $this->GetValue('isForSale'); $this->isInPrint = $this->GetValue('isInPrint'); $this->qtyInStock = $this->GetValue('qtyInStock'); $this->idTitle = $this->GetValue('ID_Title'); $this->idItTyp = $this->GetValue('ID_ItTyp'); $this->idItOpt = $this->GetValue('ID_ItOpt'); $this->ItOptDescr = $this->GetValue('ItOpt_Descr'); $this->PriceSell = $this->GetValue('PriceSell'); $this->PriceList = $this->GetValue('PriceList'); assert($this->ID); CallExit('clsItem.LoadResults()'); } public function Print_TableRow() { // ASSUMES: This item is ForSale, so isForSale = true and (qtyForSale>0 || isInPrint) = true $qtyInStock = $this->QtyInStock(true); if ($qtyInStock) { $strClass = 'inStock'; $strStock = $qtyInStock.' in stock'; } else { $strClass = 'noStock'; } $out = ''; $out .= ' '.$this->ItOptDescr; if ($this->isInPrint) { if ($qtyInStock) { $strStatus = $strStock.'; more available'; } else { $strStatus = 'available, not in stock'; } } else { $strStatus = ''.$strStock.' - out of print!'; } $out .= ''.$strStatus.''; $out .= ''.DataCurr($this->PriceSell).''; $out .= ''.''; if ($this->PriceList) { $out .= ''.DataCurr($this->PriceList).''; } $out .= ''; return $out; } public function QtyInStock($iNeedQty) { // DEPRECATED // Originally, this field might have contained a "-1" to indicate // that some items were in stock but the number hadn't been // calculated. We're not doing that anymore. /* if (is_null($this->qtyInStock)) { $doFigure = true; } else { if ($this->qtyInStock == -1) { if ($iNeedQty) { $doFigure = true; } } } if ($doFigure) { $this->DoFigureStock(); } */ return $this->qtyInStock; } public function Title() { global $objFactory; $doLoad = TRUE; if (is_object($this->objTitle)) { if ($this->objTitle == $this->idTitle) { $doLoad = FALSE; } } if ($doLoad) { $this->objTitle = $objFactory->Titles()->GetItem($this->idTitle); } return $this->objTitle; } public function StoreLink() { /* RETURNS: HTML suitable for use within the store NOTE: Since the store doesn't yet have pages for each item, this returns the store's Title link */ return $this->Title-Link(); } public function AdminLink() { return ''; } /* private function DoFigureStock() { global $objFactory; $qtyInStock = $objFactory->StkItems()->QtyInStock_forItem($this->ID); // assert(!is_null($qtyInStock)); // $sql = 'UPDATE cat_items SET qtyInStock='.$qtyInStock.' WHERE ID='.$this->ID; assert(is_object($this->Table)); assert(is_object($this->Table->DB())); $this->Table->DB()->Exec($sql); $this->qtyInStock = $qtyInStock; } */ } class clsItemsExt extends clsItems { public function __construct($iDB,$iTable='v_items') { parent::__construct($iDB,$iTable); } protected function _newItem() { CallStep('clsItemsExt._newItem()'); return new clsItemExt($this); } } class clsItemExt extends clsItem { public $OptSort; protected function LoadResults() { CallEnter('clsItemExt.LoadResults()'); parent::LoadResults(); $this->OptSort = $this->GetValue('OptSort'); $this->CatWeb = $this->GetValue('CatWeb'); $this->currMinPrice = $this->GetValue('currMinPrice'); $this->currMaxPrice = $this->GetValue('currMaxPrice'); $this->idItTyp = $this->GetValue('ID_ItTyp'); $this->qtyInStock = $this->GetValue('qtyInStock'); CallExit('clsItemExt.LoadResults()'); } } /* -------------------- *\ ITEM TYPE classes \* -------------------- */ class clsItTyps extends clsDataTable { public function __construct($iDB) { global $objDataMgr; $objDataMgr->Update('cat_ittyps','clsItems()'); parent::__construct($iDB,'cat_ittyps'); } protected function _newItem() { CallStep('clsItTyps._newItem()'); return new clsItTyp($this); } } class clsItTyp extends clsDataItem { public $ID; public $NameSng; public $NamePlr; // public $cntInPrint; // public $qtyInStock; // public $usePrefix; protected function LoadResults() { CallEnter('clsItTyp.LoadResults()'); /* if ($this->usePrefix) { $this->ID = $this->GetValue('ID_ItTyp'); $this->NameSng = $this->GetValue('ItTypNameSng'); $this->NamePlr = $this->GetValue('ItTypNamePlr'); $this->cntInPrint = $this->GetValue('cntInPrint'); } else { /**/ $this->ID = $this->GetValue('ID'); $this->NameSng = $this->GetValue('NameSng'); $this->NamePlr = $this->GetValue('NamePlr'); // } assert($this->ID); CallExit('clsItTyp.LoadResults()'); } public function Name($iCount=-1) { if ($iCount == -1) { $iCount = $this->cntInPrint; } if ($iCount == 1) { return $this->NameSng; } else { return $this->NamePlr; } } } /* -------------------- *\ STOCK ITEM classes \* -------------------- */ class clsStkItems extends clsDataTable { public function __construct($iDB) { parent::__construct($iDB,'stk_items'); } public function QtyInStock_forItem($iItemID) { $sql = 'SELECT SUM(s.Qty) AS Qty FROM stk_items AS s LEFT JOIN stk_bins AS sb ON s.ID_Bin=sb.ID WHERE (s.ID_Item='.$iItemID.') AND (s.WhenRemoved IS NULL) AND (sb.WhenVoided IS NULL) AND (sb.isForSale) GROUP BY s.ID_Item'; // ** TO DO: maybe this can use a view or one of the calculated tables now? $objStock = new clsDataItem($this); $objStock->Query($sql); if ($objStock->HasData()) { if ($objStock->RowCount()) { assert($objStock->RowCount() == 1); return $objStock->GetValue('Qty'); } } } /* protected function _newItem() { CallStep('clsStkItems._newItem()'); return new clsStkItem($this); } */ } /* -------------------- *\ IMAGE classes \* -------------------- */ class clsImages extends clsDataTable { public function __construct($iDB) { parent::__construct($iDB,'cat_images'); } protected function _newItem() { CallStep('clsImages._newItem()'); return new clsImage($this); } } class clsImage extends clsDataItem { public $idTitle; public $Ab_Size; public $AttrFldr; public $Spec; // object cache private $objTitle; protected function LoadResults() { CallEnter('clsImage.LoadResults()'); $this->ID = $this->GetValue('ID'); $this->idTitle = $this->GetValue('ID_Title'); $this->AbSize = $this->GetValue('Ab_Size'); $this->AttrFldr = $this->GetValue('AttrFldr'); $this->AttrDispl = $this->GetValue('AttrDispl'); $this->Spec = $this->GetValue('Spec'); assert($this->ID); CallExit('clsImage.LoadResults()'); } public function ImgForSize($iSize) { // ACTION: Get the image with the same title and attribute but with the given size if ($this->AttrFldr) { $sqlAttr = '="'.$this->AttrFldr.'"'; } else { $sqlAttr = ' IS NULL'; } $sql = 'SELECT * FROM cat_images WHERE (ID_Title='.$this->idTitle.') AND (AttrFldr'.$sqlAttr.') AND (Ab_Size="'.$iSize.'");'; $objImgOut = new clsImage($this->Table); $objImgOut->Query($sql); return $objImgOut; } public function Title() { global $objFactory; if (!is_object($this->objTitle)) { $objTitleTbl = $objFactory->TitlesExt(); $this->objTitle = $objTitleTbl->GetItem($this->idTitle); } return $this->objTitle; } public function DoPage() { global $objFactory; $objTitle = $this->Title(); $strCatNum = $objTitle->CatNum; $strTitle = $objTitle->Name; $htmlTitle = KS_STORE_NAME.' - '.$strCatNum.' “'.$strTitle.'”'; echo '
'; // show list of available image sizes (except th and sm) $objImgs = $this->ListImages_sameAttr(); if ($objImgs->HasData()) { $strImgCount = 0; while ($objImgs->HasData()) { $strImgType = $objImgs->AbSize; if (($strImgType != 'th') && ($strImgType != 'sm')) { $strImgCount++; $strImgTag = $imgSize[$strImgType]; if ($strOut) { $strOut .= ' .. '; } $strOut .= $strImgTag; } $objImgs->NextRow(); } if ($strImgCount > 1) { echo $strOut.'
'; } } // show list of available images for this title at this size $objImgs = $this->ListImages_sameSize(); if ($objImgs->HasData()) { $strImgCount = 0; $strOut .= ''; if ($objImgs->HasData()) { while ($objImgs->HasData()) { $strImgFldr = $objImgs->AttrFldr; $strImgDescr = $objImgs->AttrDispl; $strImgCount++; if ($strOut) { $strOut .= ' .. '; } if ($objImgs->ID == $this->ID) { $strOut .= ''.$strImgDescr.''; } else { $strOut .= $objImgs->Href(TRUE).$strImgDescr.''; } $objImgs->NextRow(); } if ($strImgCount > 1) { echo $strOut.'
'; } } } echo $objTitle->Link().'ordering page
'; echo $this->ImgSrc(); echo ''; } public function ListImages_sameAttr() { if ($this->AttrFldr) { $sqlFilt = '(ID_Title='.$this->idTitle.') AND (AttrFldr="'.$this->AttrFldr.'")'; } else { $sqlFilt = '(ID_Title='.$this->idTitle.')'; } $objImgOut = $this->Table->GetData($sqlFilt); return $objImgOut; } public function ListImages_sameSize() { $sqlFilt = '(ID_Title='.$this->idTitle.') AND (Ab_Size="'.$this->AbSize.'")'; $objImgOut = $this->Table->GetData($sqlFilt); return $objImgOut; } public function Href($iAbs=false) { if ($iAbs) { $strFldr = $this->Title()->URL(); } $strFldr .= $this->AttrFldr; if ($strFldr) { $strFldr .= '-'; } $strFldr .= $this->AbSize; return '<a href="'.$strFldr.'/">'; } public function ImgSrc() { return '<img src="'.KWP_IMG_MERCH.$this->Spec.'">'; }
}
/* ------------------ *\
CATALOG BROWSING
\* ------------------ */ class clsTopics extends clsDataTable {
public function __construct($iDB) { parent::__construct($iDB,'brs_topics'); } protected function _newItem() { CallStep('clsTopics._newItem()'); return new clsTopic($this); } public function DoIndex() { global $objFactory,$objDataMgr;
CallEnter('clsTopics.DoIndex()'); $objSection = new clsPageOutput();
$objTopics = $this->GetData('ID_Parent IS NULL','Sort,Name,NameTree'); while ($objTopics->HasData()) { if ($isFirst) { $isFirst = false; $objSection->SectionHdr('Root Topics'); } else { $objSection->AddText($objTopics->Name.'
'); } $objTopics->NextRow(); }
CallExit('clsTopic.DoIndex()'); return $objSection->out; }
} class clsTopic extends clsDataItem {
public $ID_Parent; public $Name; public $NameTree; public $NameFull; public $Variants; public $Mispeled;
protected function LoadResults() { CallEnter('clsTopic.LoadResults()'); $this->ID = $this->GetValue('ID'); $this->ID_Parent = $this->GetValue('ID_Parent'); $this->Name = $this->GetValue('Name'); $this->NameTree = $this->GetValue('NameTree'); $this->NameFull = $this->GetValue('NameFull'); $this->Variants = $this->GetValue('Variants'); $this->Mispeled = $this->GetValue('Mispeled'); assert($this->ID); CallExit('clsTopic.LoadResults()'); }
public function DoPage() { global $objFactory,$objDataMgr;
CallEnter('clsTopic.DoPage()'); assert($this->ID); $objSection = new clsPageOutput();
$objTbl = $objFactory->Table_noID('brs_titles_x_topics'); $objTitles = $objTbl->GetData('ID_Topic='.$this->ID); while ($objTitles->HasData()) { if ($isFirst) { $isFirst = false; $objSection->SectionHdr('Titles'); } else { $objSection->AddText($objTitles->Name.'
'); } $objTitles->NextRow(); }
CallExit('clsTopic.DoPage()'); return $out; } public function WebName() { return sprintf(KS_FMT_TOPICID,$this->ID); }
}
/* ==================== *\
UTILITY FUNCTIONS
\* ==================== */
function DataCents($iCents,$iPfx='$') {
$out = $iPfx.sprintf("%01.2f",$iCents/100); return $out;
} function DataCurr($iCurr,$iPfx='$') {
$out = $iPfx.sprintf("%01.2f",$iCurr); return $out;
} function DataDate($iDate) {
if (is_string($iDate)) { $objDate = new DateTime($iDate);
// if ($iDate == 0) { // $out = ; // } else { // $out = date('Y-m-d',$iDate);
$out = $objDate->format('Y-m-d'); } else { $out = ; } return $out;
}</php>