public function getSelectedFilterOptions($filter)
    {
        $selectedOptions = array();

        // run through all the filter options and check if one of them
        // has been selected.
        foreach ($filter['options'] as $option) {
            // Is the filter option selected in the frontend via piVars
            // or in the backend via flexform configuration ("preselected filters")?
            $selected = false;

            if ($this->pObj->piVars['filter'][$filter['uid']] == $option['tag']) {
                $selected = true;
            } elseif (is_array($this->pObj->piVars['filter'][$filter['uid']])) { // if a this filter is set
                // test pre selected filter again
                if (is_array($this->pObj->preselectedFilter)
                    && $this->pObj->in_multiarray($option['tag'], $this->pObj->preselectedFilter)) {
                    $selected = true;
                    // add preselected filter to piVars
                    $this->pObj->piVars['filter'][$filter['uid']][$option['uid']] = $option['tag'];
                } else { // else test all other filter
                    $isInArray = in_array($option['tag'], $this->pObj->piVars['filter'][$filter['uid']]);
                    if ($isInArray) {
                        $selected = true;
                    }
                }
            } elseif (!isset($this->pObj->piVars['filter'][$filter['uid']])
                && !is_array($this->pObj->piVars['filter'][$filter['uid']])
            ) {
                if (is_array($this->pObj->preselectedFilter)
                    && $this->pObj->in_multiarray($option['tag'], $this->pObj->preselectedFilter)
                ) {
                    $selected = true;
                    // add preselected filter to piVars
                    $this->pObj->piVars['filter'][$filter['uid']] = array($option['uid'] => $option['tag']);
                }
            }

            if ($selected) {
                $selectedOptions[] = $option['uid'];
            }
        }

        return $selectedOptions;
    }