Skip to content
Snippets Groups Projects
Commit 952ceece authored by jaapjansma's avatar jaapjansma
Browse files

Added location to event data source

parent 7dae749f
No related branches found
No related tags found
No related merge requests found
......@@ -6,12 +6,23 @@
namespace Civi\DataProcessor\Source\Event;
use Civi\DataProcessor\DataFlow\MultipleDataFlows\DataFlowDescription;
use Civi\DataProcessor\DataFlow\MultipleDataFlows\SimpleNonRequiredJoin;
use Civi\DataProcessor\DataFlow\SqlTableDataFlow;
use Civi\DataProcessor\DataSpecification\DataSpecification;
use Civi\DataProcessor\DataSpecification\FieldSpecification;
use Civi\DataProcessor\DataSpecification\Utils;
use Civi\DataProcessor\Source\AbstractCivicrmEntitySource;
use CRM_Dataprocessor_ExtensionUtil as E;
class EventSource extends AbstractCivicrmEntitySource {
/**
* @var SqlTableDataFlow
*/
protected $locBlockDataFlow;
/**
* Returns the entity name
*
......@@ -30,4 +41,76 @@ class EventSource extends AbstractCivicrmEntitySource {
return 'civicrm_event';
}
/**
* Load the fields from this entity.
*
* @param DataSpecification $dataSpecification
* @throws \Civi\DataProcessor\DataSpecification\FieldExistsException
*/
protected function loadFields(DataSpecification $dataSpecification, $fieldsToSkip=array()) {
parent::loadFields($dataSpecification, $fieldsToSkip);
// Add the location block fields.
$daoClass = \CRM_Core_DAO_AllCoreTables::getFullName('LocBlock');
$aliasPrefix = $this->getSourceName().'_locblock_';
Utils::addDAOFieldsToDataSpecification($daoClass, $dataSpecification, array('id'), '', $aliasPrefix);
}
/**
* Ensure that the entity table is added the to the data flow.
*
* @return \Civi\DataProcessor\DataFlow\AbstractDataFlow
* @throws \Exception
*/
protected function ensureEntity() {
$dataFlow = parent::ensureEntity();
$locBlockDataFlowFound = false;
foreach($this->additionalDataFlowDescriptions as $descriptor) {
if ($descriptor->getDataFlow()->getName() == $this->getSourceName() . '_locblock') {
$locBlockDataFlowFound = true;
}
}
if (!$locBlockDataFlowFound) {
$this->locBlockDataFlow = new SqlTableDataFlow('civicrm_loc_block', $this->getSourceName() . '_locblock');
$join = new SimpleNonRequiredJoin($this->primaryDataFlow->getName(), 'loc_block_id', $this->getSourceName() . '_locblock', 'id');
$join->setDataProcessor($this->dataProcessor);
$this->additionalDataFlowDescriptions[] = new DataFlowDescription($this->locBlockDataFlow, $join);
}
return $dataFlow;
}
/**
* Ensure that filter field is accesible in the query
*
* @param String $fieldName
* @return \Civi\DataProcessor\DataFlow\AbstractDataFlow|null
* @throws \Exception
*/
public function ensureField($fieldName) {
if ($this->getAvailableFilterFields()->doesFieldExist($fieldName)) {
$spec = $this->getAvailableFilterFields()->getFieldSpecificationByName($fieldName);
if (stripos($spec->alias, $this->getSourceName().'_locblock_') === 0) {
$this->ensureEntity();
return $this->locBlockDataFlow;
}
}
return parent::ensureField($fieldName);
}
/**
* Ensures a field is in the data source
*
* @param \Civi\DataProcessor\DataSpecification\FieldSpecification $fieldSpecification
* @return SourceInterface
* @throws \Exception
*/
public function ensureFieldInSource(FieldSpecification $fieldSpecification) {
if (stripos($fieldSpecification->alias, $this->getSourceName().'_locblock_') === 0) {
$this->ensureEntity();
$this->locBlockDataFlow->getDataSpecification()->addFieldSpecification($fieldSpecification);
} else {
parent::ensureFieldInSource($fieldSpecification);
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment