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...")
 
(more obsessive archival tidying)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
<hide>
 
[[file::VbzCart/code/files/base.cat.php]]
 
</hide>
 
{| style="float:right;"
 
|-
 
|__TOC__
 
|}
 
 
==References==
 
==References==
* created by: {{l/same|clsVbzTitles}}
+
* '''created by''': {{l/same|clsVbzTitles}}
 
==Code==
 
==Code==
 +
<syntaxhighlight lang=php>
 
class clsVbzTitle extends clsDataSet {
 
class clsVbzTitle extends clsDataSet {
<php>
 
 
// object cache
 
// object cache
 
     private $objDept;
 
     private $objDept;
Line 16: Line 9:
 
// options
 
// options
 
     public $hideImgs;
 
     public $hideImgs;
</php>
 
===Dept()===
 
<php>
 
 
     public function Dept() {
 
     public function Dept() {
 
$doLoad = FALSE;
 
$doLoad = FALSE;
Line 42: Line 32:
 
return $this->objDept;
 
return $this->objDept;
 
     }
 
     }
</php>
 
===Supplier_ID()===
 
<php>
 
 
     /*----
 
     /*----
 
       RETURNS: ID of this title's supplier
 
       RETURNS: ID of this title's supplier
Line 59: Line 46:
 
return $idSupp;
 
return $idSupp;
 
     }
 
     }
</php>
 
===Supplier()===
 
<php>
 
 
     // DEPRECATED -- use SuppObj()
 
     // DEPRECATED -- use SuppObj()
 
     public function Supplier() {
 
     public function Supplier() {
 
return $this->SuppObj();
 
return $this->SuppObj();
 
     }
 
     }
</php>
 
===SuppObj()===
 
<php>
 
 
     public function SuppObj() {
 
     public function SuppObj() {
 
$doLoad = FALSE;
 
$doLoad = FALSE;
Line 92: Line 73:
 
return $this->objSupp;
 
return $this->objSupp;
 
     }
 
     }
</php>
 
===Items()===
 
<php>
 
 
     public function Items() {
 
     public function Items() {
 
$sqlFilt = 'ID_Title='.$this->ID;
 
$sqlFilt = 'ID_Title='.$this->ID;
Line 101: Line 79:
 
return $objRows;
 
return $objRows;
 
     }
 
     }
</php>
 
===Topics()===
 
<php>
 
 
     public function Topics() {
 
     public function Topics() {
 
$objTbl = $this->Engine()->TitleTopic_Topics();
 
$objTbl = $this->Engine()->TitleTopic_Topics();
Line 109: Line 84:
 
return $objRows;
 
return $objRows;
 
     }
 
     }
</php>
 
===Indicia(array $iarAttr=NULL)===
 
<php>
 
 
     /*----
 
     /*----
 
       RETURNS: Array containing summary information about this title
 
       RETURNS: Array containing summary information about this title
Line 146: Line 118:
 
return $arOut;
 
return $arOut;
 
     }
 
     }
</php>
 
===Summary_ItTyps($iSep=', ')===
 
<php>
 
 
     /*----
 
     /*----
 
       RETURNS: Array containing summaries of ItTyps in which this Title is available
 
       RETURNS: Array containing summaries of ItTyps in which this Title is available
Line 195: Line 164:
 
return $arOut;
 
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
 
// LATER: change name to DataSet_Images() to clarify that this returns a dataset, not a text list or array
 
     public function ListImages($iSize) {
 
     public function ListImages($iSize) {
Line 204: Line 170:
 
return $objImgs;
 
return $objImgs;
 
     }
 
     }
</php>
 
===DataSet_ItTyps()===
 
<php>
 
 
     /*----
 
     /*----
 
       RETURNS: dataset of item types for this title
 
       RETURNS: dataset of item types for this title
Line 218: Line 181:
 
return $obj;
 
return $obj;
 
     }
 
     }
</php>
 
===CatNum($iSep='-')===
 
<php>
 
 
     /*----
 
     /*----
 
       HISTORY:
 
       HISTORY:
Line 252: Line 212:
 
return strtoupper($strOut);
 
return strtoupper($strOut);
 
     }
 
     }
</php>
 
===URL_part()===
 
<php>
 
 
     public function URL_part() {
 
     public function URL_part() {
 
return strtolower($this->CatNum('/'));
 
return strtolower($this->CatNum('/'));
 
     }
 
     }
</php>
 
===URL($iBase=KWP_CAT_REL)===
 
<php>
 
 
     public function URL($iBase=KWP_CAT_REL) {
 
     public function URL($iBase=KWP_CAT_REL) {
 
return $iBase.$this->URL_part();
 
return $iBase.$this->URL_part();
 
     }
 
     }
</php>
 
===Link(array $iarAttr=NULL)===
 
<php>
 
 
     public function Link(array $iarAttr=NULL) {
 
     public function Link(array $iarAttr=NULL) {
 
$strURL = $this->URL();
 
$strURL = $this->URL();
Line 272: Line 223:
 
return '<a'.$htAttr.' href="'.$strURL.'">';
 
return '<a'.$htAttr.' href="'.$strURL.'">';
 
     }
 
     }
</php>
 
===LinkAbs()===
 
<php>
 
 
     public function LinkAbs() {
 
     public function LinkAbs() {
 
$strURL = $this->URL(KWP_CAT);
 
$strURL = $this->URL(KWP_CAT);
 
return '<a href="'.$strURL.'">';
 
return '<a href="'.$strURL.'">';
 
     }
 
     }
</php>
 
===LinkName()===
 
<php>
 
 
     public function LinkName() {
 
     public function LinkName() {
 
return $this->Link().$this->Name.'</a>';
 
return $this->Link().$this->Name.'</a>';
 
     }
 
     }
</php>
 
 
}
 
}
 +
</syntaxhighlight>

Latest revision as of 13:31, 14 October 2022

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