VbzCart/docs/archive/code/globals/clsDept: Difference between revisions

From Woozle Writes Code
< VbzCart‎ | docs‎ | archive‎ | code‎ | globals
Jump to navigation Jump to search
imported>Woozle
(→‎Notes: more specifically)
imported>Woozle
(section for each method)
Line 1: Line 1:
{| style="float:right;"
|-
|__TOC__
|}
==Notes==
==Notes==
DoPage() is in the process of being rewritten; it doesn't currently work.
[[#DoPage()]] is in the process of being rewritten; it doesn't currently work.


==Code==
==Code==
Line 7: Line 11:
// object cache
// object cache
     private $objSupp;
     private $objSupp;
 
</php>
===function SuppObj()===
<php>
     public function SuppObj() {
     public function SuppObj() {
if (is_object($this->objSupp)) {
if (is_object($this->objSupp)) {
Line 21: Line 27:
}
}
     }
     }
</php>
===Supplier()===
<php>
     // DEPRECATED -- use SuppObj()
     // DEPRECATED -- use SuppObj()
     public function Supplier() {
     public function Supplier() {
return $this->SuppObj();
return $this->SuppObj();
     }
     }
</php>
===PageKey()===
<php>
     public function PageKey() {
     public function PageKey() {
if ($this->PageKey) {
if ($this->PageKey) {
Line 32: Line 44:
}
}
     }
     }
</php>
===Data_forStore()===
<php>
     /*----
     /*----
       PURPOSE: loads data needed to display catalog views for this department
       PURPOSE: loads data needed to display catalog views for this department
Line 48: Line 63:
return $objItTyps;
return $objItTyps;
     }
     }
</php>
===DoListing()===
<php>
     /*-----
     /*-----
       PURPOSE: Print this department's information as part of department list
       PURPOSE: Print this department's information as part of department list
Line 77: Line 95:
return $out;
return $out;
     }
     }
</php>
===DoPage()===
<php>
     /*----
     /*----
       PURPOSE: Print page for current department
       PURPOSE: Print page for current department
Line 140: Line 161:
return $out;
return $out;
     }
     }
</php>
===URL_Rel()===
<php>
     public function URL_Rel() {
     public function URL_Rel() {
$strURL = $this->Supplier()->URL();
$strURL = $this->Supplier()->URL();
Line 148: Line 172:
return $strURL;
return $strURL;
     }
     }
</php>
===URL_Abs()===
<php>
     public function URL_Abs() {
     public function URL_Abs() {
return KWP_ROOT.$this->URL_Rel();
return KWP_ROOT.$this->URL_Rel();
     }
     }
</php>
===LinkName()===
<php>
     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>';
     }
     }
</php>
===CatPfx()===
<php>
     /*-----
     /*-----
       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 165: Line 198:
return $strFull.'-';
return $strFull.'-';
     }
     }
</php>
===AffectsCatNum()===
<php>
     /*-----
     /*-----
       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)

Revision as of 02:12, 21 December 2012

Notes

#DoPage() is in the process of being rewritten; it doesn't currently work.

Code

class clsDept extends clsDataSet { <php> // object cache

   private $objSupp;

</php>

function SuppObj()

<php>

   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; } }

   }

</php>

Supplier()

<php>

   // DEPRECATED -- use SuppObj()
   public function Supplier() {

return $this->SuppObj();

   }

</php>

PageKey()

<php>

   public function PageKey() {

if ($this->PageKey) { return $this->PageKey; } else { return $this->CatKey; }

   }

</php>

Data_forStore()

<php>

   /*----
     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;

   }

</php>

DoListing()

<php>

   /*-----
     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 .= ' '.$cntAvail.' '.$strName; } return $out;

   }

</php>

DoPage()

<php>

   /*----
     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 .= 'Small coding error: this line should never happen.'; // TO DO: log an error } } if (!$cntSections) { $out .= '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.)'; } if ($objNoImgSect->inTbl) { $objNoImgSect->EndTable(); $objSection->AddText($objNoImgSect->out); $objSection->EndTable(); $out .= $objSection->out; } return $out;

   }

</php>

URL_Rel()

<php>

   public function URL_Rel() {

$strURL = $this->Supplier()->URL(); $strKey = $this->PageKey(); if ($strKey) { $strURL .= strtolower($strKey).'/'; } return $strURL;

   }

</php>

URL_Abs()

<php>

   public function URL_Abs() {

return KWP_ROOT.$this->URL_Rel();

   }

</php>

LinkName()

<php>

   public function LinkName() {

$strURL = $this->URL_Rel(); return '<a href="'.$strURL.'">'.$this->Name.'</a>';

   }

</php>

CatPfx()

<php>

   /*-----
     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.'-';

   }

</php>

AffectsCatNum()

<php>

   /*-----
     RETURNS: TRUE if this department affects the catalog number (i.e. if CatKey is non-blank)
   */
   public function AffectsCatNum() {

return ($this->CatKey != );

   }

</php> }