
lvalverdeb
Posts: 299
|
| Posted: 10/06/2004, 4:44 PM |
|
If you need to display the number of categories and subcategories in a Directory form generated by the Directory Builder:
function writeChildrenCountToLink(&$Link,$Connection,$Table,$ParentField,$Param) {
// e.g writeChildrenCountToLink($yourform->CategoryLink,new clsDB...(),"directory_table","parent_id","category_id");
// Save original link value
$CurText = $Link->GetValue();
$CurLink = $Link->Parameters;
$paramArray = explode("&",$CurLink);
$myParam = null;
$myParamValue = null;
//find our $Param in the link parameters
foreach ($paramArray as $item) {
if (substr($item,0,strlen($Param)) == $Param) {
$myParam = substr($item,0,strlen($Param));
$myParamValue = substr($item,strlen($Param)+1,strlen($myParam));
}
}
if ($myParam != null && $myParamValue != null) {
// if our parameter and its corresponding value were found then compute the count and modify the link text
$Result = CCDLookUp("count(*)",$Table,$ParentField."=".$Connection->ToSQL($myParamValue,ccsInteger),$Connection);
$Link->SetValue($CurText."(".$Result.")");
}
return $Link;
}
Using the Directory example in the sample pack:
1) Place the above function in the Common.php
2) In the BeforeShowCategory event, place the following code:
global $yp_categories,$DBInternetDB;
writeChildrenCountToLink($yp_categories->CategoryLink,$DBInternetDB,"directory_categories","category_id_parent","category_id");
3) In the BeforeShowSubCategory event, place the following code:
global $yp_categories,$DBInternetDB;
writeChildrenCountToLink($yp_categories->SubcategoryLink,$DBInternetDB,"directory_categories","category_id_parent","category_id");
Regards
Luis
_________________
lvalverdeb
CR, GMT-6
XAMPP/Ubuntu/CCS3.2/4 |
 |
 |
Karsten
Posts: 57
|
| Posted: 10/08/2004, 4:59 PM |
|
hi Ivalerdeb,
cool, thanks to provide your code to others,
this is a great example for ALL CCS developers to follow.
thx Ivalerdeb!
_________________
If one gives up, he told himself he failed. |
 |
 |
datadoit.com
|
| Posted: 03/22/2005, 3:56 PM |
|
How can this be configured to get the number of items in a particular
category or subcategory?
|
|
|
 |
lvalverdeb
Posts: 299
|
| Posted: 03/27/2005, 7:56 AM |
|
Hi, I just posted a re-write of the function in the Tips and Solution forum. If I understood your question correctly:
$myCategory = 10;
$tmp = new DirectoryCount($DBInternetDB,"directory_categories","category_id_parent","category_id");
$ChildrenCount = $tmp->getChildrenCount($myCategory);
unset($tmp);
Luis
_________________
lvalverdeb
CR, GMT-6
XAMPP/Ubuntu/CCS3.2/4 |
 |
 |
|

|
|
|
|