/** * 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) { $multipleFields = array('url'); //$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']); $fieldType = CRM_Utils_Array::value('2', $fieldArray); if (is_numeric(CRM_Utils_Array::value('1', $fieldArray))) { if (!in_array($fieldType, $multipleFields)) { $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] . "`"; } } else { $field['name'] = "`website-" . $fieldArray[1] . "-{$fieldType}`"; } } $varArray[$key] = $field; } $sort->_vars = $varArray; } $additionalWhereClause = 'contact_a.is_deleted = 0'; $returnQuery = NULL; if ($this->_multiRecordTableName) { $returnQuery = TRUE; } $result = $this->_query->searchQuery($offset, $rowCount, $sort, NULL, NULL, NULL, NULL, $returnQuery, $additionalWhereClause); if ($returnQuery) { $resQuery = preg_replace('/GROUP BY contact_a.id[\\s]+ORDER BY/', ' ORDER BY', $result); $result = CRM_Core_DAO::executeQuery($resQuery); } // process the result of the query $rows = array(); // check if edit is configured in profile settings if ($this->_gid) { $editLink = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'is_edit_link'); } //FIXME : make sure to handle delete separately. CRM-4418 $mask = CRM_Core_Action::mask(array(CRM_Core_Permission::getPermission())); if ($editLink && $mask & CRM_Core_Permission::EDIT) { // do not allow edit for anon users in joomla frontend, CRM-4668 $config = CRM_Core_Config::singleton(); if (!$config->userFrameworkFrontend) { $this->_editLink = TRUE; } } $links = self::links($this->_map, $this->_editLink, $this->_linkToUF, $this->_profileIds); $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) { // skip pseudo fields if (substr($key, 0, 9) == 'phone_ext') { continue; } if (!empty($field['in_selector']) && !in_array($key, $skipFields)) { if (strpos($key, '-') !== FALSE) { $value = explode('-', $key); $fieldName = CRM_Utils_Array::value(0, $value); $id = CRM_Utils_Array::value(1, $value); $type = CRM_Utils_Array::value(2, $value); if (!in_array($fieldName, $multipleFields)) { $locationTypeName = NULL; if (is_numeric($id)) { $locationTypeName = CRM_Utils_Array::value($id, $locationTypes); } else { if ($id == 'Primary') { $locationTypeName = 1; } } 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[] = "website-{$id}-{$fieldName}"; } } elseif ($field['name'] == 'id') { $names[] = 'contact_id'; } else { $names[] = $field['name']; } } } $multipleSelectFields = array('preferred_communication_method' => 1); $multiRecordTableId = NULL; if ($this->_multiRecordTableName) { $multiRecordTableId = "{$this->_multiRecordTableName}_id"; } // we need to determine of overlay profile should be shown $showProfileOverlay = CRM_Core_BAO_UFGroup::showOverlayProfile(); while ($result->fetch()) { $this->_query->convertToPseudoNames($result); 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_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, FALSE, $result->contact_id, $showProfileOverlay); if ($result->sort_name) { $row[] = $result->sort_name; $empty = FALSE; } else { continue; } foreach ($names as $name) { if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name)) { $row[] = CRM_Core_BAO_CustomField::getDisplayValue($result->{$name}, $cfID, $this->_options, $result->contact_id); } elseif (substr($name, -4) == '-url' && !empty($result->{$name})) { $url = CRM_Utils_System::fixURL($result->{$name}); $typeId = substr($name, 0, -4) . "-website_type_id"; $typeName = CRM_Core_PseudoConstant::getLabel('CRM_Core_DAO_Website', 'website_type_id', $result->{$typeId}); if ($typeName) { $row[] = "<a href=\"{$url}\">{$result->{$name}} ({$typeName})</a>"; } else { $row[] = "<a href=\"{$url}\">{$result->{$name}}</a>"; } } elseif ($name == 'preferred_language') { $row[] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_DAO_Contact', 'preferred_language', $result->{$name}); } elseif ($multipleSelectFields && array_key_exists($name, $multipleSelectFields)) { $paramsNew = array($name => $result->{$name}); $name = array($name => array('newName' => $name, 'groupName' => $name)); CRM_Core_OptionGroup::lookupValues($paramsNew, $name, FALSE); $row[] = $paramsNew[$key]; } elseif (strpos($name, '-im')) { if (!empty($result->{$name})) { $providerId = $name . "-provider_id"; $providerName = CRM_Core_PseudoConstant::getLabel('CRM_Core_DAO_IM', 'provider_id', $result->{$providerId}); $row[] = $result->{$name} . " ({$providerName})"; } else { $row[] = ''; } } elseif (strpos($name, '-phone-')) { $phoneExtField = str_replace('phone', 'phone_ext', $name); if (isset($result->{$phoneExtField})) { $row[] = $result->{$name} . " (" . $result->{$phoneExtField} . ")"; } else { $row[] = $result->{$name}; } } elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting'))) { $dname = $name . '_display'; $row[] = $result->{$dname}; } elseif (in_array($name, array('birth_date', 'deceased_date'))) { $row[] = CRM_Utils_Date::customFormat($result->{$name}); } elseif (isset($result->{$name})) { $row[] = $result->{$name}; } else { $row[] = ''; } if (!empty($result->{$name})) { $empty = FALSE; } } $newLinks = $links; $params = array('id' => $result->contact_id, 'gid' => implode(',', $this->_profileIds)); // pass record id param to view url for multi record view if ($multiRecordTableId && $newLinks) { if ($result->{$multiRecordTableId}) { if ($newLinks[CRM_Core_Action::VIEW]['url'] == 'civicrm/profile/view') { $newLinks[CRM_Core_Action::VIEW]['qs'] .= "&multiRecord=view&recordId=%%recordId%%&allFields=1"; $params['recordId'] = $result->{$multiRecordTableId}; } } } if ($this->_linkToUF) { $ufID = CRM_Core_BAO_UFMatch::getUFId($result->contact_id); if (!$ufID) { unset($newLinks[CRM_Core_Action::PROFILE]); } else { $params['ufID'] = $ufID; } } $row[] = CRM_Core_Action::formLink($newLinks, $mask, $params, ts('more'), FALSE, 'profile.selector.row', 'Contact', $result->contact_id); if (!$empty) { $rows[] = $row; } } return $rows; }