本文整理汇总了PHP中CRM_Contact_BAO_SavedSearch::getFormValues方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contact_BAO_SavedSearch::getFormValues方法的具体用法?PHP CRM_Contact_BAO_SavedSearch::getFormValues怎么用?PHP CRM_Contact_BAO_SavedSearch::getFormValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Contact_BAO_SavedSearch
的用法示例。
在下文中一共展示了CRM_Contact_BAO_SavedSearch::getFormValues方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: details
static function details($csID, $ssID = null, $gID = null)
{
$error = array(null, null, null);
if (!$csID && !$ssID && !$gID) {
return $error;
}
$customSearchID = $csID;
$formValues = array();
if ($ssID || $gID) {
if ($gID) {
$ssID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $gID, 'saved_search_id');
}
$formValues = CRM_Contact_BAO_SavedSearch::getFormValues($ssID);
$customSearchID = CRM_Utils_Array::value('customSearchID', $formValues);
}
if (!$customSearchID) {
return $error;
}
// check that the csid exists in the db along with the right file
// and implements the right interface
require_once 'CRM/Core/OptionGroup.php';
$customSearchClass = CRM_Core_OptionGroup::getLabel('custom_search', $customSearchID);
if (!$customSearchClass) {
return $error;
}
$customSearchFile = str_replace('_', DIRECTORY_SEPARATOR, $customSearchClass) . '.php';
$error = (include_once $customSearchFile);
if ($error == false) {
CRM_Core_Error::fatal('Custom search file: ' . $customSearchFile . ' does not exist. Please verify your custom search settings in CiviCRM administrative panel.');
}
return array($customSearchID, $customSearchClass, $formValues);
}
示例2: testGetFormValues
/**
* Test fixValues function.
*
* @dataProvider getSavedSearches
*/
public function testGetFormValues($formValues, $expectedResult, $searchDescription)
{
CRM_Core_DAO::executeQuery("INSERT INTO civicrm_saved_search (form_values) VALUES('" . serialize($formValues) . "')");
$result = CRM_Contact_BAO_SavedSearch::getFormValues(CRM_Core_DAO::singleValueQuery('SELECT LAST_INSERT_ID()'));
$this->assertEquals(array('membership_type_id', 'membership_status_id'), array_keys($result));
foreach ($result as $key => $value) {
$this->assertEquals($expectedResult, $value, 'failure on set ' . $searchDescription);
}
}
示例3: details
/**
* @param int $csID
* @param int $ssID
* @param int $gID
*
* @return array
* @throws Exception
*/
public static function details($csID, $ssID = NULL, $gID = NULL)
{
$error = array(NULL, NULL, NULL);
if (!$csID && !$ssID && !$gID) {
return $error;
}
$customSearchID = $csID;
$formValues = array();
if ($ssID || $gID) {
if ($gID) {
$ssID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $gID, 'saved_search_id');
}
$formValues = CRM_Contact_BAO_SavedSearch::getFormValues($ssID);
$customSearchID = CRM_Utils_Array::value('customSearchID', $formValues);
}
if (!$customSearchID) {
return $error;
}
// check that the csid exists in the db along with the right file
// and implements the right interface
$customSearchClass = CRM_Core_OptionGroup::getLabel('custom_search', $customSearchID);
if (!$customSearchClass) {
return $error;
}
$ext = CRM_Extension_System::singleton()->getMapper();
if (!$ext->isExtensionKey($customSearchClass)) {
$customSearchFile = str_replace('_', DIRECTORY_SEPARATOR, $customSearchClass) . '.php';
} else {
$customSearchFile = $ext->keyToPath($customSearchClass);
$customSearchClass = $ext->keyToClass($customSearchClass);
}
$error = (include_once $customSearchFile);
if ($error == FALSE) {
CRM_Core_Error::fatal('Custom search file: ' . $customSearchFile . ' does not exist. Please verify your custom search settings in CiviCRM administrative panel.');
}
return array($customSearchID, $customSearchClass, $formValues);
}
示例4: postProcess
/**
* 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();
}
示例5: load
/**
* Load the smart group cache for a saved search.
*
* @param object $group
* The smart group that needs to be loaded.
* @param bool $force
* Should we force a search through.
*/
public static function load(&$group, $force = FALSE)
{
$groupID = $group->id;
$savedSearchID = $group->saved_search_id;
if (array_key_exists($groupID, self::$_alreadyLoaded) && !$force) {
return;
}
// grab a lock so other processes don't compete and do the same query
$lock = Civi::lockManager()->acquire("data.core.group.{$groupID}");
if (!$lock->isAcquired()) {
// this can cause inconsistent results since we don't know if the other process
// will fill up the cache before our calling routine needs it.
// however this routine does not return the status either, so basically
// its a "lets return and hope for the best"
return;
}
self::$_alreadyLoaded[$groupID] = 1;
// we now have the lock, but some other process could have actually done the work
// before we got here, so before we do any work, lets ensure that work needs to be
// done
// we allow hidden groups here since we dont know if the caller wants to evaluate an
// hidden group
if (!$force && !self::shouldGroupBeRefreshed($groupID, TRUE)) {
$lock->release();
return;
}
$sql = NULL;
$idName = 'id';
$customClass = NULL;
if ($savedSearchID) {
$ssParams = CRM_Contact_BAO_SavedSearch::getSearchParams($savedSearchID);
// rectify params to what proximity search expects if there is a value for prox_distance
// CRM-7021
if (!empty($ssParams)) {
CRM_Contact_BAO_ProximityQuery::fixInputParams($ssParams);
}
$returnProperties = array();
if (CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $savedSearchID, 'mapping_id')) {
$fv = CRM_Contact_BAO_SavedSearch::getFormValues($savedSearchID);
$returnProperties = CRM_Core_BAO_Mapping::returnProperties($fv);
}
if (isset($ssParams['customSearchID'])) {
// if custom search
// we split it up and store custom class
// so temp tables are not destroyed if they are used
// hence customClass is defined above at top of function
$customClass = CRM_Contact_BAO_SearchCustom::customClass($ssParams['customSearchID'], $savedSearchID);
$searchSQL = $customClass->contactIDs();
$searchSQL = str_replace('ORDER BY contact_a.id ASC', '', $searchSQL);
if (!strstr($searchSQL, 'WHERE')) {
$searchSQL .= " WHERE ( 1 ) ";
}
$idName = 'contact_id';
} else {
$formValues = CRM_Contact_BAO_SavedSearch::getFormValues($savedSearchID);
// CRM-17075 using the formValues in this way imposes extra logic and complexity.
// we have the where_clause and where tables stored in the saved_search table
// and should use these rather than re-processing the form criteria (which over-works
// the link between the form layer & the query layer too).
// It's hard to think of when you would want to use anything other than return
// properties = array('contact_id' => 1) here as the point would appear to be to
// generate the list of contact ids in the group.
// @todo review this to use values in saved_search table (preferably for 4.8).
$query = new CRM_Contact_BAO_Query($ssParams, $returnProperties, NULL, FALSE, FALSE, 1, TRUE, TRUE, FALSE, CRM_Utils_Array::value('display_relationship_type', $formValues), CRM_Utils_Array::value('operator', $formValues, 'AND'));
$query->_useDistinct = FALSE;
$query->_useGroupBy = FALSE;
$searchSQL = $query->searchQuery(0, 0, NULL, FALSE, FALSE, FALSE, TRUE, TRUE, NULL, NULL, NULL, TRUE);
}
$groupID = CRM_Utils_Type::escape($groupID, 'Integer');
$sql = $searchSQL . " AND contact_a.id NOT IN (\n SELECT contact_id FROM civicrm_group_contact\n WHERE civicrm_group_contact.status = 'Removed'\n AND civicrm_group_contact.group_id = {$groupID} ) ";
}
if ($sql) {
$sql = preg_replace("/^\\s*SELECT/", "SELECT {$groupID} as group_id, ", $sql);
}
// lets also store the records that are explicitly added to the group
// this allows us to skip the group contact LEFT JOIN
$sqlB = "\nSELECT {$groupID} as group_id, contact_id as {$idName}\nFROM civicrm_group_contact\nWHERE civicrm_group_contact.status = 'Added'\n AND civicrm_group_contact.group_id = {$groupID} ";
$groupIDs = array($groupID);
self::remove($groupIDs);
$processed = FALSE;
$tempTable = 'civicrm_temp_group_contact_cache' . rand(0, 2000);
foreach (array($sql, $sqlB) as $selectSql) {
if (!$selectSql) {
continue;
}
$insertSql = "CREATE TEMPORARY TABLE {$tempTable} ({$selectSql});";
$processed = TRUE;
CRM_Core_DAO::executeQuery($insertSql);
CRM_Core_DAO::executeQuery("INSERT IGNORE INTO civicrm_group_contact_cache (contact_id, group_id)\n SELECT DISTINCT {$idName}, group_id FROM {$tempTable}\n ");
CRM_Core_DAO::executeQuery(" DROP TEMPORARY TABLE {$tempTable}");
}
self::updateCacheTime($groupIDs, $processed);
//.........这里部分代码省略.........
示例6: postProcess
/**
* 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();
}
示例7: postProcess
/**
* 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();
}
示例8: postProcess
/**
* 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();
}
示例9: testSavedSearch
/**
* Test CRM_Contact_Form_Search_Custom_Sample with saved_search_id
* With true argument it returns list of contact IDs
*/
public function testSavedSearch()
{
$this->quickCleanup($this->_tablesToTruncate);
$op = new PHPUnit_Extensions_Database_Operation_Insert();
$op->execute($this->_dbconn, $this->createFlatXMLDataSet(dirname(__FILE__) . '/datasets/sample-dataset.xml'));
$dataset[1] = array('id' => array(12));
$dataset[2] = array('id' => array(10, 11));
$ssdao = CRM_Core_DAO::executeQuery("SELECT * FROM civicrm_saved_search");
while ($ssdao->fetch()) {
$fv = CRM_Contact_BAO_SavedSearch::getFormValues($ssdao->id);
$obj = new CRM_Contact_Form_Search_Custom_Sample($fv);
$sql = $obj->contactIDs();
$this->assertTrue(is_string($sql));
$dao = CRM_Core_DAO::executeQuery($sql);
$contacts = array();
while ($dao->fetch()) {
$contacts[] = $dao->contact_id;
}
sort($contacts, SORT_NUMERIC);
$this->assertEquals($dataset[$ssdao->id]['id'], $contacts);
}
}
示例10: postProcess
/**
* 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()
{
$session =& CRM_Core_Session::singleton();
$session->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);
// 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]);
}
}
//assigning event values for autocomplete event selection
$eventSearchIds = array('event_id' => 'event_name_id', 'event_type' => 'event_type_id', 'participant_fee_level' => 'participant_fee_id');
foreach ($eventSearchIds as $key => $value) {
$this->_formValues[$key] = empty($this->_formValues[$key]) ? '' : $this->_formValues[$value];
$this->_formValues[$value] = '';
}
// set the group if group is submitted
if ($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)) {
if (array_key_exists('case_owner', $this->_formValues) && !$this->_formValues['case_owner'] && !$this->_force) {
$this->_formValues['case_owner'] = 0;
} else {
if (array_key_exists('case_owner', $this->_formValues)) {
$this->_formValues['case_owner'] = 1;
}
}
}
// 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;
}
}
require_once 'CRM/Core/BAO/CustomValue.php';
CRM_Core_BAO_CustomValue::fixFieldValueOfTypeMemo($this->_formValues);
require_once 'CRM/Contact/BAO/Query.php';
$this->_params =& CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
$this->_returnProperties =& $this->returnProperties();
parent::postProcess();
}
示例11: postProcess
/**
* 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');
// 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_Error::debug( 'fv', $this->_formValues );
// also reset the sort by character
$this->_sortByCharacter = null;
$this->set('sortByCharacter', null);
}
if (isset($this->_groupID) && !CRM_Utils_Array::value('group', $this->_formValues)) {
$this->_formValues['group'][$this->_groupID] = 1;
// add group_contact_status as added if not present
if (!CRM_Utils_Array::value('group_contact_status', $this->_formValues)) {
$this->_formValues['group_contact_status'] = array('Added' => true);
}
} 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);
}
}
$this->postProcessCommon();
}
示例12: normalizeDefaultValues
/**
* Normalize default values for multiselect plugins.
*
* @param array $defaults
*
* @return array
*/
public function normalizeDefaultValues(&$defaults)
{
if (!is_array($defaults)) {
$defaults = array();
}
$this->loadDefaultCountryBasedOnState($defaults);
if ($this->_ssID && empty($_POST)) {
$defaults = array_merge($defaults, CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID));
}
/*
* CRM-18656 - reverse the normalisation of 'contact_taglist' done in
* self::normalizeFormValues(). Remove tagset tags from the default
* 'contact_tags' and put them in 'contact_taglist[N]' where N is the
* id of the tagset.
*/
if (isset($defaults['contact_tags'])) {
foreach ($defaults['contact_tags'] as $key => $tagId) {
if (!is_array($tagId)) {
$parentId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Tag', $tagId, 'parent_id');
$element = "contact_taglist[{$parentId}]";
if ($this->elementExists($element)) {
// This tag is a tagset
unset($defaults['contact_tags'][$key]);
if (!isset($defaults[$element])) {
$defaults[$element] = array();
}
$defaults[$element][] = $tagId;
}
}
}
if (empty($defaults['contact_tags'])) {
unset($defaults['contact_tags']);
}
}
return $defaults;
}
示例13: load
/**
* load the smart group cache for a saved search
*/
static function load(&$group, $fresh = FALSE)
{
$groupID = $group->id;
$savedSearchID = $group->saved_search_id;
if (array_key_exists($groupID, self::$_alreadyLoaded) && !$fresh) {
return;
}
self::$_alreadyLoaded[$groupID] = 1;
$sql = NULL;
$idName = 'id';
$customClass = NULL;
if ($savedSearchID) {
$ssParams = CRM_Contact_BAO_SavedSearch::getSearchParams($savedSearchID);
// rectify params to what proximity search expects if there is a value for prox_distance
// CRM-7021
if (!empty($ssParams)) {
CRM_Contact_BAO_ProximityQuery::fixInputParams($ssParams);
}
$returnProperties = array();
if (CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $savedSearchID, 'mapping_id')) {
$fv = CRM_Contact_BAO_SavedSearch::getFormValues($savedSearchID);
$returnProperties = CRM_Core_BAO_Mapping::returnProperties($fv);
}
if (isset($ssParams['customSearchID'])) {
// if custom search
// we split it up and store custom class
// so temp tables are not destroyed if they are used
// hence customClass is defined above at top of function
$customClass = CRM_Contact_BAO_SearchCustom::customClass($ssParams['customSearchID'], $savedSearchID);
$searchSQL = $customClass->contactIDs();
$idName = 'contact_id';
} else {
$formValues = CRM_Contact_BAO_SavedSearch::getFormValues($savedSearchID);
$query = new CRM_Contact_BAO_Query($ssParams, $returnProperties, NULL, FALSE, FALSE, 1, TRUE, TRUE, FALSE, CRM_Utils_Array::value('display_relationship_type', $formValues), CRM_Utils_Array::value('operator', $formValues, 'AND'));
$query->_useDistinct = FALSE;
$query->_useGroupBy = FALSE;
$searchSQL = $query->searchQuery(0, 0, NULL, FALSE, FALSE, FALSE, TRUE, TRUE, NULL, NULL, NULL, TRUE);
}
$groupID = CRM_Utils_Type::escape($groupID, 'Integer');
$sql = $searchSQL . " AND contact_a.id NOT IN (\n SELECT contact_id FROM civicrm_group_contact\n WHERE civicrm_group_contact.status = 'Removed'\n AND civicrm_group_contact.group_id = {$groupID} ) ";
}
if ($sql) {
$sql = preg_replace("/^\\s*SELECT/", "SELECT {$groupID} as group_id, ", $sql);
}
// lets also store the records that are explicitly added to the group
// this allows us to skip the group contact LEFT JOIN
$sqlB = "\nSELECT {$groupID} as group_id, contact_id as {$idName}\nFROM civicrm_group_contact\nWHERE civicrm_group_contact.status = 'Added'\n AND civicrm_group_contact.group_id = {$groupID} ";
$groupIDs = array($groupID);
self::remove($groupIDs);
foreach (array($sql, $sqlB) as $selectSql) {
if (!$selectSql) {
continue;
}
$insertSql = "INSERT IGNORE INTO civicrm_group_contact_cache (group_id,contact_id) ({$selectSql});";
$processed = TRUE;
// FIXME
$result = CRM_Core_DAO::executeQuery($insertSql);
}
self::updateCacheTime($groupIDs, $processed);
if ($group->children) {
//Store a list of contacts who are removed from the parent group
$sql = "\nSELECT contact_id\nFROM civicrm_group_contact\nWHERE civicrm_group_contact.status = 'Removed'\nAND civicrm_group_contact.group_id = {$groupID} ";
$dao = CRM_Core_DAO::executeQuery($sql);
$removed_contacts = array();
while ($dao->fetch()) {
$removed_contacts[] = $dao->contact_id;
}
$childrenIDs = explode(',', $group->children);
foreach ($childrenIDs as $childID) {
$contactIDs = CRM_Contact_BAO_Group::getMember($childID, FALSE);
//Unset each contact that is removed from the parent group
foreach ($removed_contacts as $removed_contact) {
unset($contactIDs[$removed_contact]);
}
$values = array();
foreach ($contactIDs as $contactID => $dontCare) {
$values[] = "({$groupID},{$contactID})";
}
self::store($groupIDs, $values);
}
}
}
示例14: postProcess
/**
* 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()
{
$session =& CRM_Core_Session::singleton();
$session->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);
// also reset the sort by character
$this->_sortByCharacter = null;
$this->set('sortByCharacter', null);
}
// 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);
}
$this->postProcessCommon();
}
示例15: savedSearch
/**
* where / qill clause for smart groups
*
* @return void
* @access public
*/
function savedSearch()
{
$config =& CRM_Core_Config::singleton();
$ssWhere = array();
$group =& new CRM_Contact_BAO_Group();
foreach (array_keys($this->_params['group']) as $group_id) {
$group->id = $group_id;
$group->find(true);
if (isset($group->saved_search_id)) {
require_once 'CRM/Contact/BAO/SavedSearch.php';
if ($config->mysqlVersion >= 4.1) {
$sfv =& CRM_Contact_BAO_SavedSearch::getFormValues($group->saved_search_id);
$smarts =& CRM_Contact_BAO_Contact::searchQuery($sfv, 0, 0, null, false, false, false, true, true);
$ssWhere[] = " \n (civicrm_contact.id IN ({$smarts}) \n AND civicrm_contact.id NOT IN ( \n SELECT contact_id FROM civicrm_group_contact \n WHERE civicrm_group_contact.group_id = " . CRM_Utils_Type::escape($group_id, 'Integer') . " AND civicrm_group_contact.status = 'Removed'))";
} else {
$ssw = CRM_Contact_BAO_SavedSearch::whereClause($group->saved_search_id, $this->_tables, $this->_whereTables);
/* FIXME: bug with multiple group searches */
$ssWhere[] = "({$ssw} AND\n (civicrm_group_contact.id is null OR\n (civicrm_group_contact.group_id = " . CRM_Utils_Type::escape($group_id, 'Integer') . " AND\n civicrm_group_contact.status = 'Added')))";
}
}
$group->reset();
$group->selectAdd('*');
}
if (!empty($ssWhere)) {
$this->_tables['civicrm_group_contact'] = "civicrm_contact.id = civicrm_group_contact.contact_id AND civicrm_group_contact.group_id IN (" . implode(',', array_keys($this->_params['group'])) . ')';
$this->_whereTables['civicrm_group_contact'] = $this->_tables['civicrm_group_contact'];
return implode(' OR ', $ssWhere);
}
return null;
}