public static
nestedToCheckBox
(mixed $data, mixed $d, mixed $currentCatid = 0, mixed &$active = 0, mixed $forceCategoryId = 0)
public static function nestedToCheckBox($data, $d, $currentCatid = 0, &$active = 0, $forceCategoryId = 0)
{
$s = PhocacartRenderStyle::getStyles();
$result = array();
if (!empty($data) && count($data) > 0) {
$result[] = '<ul class="ph-filter-module-category-tree">';
foreach ($data as $k => $v) {
$checked = '';
$value = htmlspecialchars($v['alias']);
if (isset($d['nrinalias']) && $d['nrinalias'] == 1) {
$value = (int) $v['id'] . '-' . htmlspecialchars($v['alias']);
}
if (in_array($value, $d['getparams'])) {
$checked = 'checked';
$active = 1;
}
// This only can happen in category view (category filters are empty, id of category is larger then zero)
// This is only marking the category as active in category list
if (empty($d['getparams']) || isset($d['getparams'][0]) && $d['getparams'][0] == '') {
// Empty parameters, so we can set category id by id of category view
if ($forceCategoryId > 0 && (int) $forceCategoryId == (int) $v['id']) {
$checked = 'checked';
$active = 1;
}
}
$count = '';
// If we are in item view - one category is selected but if user click on filter to select other category, this one should be still selected - we go to items view with 2 selected
// because force category is on
if (isset($v['count_products']) && isset($d['params']['display_category_count']) && $d['params']['display_category_count'] == 1) {
$count = ' <span class="ph-filter-count">' . (int) $v['count_products'] . '</span>';
}
$icon = '';
if ($v['icon_class'] != '') {
$icon = '<span class="' . PhocacartText::filterValue($v['icon_class'], 'text') . ' ph-filter-item-icon"></span> ';
}
$jsSet = '';
if (isset($d['forcecategory']['idalias']) && $d['forcecategory']['idalias'] != '') {
// Category View - force the category parameter if set in parameters
$jsSet .= 'phChangeFilter(\'c\', \'' . $d['forcecategory']['idalias'] . '\', 1, \'text\', 0, 1, 1);';
// ADD IS FIXED ( use "text" as formType - it cannot by managed by checkbox, it is fixed - always 1 - does not depends on checkbox, it is fixed 1
}
$jsSet .= 'phChangeFilter(\'' . $d['param'] . '\', \'' . $value . '\', this, \'' . $d['formtype'] . '\',\'' . $d['uniquevalue'] . '\', 0, 1);';
// ADD OR REMOVE
$result[] = '<li><div class="' . $s['c']['controls'] . '">';
$result[] = '<label class="ph-checkbox-container"><input class="' . $s['c']['inputbox.checkbox'] . '" type="checkbox" name="tag" value="' . $value . '" ' . $checked . ' onchange="' . $jsSet . '" />' . $icon . $v['title'] . $count . '<span class="ph-checkbox-checkmark"></span></label>';
$result[] = '</div></li>';
$result[] = self::nestedToCheckBox($v['children'], $d, $currentCatid, $active);
}
$result[] = '</ul>';
}
return implode("\n", $result);
}