/**
  * The post processing of the form gets done here.
  *
  * Key things done during post processing are
  *      - check for reset or next request. if present, skip post processing.
  *      - now check if user requested running a saved search, if so, then
  *        the form values associated with the saved search are used for searching.
  *      - if user has done a submit with new values the regular post submission is
  *        done.
  * The processing consists of using a Selector / Controller framework for getting the
  * search results.
  */
 public function postProcess()
 {
     // get user submitted values
     // get it from controller only if form has been submitted, else preProcess has set this
     if (!empty($_POST)) {
         $this->_formValues = $this->controller->exportValues($this->_name);
         $this->normalizeFormValues();
     }
     CRM_Core_BAO_CustomValue::fixCustomFieldValue($this->_formValues);
     $this->_params = CRM_Relationship_BAO_Query::convertFormValues($this->_formValues);
     $this->_returnProperties =& $this->returnProperties();
     if ($this->_done) {
         return;
     }
     $this->_done = TRUE;
     //for prev/next pagination
     $crmPID = CRM_Utils_Request::retrieve('crmPID', 'Integer', CRM_Core_DAO::$_nullObject);
     if (array_key_exists($this->_searchButtonName, $_POST) || $this->_force && !$crmPID) {
         //reset the cache table for new search
         $cacheKey = "civicrm search {$this->controller->_key}";
         CRM_Core_BAO_PrevNextCache::deleteItem(NULL, $cacheKey);
     }
     //get the button name
     $buttonName = $this->controller->getButtonName();
     if (isset($this->_componentMode) && empty($this->_formValues['component_mode'])) {
         $this->_formValues['component_mode'] = $this->_componentMode;
     }
     if (isset($this->_operator) && empty($this->_formValues['operator'])) {
         $this->_formValues['operator'] = $this->_operator;
     }
     if (empty($this->_formValues['qfKey'])) {
         $this->_formValues['qfKey'] = $this->controller->_key;
     }
     $this->set('type', $this->_action);
     $this->set('formValues', $this->_formValues);
     $this->set('queryParams', $this->_params);
     $this->set('returnProperties', $this->_returnProperties);
     if ($buttonName == $this->_actionButtonName) {
         // check actionName and if next, then do not repeat a search, since we are going to the next page
         // hack, make sure we reset the task values
         $stateMachine = $this->controller->getStateMachine();
         $formName = $stateMachine->getTaskFormName();
         $this->controller->resetPage($formName);
         return;
     } else {
         $output = CRM_Core_Selector_Controller::SESSION;
         // create the selector, controller and run - store results in session
         $searchChildGroups = TRUE;
         $setDynamic = FALSE;
         if (strpos(self::$_selectorName, 'CRM_Relationship_Selector') !== FALSE) {
             $selector = new self::$_selectorName($this->_customSearchClass, $this->_formValues, $this->_params, $this->_returnProperties, $this->_action, FALSE, $this->_context, $this->_contextMenu);
             $setDynamic = TRUE;
         } else {
             $selector = new self::$_selectorName($this->_params, $this->_action, NULL, FALSE, NULL, "search", "advanced");
         }
         $selector->setKey($this->controller->_key);
         // added the sorting  character to the form array
         $config = CRM_Core_Config::singleton();
         // do this only for contact search
         $sortID = NULL;
         if ($this->get(CRM_Utils_Sort::SORT_ID)) {
             $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID), $this->get(CRM_Utils_Sort::SORT_DIRECTION));
         }
         $controller = new CRM_Relationship_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), $sortID, CRM_Core_Action::VIEW, $this, $output);
         $controller->setEmbedded(TRUE);
         $controller->setDynamicAction($setDynamic);
         $controller->run();
     }
 }