+ /**
+ * Get an array of the columns that have been selected for display.
+ *
+ * @return array
+ */
+ public function getSelectColumns() {
+ $selectColumns = array();
+ foreach ($this->_columns as $tableName => $table) {
+ if (array_key_exists('fields', $table)) {
+ foreach ($table['fields'] as $fieldName => $field) {
+ if (!empty($field['required']) ||
+ !empty($this->_params['fields'][$fieldName])
+ ) {
+
+ $selectColumns["{$tableName}_{$fieldName}"] = 1;
+ }
+ }
+ }
+ }
+ return $selectColumns;
+ }
+
+ /**
+ * Add location tables to the query if they are used for filtering.
+ *
+ * This is for when we are running the query separately for filtering and retrieving display fields.
+ */
+ public function selectivelyAddLocationTablesJoinsToFilterQuery() {
+ if ($this->isTableFiltered('civicrm_email')) {
+ $this->_from .= "
+ LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
+ ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id
+ AND {$this->_aliases['civicrm_email']}.is_primary = 1";
+ }
+ if ($this->isTableFiltered('civicrm_phone')) {
+ $this->_from .= "
+ LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
+ ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id
+ AND {$this->_aliases['civicrm_phone']}.is_primary = 1";
+ }
+ if ($this->isTableFiltered('civicrm_address')) {
+ $this->_from .= "
+ LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
+ ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id)
+ AND {$this->_aliases['civicrm_address']}.is_primary = 1\n";
+ }
+ }
+