VbzCart/docs/archive/code/globals/clsDept: Difference between revisions
Jump to navigation
Jump to search
imported>Woozle (section for each method) |
m (Woozle moved page VbzCart/VbzCart/archive/code/globals/clsDept to VbzCart/docs/archive/code/globals/clsDept without leaving a redirect: correct naming (was no way to import directly to this name)) |
||
(3 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
==Notes== | ==Notes== | ||
<code>DoPage()</code> is in the process of being rewritten; it doesn't currently work. | |||
==Code== | ==Code== | ||
<syntaxhighlight lang=php> | |||
class clsDept extends {{l/same|clsDataSet}} { | class clsDept extends {{l/same|clsDataSet}} { | ||
// object cache | // object cache | ||
private $objSupp; | private $objSupp; | ||
public function SuppObj() { | public function SuppObj() { | ||
if (is_object($this->objSupp)) { | if (is_object($this->objSupp)) { | ||
Line 27: | Line 19: | ||
} | } | ||
} | } | ||
// DEPRECATED -- use SuppObj() | // DEPRECATED -- use SuppObj() | ||
public function Supplier() { | public function Supplier() { | ||
return $this->SuppObj(); | return $this->SuppObj(); | ||
} | } | ||
public function PageKey() { | public function PageKey() { | ||
if ($this->PageKey) { | if ($this->PageKey) { | ||
Line 44: | Line 30: | ||
} | } | ||
} | } | ||
/*---- | /*---- | ||
PURPOSE: loads data needed to display catalog views for this department | PURPOSE: loads data needed to display catalog views for this department | ||
Line 63: | Line 46: | ||
return $objItTyps; | return $objItTyps; | ||
} | } | ||
/*----- | /*----- | ||
PURPOSE: Print this department's information as part of department list | PURPOSE: Print this department's information as part of department list | ||
Line 95: | Line 75: | ||
return $out; | return $out; | ||
} | } | ||
/*---- | /*---- | ||
PURPOSE: Print page for current department | PURPOSE: Print page for current department | ||
Line 161: | Line 138: | ||
return $out; | return $out; | ||
} | } | ||
public function URL_Rel() { | public function URL_Rel() { | ||
$strURL = $this->Supplier()->URL(); | $strURL = $this->Supplier()->URL(); | ||
Line 172: | Line 146: | ||
return $strURL; | return $strURL; | ||
} | } | ||
public function URL_Abs() { | public function URL_Abs() { | ||
return KWP_ROOT.$this->URL_Rel(); | return KWP_ROOT.$this->URL_Rel(); | ||
} | } | ||
public function LinkName() { | public function LinkName() { | ||
$strURL = $this->URL_Rel(); | $strURL = $this->URL_Rel(); | ||
return '<a href="'.$strURL.'">'.$this->Name.'</a>'; | return '<a href="'.$strURL.'">'.$this->Name.'</a>'; | ||
} | } | ||
/*----- | /*----- | ||
RETURNS: The string which, when prepended to a Title's CatKey, would form the Title's catalog number | RETURNS: The string which, when prepended to a Title's CatKey, would form the Title's catalog number | ||
Line 198: | Line 163: | ||
return $strFull.'-'; | return $strFull.'-'; | ||
} | } | ||
/*----- | /*----- | ||
RETURNS: TRUE if this department affects the catalog number (i.e. if CatKey is non-blank) | RETURNS: TRUE if this department affects the catalog number (i.e. if CatKey is non-blank) | ||
Line 207: | Line 169: | ||
return ($this->CatKey != ''); | return ($this->CatKey != ''); | ||
} | } | ||
} | } | ||
</syntaxhighlight> |
Latest revision as of 01:53, 25 February 2024
Notes
DoPage()
is in the process of being rewritten; it doesn't currently work.
Code
class clsDept extends {{l/same|clsDataSet}} {
// object cache
private $objSupp;
public function SuppObj() {
if (is_object($this->objSupp)) {
return $this->objSupp;
} else {
$idSupp = $this->ID_Supplier;
if ($idSupp) {
$this->objSupp = $this->objDB->Suppliers()->GetItem($idSupp);
return $this->objSupp;
} else {
return NULL;
}
}
}
// DEPRECATED -- use SuppObj()
public function Supplier() {
return $this->SuppObj();
}
public function PageKey() {
if ($this->PageKey) {
return $this->PageKey;
} else {
return $this->CatKey;
}
}
/*----
PURPOSE: loads data needed to display catalog views for this department
HISTORY
2010-11-12 disabled automatic cache update
2010-11-16 changed sorting field from cntInPrint to cntForSale
2011-02-02 using _dept_ittyps now instead of qryItTypsDepts_ItTyps
Also added "AND (cntForSale)" to WHERE clause -- not listing titles with nothing to sell
*/
protected function Data_forStore() { // was GetDeptData()
//$objCache = $this->objDB->CacheMgr();
//$objCache->Update_byName('_dept_ittyps','clsDept.DoListing() for ID='.$this->ID);
//$sql = 'SELECT * FROM qryItTypsDepts_ItTyps WHERE (ID_Dept='.$this->ID.') ORDER BY cntForSale DESC';
$sql = 'SELECT * FROM _dept_ittyps WHERE (ID_Dept='.$this->ID.') AND (cntForSale) ORDER BY cntForSale DESC';
$objItTyps = $this->objDB->DataSet($sql,'clsItTyp');
return $objItTyps;
}
/*-----
PURPOSE: Print this department's information as part of department list
HISTORY:
2010-11-16 $cntAvail is now cntForSale, not cntInPrint+qtyInStock
*/
public function DoListing() {
assert('$this->ID');
$objItTyps = $this->Data_forStore();
$isFirst = true;
$out = '';
while ($objItTyps->NextRow()) {
if ($isFirst) {
$isFirst = false;
} else {
$out .= ', ';
}
$cntInPrint = $objItTyps->cntInPrint;
$qtyInStock = $objItTyps->qtyForSale;
//$cntAvail = $cntInPrint + $qtyInStock;
$cntForSale = $objItTyps->cntForSale;
if ($cntAvail == 1) {
$strName = $objItTyps->ItTyp_Sng;
} else {
$strName = $objItTyps->ItTyp_Plr;
}
$out .= ' <b>'.$cntAvail.'</b> '.$strName;
}
return $out;
}
/*----
PURPOSE: Print page for current department
ACTION:
* Iterates through item types available for this department.
* For each item type, prints header and then a list of titles.
HISTORY:
2010-11-?? Started using cached table _title_ittyps instead of qryTitles_ItTyps_Titles
2010-11-16 $cntAvail is now cntForSale, not cntInPrint+qtyInStock
2011-02-02 $qtyInStock now set to Row['qtyInStock'], not Row['qtyForSale'] which didn't make sense anyway
*/
public function DoPage() {
$out = '';
$idDept = $this->ID;
if (empty($idDept)) {
throw new exception('Department object has no ID');
}
//$objSection = new clsPageOutput();
// calculate the list of item types available in this department
$objItTyps = $this->Data_forStore();
$objTitles = new clsVbzTitle($this->objDB);
//$objNoImgSect = new clsPageOutput();
$objNoImgSect = new clsRTDoc_HTML();
$cntSections = 0;
while ($objItTyps->NextRow()) {
$cntInPrint = $objItTyps->Row['cntInPrint'];
$qtyInStock = $objItTyps->Row['qtyInStock'];
$cntAvail = $objItTyps->Row['cntForSale'];
if ($cntAvail) {
$cntSections++;
$idItTyp = $objItTyps->Row['ID_ItTyp'];
$sql = 'SELECT *, ID_Title AS ID, TitleName AS Name, cntInStock FROM _title_ittyps WHERE ((cntForSale) AND (ID_ItTyp='.$idItTyp.') AND (ID_Dept='.$idDept.'));';
//$sql = 'SELECT t.ID_Title AS ID, t.* FROM qryTitles_ItTyps_Titles AS t WHERE (ID_ItTyp='.$idItTyp.') AND (ID_Dept='.$idDept.');';
$objTitles->Query($sql);
$arTitles = NULL;
if ($objTitles->hasRows()) {
while ($objTitles->NextRow()) {
// add title to display list
$arTitles[] = $objTitles->Values(); // save it in a list
}
assert('is_array($arTitles)');
// We've generated the list of titles for this section; now display the section header and titles:
$out .= $this->objDB->ShowTitles($objItTyps->Row['ItTypNamePlr'].':',$arTitles,$objNoImgSect);
} else {
echo 'ERROR: No titles found! SQL='.$sql;
}
$objSection->Clear();
} else {
$out .= '<span class=main>Small coding error: this line should never happen.</span>'; // TO DO: log an error
}
}
if (!$cntSections) {
$out .= '<span class=main>This department appears to have been emptied of all leftover stock. (Eventually there will be a way to see what items used to be here.)</span>';
}
if ($objNoImgSect->inTbl) {
$objNoImgSect->EndTable();
$objSection->AddText($objNoImgSect->out);
$objSection->EndTable();
$out .= $objSection->out;
}
return $out;
}
public function URL_Rel() {
$strURL = $this->Supplier()->URL();
$strKey = $this->PageKey();
if ($strKey) {
$strURL .= strtolower($strKey).'/';
}
return $strURL;
}
public function URL_Abs() {
return KWP_ROOT.$this->URL_Rel();
}
public function LinkName() {
$strURL = $this->URL_Rel();
return '<a href="'.$strURL.'">'.$this->Name.'</a>';
}
/*-----
RETURNS: The string which, when prepended to a Title's CatKey, would form the Title's catalog number
*/
public function CatPfx() {
$strFull = strtoupper($this->Supplier()->CatKey);
if ($this->AffectsCatNum()) {
$strFull .= '-'.strtoupper($this->CatKey);
}
return $strFull.'-';
}
/*-----
RETURNS: TRUE if this department affects the catalog number (i.e. if CatKey is non-blank)
*/
public function AffectsCatNum() {
return ($this->CatKey != '');
}
}