Example #1
0
 /**
  * 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 procesing.
  *      - 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 submissing is
  *        done.
  *
  * The processing consists of using a Selector / Controller framework for getting the
  * search results.
  */
 public function postProcess()
 {
     if ($this->_done) {
         return;
     }
     $this->_done = TRUE;
     if (!empty($_POST)) {
         $this->_formValues = $this->controller->exportValues($this->_name);
         foreach (array('activity_type_id', 'status_id', 'activity_subject') as $element) {
             $value = CRM_Utils_Array::value($element, $this->_formValues);
             if ($value) {
                 if (is_array($value)) {
                     if ($element == 'status_id') {
                         unset($this->_formValues[$element]);
                         $this->_formValues['activity_' . $element] = $value;
                     }
                 } else {
                     $this->_formValues[$element] = array('LIKE' => "%{$value}%");
                 }
             }
         }
     }
     $this->fixFormValues();
     if (isset($this->_ssID) && empty($_POST)) {
         // if we are editing / running a saved search and the form has not been posted
         $this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID);
     }
     // We don't show test records in summaries or dashboards
     if (empty($this->_formValues['activity_test']) && $this->_force) {
         $this->_formValues["activity_test"] = 0;
     }
     CRM_Core_BAO_CustomValue::fixCustomFieldValue($this->_formValues);
     $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
     $this->set('formValues', $this->_formValues);
     $this->set('queryParams', $this->_queryParams);
     $buttonName = $this->controller->getButtonName();
     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;
     }
     $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));
     }
     $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
     $selector = new CRM_Activity_Selector_Search($this->_queryParams, $this->_action, NULL, $this->_single, $this->_limit, $this->_context);
     $selector->setKey($this->controller->_key);
     $prefix = NULL;
     if ($this->_context == 'basic' || $this->_context == 'user') {
         $prefix = $this->_prefix;
     }
     $controller = new CRM_Core_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), $sortID, CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::SESSION, $prefix);
     $controller->setEmbedded(TRUE);
     $query =& $selector->getQuery();
     if ($this->_context == 'user') {
         $query->setSkipPermission(TRUE);
     }
     $controller->run();
 }
 /**
  * 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 procesing.
  *      - 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 submissing is
  *        done.
  * The processing consists of using a Selector / Controller framework for getting the
  * search results.
  *
  * @param
  *
  * @return void
  * @access public
  */
 function postProcess()
 {
     if ($this->_done) {
         return;
     }
     $this->_done = TRUE;
     if (!empty($_POST)) {
         $this->_formValues = $this->controller->exportValues($this->_name);
     }
     $this->fixFormValues();
     if (isset($this->_ssID) && empty($_POST)) {
         // if we are editing / running a saved search and the form has not been posted
         $this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID);
     }
     if (CRM_Utils_Array::value('activity_survey_id', $this->_formValues)) {
         // if the user has choosen a survey but not any activity type, we force the activity type
         $sid = CRM_Utils_Array::value('activity_survey_id', $this->_formValues);
         $activity_type_id = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $sid, 'activity_type_id');
         $this->_formValues['activity_type_id'][$activity_type_id] = 1;
     }
     if (!CRM_Utils_Array::value('activity_test', $this->_formValues)) {
         $this->_formValues["activity_test"] = 0;
     }
     if (!CRM_Utils_Array::value('activity_contact_name', $this->_formValues) && !CRM_Utils_Array::value('contact_id', $this->_formValues)) {
         $this->_formValues['activity_role'] = NULL;
     }
     CRM_Core_BAO_CustomValue::fixFieldValueOfTypeMemo($this->_formValues);
     $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
     $this->set('formValues', $this->_formValues);
     $this->set('queryParams', $this->_queryParams);
     $buttonName = $this->controller->getButtonName();
     if ($buttonName == $this->_actionButtonName || $buttonName == $this->_printButtonName) {
         // 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;
     }
     $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));
     }
     $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
     $selector = new CRM_Activity_Selector_Search($this->_queryParams, $this->_action, NULL, $this->_single, $this->_limit, $this->_context);
     $selector->setKey($this->controller->_key);
     $prefix = NULL;
     if ($this->_context == 'basic' || $this->_context == 'user') {
         $prefix = $this->_prefix;
     }
     $controller = new CRM_Core_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), $sortID, CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::SESSION, $prefix);
     $controller->setEmbedded(TRUE);
     $query =& $selector->getQuery();
     if ($this->_context == 'user') {
         $query->setSkipPermission(TRUE);
     }
     $controller->run();
 }