/** * returns all the rows in the given offset and rowCount * * @param enum $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 enum $output what should the result set include (web/email/csv) * * @return int the total number of rows for this action */ function &getRows($action, $offset, $rowCount, $sort, $output = null) { //$sort object processing for location fields if ($sort) { $vars = $sort->_vars; $varArray = array(); foreach ($vars as $key => $field) { $field = $vars[$key]; $fieldArray = explode('-', $field['name']); if (is_numeric($fieldArray[1])) { $locationType =& new CRM_Core_DAO_LocationType(); $locationType->id = $fieldArray[1]; $locationType->find(true); if ($fieldArray[0] == 'email' || $fieldArray[0] == 'im' || $fieldArray[0] == 'phone') { $field['name'] = "`" . $locationType->name . "-" . $fieldArray[0] . "-1`"; } else { $field['name'] = "`" . $locationType->name . "-" . $fieldArray[0] . "`"; } } $varArray[$key] = $field; } } $sort->_vars = $varArray; $result = $this->_query->searchQuery($offset, $rowCount, $sort, null, null, null, null, null); // process the result of the query $rows = array(); $mask = CRM_Core_Action::mask(CRM_Core_Permission::getPermission()); require_once 'CRM/Core/PseudoConstant.php'; $locationTypes = CRM_Core_PseudoConstant::locationType(); $links =& CRM_Profile_Selector_Listings::links(); $names = array(); foreach ($this->_fields as $key => $field) { if ($field['in_selector'] && !in_array($key, $GLOBALS['_CRM_PROFILE_SELECTOR_LISTINGS']['skipFields'])) { if (strpos($key, '-') !== false) { list($fieldName, $id, $type) = explode('-', $key); $locationTypeName = CRM_Utils_Array::value($id, $locationTypes); if (!$locationTypeName) { continue; } if (in_array($fieldName, array('phone', 'im', 'email'))) { if ($type) { $names[] = "{$locationTypeName}-{$fieldName}-{$type}"; } else { $names[] = "{$locationTypeName}-{$fieldName}-1"; } } else { $names[] = "{$locationTypeName}-{$fieldName}"; } } else { $names[] = $field['name']; } } } while ($result->fetch()) { if (isset($result->country)) { // the query returns the untranslated country name $i18n =& CRM_Core_I18n::singleton(); $result->country = $i18n->translate($result->country); } $row = array(); $empty = true; $row[] = CRM_Contact_BAO_Contact::getImage($result->contact_type); $row['sort_name'] = $result->sort_name; foreach ($names as $name) { if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name)) { $row[] = CRM_Core_BAO_CustomField::getDisplayValue($result->{$name}, $cfID, $this->_options); } else { $row[] = $result->{$name}; } if (!empty($result->{$name})) { $empty = false; } } $row[] = CRM_Core_Action::formLink(CRM_Profile_Selector_Listings::links(), $mask, array('id' => $result->contact_id, 'gid' => $this->_gid)); if (!$empty) { $rows[] = $row; } } return $rows; }
/** * Get the display name and image of a contact * * @param int $id the contactId * * @return array the displayName and contactImage for this contact * @access public * @static */ function getDisplayAndImage($id) { $sql = "\nSELECT civicrm_contact.display_name as display_name,\n civicrm_contact.contact_type as contact_type,\n civicrm_email.email as email \nFROM civicrm_contact\nLEFT JOIN civicrm_location ON (civicrm_location.entity_table = 'civicrm_contact' AND\n civicrm_contact.id = civicrm_location.entity_id AND\n civicrm_location.is_primary = 1)\nLEFT JOIN civicrm_email ON (civicrm_location.id = civicrm_email.location_id AND civicrm_email.is_primary = 1)\nWHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); $dao =& new CRM_Core_DAO(); $dao->query($sql); if ($dao->fetch()) { $image = CRM_Contact_BAO_Contact::getImage($dao->contact_type); // use email if display_name is empty if (empty($dao->display_name)) { $dao->display_name = $dao->email; } return array($dao->display_name, $image); } return null; }