Commit 7dae749f authored by jaapjansma's avatar jaapjansma
Browse files

fixed minor bugs

parent 440229e6
......@@ -17,12 +17,12 @@ class CRM_Dataprocessor_Utils_DataSourceFields {
* @return array
* @throws \Exception
*/
public static function getAvailableFieldsInDataSources($dataProcessorId, $filterFieldsCallback=null) {
public static function getAvailableFieldsInDataSources($dataProcessorId, $callback=null) {
$dataProcessor = civicrm_api3('DataProcessor', 'getsingle', array('id' => $dataProcessorId));
$dataProcessorClass = \CRM_Dataprocessor_BAO_DataProcessor::dataProcessorToClass($dataProcessor);
$fieldSelect = array();
foreach($dataProcessorClass->getDataSources() as $dataSource) {
$fieldSelect = array_merge($fieldSelect, self::getAvailableFieldsInDataSource($dataSource, $dataSource->getSourceTitle().' :: ', $dataSource->getSourceName().'::', $filterFieldsCallback));
$fieldSelect = array_merge($fieldSelect, self::getAvailableFieldsInDataSource($dataSource, $dataSource->getSourceTitle().' :: ', $dataSource->getSourceName().'::', $callback));
}
return $fieldSelect;
}
......@@ -38,15 +38,15 @@ class CRM_Dataprocessor_Utils_DataSourceFields {
* @return array
* @throws \Exception
*/
public static function getAvailableFieldsInDataSource(SourceInterface $dataSource, $titlePrefix='', $namePrefix='', $filterFieldsCallback=null) {
public static function getAvailableFieldsInDataSource(SourceInterface $dataSource, $titlePrefix='', $namePrefix='', $callback=null) {
$fieldSelect = array();
foreach($dataSource->getAvailableFields()->getFields() as $field) {
foreach($dataSource->getAvailableFields()->getFields() as $fieldName => $field) {
$isFieldValid = true;
if ($filterFieldsCallback) {
$isFieldValid = call_user_func($filterFieldsCallback, $field);
if ($callback) {
$isFieldValid = call_user_func($callback, $field);
}
if ($isFieldValid) {
$fieldSelect[$namePrefix . $field->name] = $titlePrefix . $field->title;
$fieldSelect[$namePrefix . $fieldName] = $titlePrefix . $field->title;
}
}
return $fieldSelect;
......@@ -66,7 +66,7 @@ class CRM_Dataprocessor_Utils_DataSourceFields {
$dataProcessorClass = \CRM_Dataprocessor_BAO_DataProcessor::dataProcessorToClass($dataProcessor);
$fieldSelect = array();
foreach($dataProcessorClass->getDataSources() as $dataSource) {
$fieldSelect = array_merge($fieldSelect, self::getAvailableFieldsInDataSource($dataSource, $dataSource->getSourceTitle().' :: ', $dataSource->getSourceName().'::', $filterFieldsCallback));
$fieldSelect = array_merge($fieldSelect, self::getAvailableFilterFieldsInDataSource($dataSource, $dataSource->getSourceTitle().' :: ', $dataSource->getSourceName().'::', $filterFieldsCallback));
}
return $fieldSelect;
}
......@@ -84,13 +84,13 @@ class CRM_Dataprocessor_Utils_DataSourceFields {
*/
public static function getAvailableFilterFieldsInDataSource(SourceInterface $dataSource, $titlePrefix='', $namePrefix='', $filterFieldsCallback=null) {
$fieldSelect = array();
foreach($dataSource->getAvailableFilterFields()->getFields() as $field) {
foreach($dataSource->getAvailableFilterFields()->getFields() as $fieldName => $field) {
$isFieldValid = true;
if ($filterFieldsCallback) {
$isFieldValid = call_user_func($filterFieldsCallback, $field);
}
if ($isFieldValid) {
$fieldSelect[$namePrefix . $field->name] = $titlePrefix . $field->title;
$fieldSelect[$namePrefix . $fieldName] = $titlePrefix . $field->title;
}
}
return $fieldSelect;
......
......@@ -84,12 +84,8 @@ abstract class SqlDataFlow extends AbstractDataFlow {
$this->sqlCountStatements[] = $countSql;
$countDao = \CRM_Core_DAO::executeQuery($countSql);
$this->count = 0;
if (count($this->getFieldsForGroupByStatement()) > 0) {
$this->count = $countDao->N;
} else {
while ($countDao->fetch()) {
$this->count = $this->count + $countDao->count;
}
while ($countDao->fetch()) {
$this->count = $this->count + $countDao->count;
}
// Build Limit and Offset.
......
......@@ -16,7 +16,7 @@ class CountFieldSpecification extends FieldSpecification {
* @return string
*/
public function getSqlSelectStatement($table_alias) {
return "COUNT(`{$table_alias}`.`{$this->name}`) AS `{$this->alias}`";
return "COUNT(DISTINCT `{$table_alias}`.`{$this->name}`) AS `{$this->alias}`";
}
}
\ No newline at end of file
......@@ -386,6 +386,7 @@ class Api implements OutputInterface, API_ProviderInterface, EventSubscriberInte
if (isset($params['debug']) && $params['debug']) {
$return['debug_info'] = $dataProcessorClass->getDataFlow()->getDebugInformation();
}
return $return;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment