/** * Creates an XhtmlOption from a category * * @param int $id * @param Category $object * @return XhtmlOption */ protected function CreateOption($id, $object) { $opt = new XhtmlOption(ucfirst($object->__toString()), $id . RelatedItemEditor::VALUE_DIVIDER . ucfirst($object->__toString())); $opt->AddAttribute('style', 'padding-left: ' . ($object->GetHierarchyLevel() - 1) * 20 . 'px'); return $opt; }
/** * @return Category[] * @param Category $o_parent_category * @param int $i_number_of_levels * @desc Get an array of Categories which are children of the provided category */ function GetChildren($o_parent_category, $i_number_of_levels = 1) { $b_start_flag = false; $b_finished_flag = false; $b_collect_flag = false; $a_child_categories = array(); if (is_array($this->a_items) and $o_parent_category instanceof Category) { foreach ($this->a_items as $o_category) { # finish point is another category at same level as root if ($b_start_flag and $o_category->GetHierarchyLevel() <= $o_parent_category->GetHierarchyLevel() and $o_category->GetId() != $o_parent_category->GetId()) { $b_finished_flag = true; } # don't collect too deep if ($o_category->GetHierarchyLevel() > $o_parent_category->GetHierarchyLevel() + $i_number_of_levels) { $b_collect_flag = false; } # identify category to collect if ($o_category->GetHierarchyLevel() > $o_parent_category->GetHierarchyLevel() and $o_category->GetHierarchyLevel() <= $o_parent_category->GetHierarchyLevel() + $i_number_of_levels) { $b_collect_flag = true; } # collect category if ($b_start_flag and $b_collect_flag and !$b_finished_flag) { $a_child_categories[] = $o_category; } # find category to start at if ($o_category->GetId() == $o_parent_category->GetId()) { $b_start_flag = true; } } } return $a_child_categories; }