protected function QueryPathCssEventHandler::nthOfTypeChild in QueryPath 7.3
Same name and namespace in other branches
- 6 QueryPath/CssEventHandler.php \QueryPathCssEventHandler::nthOfTypeChild()
- 7.2 QueryPath/CssEventHandler.php \QueryPathCssEventHandler::nthOfTypeChild()
2 calls to QueryPathCssEventHandler::nthOfTypeChild()
File
- QueryPath/
CssEventHandler.php, line 678
Class
Code
protected function nthOfTypeChild($groupSize, $elementInGroup, $lastChild) {
$parents = new SplObjectStorage();
$matches = new SplObjectStorage();
$i = 0;
foreach ($this->matches as $item) {
$parent = $item->parentNode;
if (!$parents
->contains($parent)) {
$c = 0;
foreach ($parent->childNodes as $child) {
if ($child->nodeType == XML_ELEMENT_NODE && $child->tagName == $item->tagName) {
$child->nodeIndex = ++$c;
}
}
$parent->numElements = $c;
$parents
->attach($parent);
}
if ($lastChild) {
$indexToMatch = $item->parentNode->numElements - $item->nodeIndex + 1;
}
else {
$indexToMatch = $item->nodeIndex;
}
if ($groupSize == 0) {
if ($indexToMatch == $elementInGroup) {
$matches
->attach($item);
}
}
else {
if (($indexToMatch - $elementInGroup) % $groupSize == 0 && ($indexToMatch - $elementInGroup) / $groupSize >= 0) {
$matches
->attach($item);
}
}
++$i;
}
$this->matches = $matches;
}