/**
  * Finds the selected filter options for a given filter.
  * Checks
  * - piVars one-dimensional filter
  * - piVars multi-dimensional filter
  * - backend preselected filter options
  *
  * returns the filter options uids as values of an array or zero if no option has been selected.
  *
  * @param array $filter
  * @return integer
  * @author Christian Bülter <*****@*****.**>
  * @since 09.09.14
  */
 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;
         } else {
             if (is_array($this->pObj->piVars['filter'][$filter['uid']])) {
                 $isInArray = TYPO3\CMS\Core\Utility\GeneralUtility::inArray($this->pObj->piVars['filter'][$filter['uid']], $option['tag']);
                 if ($isInArray) {
                     $selected = true;
                 }
             } else {
                 if (!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;
 }
 /**
  * change ordering
  * f.e. asc to desc and desc to asc
  *
  * @param string $direction asc or desc
  * @return string desc or asc. If you call this function with a not allowed string, exactly this string will be returned. Short: The function do nothing
  */
 public function changeOrdering($direction)
 {
     $allowedDirections = array('asc', 'desc');
     $direction = strtolower($direction);
     if (TYPO3_VERSION_INTEGER >= 7000000) {
         $isInArray = TYPO3\CMS\Core\Utility\GeneralUtility::inArray($allowedDirections, $direction);
     } else {
         $isInArray = t3lib_div::inArray($allowedDirections, $direction);
     }
     if (!empty($direction) && $isInArray) {
         if ($direction == 'asc') {
             $direction = 'desc';
         } else {
             $direction = 'asc';
         }
     }
     return $direction;
 }