本文整理汇总了PHP中CRM_Contact_BAO_Query::query方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contact_BAO_Query::query方法的具体用法?PHP CRM_Contact_BAO_Query::query怎么用?PHP CRM_Contact_BAO_Query::query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Contact_BAO_Query
的用法示例。
在下文中一共展示了CRM_Contact_BAO_Query::query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetExportStructureArrays
/**
* Test the function that extracts the arrays used to structure the output.
*
* The keys in the output fields array should by matched by field aliases in the sql query (with
* exceptions of course - currently country is one - although maybe a future refactor can change that!).
*
* We are trying to move towards simpler processing in the per row iteration as that may be
* repeated 100,000 times and in general we should simply be able to match the query fields to
* our expected rows & do a little pseudoconstant mapping.
*/
public function testGetExportStructureArrays()
{
// This is how return properties are formatted internally within the function for passing to the BAO query.
$returnProperties = array('first_name' => 1, 'last_name' => 1, 'receive_date' => 1, 'contribution_source' => 1, 'location' => array('Home' => array('street_address' => 1, 'city' => 1, 'country' => 1, 'email' => 1, 'im-1' => 1, 'im_provider' => 1, 'phone-1' => 1)), 'phone' => 1, 'trxn_id' => 1, 'contribution_id' => 1);
$phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
$imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id');
$contactRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, NULL, TRUE, 'name', FALSE);
$query = new CRM_Contact_BAO_Query(array(), $returnProperties, NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_CONTRIBUTE, FALSE, TRUE, TRUE, NULL, 'AND');
list($select) = $query->query();
$pattern = '/as `?([^`,]*)/';
$queryFieldAliases = array();
preg_match_all($pattern, $select, $queryFieldAliases, PREG_PATTERN_ORDER);
list($outputFields) = CRM_Export_BAO_Export::getExportStructureArrays($returnProperties, $query, $phoneTypes, $imProviders, $contactRelationshipTypes, '', array());
foreach (array_keys($outputFields) as $fieldAlias) {
if ($fieldAlias == 'Home-country') {
$this->assertTrue(in_array($fieldAlias . '_id', $queryFieldAliases[1]), 'Country is subject to some funky translate so we make sure country id is present');
} else {
$this->assertTrue(in_array($fieldAlias, $queryFieldAliases[1]), 'looking for field ' . $fieldAlias . ' in generaly the alias fields need to match the outputfields');
}
}
}
示例2: postProcess
/**
* process the form after the input has been submitted and validated
*
* @access public
* @return void
*/
public function postProcess()
{
$params = $this->controller->exportValues($this->_name);
$config = CRM_Core_Config::singleton();
require_once 'CRM/Event/BAO/Query.php';
require_once 'CRM/Contact/BAO/Query.php';
$returnProperties =& CRM_Event_BAO_Query::defaultReturnProperties(CRM_Contact_BAO_Query::MODE_EVENT);
$additionalFields = array('first_name', 'last_name', 'middle_name', 'current_employer');
foreach ($additionalFields as $field) {
$returnProperties[$field] = 1;
}
if ($this->_single) {
$queryParams = null;
} else {
$queryParams = $this->get('queryParams');
}
$query = new CRM_Contact_BAO_Query($queryParams, $returnProperties, null, false, false, CRM_Contact_BAO_Query::MODE_EVENT);
list($select, $from, $where) = $query->query();
if (empty($where)) {
$where = "WHERE {$this->_componentClause}";
} else {
$where .= " AND {$this->_componentClause}";
}
$queryString = "{$select} {$from} {$where}";
$dao = CRM_Core_DAO::executeQuery($queryString);
$rows = array();
while ($dao->fetch()) {
$rows[$dao->participant_id] = array();
foreach ($returnProperties as $key => $dontCare) {
$rows[$dao->participant_id][$key] = isset($dao->{$key}) ? $dao->{$key} : null;
}
}
// get the class name from the participantListingID
require_once 'CRM/Core/OptionGroup.php';
$className = CRM_Core_OptionGroup::getValue('event_badge', $params['badge_id'], 'value', 'Integer', 'name');
$classFile = str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
$error = (include_once $classFile);
if ($error == false) {
CRM_Core_Error::fatal('Event Badge code file: ' . $classFile . ' does not exist. Please verify your custom event badge settings in CiviCRM administrative panel.');
}
eval("\$eventBadgeClass = new {$className}( );");
$eventBadgeClass->run($rows);
}
示例3: apiQuery
/**
* These are stub comments as this function needs more explanation - particularly in terms of how it
* relates to $this->searchQuery and why it replicates rather than calles $this->searchQuery.
*
* This function was originally written as a wrapper for the api query but is called from multiple places
* in the core code directly so the name is misleading. This function does not use the searchQuery function
* but it is unclear as to whehter that is historical or there is a reason
* CRM-11290 led to the permissioning action being extracted from searchQuery & shared with this function
*
* @param array $params
* @param array $returnProperties
* @param null $fields
* @param string $sort
* @param int $offset
* @param int $row_count
* @param bool $smartGroupCache
* ?? update smart group cache?.
* @param bool $count
* Return count obnly.
* @param bool $skipPermissions
* Should permissions be ignored or should the logged in user's permissions be applied.
*
*
* @return array
*/
public static function apiQuery($params = NULL, $returnProperties = NULL, $fields = NULL, $sort = NULL, $offset = 0, $row_count = 25, $smartGroupCache = TRUE, $count = FALSE, $skipPermissions = TRUE)
{
$query = new CRM_Contact_BAO_Query($params, $returnProperties, NULL, TRUE, FALSE, 1, $skipPermissions, TRUE, $smartGroupCache);
//this should add a check for view deleted if permissions are enabled
if ($skipPermissions) {
$query->_skipDeleteClause = TRUE;
}
$query->generatePermissionClause(FALSE, $count);
// note : this modifies _fromClause and _simpleFromClause
$query->includePseudoFieldsJoin($sort);
list($select, $from, $where, $having) = $query->query($count);
$options = $query->_options;
if (!empty($query->_permissionWhereClause)) {
if (empty($where)) {
$where = "WHERE {$query->_permissionWhereClause}";
} else {
$where = "{$where} AND {$query->_permissionWhereClause}";
}
}
$sql = "{$select} {$from} {$where} {$having}";
// add group by
if ($query->_useGroupBy) {
$sql .= ' GROUP BY contact_a.id';
}
if (!empty($sort)) {
$sort = CRM_Utils_Type::escape($sort, 'String');
$sql .= " ORDER BY {$sort} ";
}
if ($row_count > 0 && $offset >= 0) {
$offset = CRM_Utils_Type::escape($offset, 'Int');
$rowCount = CRM_Utils_Type::escape($row_count, 'Int');
$sql .= " LIMIT {$offset}, {$row_count} ";
}
$dao = CRM_Core_DAO::executeQuery($sql);
$values = array();
while ($dao->fetch()) {
if ($count) {
$noRows = $dao->rowCount;
$dao->free();
return array($noRows, NULL);
}
$val = $query->store($dao);
$convertedVals = $query->convertToPseudoNames($dao, TRUE);
if (!empty($convertedVals)) {
$val = array_replace_recursive($val, $convertedVals);
}
$values[$dao->contact_id] = $val;
}
$dao->free();
return array($values, $options);
}
示例4: apiQuery
/**
* wrapper for a api search query
*
* @param array $params
* @param array $returnProperties
* @param string $sort
* @param int $offset
* @param int $row_count
*
* @return void
* @access public
*/
function apiQuery($params = null, $returnProperties = null, $options = null, $sort = null, $offset = 0, $row_count = 25)
{
$query = new CRM_Contact_BAO_Query($params, $returnProperties, null);
list($select, $from, $where) = $query->query();
$options = $query->_options;
$sql = "{$select} {$from} {$where}";
if (!empty($sort)) {
$sql .= " ORDER BY {$sort} ";
}
if ($row_count > 0 && $offset >= 0) {
$sql .= " LIMIT {$offset}, {$row_count} ";
}
$dao =& CRM_Core_DAO::executeQuery($sql);
$values = array();
while ($dao->fetch()) {
$values[$dao->contact_id] = $query->store($dao);
}
return array($values, $options);
}
示例5: buildBadges
/**
* Build badges parameters before actually creating badges.
*
* @param array $params
* Associated array of submitted values.
* @param CRM_Core_Form $form
*
* @return void
*/
public static function buildBadges(&$params, &$form)
{
// get name badge layout info
$layoutInfo = CRM_Badge_BAO_Layout::buildLayout($params);
// split/get actual field names from token and individual contact image URLs
$returnProperties = array();
if (!empty($layoutInfo['data']['token'])) {
foreach ($layoutInfo['data']['token'] as $index => $value) {
$element = '';
if ($value) {
$token = CRM_Utils_Token::getTokens($value);
if (key($token) == 'contact') {
$element = $token['contact'][0];
} elseif (key($token) == 'event') {
$element = $token['event'][0];
//FIX ME - we need to standardize event token names
if (substr($element, 0, 6) != 'event_') {
$element = 'event_' . $element;
}
} elseif (key($token) == 'participant') {
$element = $token['participant'][0];
}
// build returnproperties for query
$returnProperties[$element] = 1;
}
// add actual field name to row element
$layoutInfo['data']['rowElements'][$index] = $element;
}
}
// add additional required fields for query execution
$additionalFields = array('participant_register_date', 'participant_id', 'event_id', 'contact_id', 'image_URL');
foreach ($additionalFields as $field) {
$returnProperties[$field] = 1;
}
if ($form->_single) {
$queryParams = NULL;
} else {
$queryParams = $form->get('queryParams');
}
$query = new CRM_Contact_BAO_Query($queryParams, $returnProperties, NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_EVENT);
list($select, $from, $where, $having) = $query->query();
if (empty($where)) {
$where = "WHERE {$form->_componentClause}";
} else {
$where .= " AND {$form->_componentClause}";
}
$sortOrder = NULL;
if ($form->get(CRM_Utils_Sort::SORT_ORDER)) {
$sortOrder = $form->get(CRM_Utils_Sort::SORT_ORDER);
if (!empty($sortOrder)) {
$sortOrder = " ORDER BY {$sortOrder}";
}
}
$queryString = "{$select} {$from} {$where} {$having} {$sortOrder}";
$dao = CRM_Core_DAO::executeQuery($queryString);
$rows = array();
while ($dao->fetch()) {
$query->convertToPseudoNames($dao);
$rows[$dao->participant_id] = array();
foreach ($returnProperties as $key => $dontCare) {
$value = isset($dao->{$key}) ? $dao->{$key} : NULL;
// Format custom fields
if (strstr($key, 'custom_') && isset($value)) {
$value = CRM_Core_BAO_CustomField::getDisplayValue($value, substr($key, 7), $query->_options, $dao->contact_id);
}
$rows[$dao->participant_id][$key] = $value;
}
}
$eventBadgeClass = new CRM_Badge_BAO_Badge();
$eventBadgeClass->createLabels($rows, $layoutInfo);
}
示例6: civicrm_api3_contact_getstat
function civicrm_api3_contact_getstat ($params) {
// mostly copy pasted from contact_get and the functions called by it
$options = array();
_civicrm_api3_contact_get_supportanomalies($params, $options);
$contacts = _civicrm_api3_get_using_query_object('contact', $params, $options);
$options = _civicrm_api3_get_options_from_params($params, TRUE);
$inputParams = CRM_Utils_Array::value('input_params', $options, array());
$returnProperties = CRM_Utils_Array::value('return', $options, array());
if(!empty($params['check_permissions'])){
// we will filter query object against getfields
$fields = civicrm_api("contact", 'getfields', array('version' => 3, 'action' => 'get'));
// we need to add this in as earlier in this function 'id' was unset in favour of $entity_id
$fields['values'][$entity . '_id'] = array();
$varsToFilter = array('returnProperties', 'inputParams');
foreach ($varsToFilter as $varToFilter){
if(!is_array($$varToFilter)){
continue;
}
$$varToFilter = array_intersect_key($$varToFilter, $fields['values']);
}
}
// $options = array_merge($options,$additional_options);
$sort = CRM_Utils_Array::value('sort', $options, NULL);
$returnSQL = CRM_Utils_Array::value('sql', $options, CRM_Utils_Array::value('options_sql', $options['input_params']));
$smartGroupCache = CRM_Utils_Array::value('smartGroupCache', $params);
$newParams = CRM_Contact_BAO_Query::convertFormValues($inputParams);
$skipPermissions = CRM_Utils_Array::value('check_permissions', $params)? 0 :1;
$query = new CRM_Contact_BAO_Query(
$params, $returnProperties,
NULL, TRUE, FALSE, 1,
$skipPermissions,
TRUE, $smartGroupCache
);
//this should add a check for view deleted if permissions are enabled
if ($skipPermissions){
$query->_skipDeleteClause = TRUE;
}
$query->generatePermissionClause(FALSE, $count);
list($select, $from, $where, $having) = $query->query($count);
$options = $query->_options;
if(!empty($query->_permissionWhereClause)){
if (empty($where)) {
$where = "WHERE $query->_permissionWhereClause";
} else {
$where = "$where AND $query->_permissionWhereClause";
}
}
$sql = "$select $from $where $having";
if (!empty($returnProperties)) {
$extra = array();
$sql = "SELECT count(*) AS total,". substr ($sql, 34,10000); //replace select contact_id, by select count(*)
$sql .= " GROUP BY ". implode (",",array_keys($returnProperties)) ;
} else {
$sql = "SELECT count(*) AS total $from $where $having";
$extra = array ("tip"=>"if you need to group by a field, use the return param, eg return=contact_type,gender",
"warning"=> "use getcount, getstat without param might be blocked in the future");
if (!empty($sort)) {
$sql .= " ORDER BY $sort ";
} else {
$sql .= " ORDER BY total DESC ";
}
}
if ($returnSQL) {
return array("is_error"=>1,"sql"=>$sql,"from"=>$from,"where"=>$where,"having"=>$having);
}
$dao = CRM_Core_DAO::executeQuery($sql);
$values = array();
while ($dao->fetch()) {
$values[] = $dao->toArray();
}
return civicrm_api3_create_success($values, $params, "contact", "getstat", $dao,$extra);
}
示例7: civicrm_api3_pledge_get
/**
* 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);
}
示例8: testGroupContactCacheAddSearch
/**
* Test set up to test calling the query object per GroupContactCache BAO usage.
*
* CRM-17254 ensure that if only the contact_id is required other fields should
* not be appended.
*/
public function testGroupContactCacheAddSearch()
{
$returnProperties = array('contact_id');
$params = array(array('group', 'IN', array(1), 0, 0));
$query = new CRM_Contact_BAO_Query($params, $returnProperties, NULL, TRUE, FALSE, 1, TRUE, TRUE, FALSE);
list($select) = $query->query(FALSE);
$this->assertEquals('SELECT contact_a.id as contact_id', $select);
}
示例9: array
/**
* 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
* @static void
* @access public
*/
function &civicrm_pledge_get(&$params)
{
_civicrm_initialize();
if (!is_array($params)) {
return civicrm_create_error('Input parameters is not an array');
}
$inputParams = array();
$returnProperties = array();
$otherVars = array('sort', 'offset', 'rowCount');
$sort = NULL;
$offset = 0;
$rowCount = 25;
foreach ($params as $n => $v) {
if (substr($n, 0, 7) == 'return.') {
$returnProperties[substr($n, 7)] = $v;
} elseif (in_array($n, $otherVars)) {
${$n} = $v;
} else {
$inputParams[$n] = $v;
}
}
// add is_test to the clause if not present
if (!array_key_exists('pledge_test', $inputParams)) {
$inputParams['pledge_test'] = 0;
}
require_once 'CRM/Pledge/BAO/Query.php';
require_once 'CRM/Contact/BAO/Query.php';
if (empty($returnProperties)) {
$returnProperties = CRM_Pledge_BAO_Query::defaultReturnProperties(CRM_Contact_BAO_Query::MODE_PLEDGE);
} else {
$returnProperties['pledge_id'] = 1;
}
$newParams = CRM_Contact_BAO_Query::convertFormValues($inputParams);
$query = new CRM_Contact_BAO_Query($newParams, $returnProperties, NULL);
list($select, $from, $where) = $query->query();
$sql = "{$select} {$from} {$where}";
if (!empty($sort)) {
$sql .= " ORDER BY {$sort} ";
}
$sql .= " LIMIT {$offset}, {$rowCount} ";
$dao = CRM_Core_DAO::executeQuery($sql);
$pledge = array();
while ($dao->fetch()) {
if ($params['sequential']) {
$pledge[] = $query->store($dao);
} else {
$pledge[$dao->pledge_id] = $query->store($dao);
}
}
$dao->free();
return $pledge;
}
示例10: testNonNumericEqualsPostal
/**
* Test smart groups with non-numeric don't fail on equal queries.
*
* CRM-14720
*/
public function testNonNumericEqualsPostal()
{
$this->individualCreate(array('api.address.create' => array('postal_code' => 5, 'location_type_id' => 'Main')));
$this->individualCreate(array('api.address.create' => array('postal_code' => 'EH10 4RB-889', 'location_type_id' => 'Main')));
$this->individualCreate(array('api.address.create' => array('postal_code' => '4', 'location_type_id' => 'Main')));
$this->individualCreate(array('api.address.create' => array('postal_code' => '6', 'location_type_id' => 'Main')));
$params = array(array('postal_code', '=', 'EH10 4RB-889', 0, 0));
CRM_Contact_BAO_Query::convertFormValues($params);
$query = new CRM_Contact_BAO_Query($params, array('contact_id'), NULL, TRUE, FALSE, 1, TRUE, TRUE, FALSE);
$sql = $query->query(FALSE);
$this->assertEquals("WHERE ( civicrm_address.postal_code = 'eh10 4rb-889' ) AND (contact_a.is_deleted = 0)", $sql[2]);
$result = CRM_Core_DAO::executeQuery(implode(' ', $sql));
$this->assertEquals(1, $result->N);
}
示例11: civicrm_api3_contribution_get
/**
* Retrieve a set of contributions, given a set of input params
*
* @param array $params (reference ) input parameters
* @param array $returnProperties Which properties should be included in the
* returned Contribution object. If NULL, the default
* set of properties will be included.
*
* @return array (reference ) array of contributions, if error an array with an error id and error message
* @static void
* @access public
* {@getfields Contribution_get}
* @example ContributionGet.php
*/
function civicrm_api3_contribution_get($params)
{
$options = _civicrm_api3_get_options_from_params($params, TRUE, 'contribution', 'get');
$sort = CRM_Utils_Array::value('sort', $options, NULL);
$offset = CRM_Utils_Array::value('offset', $options);
$rowCount = CRM_Utils_Array::value('limit', $options);
$smartGroupCache = CRM_Utils_Array::value('smartGroupCache', $params);
$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(CRM_Contact_BAO_Query::MODE_CONTRIBUTE);
}
$newParams = CRM_Contact_BAO_Query::convertFormValues($inputParams);
$query = new CRM_Contact_BAO_Query($newParams, $returnProperties, NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_CONTRIBUTE);
list($select, $from, $where, $having) = $query->query();
$sql = "{$select} {$from} {$where} {$having}";
if (!empty($sort)) {
$sql .= " ORDER BY {$sort} ";
}
$sql .= " LIMIT {$offset}, {$rowCount} ";
$dao = CRM_Core_DAO::executeQuery($sql);
$contribution = array();
while ($dao->fetch()) {
//CRM-8662
$contribution_details = $query->store($dao);
$softContribution = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($dao->contribution_id, TRUE);
$contribution[$dao->contribution_id] = array_merge($contribution_details, $softContribution);
if (isset($contribution[$dao->contribution_id]['financial_type_id'])) {
$contribution[$dao->contribution_id]['financial_type_id'] = $contribution[$dao->contribution_id]['financial_type_id'];
}
// format soft credit for backward compatibility
_civicrm_api3_format_soft_credit($contribution[$dao->contribution_id]);
}
return civicrm_api3_create_success($contribution, $params, 'contribution', 'get', $dao);
}
示例12: civicrm_api3_participant_get
/**
* Retrieve a specific participant, given a set of input params
* If more than one matching participant exists, return an error, unless
* the client has requested to return the first found contact
*
* @param array $params (reference ) input parameters
*
* @return array (reference ) array of properties, if error an array with an error id and error message
* {@getfields participant_get}
* @access public
*/
function civicrm_api3_participant_get($params)
{
$options = _civicrm_api3_get_options_from_params($params, TRUE, 'participant', 'get');
$sort = CRM_Utils_Array::value('sort', $options, NULL);
$offset = CRM_Utils_Array::value('offset', $options);
$rowCount = CRM_Utils_Array::value('limit', $options);
$smartGroupCache = CRM_Utils_Array::value('smartGroupCache', $params);
$inputParams = CRM_Utils_Array::value('input_params', $options, array());
$returnProperties = CRM_Utils_Array::value('return', $options, NULL);
if (empty($returnProperties)) {
$returnProperties = CRM_Event_BAO_Query::defaultReturnProperties(CRM_Contact_BAO_Query::MODE_EVENT);
}
$newParams = CRM_Contact_BAO_Query::convertFormValues($inputParams);
$query = new CRM_Contact_BAO_Query($newParams, $returnProperties, NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_EVENT);
list($select, $from, $where, $having) = $query->query();
$sql = "{$select} {$from} {$where} {$having}";
if (!empty($sort)) {
$sql .= " ORDER BY {$sort} ";
}
$sql .= " LIMIT {$offset}, {$rowCount} ";
$dao = CRM_Core_DAO::executeQuery($sql);
$participant = array();
while ($dao->fetch()) {
$participant[$dao->participant_id] = $query->store($dao);
_civicrm_api3_custom_data_get($participant[$dao->participant_id], 'Participant', $dao->participant_id, NULL);
}
return civicrm_api3_create_success($participant, $params, 'participant', 'get', $dao);
}
示例13: exportComponents
/**
* Function to get the list the export fields
*
* @param int $selectAll user preference while export
* @param array $ids contact ids
* @param array $params associated array of fields
* @param string $order order by clause
* @param array $fields associated array of fields
* @param array $moreReturnProperties additional return fields
* @param int $exportMode export mode
* @param string $componentClause component clause
* @param string $componentTable component table
* @param bool $mergeSameAddress merge records if they have same address
* @param bool $mergeSameHousehold merge records if they belong to the same household
*
* @static
* @access public
*/
static function exportComponents($selectAll, $ids, $params, $order = null, $fields = null, $moreReturnProperties = null, $exportMode = CRM_Export_Form_Select::CONTACT_EXPORT, $componentClause = null, $componentTable = null, $mergeSameAddress = false, $mergeSameHousehold = false)
{
$headerRows = $returnProperties = array();
$primary = $paymentFields = false;
$origFields = $fields;
$queryMode = null;
$phoneTypes = CRM_Core_PseudoConstant::phoneType();
$imProviders = CRM_Core_PseudoConstant::IMProvider();
$contactRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, null, null, null, true, 'label', false);
$queryMode = CRM_Contact_BAO_Query::MODE_CONTACTS;
switch ($exportMode) {
case CRM_Export_Form_Select::CONTRIBUTE_EXPORT:
$queryMode = CRM_Contact_BAO_Query::MODE_CONTRIBUTE;
break;
case CRM_Export_Form_Select::EVENT_EXPORT:
$queryMode = CRM_Contact_BAO_Query::MODE_EVENT;
break;
case CRM_Export_Form_Select::MEMBER_EXPORT:
$queryMode = CRM_Contact_BAO_Query::MODE_MEMBER;
break;
case CRM_Export_Form_Select::PLEDGE_EXPORT:
$queryMode = CRM_Contact_BAO_Query::MODE_PLEDGE;
break;
case CRM_Export_Form_Select::CASE_EXPORT:
$queryMode = CRM_Contact_BAO_Query::MODE_CASE;
break;
case CRM_Export_Form_Select::GRANT_EXPORT:
$queryMode = CRM_Contact_BAO_Query::MODE_GRANT;
break;
case CRM_Export_Form_Select::ACTIVITY_EXPORT:
$queryMode = CRM_Contact_BAO_Query::MODE_ACTIVITY;
break;
}
require_once 'CRM/Core/BAO/CustomField.php';
if ($fields) {
//construct return properties
$locationTypes = CRM_Core_PseudoConstant::locationType();
$locationTypeFields = array('street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'postal_code', 'postal_code_suffix', 'geo_code_1', 'geo_code_2', 'state_province', 'country', 'phone', 'email', 'im');
foreach ($fields as $key => $value) {
$phoneTypeId = $imProviderId = null;
$relationshipTypes = $fieldName = CRM_Utils_Array::value(1, $value);
if (!$fieldName) {
continue;
}
// get phoneType id and IM service provider id seperately
if ($fieldName == 'phone') {
$phoneTypeId = CRM_Utils_Array::value(3, $value);
} else {
if ($fieldName == 'im') {
$imProviderId = CRM_Utils_Array::value(3, $value);
}
}
if (array_key_exists($relationshipTypes, $contactRelationshipTypes)) {
if (CRM_Utils_Array::value(2, $value)) {
$relationField = CRM_Utils_Array::value(2, $value);
if (trim(CRM_Utils_Array::value(3, $value))) {
$relLocTypeId = CRM_Utils_Array::value(3, $value);
} else {
$relLocTypeId = 'Primary';
}
if ($relationField == 'phone') {
$relPhoneTypeId = CRM_Utils_Array::value(4, $value);
} else {
if ($relationField == 'im') {
$relIMProviderId = CRM_Utils_Array::value(4, $value);
}
}
} else {
if (CRM_Utils_Array::value(4, $value)) {
$relationField = CRM_Utils_Array::value(4, $value);
$relLocTypeId = CRM_Utils_Array::value(5, $value);
if ($relationField == 'phone') {
$relPhoneTypeId = CRM_Utils_Array::value(6, $value);
} else {
if ($relationField == 'im') {
$relIMProviderId = CRM_Utils_Array::value(6, $value);
}
}
}
}
}
$contactType = CRM_Utils_Array::value(0, $value);
//.........这里部分代码省略.........
示例14: array
/**
* Get contact participant record.
*
* This api is used for finding an existing participant record.
*
* @param array $params an associative array of name/value property values of civicrm_participant
*
* @return participant property values.
* @access public
*/
function &civicrm_participant_search(&$params)
{
if (!is_array($params)) {
return civicrm_create_error('Params need to be of type array!');
}
$inputParams = array();
$returnProperties = array();
$otherVars = array('sort', 'offset', 'rowCount');
$sort = NULL;
$offset = 0;
$rowCount = 25;
foreach ($params as $n => $v) {
if (substr($n, 0, 7) == 'return.') {
$returnProperties[substr($n, 7)] = $v;
} elseif (in_array($n, $otherVars)) {
${$n} = $v;
} else {
$inputParams[$n] = $v;
}
}
// add is_test to the clause if not present
if (!array_key_exists('participant_test', $inputParams)) {
$inputParams['participant_test'] = 0;
}
require_once 'CRM/Contact/BAO/Query.php';
require_once 'CRM/Event/BAO/Query.php';
if (empty($returnProperties)) {
$returnProperties = CRM_Event_BAO_Query::defaultReturnProperties(CRM_Contact_BAO_Query::MODE_EVENT);
}
$newParams = CRM_Contact_BAO_Query::convertFormValues($params);
$query = new CRM_Contact_BAO_Query($newParams, $returnProperties, NULL);
list($select, $from, $where, $having) = $query->query();
$sql = "{$select} {$from} {$where} {$having}";
if (!empty($sort)) {
$sql .= " ORDER BY {$sort} ";
}
$sql .= " LIMIT {$offset}, {$rowCount} ";
$dao = CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
$participant = array();
while ($dao->fetch()) {
$participant[$dao->participant_id] = $query->store($dao);
}
$dao->free();
return $participant;
}
示例15: apiQuery
/**
* wrapper for a api search query
*
* @param array $params
* @param array $returnProperties
* @param string $sort
* @param int $offset
* @param int $row_count
*
* @return void
* @access public
*/
static function apiQuery($params = NULL, $returnProperties = NULL, $fields = NULL, $sort = NULL, $offset = 0, $row_count = 25, $smartGroupCache = TRUE)
{
$query = new CRM_Contact_BAO_Query($params, $returnProperties, NULL, TRUE, FALSE, 1, FALSE, TRUE, $smartGroupCache);
list($select, $from, $where, $having) = $query->query();
$options = $query->_options;
$sql = "{$select} {$from} {$where} {$having}";
// add group by
if ($query->_useGroupBy) {
$sql .= ' GROUP BY contact_a.id';
}
if (!empty($sort)) {
$sql .= " ORDER BY {$sort} ";
}
if ($row_count > 0 && $offset >= 0) {
$sql .= " LIMIT {$offset}, {$row_count} ";
}
$dao = CRM_Core_DAO::executeQuery($sql);
$values = array();
while ($dao->fetch()) {
$values[$dao->contact_id] = $query->store($dao);
}
$dao->free();
return array($values, $options);
}