public $_orderBy = NULL;
public $_orderByFields = array();
public $_orderByArray = array();
+ /**
+ * Array of clauses to group by.
+ *
+ * @var array
+ */
+ protected $_groupByArray = array();
public $_groupBy = NULL;
public $_whereClauses = array();
public $_havingClauses = array();
}
foreach ($this->_columns as $tableName => $table) {
- // set alias
- if (!isset($table['alias'])) {
- $this->_columns[$tableName]['alias'] = substr($tableName, 8) .
- '_civireport';
- }
- else {
- $this->_columns[$tableName]['alias'] = $table['alias'] . '_civireport';
- }
-
- $this->_aliases[$tableName] = $this->_columns[$tableName]['alias'];
+ $this->setTableAlias($table, $tableName);
$expFields = array();
// higher preference to bao object
}
}
- $doNotCopy = array('required');
+ $doNotCopy = array('required', 'default');
$fieldGroups = array('fields', 'filters', 'group_bys', 'order_bys');
foreach ($fieldGroups as $fieldGrp) {
* Build group by clause.
*/
public function groupBy() {
- $groupBys = array();
if (!empty($this->_params['group_bys']) &&
is_array($this->_params['group_bys'])
) {
if (array_key_exists('group_bys', $table)) {
foreach ($table['group_bys'] as $fieldName => $field) {
if (!empty($this->_params['group_bys'][$fieldName])) {
- $groupBys[] = $field['dbAlias'];
+ $this->_groupByArray[] = $field['dbAlias'];
}
}
}
}
}
- if (!empty($groupBys)) {
- $this->_groupBy = CRM_Contact_BAO_Query::getGroupByFromSelectColumns($this->_selectClauses, $groupBys);
+ if (!empty($this->_groupByArray)) {
+ $this->_groupBy = CRM_Contact_BAO_Query::getGroupByFromSelectColumns($this->_selectClauses, $this->_groupByArray);
}
}
$smartGroups = array_keys($groups['values']);
$query = "
- SELECT group_contact.contact_id as id
+ SELECT DISTINCT group_contact.contact_id as id
FROM civicrm_group_contact group_contact
WHERE group_contact.group_id IN (" . implode(', ', $filteredGroups) . ")
AND group_contact.status = 'Added' ";
return $select;
}
+ /**
+ * Set table alias.
+ *
+ * @param array $table
+ * @param string $tableName
+ *
+ * @return string
+ * Alias for table.
+ */
+ protected function setTableAlias($table, $tableName) {
+ if (!isset($table['alias'])) {
+ $this->_columns[$tableName]['alias'] = substr($tableName, 8) .
+ '_civireport';
+ }
+ else {
+ $this->_columns[$tableName]['alias'] = $table['alias'] . '_civireport';
+ }
+
+ $this->_aliases[$tableName] = $this->_columns[$tableName]['alias'];
+ return $this->_aliases[$tableName];
+ }
+
}