Difference between revisions of "VbzCart/archive/code/globals/clsVbzTitle"

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
< VbzCart‎ | archive‎ | code‎ | globals
Jump to navigation Jump to search
(Created page with "<hide> [[file::VbzCart/code/files/base.cat.php]] </hide> {| style="float:right;" |- |__TOC__ |} ==References== * created by: {{l/same|clsVbzTitles}} ==Code== class clsVbzTitle...")
 
(No difference)

Revision as of 02:09, 19 December 2014

References

Code

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

   private $objDept;
   private $objSupp;

// options

   public $hideImgs;

</php>

Dept()

<php>

   public function Dept() {

$doLoad = FALSE; if (empty($this->objDept)) { $doLoad = TRUE; } else if (is_object($this->objDept)) { if ($this->ID_Dept != $this->objDept->ID) { $doLoad = TRUE; } } else { $doLoad = TRUE; } if ($doLoad) { $idDept = $this->ID_Dept; if (empty($idDept)) { $objDept = NULL; } else { $objDept = $this->objDB->Depts()->GetItem($idDept); assert('is_object($objDept)'); } $this->objDept = $objDept; } return $this->objDept;

   }

</php>

Supplier_ID()

<php>

   /*----
     RETURNS: ID of this title's supplier
     HISTORY:

2011-09-28 revised to get ID directly from the new ID_Supp field instead of having to look up the Dept and get it from there.

   */
   public function Supplier_ID() {

/* $objDept = $this->Dept(); $idSupp = $objDept->ID_Supplier;

  • /

$idSupp = $this->Value('ID_Supp'); return $idSupp;

   }

</php>

Supplier()

<php>

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

return $this->SuppObj();

   }

</php>

SuppObj()

<php>

   public function SuppObj() {

$doLoad = FALSE; if (empty($this->objSupp)) { $doLoad = TRUE; } else if (is_object($this->objSupp)) { if ($this->ID_Supplier != $this->objSupp->ID) { $doLoad = TRUE; } } else { $doLoad = TRUE; } if ($doLoad) { $idSupp = $this->Supplier_ID(); if (empty($idSupp)) { $objSupp = NULL; } else { $objSupp = $this->objDB->Suppliers()->GetItem($idSupp); assert('is_object($objSupp)'); } $this->objSupp = $objSupp; } return $this->objSupp;

   }

</php>

Items()

<php>

   public function Items() {

$sqlFilt = 'ID_Title='.$this->ID; $objTbl = $this->objDB->Items(); $objRows = $objTbl->GetData($sqlFilt); return $objRows;

   }

</php>

Topics()

<php>

   public function Topics() {

$objTbl = $this->Engine()->TitleTopic_Topics(); $objRows = $objTbl->GetTitle($this->KeyValue()); return $objRows;

   }

</php>

Indicia(array $iarAttr=NULL)

<php>

   /*----
     RETURNS: Array containing summary information about this title
   */
   public function Indicia(array $iarAttr=NULL) {

$objItems = $this->Items(); $intActive = 0; $intRetired = 0; if ($objItems->HasRows()) { while ($objItems->NextRow()) { if ($objItems->isForSale) { $intActive++; } else { $intRetired++; } } } // "dark-bg" brings up link colors for a dark background $arLink = array('class'=>'dark-bg'); // merge in any overrides or additions from iarAttr: if (is_array($iarAttr)) { $arLink = array_merge($arLink,$iarAttr); } $htLink = $this->Link($arLink); $txtCatNum = $this->CatNum(); $txtName = $this->Name;

$arOut['cnt.active'] = $intActive; $arOut['cnt.retired'] = $intRetired; $arOut['txt.cat.num'] = $txtCatNum; $arOut['ht.link.open'] = $htLink; $arOut['ht.cat.line'] = $htLink.$txtCatNum.'</a> '.$txtName;

return $arOut;

   }

</php>

Summary_ItTyps($iSep=', ')

<php>

   /*----
     RETURNS: Array containing summaries of ItTyps in which this Title is available

array['text.!num'] = plaintext version with no numbers (types only) array['text.cnt'] = plaintext version with line counts array['html.cnt'] = HTML version with line counts array['html.qty'] = HTML version with stock quantities

     HISTORY:

2011-01-23 written

   */
   public function Summary_ItTyps($iSep=', ') {

$dsRows = $this->DataSet_ItTyps(); $outTextNoQ = $outTextType = $outTextCnt = $outHTMLCnt = $outHTMLQty = NULL; if ($dsRows->HasRows()) { $isFirst = TRUE; while ($dsRows->NextRow()) { $cntType = $dsRows->Value('cntForSale'); if ($cntType > 0) { $qtyStk = $dsRows->Value('qtyInStock'); $txtSng = $dsRows->Value('ItTypNameSng'); $txtPlr = $dsRows->Value('ItTypNamePlr'); $strType = Pluralize($cntType,$txtSng,$txtPlr); if ($isFirst) { $isFirst = FALSE; } else { $outTextType .= $iSep; $outTextCnt .= $iSep; $outHTMLCnt .= $iSep; if (!is_null($outHTMLQty)) { $outHTMLQty .= $iSep; } } $outTextType .= $txtSng; $outTextCnt .= $cntType.' '.$strType; $outHTMLCnt .= ''.$cntType.' '.$strType; if (!empty($qtyStk)) { $outHTMLQty .= ''.$qtyStk.' '.Pluralize($qtyStk,$txtSng,$txtPlr); } } } } $arOut['text.!num'] = $outTextType; $arOut['text.cnt'] = $outTextCnt; $arOut['html.cnt'] = $outHTMLCnt; $arOut['html.qty'] = $outHTMLQty; return $arOut;

   }

</php>

ListImages($iSize)

<php> // LATER: change name to DataSet_Images() to clarify that this returns a dataset, not a text list or array

   public function ListImages($iSize) {

$sqlFilt = '(ID_Title='.$this->ID.') AND (Ab_Size="'.$iSize.'") AND isActive'; $objImgs = $this->objDB->Images()->GetData($sqlFilt,'clsImage','AttrSort'); return $objImgs;

   }

</php>

DataSet_ItTyps()

<php>

   /*----
     RETURNS: dataset of item types for this title
     USES: _title_ittyps (cached table)
     HISTORY:

2011-01-19 written

   */
   public function DataSet_ItTyps() {

$sql = 'SELECT * FROM _title_ittyps WHERE ID_Title='.$this->KeyValue(); $obj = $this->Engine()->DataSet($sql,'clsTitleIttyp'); return $obj;

   }

</php>

CatNum($iSep='-')

<php>

   /*----
     HISTORY:

2010-10-19 added optimization to fetch answer from CatKey field if it exists. This may cause future problems. Remove $iSep field and create individual functions if so. 2012-02-02 allowed bypass of Dept if it isn't set

   */
   public function CatNum($iSep='-') {

if (empty($this->Row['CatNum'])) {

$objDept = $this->Dept(); $objSupp = $this->SuppObj(); if (is_object($objDept)) { $strDeptKey = $objDept->CatKey; $strOut = $objSupp->CatKey; if ($strDeptKey) { $strOut .= $iSep.$strDeptKey; } } else { if (is_object($objSupp)) { $strOut = $objSupp->CatKey; } else { $strOut = '?'; } } $strOut .= $iSep.$this->CatKey; } else { $strOut = $this->CatNum; } return strtoupper($strOut);

   }

</php>

URL_part()

<php>

   public function URL_part() {

return strtolower($this->CatNum('/'));

   }

</php>

URL($iBase=KWP_CAT_REL)

<php>

   public function URL($iBase=KWP_CAT_REL) {

return $iBase.$this->URL_part();

   }

</php>

Link(array $iarAttr=NULL)

<php>

   public function Link(array $iarAttr=NULL) {

$strURL = $this->URL(); $htAttr = ArrayToAttrs($iarAttr); return '<a'.$htAttr.' href="'.$strURL.'">';

   }

</php>

LinkAbs()

<php>

   public function LinkAbs() {

$strURL = $this->URL(KWP_CAT); return '<a href="'.$strURL.'">';

   }

</php>

LinkName()

<php>

   public function LinkName() {

return $this->Link().$this->Name.'</a>';

   }

</php> }