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

References

Code

class clsVbzTitle extends clsDataSet {
// object cache
    private $objDept;
    private $objSupp;
// options
    public $hideImgs;
    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;
    }
    /*----
      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;
    }
    // DEPRECATED -- use SuppObj()
    public function Supplier() {
	return $this->SuppObj();
    }
    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;
    }
    public function Items() {
	$sqlFilt = 'ID_Title='.$this->ID;
	$objTbl = $this->objDB->Items();
	$objRows = $objTbl->GetData($sqlFilt);
	return $objRows;
    }
    public function Topics() {
	$objTbl = $this->Engine()->TitleTopic_Topics();
	$objRows = $objTbl->GetTitle($this->KeyValue());
	return $objRows;
    }
    /*----
      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;
    }
    /*----
      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 .= '<b>'.$cntType.'</b> '.$strType;
		    if (!empty($qtyStk)) {
			$outHTMLQty .= '<b>'.$qtyStk.'</b> '.Pluralize($qtyStk,$txtSng,$txtPlr);
		    }
		}
	    }
	}
	$arOut['text.!num'] = $outTextType;
	$arOut['text.cnt'] = $outTextCnt;
	$arOut['html.cnt'] = $outHTMLCnt;
	$arOut['html.qty'] = $outHTMLQty;
	return $arOut;
    }
// 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;
    }
    /*----
      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;
    }
    /*----
      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);
    }
    public function URL_part() {
	return strtolower($this->CatNum('/'));
    }
    public function URL($iBase=KWP_CAT_REL) {
	return $iBase.$this->URL_part();
    }
    public function Link(array $iarAttr=NULL) {
	$strURL = $this->URL();
	$htAttr = ArrayToAttrs($iarAttr);
	return '<a'.$htAttr.' href="'.$strURL.'">';
    }
    public function LinkAbs() {
	$strURL = $this->URL(KWP_CAT);
	return '<a href="'.$strURL.'">';
    }
    public function LinkName() {
	return $this->Link().$this->Name.'</a>';
    }
}