/** * Check that running convertFormValues more than one doesn't mangle the array. * * Unfortunately the convertFormValues & indeed much of the query code is run in pre-process AND post-process. * * The convertFormValues function should cope with this until such time as we can rationalise that. */ public function testConvertEntityFieldMultipleValueEntityRefDoubleRun() { $formValues = array('membership_type_id' => '1,2'); $params = CRM_Contact_BAO_Query::convertFormValues($formValues, 0, FALSE, NULL, array('membership_type_id')); $this->assertEquals(array('membership_type_id', 'IN', array(1, 2), 0, 0), $params[0]); $params = CRM_Contact_BAO_Query::convertFormValues($params, 0, FALSE, NULL, array('membership_type_id')); $this->assertEquals(array('membership_type_id', 'IN', array(1, 2), 0, 0), $params[0]); $obj = new CRM_Contact_BAO_Query($params); $this->assertEquals(array('civicrm_membership.membership_type_id IN ("1", "2")'), $obj->_where[0]); }
function __construct(&$formValues) { parent::__construct($formValues); $this->normalize(); $this->_columns = array(ts('') => 'contact_type', ts('Name') => 'sort_name', ts('Address') => 'street_address', ts('City') => 'city', ts('State') => 'state_province', ts('Postal') => 'postal_code', ts('Country') => 'country', ts('Email') => 'email', ts('Phone') => 'phone'); $params =& CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $returnProperties = array(); foreach ($this->_columns as $name => $field) { $returnProperties[$field] = 1; } $this->_query =& new CRM_Contact_BAO_Query($params, $returnProperties, null, false, false, 1, false, false); }
/** * Test the query from the selector class is consistent with the dataset expectation. * * @param array $dataSet * The data set to be tested. Note that when adding new datasets often only form_values and expected where * clause will need changing. * * @dataProvider querySets */ public function testSelectorQuery($dataSet) { $params = CRM_Contact_BAO_Query::convertFormValues($dataSet['form_values'], 0, FALSE, NULL, array()); foreach ($dataSet['settings'] as $setting) { $this->callAPISuccess('Setting', 'create', array($setting['name'] => $setting['value'])); } $selector = new CRM_Contact_Selector($dataSet['class'], $dataSet['form_values'], $params, $dataSet['return_properties'], $dataSet['action'], $dataSet['includeContactIds'], $dataSet['searchDescendentGroups'], $dataSet['context']); $queryObject = $selector->getQueryObject(); $sql = $queryObject->query(); $this->wrangleDefaultClauses($dataSet['expected_query']); foreach ($dataSet['expected_query'] as $index => $queryString) { $this->assertEquals($this->strWrangle($queryString), $this->strWrangle($sql[$index])); } }
/** * Test CRM_Contact_BAO_Query::searchQuery() * @dataProvider dataProvider */ function testSearch($fv, $count, $ids, $full) { $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet(dirname(__FILE__) . '/queryDataset.xml')); $params = CRM_Contact_BAO_Query::convertFormValues($fv); $obj = new CRM_Contact_BAO_Query($params); $obj->_useGroupBy = TRUE; $dao = $obj->searchQuery(); $contacts = array(); while ($dao->fetch()) { $contacts[] = $dao->contact_id; } sort($contacts, SORT_NUMERIC); $this->assertEquals($ids, $contacts, 'In line ' . __LINE__); }
/** * Test CRM_Contact_BAO_Query::searchQuery() * @dataProvider dataProvider * @param $fv * @param $count * @param $ids * @param $full */ public function testSearch($fv, $count, $ids, $full) { $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, $this->createFlatXMLDataSet(dirname(__FILE__) . '/queryDataset.xml')); $params = CRM_Contact_BAO_Query::convertFormValues($fv); $obj = new CRM_Contact_BAO_Query($params); // let's set useGroupBy=true since we are listing contacts here who might belong to // more than one group / tag / notes etc. $obj->_useGroupBy = TRUE; $dao = $obj->searchQuery(); $contacts = array(); while ($dao->fetch()) { $contacts[] = $dao->contact_id; } sort($contacts, SORT_NUMERIC); $this->assertEquals($ids, $contacts); }
/** * Class constructor. * * @param array $formValues */ public function __construct(&$formValues) { parent::__construct($formValues); $this->_columns = array('' => 'contact_type', ts('Name') => 'sort_name', ts('Address') => 'street_address', ts('City') => 'city', ts('State') => 'state_province', ts('Postal') => 'postal_code', ts('Country') => 'country', ts('Email') => 'email', ts('Phone') => 'phone'); $params = CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $returnProperties = array(); $returnProperties['contact_sub_type'] = 1; $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE); foreach ($this->_columns as $name => $field) { if (in_array($field, array('street_address', 'city', 'state_province', 'postal_code', 'country')) && empty($addressOptions[$field])) { unset($this->_columns[$name]); continue; } $returnProperties[$field] = 1; } $this->_query = new CRM_Contact_BAO_Query($params, $returnProperties, NULL, FALSE, FALSE, 1, FALSE, FALSE); }
/** * This method is called for processing a submitted search form. */ public function postProcess() { $this->set('isAdvanced', '0'); $this->set('isSearchBuilder', '0'); // 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); } if (isset($this->_groupID) && empty($this->_formValues['group'])) { $this->_formValues['group'] = $this->_groupID; } elseif (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); //fix for CRM-1505 if (CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID, 'mapping_id')) { $this->_params = CRM_Contact_BAO_SavedSearch::getSearchParams($this->_ssID); } } // we dont want to store the sortByCharacter in the formValue, it is more like // a filter on the result set // this filter is reset if we click on the search button if ($this->_sortByCharacter !== NULL && empty($_POST)) { if (strtolower($this->_sortByCharacter) == 'all') { $this->_formValues['sortByCharacter'] = NULL; } else { $this->_formValues['sortByCharacter'] = $this->_sortByCharacter; } } else { $this->_sortByCharacter = NULL; } $this->_params = CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $this->_returnProperties =& $this->returnProperties(); parent::postProcess(); }
/** * processing needed for buildForm and later * * @return void * @access public */ function preProcess() { /** * set the varios class variables */ $this->_group =& CRM_Core_PseudoConstant::group(); $this->_groupIterator =& CRM_Core_PseudoConstant::groupIterator(); $this->_tag =& CRM_Core_PseudoConstant::tag(); $this->_done = false; /** * set the button names */ $this->_searchButtonName = $this->getButtonName('refresh'); $this->_printButtonName = $this->getButtonName('next', 'print'); $this->_actionButtonName = $this->getButtonName('next', 'action'); /* * we allow the controller to set force/reset externally, useful when we are being * driven by the wizard framework */ $this->_reset = CRM_Utils_Request::retrieve('reset', 'Boolean', CRM_Core_DAO::$_nullObject); $this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', CRM_Core_DAO::$_nullObject); $this->_groupID = CRM_Utils_Request::retrieve('gid', 'Positive', $this); $this->_amtgID = CRM_Utils_Request::retrieve('amtgID', 'Positive', $this); $this->_ssID = CRM_Utils_Request::retrieve('ssID', 'Positive', $this); $this->_sortByCharacter = CRM_Utils_Request::retrieve('sortByCharacter', 'String', $this); $this->_ufGroupID = CRM_Utils_Request::retrieve('id', 'Positive', $this); // reset from session, CRM-3526 $session =& CRM_Core_Session::singleton(); if ($this->_force && $session->get('selectedSearchContactIds')) { $session->resetScope('selectedSearchContactIds'); } // if we dont get this from the url, use default if one exsts $config =& CRM_Core_Config::singleton(); if ($this->_ufGroupID == null && $config->defaultSearchProfileID != null) { $this->_ufGroupID = $config->defaultSearchProfileID; } /* * assign context to drive the template display, make sure context is valid */ $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this, false, 'search'); if (!CRM_Utils_Array::value($this->_context, self::validContext())) { $this->_context = 'search'; $this->set('context', $this->_context); } $this->assign('context', $this->_context); $this->set('selectorName', $this->_selectorName); // get user submitted values // get it from controller only if form has been submitted, else preProcess has set this // $this->controller->isModal( ) returns true if page is // valid, i.e all the validations are true if (!empty($_POST) && !$this->controller->isModal()) { $this->_formValues = $this->controller->exportValues($this->_name); $this->normalizeFormValues(); $this->_params =& CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $this->_returnProperties =& $this->returnProperties(); // also get the uf group id directly from the post value $this->_ufGroupID = CRM_Utils_Array::value('uf_group_id', $_POST, $this->_ufGroupID); $this->_formValues['uf_group_id'] = $this->_ufGroupID; $this->set('id', $this->_ufGroupID); } else { $this->_formValues = $this->get('formValues'); $this->_params =& CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $this->_returnProperties =& $this->returnProperties(); } if (empty($this->_formValues)) { //check if group is a smart group (fix for CRM-1255) if ($this->_groupID) { if ($ssId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID, 'saved_search_id')) { $this->_ssID = $ssId; } } // fix for CRM-1907 if (isset($this->_ssID) && $this->_context != 'smog') { // we only retrieve the saved search values if out current values are null $this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID); //fix for CRM-1505 if (CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID, 'mapping_id')) { $this->_params =& CRM_Contact_BAO_SavedSearch::getSearchParams($this->_ssID); } else { $this->_params =& CRM_Contact_BAO_Query::convertFormValues($this->_formValues); } $this->_returnProperties =& $this->returnProperties(); } else { if (isset($this->_ufGroupID)) { // also set the uf group id if not already present $this->_formValues['uf_group_id'] = $this->_ufGroupID; } } } $this->assign('id', CRM_Utils_Array::value('uf_group_id', $this->_formValues)); require_once 'CRM/Contact/BAO/Contact.php'; $menuItems = CRM_Contact_BAO_Contact::contextMenu(); $primaryActions = CRM_Utils_Array::value('primaryActions', $menuItems, array()); $this->_contextMenu = CRM_Utils_Array::value('moreActions', $menuItems, array()); $this->assign('contextMenu', $primaryActions + $this->_contextMenu); // CRM_Core_Error::debug( 'f', $this->_formValues ); // CRM_Core_Error::debug( 'p', $this->_params ); eval('$selector =& new ' . $this->_selectorName . '( $this->_customSearchClass, $this->_formValues, $this->_params, $this->_returnProperties, $this->_action, false, true, $this->_context );'); $controller =& new CRM_Contact_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), $this->get(CRM_Utils_Sort::SORT_ID), CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::TRANSFER); $controller->setEmbedded(true); if ($this->_force) { $this->postProcess(); /* * Note that we repeat this, since the search creates and stores * values that potentially change the controller behavior. i.e. things * like totalCount etc */ $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_Contact_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), $sortID, CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::TRANSFER); $controller->setEmbedded(true); } $controller->moveFromSessionToTemplate(); }
/** * 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() { $this->set('isAdvanced', '1'); // 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(); // FIXME: couldn't figure out a good place to do this, // FIXME: so leaving this as a dependency for now if (array_key_exists('contribution_amount_low', $this->_formValues)) { foreach (array('contribution_amount_low', 'contribution_amount_high') as $f) { $this->_formValues[$f] = CRM_Utils_Rule::cleanMoney($this->_formValues[$f]); } } // set the group if group is submitted if (!empty($this->_formValues['uf_group_id'])) { $this->set('id', $this->_formValues['uf_group_id']); } else { $this->set('id', ''); } } // retrieve ssID values only if formValues is null, i.e. form has never been posted if (empty($this->_formValues) && isset($this->_ssID)) { $this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID); } if (isset($this->_groupID) && !CRM_Utils_Array::value('group', $this->_formValues)) { $this->_formValues['group'] = array($this->_groupID => 1); } //search for civicase if (is_array($this->_formValues)) { $allCases = FALSE; if (array_key_exists('case_owner', $this->_formValues) && !$this->_formValues['case_owner'] && !$this->_force) { foreach (array('case_type_id', 'case_status_id', 'case_deleted', 'case_tags') as $caseCriteria) { if (CRM_Utils_Array::value($caseCriteria, $this->_formValues)) { $allCases = TRUE; $this->_formValues['case_owner'] = 1; continue; } } if ($allCases) { if (CRM_Core_Permission::check('access all cases and activities')) { $this->_formValues['case_owner'] = 1; } else { $this->_formValues['case_owner'] = 2; } } else { $this->_formValues['case_owner'] = 0; } } } // we dont want to store the sortByCharacter in the formValue, it is more like // a filter on the result set // this filter is reset if we click on the search button if ($this->_sortByCharacter !== NULL && empty($_POST)) { if (strtolower($this->_sortByCharacter) == 'all') { $this->_formValues['sortByCharacter'] = NULL; } else { $this->_formValues['sortByCharacter'] = $this->_sortByCharacter; } } else { $this->_sortByCharacter = NULL; } CRM_Core_BAO_CustomValue::fixFieldValueOfTypeMemo($this->_formValues); $this->_params = CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $this->_returnProperties =& $this->returnProperties(); parent::postProcess(); }
/** * Given a saved search compute the clause and the tables and store it for future use. */ public function buildClause() { $fv = unserialize($this->form_values); if ($this->mapping_id) { $params = CRM_Core_BAO_Mapping::formattedFields($fv); } else { $params = CRM_Contact_BAO_Query::convertFormValues($fv); } if (!empty($params)) { $tables = $whereTables = array(); $this->where_clause = CRM_Contact_BAO_Query::getWhereClause($params, NULL, $tables, $whereTables); if (!empty($tables)) { $this->select_tables = serialize($tables); } if (!empty($whereTables)) { $this->where_tables = serialize($whereTables); } } }
function _civicrm_api3_get_using_query_object($object_type, $params, $additional_options = array(), $getCount = null) { // Convert id to e.g. contact_id if (empty($params[$object_type . '_id']) && isset($params['id'])) { $params[$object_type . '_id'] = $params['id']; } unset($params['id']); $options = _civicrm_api3_get_options_from_params($params, TRUE); $inputParams = array_merge(CRM_Utils_Array::value('input_params', $options, array()), CRM_Utils_Array::value('input_params', $additional_options, array())); $returnProperties = array_merge(CRM_Utils_Array::value('return', $options, array()), CRM_Utils_Array::value('return', $additional_options, array())); if (empty($returnProperties)) { $returnProperties = null; } $options = array_merge($options, $additional_options); $sort = CRM_Utils_Array::value('sort', $options, NULL); $offset = CRM_Utils_Array::value('offset', $options, NULL); $limit = CRM_Utils_Array::value('limit', $options, NULL); $smartGroupCache = CRM_Utils_Array::value('smartGroupCache', $params); if ($getCount) { $limit = NULL; $returnProperties = NULL; } $newParams = CRM_Contact_BAO_Query::convertFormValues($inputParams); list($entities, $options) = CRM_Contact_BAO_Query::apiQuery($newParams, $returnProperties, NULL, $sort, $offset, $limit, $smartGroupCache, $getCount); if ($getCount) { // only return the count of contacts return $entities[0]; } return $entities; }
/** * Function to get the list of contacts for a profile * * @param $form object * * @access public */ function getProfileContact($gid) { $session =& CRM_Core_Session::singleton(); $params = $session->get('profileParams'); $details = array(); $ufGroupParam = array('id' => $gid); require_once "CRM/Core/BAO/UFGroup.php"; CRM_Core_BAO_UFGroup::retrieve($ufGroupParam, $details); // make sure this group can be mapped if (!$details['is_map']) { CRM_Core_Error::statusBounce(ts('This profile does not have the map feature turned on.')); } $groupId = CRM_Utils_Array::value('limit_listings_group_id', $details); // add group id to params if a uf group belong to a any group if ($groupId) { if (CRM_Utils_Array::value('group', $params)) { $params['group'][$groupId] = 1; } else { $params['group'] = array($groupId => 1); } } $fields = CRM_Core_BAO_UFGroup::getListingFields(CRM_Core_Action::VIEW, CRM_Core_BAO_UFGroup::PUBLIC_VISIBILITY | CRM_Core_BAO_UFGroup::LISTINGS_VISIBILITY, false, $gid); $returnProperties =& CRM_Contact_BAO_Contact::makeHierReturnProperties($fields); $returnProperties['contact_type'] = 1; $returnProperties['sort_name'] = 1; $queryParams =& CRM_Contact_BAO_Query::convertFormValues($params, 1); $query =& new CRM_Contact_BAO_Query($queryParams, $returnProperties, $fields); $ids = $query->searchQuery(0, 0, null, false, false, false, true, false); $contactIds = explode(',', $ids); return $contactIds; }
/** * 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; $this->_formValues = $this->controller->exportValues($this->_name); $this->fixFormValues(); // We don't show test records in summaries or dashboards if (empty($this->_formValues['member_test']) && $this->_force) { $this->_formValues["member_test"] = 0; } 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) { // 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_Member_Selector_Search($this->_queryParams, $this->_action, NULL, $this->_single, $this->_limit, $this->_context); $selector->setKey($this->controller->_key); $prefix = NULL; if ($this->_context == 'basic') { $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(); $controller->run(); }
/** * given a saved search compute the clause and the tables * and store it for future use */ function buildClause() { $fv = unserialize($this->form_values); if ($this->mapping_id) { require_once 'CRM/Core/BAO/Mapping.php'; $params = CRM_Core_BAO_Mapping::formattedFields($fv); } else { require_once 'CRM/Contact/BAO/Query.php'; $params = CRM_Contact_BAO_Query::convertFormValues($fv); } if (!empty($params)) { $tables = $whereTables = array(); $this->where_clause = CRM_Contact_BAO_Query::getWhereClause($params, null, $tables, $whereTables); if (!empty($tables)) { $this->select_tables = serialize($tables); } if (!empty($whereTables)) { $this->where_tables = serialize($whereTables); } } return; }
/** * 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 */ public function postProcess() { if ($this->_done) { return; } $this->_done = TRUE; if (!empty($_POST)) { $this->_formValues = $this->controller->exportValues($this->_name); CRM_Contact_BAO_Query::processSpecialFormValue($this->_formValues, array('participant_status_id')); } if (empty($this->_formValues)) { $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); } // We don't show test records in summaries or dashboards if (empty($this->_formValues['participant_test']) && $this->_force) { $this->_formValues["participant_test"] = 0; } CRM_Core_BAO_CustomValue::fixCustomFieldValue($this->_formValues); $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 0, FALSE, NULL, array('event_id')); $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, 0, FALSE, NULL, array('event_id')); $selector = new CRM_Event_Selector_Search($this->_queryParams, $this->_action, NULL, $this->_single, $this->_limit, $this->_context); $selector->setKey($this->controller->_key); $prefix = NULL; if ($this->_context == 'user') { $prefix = $this->_prefix; } $this->assign("{$prefix}limit", $this->_limit); $this->assign("{$prefix}single", $this->_single); $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(); }
/** * Retrieve a set of pledges, given a set of input params * * @param array $params (reference ) input parameters. Use interogate for possible fields * * @return array (reference ) array of pledges, if error an array with an error id and error message * {@getfields pledge_get} * @example PledgeGet.php * @access public */ function civicrm_api3_pledge_get($params) { $options = _civicrm_api3_get_options_from_params($params, TRUE, 'pledge', 'get'); if (empty($options['return'])) { $options['return'] = CRM_Pledge_BAO_Query::defaultReturnProperties(CRM_Contact_BAO_Query::MODE_PLEDGE); } else { $options['return']['pledge_id'] = 1; } $newParams = CRM_Contact_BAO_Query::convertFormValues($options['input_params']); $query = new CRM_Contact_BAO_Query($newParams, $options['return'], NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_PLEDGE); list($select, $from, $where) = $query->query(); $sql = "{$select} {$from} {$where}"; if (!empty($options['sort'])) { $sql .= " ORDER BY " . $options['sort']; } $sql .= " LIMIT " . $options['offset'] . " , " . $options['limit']; $dao = CRM_Core_DAO::executeQuery($sql); $pledge = array(); while ($dao->fetch()) { $pledge[$dao->pledge_id] = $query->store($dao); } return civicrm_api3_create_success($pledge, $params, 'pledge', 'get', $dao); }
public function voterList() { //get the search criteria params. $searchCriteria = CRM_Utils_Request::retrieve('searchCriteria', 'String', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'POST'); $searchParams = explode(',', $searchCriteria); $params = $searchRows = array(); foreach ($searchParams as $param) { if (!empty($_POST[$param])) { $params[$param] = $_POST[$param]; } } //format multi-select group and contact types. foreach (array('group', 'contact_type') as $param) { $paramValue = CRM_Utils_Array::value($param, $params); if ($paramValue) { unset($params[$param]); $paramValue = explode(',', $paramValue); foreach ($paramValue as $key => $value) { $params[$param][$value] = 1; } } } $voterClauseParams = array(); foreach (array('campaign_survey_id', 'survey_interviewer_id', 'campaign_search_voter_for') as $fld) { $voterClauseParams[$fld] = CRM_Utils_Array::value($fld, $params); } $interviewerId = $surveyTypeId = $surveyId = NULL; $searchVoterFor = $params['campaign_search_voter_for']; if ($searchVoterFor == 'reserve') { if (!empty($params['campaign_survey_id'])) { $survey = new CRM_Campaign_DAO_Survey(); $survey->id = $surveyId = $params['campaign_survey_id']; $survey->selectAdd('campaign_id, activity_type_id'); $survey->find(TRUE); $campaignId = $survey->campaign_id; $surveyTypeId = $survey->activity_type_id; //allow voter search in sub-part of given constituents, //but make sure in case user does not select any group. //get all associated campaign groups in where filter, CRM-7406 $groups = CRM_Utils_Array::value('group', $params); if ($campaignId && CRM_Utils_System::isNull($groups)) { $campaignGroups = CRM_Campaign_BAO_Campaign::getCampaignGroups($campaignId); foreach ($campaignGroups as $id => $group) { $params['group'][$id] = 1; } } //apply filter of survey contact type for search. $contactType = CRM_Campaign_BAO_Survey::getSurveyContactType($surveyId); if ($contactType) { $params['contact_type'][$contactType] = 1; } unset($params['campaign_survey_id']); } unset($params['survey_interviewer_id']); } else { //get the survey status in where clause. $scheduledStatusId = array_search('Scheduled', CRM_Core_PseudoConstant::activityStatus('name')); if ($scheduledStatusId) { $params['survey_status_id'] = $scheduledStatusId; } //BAO/Query knows reserve/release/interview processes. if ($params['campaign_search_voter_for'] == 'gotv') { $params['campaign_search_voter_for'] = 'release'; } } $selectorCols = array('sort_name', 'street_address', 'street_name', 'street_number', 'street_unit'); // get the data table params. $dataTableParams = array('sEcho' => array('name' => 'sEcho', 'type' => 'Integer', 'default' => 0), 'offset' => array('name' => 'iDisplayStart', 'type' => 'Integer', 'default' => 0), 'rowCount' => array('name' => 'iDisplayLength', 'type' => 'Integer', 'default' => 25), 'sort' => array('name' => 'iSortCol_0', 'type' => 'Integer', 'default' => 'sort_name'), 'sortOrder' => array('name' => 'sSortDir_0', 'type' => 'String', 'default' => 'asc')); foreach ($dataTableParams as $pName => $pValues) { ${$pName} = $pValues['default']; if (!empty($_POST[$pValues['name']])) { ${$pName} = CRM_Utils_Type::escape($_POST[$pValues['name']], $pValues['type']); if ($pName == 'sort') { ${$pName} = $selectorCols[${$pName}]; } } } $queryParams = CRM_Contact_BAO_Query::convertFormValues($params); $query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_CAMPAIGN, TRUE); //get the voter clause to restrict and validate search. $voterClause = CRM_Campaign_BAO_Query::voterClause($voterClauseParams); $searchCount = $query->searchQuery(0, 0, NULL, TRUE, FALSE, FALSE, FALSE, FALSE, CRM_Utils_Array::value('whereClause', $voterClause), NULL, CRM_Utils_Array::value('fromClause', $voterClause)); $iTotal = $searchCount; $selectorCols = array('contact_type', 'sort_name', 'street_address', 'street_name', 'street_number', 'street_unit'); $extraVoterColName = 'is_interview_conducted'; if ($params['campaign_search_voter_for'] == 'reserve') { $extraVoterColName = 'reserve_voter'; } if ($searchCount > 0) { if ($searchCount < $offset) { $offset = 0; } $config = CRM_Core_Config::singleton(); // get the result of the search $result = $query->searchQuery($offset, $rowCount, $sort, FALSE, FALSE, FALSE, FALSE, FALSE, CRM_Utils_Array::value('whereClause', $voterClause), $sortOrder, CRM_Utils_Array::value('fromClause', $voterClause)); while ($result->fetch()) { $contactID = $result->contact_id; $typeImage = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, FALSE, $result->contact_id); $searchRows[$contactID] = array('id' => $contactID); foreach ($selectorCols as $col) { $val = $result->{$col}; if ($col == 'contact_type') { $val = $typeImage; } $searchRows[$contactID][$col] = $val; } if ($searchVoterFor == 'reserve') { $voterExtraColHtml = '<input type="checkbox" id="survey_activity[' . $contactID . ']" name="survey_activity[' . $contactID . ']" value=' . $contactID . ' onClick="processVoterData( this, \'reserve\' );" />'; $msg = ts('Respondent Reserved.'); $voterExtraColHtml .= " <span id='success_msg_{$contactID}' class='ok' style='display:none;'>{$msg}</span>"; } elseif ($searchVoterFor == 'gotv') { $surveyActId = $result->survey_activity_id; $voterExtraColHtml = '<input type="checkbox" id="survey_activity[' . $surveyActId . ']" name="survey_activity[' . $surveyActId . ']" value=' . $surveyActId . ' onClick="processVoterData( this, \'gotv\' );" />'; $msg = ts('Vote Recorded.'); $voterExtraColHtml .= " <span id='success_msg_{$surveyActId}' class='ok' style='display:none;'>{$msg}</span>"; } else { $surveyActId = $result->survey_activity_id; $voterExtraColHtml = '<input type="checkbox" id="survey_activity[' . $surveyActId . ']" name="survey_activity[' . $surveyActId . ']" value=' . $surveyActId . ' onClick="processVoterData( this, \'release\' );" />'; $msg = ts('Vote Recorded.'); $voterExtraColHtml .= " <span id='success_msg_{$surveyActId}' class='ok' style='display:none;'>{$msg}</span>"; } $searchRows[$contactID][$extraVoterColName] = $voterExtraColHtml; } } $selectorElements = array_merge($selectorCols, array($extraVoterColName)); $iFilteredTotal = $iTotal; CRM_Utils_System::setHttpHeader('Content-Type', 'application/json'); echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); CRM_Utils_System::civiExit(); }
/** * this method is called for processing a submitted search form * * @return void * @access public */ function postProcess() { $session =& CRM_Core_Session::singleton(); $session->set('isAdvanced', '0'); $session->set('isSearchBuilder', '0'); // 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(); } if (isset($this->_groupID) && !CRM_Utils_Array::value('group', $this->_formValues)) { $this->_formValues['group'][$this->_groupID] = 1; } else { 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); //fix for CRM-1505 if (CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID, 'mapping_id')) { $this->_params =& CRM_Contact_BAO_SavedSearch::getSearchParams($this->_ssID); } } } // we dont want to store the sortByCharacter in the formValue, it is more like // a filter on the result set // this filter is reset if we click on the search button if ($this->_sortByCharacter && empty($_POST)) { if ($this->_sortByCharacter == 1) { $this->_formValues['sortByCharacter'] = null; } else { $this->_formValues['sortByCharacter'] = $this->_sortByCharacter; } } $this->_params =& CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $this->_returnProperties =& $this->returnProperties(); // CRM_Core_Error::debug( 'f', $this->_formValues ); // CRM_Core_Error::debug( 'p', $this->_params ); parent::postProcess(); }
/** * Returns the number of Contact objects which match the search criteria specified in $params. * * @deprecated deprecated since version 2.2.3; civicrm_contact_get now returns a record_count value * * @param array $params * * @return int * @access public */ function civicrm_contact_search_count(&$params) { // convert the params to new format require_once 'CRM/Contact/Form/Search.php'; $newP = CRM_Contact_BAO_Query::convertFormValues($params); $query = new CRM_Contact_BAO_Query($newP); return $query->searchQuery(0, 0, NULL, TRUE); }
/** * Get dao query object based on input params. * * Ideally this would be merged with _civicrm_get_using_query_object but we need to resolve differences in what the * 2 variants call * * @param array $params * @param string $mode * @param string $entity * * @return array * [CRM_Core_DAO|CRM_Contact_BAO_Query] */ function _civicrm_api3_get_query_object($params, $mode, $entity) { $options = _civicrm_api3_get_options_from_params($params, TRUE, $entity, 'get'); $sort = CRM_Utils_Array::value('sort', $options, NULL); $offset = CRM_Utils_Array::value('offset', $options); $rowCount = CRM_Utils_Array::value('limit', $options); $inputParams = CRM_Utils_Array::value('input_params', $options, array()); $returnProperties = CRM_Utils_Array::value('return', $options, NULL); if (empty($returnProperties)) { $returnProperties = CRM_Contribute_BAO_Query::defaultReturnProperties($mode); } $newParams = CRM_Contact_BAO_Query::convertFormValues($inputParams, 0, FALSE, $entity); $query = new CRM_Contact_BAO_Query($newParams, $returnProperties, NULL, FALSE, FALSE, $mode, empty($params['check_permissions'])); list($select, $from, $where, $having) = $query->query(); $sql = "{$select} {$from} {$where} {$having}"; if (!empty($sort)) { $sql .= " ORDER BY {$sort} "; } if (!empty($rowCount)) { $sql .= " LIMIT {$offset}, {$rowCount} "; } $dao = CRM_Core_DAO::executeQuery($sql); return array($dao, $query); }
/** * Test filtering by relative custom data dates. */ public function testSearchCustomDataDateEquals() { $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, 'ContactTestTest'); $dateCustomField = $this->customFieldCreate(array('custom_group_id' => $ids['custom_group_id'], 'label' => 'date field', 'data_type' => 'Date', 'html_type' => 'Select Date', 'default_value' => NULL)); $dateCustomFieldName = 'custom_' . $dateCustomField['id']; $this->individualCreate(array($dateCustomFieldName => "2015-01-01")); // Assigning the relevant form value to be within a custom key is normally done in // build field params. It would be better if it were all done in convertFormValues // but for now we just imitate it. $formValues = array($dateCustomFieldName => '2015-06-06'); $params[$dateCustomField['id']] = CRM_Contact_BAO_Query::convertFormValues($formValues); $queryObj = new CRM_Core_BAO_CustomQuery($params); $queryObj->Query(); $this->assertEquals("civicrm_value_testsearchcus_1.date_field_2 = '2015-06-06'", $queryObj->_where[0][0]); $this->assertEquals($queryObj->_qill[0][0], "date field = 'June 6th, 2015'"); }
/** * 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); } if (empty($this->_formValues)) { $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); } // we don't show test registrations in Contact Summary / User Dashboard // in Search mode by default we hide test registrations if (!CRM_Utils_Array::value('participant_test', $this->_formValues)) { $this->_formValues["participant_test"] = 0; } require_once 'CRM/Core/BAO/CustomValue.php'; CRM_Core_BAO_CustomValue::fixFieldValueOfTypeMemo($this->_formValues); require_once 'CRM/Contact/BAO/Query.php'; $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)); } require_once 'CRM/Contact/BAO/Query.php'; $this->_queryParams =& CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $selector =& new CRM_Event_Selector_Search($this->_queryParams, $this->_action, null, $this->_single, $this->_limit, $this->_context); $prefix = null; if ($this->_context == 'user') { $prefix = $this->_prefix; } $this->assign("{$prefix}limit", $this->_limit); $this->assign("{$prefix}single", $this->_single); $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. */ public function postProcess() { if ($this->_done) { return; } $this->_done = TRUE; $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); } //search for civicase if (!$this->_force) { if (array_key_exists('case_owner', $this->_formValues) && !$this->_formValues['case_owner']) { $this->_formValues['case_owner'] = 0; } } if (empty($this->_formValues['case_deleted'])) { $this->_formValues['case_deleted'] = 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_Case_Selector_Search($this->_queryParams, $this->_action, NULL, $this->_single, $this->_limit, $this->_context); $selector->setKey($this->controller->_key); $prefix = NULL; if ($this->_context == 'user') { $prefix = $this->_prefix; } $this->assign("{$prefix}limit", $this->_limit); $this->assign("{$prefix}single", $this->_single); $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(); }
/** * Class constructor * * @param string params the params for the where clause * * @return CRM_Contact_Selector_Profile * @access public */ function __construct(&$params, &$customFields, $ufGroupIds = NULL, $map = FALSE, $editLink = FALSE, $linkToUF = FALSE) { $this->_params = $params; if (is_array($ufGroupIds)) { $this->_profileIds = $ufGroupIds; $this->_gid = $ufGroupIds[0]; } else { $this->_profileIds = array($ufGroupIds); $this->_gid = $ufGroupIds; } $this->_map = $map; $this->_editLink = $editLink; $this->_linkToUF = $linkToUF; //get the details of the uf group if ($this->_gid) { $groupId = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_UFGroup', $this->_gid, 'limit_listings_group_id'); } // add group id to params if a uf group belong to a any group if ($groupId) { if (!empty($this->_params['group'])) { $this->_params['group'][$groupId] = 1; } else { $this->_params['group'] = array($groupId => 1); } } $this->_fields = CRM_Core_BAO_UFGroup::getListingFields(CRM_Core_Action::VIEW, CRM_Core_BAO_UFGroup::PUBLIC_VISIBILITY | CRM_Core_BAO_UFGroup::LISTINGS_VISIBILITY, FALSE, $this->_profileIds); $this->_customFields =& $customFields; $returnProperties = CRM_Contact_BAO_Contact::makeHierReturnProperties($this->_fields); $returnProperties['contact_type'] = 1; $returnProperties['contact_sub_type'] = 1; $returnProperties['sort_name'] = 1; $queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_params, 1); $this->_query = new CRM_Contact_BAO_Query($queryParams, $returnProperties, $this->_fields); //the below is done for query building for multirecord custom field listing //to show all the custom field multi valued records of a particular contact $this->setMultiRecordTableName($this->_fields); $this->_options =& $this->_query->_options; }
/** * 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; $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); } require_once 'CRM/Contact/BAO/Query.php'; $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)); } require_once 'CRM/Contact/BAO/Query.php'; $selector =& new CRM_Grant_Selector_Search($this->_queryParams, $this->_action, null, $this->_single, $this->_limit, $this->_context); $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 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() { if ($this->_done) { return; } $this->_done = TRUE; if (!empty($_POST)) { $this->_formValues = $this->controller->exportValues($this->_name); } $this->fixFormValues(); // We don't show test records in summaries or dashboards if (empty($this->_formValues['contribution_test']) && $this->_force && !empty($this->_context) && $this->_context == 'dashboard') { $this->_formValues["contribution_test"] = 0; } foreach (array('contribution_amount_low', 'contribution_amount_high') as $f) { if (isset($this->_formValues[$f])) { $this->_formValues[$f] = CRM_Utils_Rule::cleanMoney($this->_formValues[$f]); } } $config = CRM_Core_Config::singleton(); if (!empty($_POST)) { $specialParams = array('financial_type_id', 'contribution_soft_credit_type_id', 'contribution_status_id', 'contribution_source', 'contribution_trxn_id', 'contribution_page_id', 'contribution_product_id'); foreach ($specialParams as $element) { $value = CRM_Utils_Array::value($element, $this->_formValues); if ($value) { if (is_array($value)) { $this->_formValues[$element] = array('IN' => $value); } else { $this->_formValues[$element] = array('LIKE' => "%{$value}%"); } } } $tags = CRM_Utils_Array::value('contact_tags', $this->_formValues); if ($tags && !is_array($tags)) { unset($this->_formValues['contact_tags']); $this->_formValues['contact_tags'][$tags] = 1; } if ($tags && is_array($tags)) { unset($this->_formValues['contact_tags']); foreach ($tags as $notImportant => $tagID) { $this->_formValues['contact_tags'][$tagID] = 1; } } if (!$config->groupTree) { $group = CRM_Utils_Array::value('group', $this->_formValues); if ($group && !is_array($group)) { unset($this->_formValues['group']); $this->_formValues['group'][$group] = 1; } if ($group && is_array($group)) { unset($this->_formValues['group']); foreach ($group as $notImportant => $groupID) { $this->_formValues['group'][$groupID] = 1; } } } } 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) { // 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_Contribute_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); } $summary =& $query->summaryContribution($this->_context); $this->set('summary', $summary); $this->assign('contributionSummary', $summary); $controller->run(); }
/** * Processing needed for buildForm and later. */ public function preProcess() { // set the various class variables $this->_group = CRM_Core_PseudoConstant::group(); $this->_groupIterator = CRM_Core_PseudoConstant::groupIterator(); $this->_tag = CRM_Core_BAO_Tag::getTags(); $this->_done = FALSE; /* * we allow the controller to set force/reset externally, useful when we are being * driven by the wizard framework */ $this->_reset = CRM_Utils_Request::retrieve('reset', 'Boolean', CRM_Core_DAO::$_nullObject); $this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', CRM_Core_DAO::$_nullObject); $this->_groupID = CRM_Utils_Request::retrieve('gid', 'Positive', $this); $this->_amtgID = CRM_Utils_Request::retrieve('amtgID', 'Positive', $this); $this->_ssID = CRM_Utils_Request::retrieve('ssID', 'Positive', $this); $this->_sortByCharacter = CRM_Utils_Request::retrieve('sortByCharacter', 'String', $this); $this->_ufGroupID = CRM_Utils_Request::retrieve('id', 'Positive', $this); $this->_componentMode = CRM_Utils_Request::retrieve('component_mode', 'Positive', $this, FALSE, 1, $_REQUEST); $this->_operator = CRM_Utils_Request::retrieve('operator', 'String', $this, FALSE, 1, $_REQUEST, 'AND'); /** * set the button names */ $this->_searchButtonName = $this->getButtonName('refresh'); $this->_actionButtonName = $this->getButtonName('next', 'action'); $this->assign('actionButtonName', $this->_actionButtonName); // reset from session, CRM-3526 $session = CRM_Core_Session::singleton(); if ($this->_force && $session->get('selectedSearchContactIds')) { $session->resetScope('selectedSearchContactIds'); } // if we dont get this from the url, use default if one exsts $config = CRM_Core_Config::singleton(); if ($this->_ufGroupID == NULL && $config->defaultSearchProfileID != NULL) { $this->_ufGroupID = $config->defaultSearchProfileID; } // assign context to drive the template display, make sure context is valid $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'search'); if (!CRM_Utils_Array::value($this->_context, self::validContext())) { $this->_context = 'search'; } $this->set('context', $this->_context); $this->assign('context', $this->_context); $this->_modeValue = self::getModeValue($this->_componentMode); $this->assign($this->_modeValue); $this->set('selectorName', self::$_selectorName); // get user submitted values // get it from controller only if form has been submitted, else preProcess has set this // $this->controller->isModal( ) returns TRUE if page is // valid, i.e all the validations are TRUE if (!empty($_POST) && !$this->controller->isModal()) { $this->_formValues = $this->controller->exportValues($this->_name); $this->normalizeFormValues(); $this->_params = CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $this->_returnProperties =& $this->returnProperties(); // also get the uf group id directly from the post value $this->_ufGroupID = CRM_Utils_Array::value('uf_group_id', $_POST, $this->_ufGroupID); $this->_formValues['uf_group_id'] = $this->_ufGroupID; $this->set('id', $this->_ufGroupID); // also get the object mode directly from the post value $this->_componentMode = CRM_Utils_Array::value('component_mode', $_POST, $this->_componentMode); // also get the operator from the post value if set $this->_operator = CRM_Utils_Array::value('operator', $_POST, $this->_operator); $this->_formValues['operator'] = $this->_operator; $this->set('operator', $this->_operator); } else { $this->_formValues = $this->get('formValues'); $this->_params = CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $this->_returnProperties =& $this->returnProperties(); if (!empty($this->_ufGroupID)) { $this->set('id', $this->_ufGroupID); } } if (empty($this->_formValues)) { //check if group is a smart group (fix for CRM-1255) if ($this->_groupID) { if ($ssId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID, 'saved_search_id')) { $this->_ssID = $ssId; } } // fix for CRM-1907 if (isset($this->_ssID) && $this->_context != 'smog') { // we only retrieve the saved search values if out current values are null $this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID); //fix for CRM-1505 if (CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID, 'mapping_id')) { $this->_params = CRM_Contact_BAO_SavedSearch::getSearchParams($this->_ssID); } else { $this->_params = CRM_Contact_BAO_Query::convertFormValues($this->_formValues); } $this->_returnProperties =& $this->returnProperties(); } else { if (isset($this->_ufGroupID)) { // also set the uf group id if not already present $this->_formValues['uf_group_id'] = $this->_ufGroupID; } if (isset($this->_componentMode)) { $this->_formValues['component_mode'] = $this->_componentMode; } if (isset($this->_operator)) { $this->_formValues['operator'] = $this->_operator; } // FIXME: we should generalise in a way that components could inject url-filters // just like they build their own form elements foreach (array('mailing_id', 'mailing_delivery_status', 'mailing_open_status', 'mailing_click_status', 'mailing_reply_status', 'mailing_optout', 'mailing_forward', 'mailing_unsubscribe', 'mailing_date_low', 'mailing_date_high') as $mailingFilter) { $type = 'String'; if ($mailingFilter == 'mailing_id' && ($filterVal = CRM_Utils_Request::retrieve('mailing_id', 'Positive', $this))) { $this->_formValues[$mailingFilter] = array($filterVal); } elseif ($filterVal = CRM_Utils_Request::retrieve($mailingFilter, $type, $this)) { $this->_formValues[$mailingFilter] = $filterVal; } if ($filterVal) { $this->_openedPanes['Mailings'] = 1; $this->_formValues['hidden_CiviMail'] = 1; } } } } $this->assign('id', CRM_Utils_Array::value('uf_group_id', $this->_formValues)); $operator = CRM_Utils_Array::value('operator', $this->_formValues, 'AND'); $this->set('queryOperator', $operator); if ($operator == 'OR') { $this->assign('operator', ts('OR')); } else { $this->assign('operator', ts('AND')); } // show the context menu only when we’re not searching for deleted contacts; CRM-5673 if (empty($this->_formValues['deleted_contacts'])) { $menuItems = CRM_Contact_BAO_Contact::contextMenu(); $primaryActions = CRM_Utils_Array::value('primaryActions', $menuItems, array()); $this->_contextMenu = CRM_Utils_Array::value('moreActions', $menuItems, array()); $this->assign('contextMenu', $primaryActions + $this->_contextMenu); } if (!isset($this->_componentMode)) { $this->_componentMode = CRM_Contact_BAO_Query::MODE_CONTACTS; } $modeValues = self::getModeValue($this->_componentMode); self::$_selectorName = $this->_modeValue['selectorName']; $setDynamic = FALSE; if (strpos(self::$_selectorName, 'CRM_Contact_Selector') !== FALSE) { $selector = new self::$_selectorName($this->_customSearchClass, $this->_formValues, $this->_params, $this->_returnProperties, $this->_action, FALSE, TRUE, $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); $controller = new CRM_Contact_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), $this->get(CRM_Utils_Sort::SORT_ID), CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::TRANSFER); $controller->setEmbedded(TRUE); $controller->setDynamicAction($setDynamic); if ($this->_force) { $this->postProcess(); /* * Note that we repeat this, since the search creates and stores * values that potentially change the controller behavior. i.e. things * like totalCount etc */ $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_Contact_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), $sortID, CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::TRANSFER); $controller->setEmbedded(TRUE); $controller->setDynamicAction($setDynamic); } $controller->moveFromSessionToTemplate(); }
/** * 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(); }
/** * Retrieve financial items assigned for a batch. * * @param int $entityID * @param array $returnValues * @param bool $notPresent * @param array $params * @param bool $getCount * * @return CRM_Core_DAO */ public static function getBatchFinancialItems($entityID, $returnValues, $notPresent = NULL, $params = NULL, $getCount = FALSE) { if (!$getCount) { if (!empty($params['rowCount']) && $params['rowCount'] > 0) { $limit = " LIMIT {$params['offset']}, {$params['rowCount']} "; } } // action is taken depending upon the mode $select = 'civicrm_financial_trxn.id '; if (!empty($returnValues)) { $select .= " , " . implode(' , ', $returnValues); } $orderBy = " ORDER BY civicrm_financial_trxn.id"; if (!empty($params['sort'])) { $orderBy = ' ORDER BY ' . CRM_Utils_Type::escape($params['sort'], 'String'); } $from = "civicrm_financial_trxn\nLEFT JOIN civicrm_entity_financial_trxn ON civicrm_entity_financial_trxn.financial_trxn_id = civicrm_financial_trxn.id\nLEFT JOIN civicrm_entity_batch ON civicrm_entity_batch.entity_table = 'civicrm_financial_trxn'\nAND civicrm_entity_batch.entity_id = civicrm_financial_trxn.id\nLEFT JOIN civicrm_contribution ON civicrm_contribution.id = civicrm_entity_financial_trxn.entity_id\nLEFT JOIN civicrm_financial_type ON civicrm_financial_type.id = civicrm_contribution.financial_type_id\nLEFT JOIN civicrm_contact contact_a ON contact_a.id = civicrm_contribution.contact_id\nLEFT JOIN civicrm_contribution_soft ON civicrm_contribution_soft.contribution_id = civicrm_contribution.id\n"; $searchFields = array('sort_name', 'financial_type_id', 'contribution_page_id', 'payment_instrument_id', 'contribution_trxn_id', 'contribution_source', 'contribution_currency_type', 'contribution_pay_later', 'contribution_recurring', 'contribution_test', 'contribution_thankyou_date_is_not_null', 'contribution_receipt_date_is_not_null', 'contribution_pcp_made_through_id', 'contribution_pcp_display_in_roll', 'contribution_date_relative', 'contribution_amount_low', 'contribution_amount_high', 'contribution_in_honor_of', 'contact_tags', 'group', 'contribution_date_relative', 'contribution_date_high', 'contribution_date_low', 'contribution_check_number', 'contribution_status_id'); $values = array(); foreach ($searchFields as $field) { if (isset($params[$field])) { $values[$field] = $params[$field]; if ($field == 'sort_name') { $from .= " LEFT JOIN civicrm_contact contact_b ON contact_b.id = civicrm_contribution.contact_id\n LEFT JOIN civicrm_email ON contact_b.id = civicrm_email.contact_id"; } if ($field == 'contribution_in_honor_of') { $from .= " LEFT JOIN civicrm_contact contact_b ON contact_b.id = civicrm_contribution.contact_id"; } if ($field == 'contact_tags') { $from .= " LEFT JOIN civicrm_entity_tag `civicrm_entity_tag-{$params[$field]}` ON `civicrm_entity_tag-{$params[$field]}`.entity_id = contact_a.id"; } if ($field == 'group') { $from .= " LEFT JOIN civicrm_group_contact `civicrm_group_contact-{$params[$field]}` ON contact_a.id = `civicrm_group_contact-{$params[$field]}`.contact_id "; } if ($field == 'contribution_date_relative') { $relativeDate = explode('.', $params[$field]); $date = CRM_Utils_Date::relativeToAbsolute($relativeDate[0], $relativeDate[1]); $values['contribution_date_low'] = $date['from']; $values['contribution_date_high'] = $date['to']; } $searchParams = CRM_Contact_BAO_Query::convertFormValues($values); $query = new CRM_Contact_BAO_Query($searchParams, CRM_Contribute_BAO_Query::defaultReturnProperties(CRM_Contact_BAO_Query::MODE_CONTRIBUTE, FALSE), NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_CONTRIBUTE); if ($field == 'contribution_date_high' || $field == 'contribution_date_low') { $query->dateQueryBuilder($params[$field], 'civicrm_contribution', 'contribution_date', 'receive_date', 'Contribution Date'); } } } if (!empty($query->_where[0])) { $where = implode(' AND ', $query->_where[0]) . " AND civicrm_entity_batch.batch_id IS NULL\n AND civicrm_entity_financial_trxn.entity_table = 'civicrm_contribution'"; $where = str_replace('civicrm_contribution.payment_instrument_id', 'civicrm_financial_trxn.payment_instrument_id', $where); $searchValue = TRUE; } else { $searchValue = FALSE; } if (!$searchValue) { if (!$notPresent) { $where = " ( civicrm_entity_batch.batch_id = {$entityID}\n AND civicrm_entity_batch.entity_table = 'civicrm_financial_trxn'\n AND civicrm_entity_financial_trxn.entity_table = 'civicrm_contribution') "; } else { $where = " ( civicrm_entity_batch.batch_id IS NULL\n AND civicrm_entity_financial_trxn.entity_table = 'civicrm_contribution')"; } } $sql = "\nSELECT {$select}\nFROM {$from}\nWHERE {$where}\n {$orderBy}\n"; if (isset($limit)) { $sql .= "{$limit}"; } $result = CRM_Core_DAO::executeQuery($sql); return $result; }
/** * 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(); // we don't show test contributions in Contact Summary / User Dashboard // in Search mode by default we hide test contributions if (!CRM_Utils_Array::value('contribution_test', $this->_formValues)) { $this->_formValues["contribution_test"] = 0; } foreach (array('contribution_amount_low', 'contribution_amount_high') as $f) { if (isset($this->_formValues[$f])) { $this->_formValues[$f] = CRM_Utils_Rule::cleanMoney($this->_formValues[$f]); } } require_once 'CRM/Core/BAO/CustomValue.php'; CRM_Core_BAO_CustomValue::fixFieldValueOfTypeMemo($this->_formValues); require_once 'CRM/Contact/BAO/Query.php'; $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)); } require_once 'CRM/Contact/BAO/Query.php'; $this->_queryParams =& CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $selector =& new CRM_Contribute_Selector_Search($this->_queryParams, $this->_action, null, $this->_single, $this->_limit, $this->_context); $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); } $summary =& $query->summaryContribution(); $this->set('summary', $summary); $this->assign('contributionSummary', $summary); $controller->run(); }