本文整理汇总了PHP中CRM_Contact_BAO_Query::convertToPseudoNames方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contact_BAO_Query::convertToPseudoNames方法的具体用法?PHP CRM_Contact_BAO_Query::convertToPseudoNames怎么用?PHP CRM_Contact_BAO_Query::convertToPseudoNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Contact_BAO_Query
的用法示例。
在下文中一共展示了CRM_Contact_BAO_Query::convertToPseudoNames方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: search
/**
* Get the result of the search for Add to * forms.
*
* @param CRM_Core_Form $form
* @param array $params
* This contains elements for search criteria.
*/
public function search(&$form, &$params)
{
//max records that will be listed
$searchValues = array();
if (!empty($params['rel_contact'])) {
if (isset($params['rel_contact_id']) && is_numeric($params['rel_contact_id'])) {
$searchValues[] = array('contact_id', '=', $params['rel_contact_id'], 0, 1);
} else {
$searchValues[] = array('sort_name', 'LIKE', $params['rel_contact'], 0, 1);
}
}
$contactTypeAdded = FALSE;
$excludedContactIds = array();
if (isset($form->_contactId)) {
$excludedContactIds[] = $form->_contactId;
}
if (!empty($params['relationship_type_id'])) {
$relationshipType = new CRM_Contact_DAO_RelationshipType();
list($rid, $direction) = explode('_', $params['relationship_type_id'], 2);
$relationshipType->id = $rid;
if ($relationshipType->find(TRUE)) {
if ($direction == 'a_b') {
$type = $relationshipType->contact_type_b;
$subType = $relationshipType->contact_sub_type_b;
} else {
$type = $relationshipType->contact_type_a;
$subType = $relationshipType->contact_sub_type_a;
}
$form->set('contact_type', $type);
$form->set('contact_sub_type', $subType);
if ($type == 'Individual' || $type == 'Organization' || $type == 'Household') {
$searchValues[] = array('contact_type', '=', $type, 0, 0);
$contactTypeAdded = TRUE;
}
if ($subType) {
$searchValues[] = array('contact_sub_type', '=', $subType, 0, 0);
}
}
}
if (!$contactTypeAdded && !empty($params['contact_type'])) {
$searchValues[] = array('contact_type', '=', $params['contact_type'], 0, 0);
}
// get the count of contact
$contactBAO = new CRM_Contact_BAO_Contact();
$query = new CRM_Contact_BAO_Query($searchValues);
$searchCount = $query->searchQuery(0, 0, NULL, TRUE);
$form->set('searchCount', $searchCount);
if ($searchCount <= 50) {
// get the result of the search
$result = $query->searchQuery(0, 50, NULL);
$config = CRM_Core_Config::singleton();
$searchRows = array();
//variable is set if only one record is foun and that record already has relationship with the contact
$duplicateRelationship = 0;
while ($result->fetch()) {
$query->convertToPseudoNames($result);
$contactID = $result->contact_id;
if (in_array($contactID, $excludedContactIds)) {
$duplicateRelationship++;
continue;
}
$duplicateRelationship = 0;
$searchRows[$contactID]['id'] = $contactID;
$searchRows[$contactID]['name'] = $result->sort_name;
$searchRows[$contactID]['city'] = $result->city;
$searchRows[$contactID]['state'] = $result->state_province;
$searchRows[$contactID]['email'] = $result->email;
$searchRows[$contactID]['phone'] = $result->phone;
$contact_type = '<img src="' . $config->resourceBase . 'i/contact_';
$searchRows[$contactID]['type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type);
}
$form->set('searchRows', $searchRows);
$form->set('duplicateRelationship', $duplicateRelationship);
} else {
// resetting the session variables if many records are found
$form->set('searchRows', NULL);
$form->set('duplicateRelationship', NULL);
}
}
示例3: getValues
/**
* Given a contact id and a field set, return the values from the db
* for this contact
*
* @param int $cid
* @param array $fields
* The profile fields of interest.
* @param array $values
* The values for the above fields.
* @param bool $searchable
* Searchable or not.
* @param array $componentWhere
* Component condition.
* @param bool $absolute
* Return urls in absolute form (useful when sending an email).
* @param null $additionalWhereClause
*/
public static function getValues($cid, &$fields, &$values, $searchable = TRUE, $componentWhere = NULL, $absolute = FALSE, $additionalWhereClause = NULL)
{
if (empty($cid) && empty($componentWhere)) {
return NULL;
}
// get the contact details (hier)
$returnProperties = CRM_Contact_BAO_Contact::makeHierReturnProperties($fields);
$params = $cid ? array(array('contact_id', '=', $cid, 0, 0)) : array();
// add conditions specified by components. eg partcipant_id etc
if (!empty($componentWhere)) {
$params = array_merge($params, $componentWhere);
}
$query = new CRM_Contact_BAO_Query($params, $returnProperties, $fields);
$options =& $query->_options;
$details = $query->searchQuery(0, 0, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, $additionalWhereClause);
if (!$details->fetch()) {
return;
}
$query->convertToPseudoNames($details);
$config = CRM_Core_Config::singleton();
$locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
$imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id');
$websiteTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id');
$multipleFields = array('url');
//start of code to set the default values
foreach ($fields as $name => $field) {
// fix for CRM-3962
if ($name == 'id') {
$name = 'contact_id';
}
// skip fields that should not be displayed separately
if (!empty($field['skipDisplay'])) {
continue;
}
// Create a unique, non-empty index for each field.
$index = $field['title'];
if ($index === '') {
$index = ' ';
}
while (array_key_exists($index, $values)) {
$index .= ' ';
}
$params[$index] = $values[$index] = '';
$customFieldName = NULL;
// hack for CRM-665
if (isset($details->{$name}) || $name == 'group' || $name == 'tag') {
// to handle gender / suffix / prefix
if (in_array(substr($name, 0, -3), array('gender', 'prefix', 'suffix'))) {
$params[$index] = $details->{$name};
$values[$index] = $details->{$name};
} elseif (in_array($name, CRM_Contact_BAO_Contact::$_greetingTypes)) {
$dname = $name . '_display';
$values[$index] = $details->{$dname};
$name = $name . '_id';
$params[$index] = $details->{$name};
} elseif (in_array($name, array('state_province', 'country', 'county'))) {
$values[$index] = $details->{$name};
$idx = $name . '_id';
$params[$index] = $details->{$idx};
} elseif ($name === 'preferred_communication_method') {
$communicationFields = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method');
$compref = array();
$pref = explode(CRM_Core_DAO::VALUE_SEPARATOR, $details->{$name});
foreach ($pref as $k) {
if ($k) {
$compref[] = $communicationFields[$k];
}
}
$params[$index] = $details->{$name};
$values[$index] = implode(',', $compref);
} elseif ($name === 'preferred_language') {
$params[$index] = $details->{$name};
$values[$index] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_DAO_Contact', 'preferred_language', $details->{$name});
} elseif ($name == 'group') {
$groups = CRM_Contact_BAO_GroupContact::getContactGroup($cid, 'Added', NULL, FALSE, TRUE);
$title = $ids = array();
foreach ($groups as $g) {
// CRM-8362: User and User Admin visibility groups should be included in display if user has
// VIEW permission on that group
$groupPerm = CRM_Contact_BAO_Group::checkPermission($g['group_id'], $g['title']);
if ($g['visibility'] != 'User and User Admin Only' || CRM_Utils_Array::key(CRM_Core_Permission::VIEW, $groupPerm)) {
$title[] = $g['title'];
if ($g['visibility'] == 'Public Pages') {
//.........这里部分代码省略.........
示例4: 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);
}
示例5: array
/**
* Returns all the rows in the given offset and rowCount.
*
* @param string $action
* The action being performed.
* @param int $offset
* The row number to start from.
* @param int $rowCount
* The number of rows to return.
* @param string $sort
* The sql string that describes the sort order.
* @param string $output
* What should the result set include (web/email/csv).
*
* @return int
* the total number of rows for this action
*/
public function &getRows($action, $offset, $rowCount, $sort, $output = NULL)
{
$config = CRM_Core_Config::singleton();
if (($output == CRM_Core_Selector_Controller::EXPORT || $output == CRM_Core_Selector_Controller::SCREEN) && $this->_formValues['radio_ts'] == 'ts_sel') {
$includeContactIds = TRUE;
} else {
$includeContactIds = FALSE;
}
// note the formvalues were given by CRM_Contact_Form_Search to us
// and contain the search criteria (parameters)
// note that the default action is basic
if ($rowCount) {
$cacheKey = $this->buildPrevNextCache($sort);
$result = $this->_query->getCachedContacts($cacheKey, $offset, $rowCount, $includeContactIds);
} else {
$result = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, $includeContactIds);
}
// process the result of the query
$rows = array();
$permissions = array(CRM_Core_Permission::getPermission());
if (CRM_Core_Permission::check('delete contacts')) {
$permissions[] = CRM_Core_Permission::DELETE;
}
$mask = CRM_Core_Action::mask($permissions);
// mask value to hide map link if there are not lat/long
$mapMask = $mask & 4095;
if ($this->_searchContext == 'smog') {
$gc = CRM_Core_SelectValues::groupContactStatus();
}
if ($this->_ufGroupID) {
$locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
$names = array();
static $skipFields = array('group', 'tag');
foreach ($this->_fields as $key => $field) {
if (!empty($field['in_selector']) && !in_array($key, $skipFields)) {
if (strpos($key, '-') !== FALSE) {
list($fieldName, $id, $type) = CRM_Utils_System::explode('-', $key, 3);
if ($id == 'Primary') {
$locationTypeName = 1;
} elseif ($fieldName == 'url') {
$locationTypeName = "website-{$id}";
} else {
$locationTypeName = CRM_Utils_Array::value($id, $locationTypes);
if (!$locationTypeName) {
continue;
}
}
$locationTypeName = str_replace(' ', '_', $locationTypeName);
if (in_array($fieldName, array('phone', 'im', 'email'))) {
if ($type) {
$names[] = "{$locationTypeName}-{$fieldName}-{$type}";
} else {
$names[] = "{$locationTypeName}-{$fieldName}";
}
} else {
$names[] = "{$locationTypeName}-{$fieldName}";
}
} else {
$names[] = $field['name'];
}
}
}
$names[] = "status";
} elseif (!empty($this->_returnProperties)) {
$names = self::makeProperties($this->_returnProperties);
} else {
$names = self::$_properties;
}
$multipleSelectFields = array('preferred_communication_method' => 1);
$links = self::links($this->_context, $this->_contextMenu, $this->_key);
//check explicitly added contact to a Smart Group.
$groupID = CRM_Utils_Array::value('group', $this->_formValues);
$pseudoconstants = array();
// for CRM-3157 purposes
if (in_array('world_region', $names)) {
$pseudoconstants['world_region'] = array('dbName' => 'worldregion_id', 'values' => CRM_Core_PseudoConstant::worldRegion());
}
$seenIDs = array();
while ($result->fetch()) {
$row = array();
$this->_query->convertToPseudoNames($result);
// the columns we are interested in
foreach ($names as $property) {
//.........这里部分代码省略.........
示例6: relationshipContacts
static function relationshipContacts()
{
$searchValues = $searchRows = array();
$addCount = 0;
$relType = CRM_Utils_Type::escape($_REQUEST['relType'], 'String');
$typeName = isset($_REQUEST['typeName']) ? CRM_Utils_Type::escape($_REQUEST['typeName'], 'String') : '';
$relContact = CRM_Utils_Type::escape($_REQUEST['relContact'], 'String');
$currentContactId = CRM_Utils_Type::escape($_REQUEST['cid'], 'Integer');
if (in_array($typeName, array('Employee of', 'Employer of'))) {
$addCount = 1;
}
$sortMapper = array(1 => 'sort_name', 2 + $addCount => 'city', 3 + $addCount => 'state_province', 4 + $addCount => 'email', 5 + $addCount => 'phone');
$sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
$offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
$rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
$sort = isset($_REQUEST['iSortCol_0']) ? $sortMapper[CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer')] : 'sort_name';
$sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
$searchValues[] = array('sort_name', 'LIKE', $relContact, 0, 1);
list($rid, $direction) = explode('_', $relType, 2);
$relationshipType = new CRM_Contact_DAO_RelationshipType();
$relationshipType->id = $rid;
if ($relationshipType->find(TRUE)) {
if ($direction == 'a_b') {
$type = $relationshipType->contact_type_b;
$subType = $relationshipType->contact_sub_type_b;
} else {
$type = $relationshipType->contact_type_a;
$subType = $relationshipType->contact_sub_type_a;
}
if ($type == 'Individual' || $type == 'Organization' || $type == 'Household') {
$searchValues[] = array('contact_type', '=', $type, 0, 0);
}
if ($subType) {
$searchValues[] = array('contact_sub_type', '=', $subType, 0, 0);
}
}
// exclude current contact
$searchValues[] = array('contact_id', '!=', $currentContactId, 0, 0);
$query = new CRM_Contact_BAO_Query($searchValues);
$searchCount = $query->searchQuery(0, 0, NULL, TRUE);
$iTotal = $searchCount;
if ($searchCount > 0) {
// get the result of the search
$result = $query->searchQuery($offset, $rowCount, $sort, FALSE, FALSE, FALSE, FALSE, FALSE, NULL, $sortOrder);
$config = CRM_Core_Config::singleton();
while ($result->fetch()) {
$query->convertToPseudoNames($result);
$contactID = $result->contact_id;
$typeImage = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, FALSE, $contactID);
$searchRows[$contactID]['id'] = $contactID;
$searchRows[$contactID]['name'] = $typeImage . ' ' . $result->sort_name;
$searchRows[$contactID]['city'] = $result->city;
$searchRows[$contactID]['state'] = $result->state_province;
$searchRows[$contactID]['email'] = $result->email;
$searchRows[$contactID]['phone'] = $result->phone;
}
}
foreach ($searchRows as $cid => $row) {
$searchRows[$cid]['check'] = '<input type="checkbox" id="contact_check[' . $cid . ']" name="contact_check[' . $cid . ']" value=' . $cid . ' />';
if ($typeName == 'Employee of') {
$searchRows[$cid]['employee_of'] = '<input type="radio" name="employee_of" value=' . $cid . ' >';
} elseif ($typeName == 'Employer of') {
$searchRows[$cid]['employer_of'] = '<input type="checkbox" name="employer_of[' . $cid . ']" value=' . $cid . ' />';
}
}
$selectorElements = array('check', 'name');
if ($typeName == 'Employee of') {
$selectorElements[] = 'employee_of';
} elseif ($typeName == 'Employer of') {
$selectorElements[] = 'employer_of';
}
$selectorElements = array_merge($selectorElements, array('city', 'state', 'email', 'phone'));
$iFilteredTotal = $iTotal;
echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
CRM_Utils_System::civiExit();
}