protected $_aclWhere = NULL;
/**
- * Array of DAO tables having columns included in SELECT or ORDER BY clause
+ * Array of DAO tables having columns included in SELECT or ORDER BY clause.
+ *
+ * Where has also been added to this although perhaps the 'includes both' array should have a different name.
*
* @var array
*/
protected $_selectedTables;
+ /**
+ * Array of DAO tables having columns included in WHERE or HAVING clause
+ *
+ * @var array
+ */
+ protected $filteredTables;
+
/**
* Output mode e.g 'print', 'csv', 'pdf'.
*
/**
* Build custom data from clause.
+ *
+ * @param bool $joinsForFiltersOnly
+ * Only include joins to support filters. This would be used if creating a table of contacts to include first.
*/
- public function customDataFrom() {
+ public function customDataFrom($joinsForFiltersOnly = FALSE) {
if (empty($this->_customGroupExtends)) {
return;
}
foreach ($this->_columns as $table => $prop) {
if (in_array($table, $customTables)) {
$extendsTable = $mapper[$prop['extends']];
-
- // check field is in params
- if (!$this->isFieldSelected($prop)) {
+ // Check field is required for rendering the report.
+ if ((!$this->isFieldSelected($prop)) || ($joinsForFiltersOnly && !$this->isFieldFiltered($prop))) {
continue;
}
$baseJoin = CRM_Utils_Array::value($prop['extends'], $this->_customGroupExtendsJoin, "{$this->_aliases[$extendsTable]}.id");
}
}
}
+ return $this->isFieldFiltered($prop);
+
+ }
+ /**
+ * Check if the field is used as a filter.
+ *
+ * @param string $prop
+ *
+ * @return bool
+ */
+ protected function isFieldFiltered($prop) {
if (!empty($prop['filters']) && $this->_customGroupFilters) {
foreach ($prop['filters'] as $fieldAlias => $val) {
foreach (array(
return in_array($tableName, $this->selectedTables());
}
+ /**
+ * Check if table name has columns in WHERE or HAVING clause.
+ *
+ * @param string $tableName
+ * Name of table (index of $this->_columns array).
+ *
+ * @return bool
+ */
+ public function isTableFiltered($tableName) {
+ // Cause the array to be generated if not previously done.
+ if (!$this->_selectedTables && !$this->filteredTables) {
+ $this->selectedTables();
+ }
+ return in_array($tableName, $this->filteredTables);
+ }
+
/**
* Fetch array of DAO tables having columns included in SELECT or ORDER BY clause.
*
'nnll'
) {
$this->_selectedTables[] = $tableName;
+ $this->filteredTables[] = $tableName;
break;
}
}