Commit 17d1cae1 authored by jaapjansma's avatar jaapjansma

Update, added activity data source, individual, household, organization data sources

parent 2444aadb
......@@ -108,9 +108,11 @@ class CRM_Dataprocessor_Form_Join_Simple extends CRM_Core_Form {
function buildFieldList() {
$factory = dataprocessor_get_factory();
$fields = array();
$dataProcessor = CRM_Dataprocessor_BAO_DataProcessor::getDataProcessorById($this->dataProcessorId);
$sources = CRM_Dataprocessor_BAO_Source::getValues(array('data_processor_id' => $this->dataProcessorId));
foreach($sources as $source) {
$sourceClass = $factory->getDataSourceByName($source['type']);
$sourceClass->setDataProcessor($dataProcessor);
$sourceClass->initialize($source['configuration'], $source['name']);
$sourceFields = $sourceClass->getAvailableFields()->getFields();
foreach($sourceFields as $sourceField) {
......
......@@ -68,9 +68,10 @@ class CombinedSqlDataFlow extends SqlDataFlow implements MultipleSourceDataFlows
public function getFromStatement() {
$fromStatements = array();
$sourceDataFlowDescription = reset($this->sourceDataFlowDescriptions);
if ($sourceDataFlowDescription->getDataFlow() instanceof SqlTableDataFlow) {
$fromStatements[] = "FROM `{$sourceDataFlowDescription->getDataFlow()->getTable()}` `{$sourceDataFlowDescription->getDataFlow()->getTableAlias()}`";
} elseif ($sourceDataFlowDescription->getDataFlow() instanceof CombinedSqlDataFlow) {
$dataFlow = $sourceDataFlowDescription->getDataFlow();
if ($dataFlow instanceof SqlTableDataFlow) {
$fromStatements[] = "FROM `{$dataFlow->getTable()}` `{$dataFlow->getTableAlias()}`";
} elseif ($dataFlow instanceof CombinedSqlDataFlow) {
$fromStatements[] = "FROM `{$sourceDataFlowDescription->getDataFlow()->getPrimaryTable()}` `{$sourceDataFlowDescription->getDataFlow()->getPrimaryTableAlias()}`";
}
$fromStatements = array_merge($fromStatements, $this->getJoinStatement(0));
......
......@@ -97,7 +97,10 @@ abstract class SqlDataFlow extends AbstractDataFlow {
"Error in DataFlow query.
\r\nData flow: {$this->getName()}
\r\nCount query: {$countSql}
\r\nQuery: $sql", 0, $e);
\r\nQuery: $sql
\r\nMessage: {$e->getMessage()}", 0, $e);
}
}
......@@ -242,7 +245,7 @@ abstract class SqlDataFlow extends AbstractDataFlow {
}
if ($sortSpecification->getField()) {
$fieldName = $sortSpecification->getField()->alias;
$orderBys[] = "{$fieldName} {$dir}";
$orderBys[] = "`{$fieldName}` {$dir}";
}
}
if (count($orderBys)) {
......
......@@ -35,6 +35,16 @@ class SqlTableDataFlow extends SqlDataFlow {
return $this->table_alias;
}
/**
* @param $table_alias
*
* @return SqlTableDataFlow
*/
public function setTableAlias($table_alias) {
$this->table_alias = $table_alias;
return $this;
}
/**
* Returns the From Statement.
*
......
......@@ -95,7 +95,11 @@ class Factory {
$this->dispatcher = \Civi::dispatcher();
$this->addDataProcessorType('default', 'Civi\DataProcessor\ProcessorType\DefaultProcessorType', E::ts('Default'));
$this->addDataSource('activity', 'Civi\DataProcessor\Source\Activity\ActivitySource', E::ts('Activity'));
$this->addDataSource('contact', 'Civi\DataProcessor\Source\Contact\ContactSource', E::ts('Contact'));
$this->addDataSource('individual', 'Civi\DataProcessor\Source\Contact\IndividualSource', E::ts('Individual'));
$this->addDataSource('household', 'Civi\DataProcessor\Source\Contact\HouseholdSource', E::ts('Household'));
$this->addDataSource('organization', 'Civi\DataProcessor\Source\Contact\OrganizationSource', E::ts('Organization'));
$this->addDataSource('group', 'Civi\DataProcessor\Source\Group\GroupSource', E::ts('Group'));
$this->addDataSource('group_contact', 'Civi\DataProcessor\Source\Group\GroupContactSource', E::ts('Contacts in a group'));
$this->addDataSource('email', 'Civi\DataProcessor\Source\Contact\EmailSource', E::ts('E-mail'));
......
......@@ -139,9 +139,10 @@ abstract class AbstractCivicrmEntitySource extends AbstractSource {
*
* @param DataSpecification $dataSpecification
* @param bool $onlySearchAbleFields
* @param $entity
* @throws \Civi\DataProcessor\DataSpecification\FieldExistsException
*/
protected function loadCustomGroupsAndFields(DataSpecification $dataSpecification, $onlySearchAbleFields) {
protected function loadCustomGroupsAndFields(DataSpecification $dataSpecification, $onlySearchAbleFields, $entity=null) {
$customGroupToReturnParam = array(
'custom_field' => array(
'id',
......@@ -181,7 +182,10 @@ abstract class AbstractCivicrmEntitySource extends AbstractSource {
'max_multiple',
),
);
$customGroups = \CRM_Core_BAO_CustomGroup::getTree($this->getEntity(), $customGroupToReturnParam,NULL,NULL,NULL,NULL,NULL,NULL,TRUE,FALSE,FALSE);
if (!$entity) {
$entity = $this->getEntity();
}
$customGroups = \CRM_Core_BAO_CustomGroup::getTree($entity, $customGroupToReturnParam,NULL,NULL,NULL,NULL,NULL,NULL,TRUE,FALSE,FALSE);
foreach($customGroups as $cgId => $customGroup) {
if ($cgId == 'info') {
continue;
......
......@@ -38,6 +38,10 @@ abstract class AbstractSource implements SourceInterface {
*/
protected $dataFlow;
public function __construct() {
}
/**
* @return String
*/
......
<?php
/**
* @author Jaap Jansma <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
namespace Civi\DataProcessor\Source\Activity;
use Civi\DataProcessor\DataSpecification\DataSpecification;
use Civi\DataProcessor\Source\AbstractCivicrmEntitySource;
use CRM_Dataprocessor_ExtensionUtil as E;
class ActivitySource extends AbstractCivicrmEntitySource {
/**
* Returns the entity name
*
* @return String
*/
protected function getEntity() {
return 'Activity';
}
/**
* Returns the table name of this entity
*
* @return String
*/
protected function getTable() {
return 'civicrm_activity';
}
}
\ No newline at end of file
......@@ -38,7 +38,7 @@ class ContactSource extends AbstractCivicrmEntitySource {
public function getAvailableFilterFields() {
if (!$this->availableFilterFields) {
$this->availableFilterFields = new DataSpecification();
$this->loadFields($this->availableFilterFields, array('contact_type'));
$this->loadFields($this->availableFilterFields);
$this->loadCustomGroupsAndFields($this->availableFilterFields, true);
}
return $this->availableFilterFields;
......
<?php
/**
* @author Jaap Jansma <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
namespace Civi\DataProcessor\Source\Contact;
use Civi\DataProcessor\DataSpecification\DataSpecification;
use Civi\DataProcessor\Source\AbstractCivicrmEntitySource;
use CRM_Dataprocessor_ExtensionUtil as E;
class HouseholdSource extends AbstractCivicrmEntitySource {
protected $skipFields = array(
'contact_type',
'first_name',
'middle_name',
'last_name',
'formal_title',
'job_title',
'gender_id',
'prefix_id',
'suffix_id',
'birth_date',
'organization_name',
'legal_name',
'legal_identifier',
'sic_code',
'home_URL',
'is_deceased',
'deceased_date',
);
/**
* Returns the entity name
*
* @return String
*/
protected function getEntity() {
return 'Contact';
}
/**
* Returns the table name of this entity
*
* @return String
*/
protected function getTable() {
return 'civicrm_contact';
}
/**
* @return \Civi\DataProcessor\DataSpecification\DataSpecification
* @throws \Exception
*/
public function getAvailableFilterFields() {
if (!$this->availableFilterFields) {
$this->availableFilterFields = new DataSpecification();
$this->loadFields($this->availableFilterFields, $this->skipFields);
$this->loadCustomGroupsAndFields($this->availableFilterFields, true, 'Household');
}
return $this->availableFilterFields;
}
/**
* @return \Civi\DataProcessor\DataSpecification\DataSpecification
* @throws \Exception
*/
public function getAvailableFields() {
if (!$this->availableFields) {
$this->availableFields = new DataSpecification();
$this->loadFields($this->availableFields, $this->skipFields);
$this->loadCustomGroupsAndFields($this->availableFields, false, 'Household');
}
return $this->availableFields;
}
/**
* Add the filters to the where clause of the data flow
*
* @param $configuration
* @throws \Exception
*/
protected function addFilters($configuration) {
parent::addFilters($configuration);
$this->addFilter('contact_type', '=', 'Household');
}
}
\ No newline at end of file
<?php
/**
* @author Jaap Jansma <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
namespace Civi\DataProcessor\Source\Contact;
use Civi\DataProcessor\DataSpecification\DataSpecification;
use Civi\DataProcessor\Source\AbstractCivicrmEntitySource;
use CRM_Dataprocessor_ExtensionUtil as E;
class IndividualSource extends AbstractCivicrmEntitySource {
protected $skipFields = array(
'contact_type',
'household_name',
'legal_name',
'sic_code',
'organization_name',
);
/**
* Returns the entity name
*
* @return String
*/
protected function getEntity() {
return 'Contact';
}
/**
* Returns the table name of this entity
*
* @return String
*/
protected function getTable() {
return 'civicrm_contact';
}
/**
* @return \Civi\DataProcessor\DataSpecification\DataSpecification
* @throws \Exception
*/
public function getAvailableFilterFields() {
if (!$this->availableFilterFields) {
$this->availableFilterFields = new DataSpecification();
$this->loadFields($this->availableFilterFields, $this->skipFields);
$this->loadCustomGroupsAndFields($this->availableFilterFields, true, 'Individual');
}
return $this->availableFilterFields;
}
/**
* @return \Civi\DataProcessor\DataSpecification\DataSpecification
* @throws \Exception
*/
public function getAvailableFields() {
if (!$this->availableFields) {
$this->availableFields = new DataSpecification();
$this->loadFields($this->availableFields, $this->skipFields);
$this->loadCustomGroupsAndFields($this->availableFields, false, 'Individual');
}
return $this->availableFields;
}
/**
* Add the filters to the where clause of the data flow
*
* @param $configuration
* @throws \Exception
*/
protected function addFilters($configuration) {
parent::addFilters($configuration);
$this->addFilter('contact_type', '=', 'Individual');
}
}
\ No newline at end of file
<?php
/**
* @author Jaap Jansma <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
namespace Civi\DataProcessor\Source\Contact;
use Civi\DataProcessor\DataSpecification\DataSpecification;
use Civi\DataProcessor\Source\AbstractCivicrmEntitySource;
use CRM_Dataprocessor_ExtensionUtil as E;
class OrganizationSource extends AbstractCivicrmEntitySource {
protected $skipFields = array(
'contact_type',
'first_name',
'middle_name',
'last_name',
'formal_title',
'job_title',
'gender_id',
'prefix_id',
'suffix_id',
'birth_date',
'household_name',
'is_deceased',
'deceased_date',
);
/**
* Returns the entity name
*
* @return String
*/
protected function getEntity() {
return 'Contact';
}
/**
* Returns the table name of this entity
*
* @return String
*/
protected function getTable() {
return 'civicrm_contact';
}
/**
* @return \Civi\DataProcessor\DataSpecification\DataSpecification
* @throws \Exception
*/
public function getAvailableFilterFields() {
if (!$this->availableFilterFields) {
$this->availableFilterFields = new DataSpecification();
$this->loadFields($this->availableFilterFields, $this->skipFields);
$this->loadCustomGroupsAndFields($this->availableFilterFields, true, 'Organization');
}
return $this->availableFilterFields;
}
/**
* @return \Civi\DataProcessor\DataSpecification\DataSpecification
* @throws \Exception
*/
public function getAvailableFields() {
if (!$this->availableFields) {
$this->availableFields = new DataSpecification();
$this->loadFields($this->availableFields, $this->skipFields);
$this->loadCustomGroupsAndFields($this->availableFields, false, 'Organization');
}
return $this->availableFields;
}
/**
* Add the filters to the where clause of the data flow
*
* @param $configuration
* @throws \Exception
*/
protected function addFilters($configuration) {
parent::addFilters($configuration);
$this->addFilter('contact_type', '=', 'Organization');
}
}
\ No newline at end of file
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