/** * @param string $attributeName * @param int $value * @param array|null $filters * @param bool $forceRemove * @return string */ public function getFilterUrl($attributeName = null, $value = null, $filters = null, $forceRemove = false) { if ($filters === null) { $filters = $this->searcher->filters; // Текущие фильтры } if ($attributeName !== null && $value !== null) { $attributeInfo = $this->searcher->model->getAttributesBehavior()->getAttributeInfo($attributeName); if ($attributeInfo && $attributeInfo->multiple) { StaticUrl::removeFilterValue($filters, $attributeName, $value); } else { StaticUrl::removeFilter($filters, $attributeName); } if (!$forceRemove) { $key = StaticUrl::searchFilter($filters, $attributeName); if (is_integer($key)) { if (!isset($filters[$key]['attributeValue'])) { $filters[$key]['attributeValue'] = []; } if (!is_array($filters[$key]['attributeValue'])) { $filters[$key]['attributeValue'] = [$value]; } else { $filters[$key]['attributeValue'][] = $value; } } else { $filters[] = ['attributeName' => $attributeName, 'attributeValue' => $attributeInfo && $attributeInfo->multiple ? [$value] : $value]; } } else { StaticUrl::removeFilterValue($filters, $attributeName, $value); } StaticUrl::sortParts($filters); // StaticUrl::clearFilters($filters); } return StaticUrl::generateUrl($this->searcher->category, $filters); }
/** * @param string $attributeName * @param string|int $attributeValue * @param bool $multiple */ public function setFilter($attributeName, $attributeValue, $multiple = false) { $key = StaticUrl::searchFilter($this->filters, $attributeName); if (is_integer($key)) { if (is_array($this->filters[$key]['attributeValue'])) { if (!in_array($attributeValue, $this->filters[$key]['attributeValue'])) { $this->filters[$key]['attributeValue'][] = $attributeValue; } } else { $this->filters[$key]['attributeValue'] = $attributeValue; } } else { $this->filters[] = ['attributeName' => $attributeName, 'attributeValue' => $multiple ? [$attributeValue] : $attributeValue]; } }