Commit b9df5df3 authored by jaapjansma's avatar jaapjansma
Browse files

Added case tokens

parent 704ce43a
......@@ -39,6 +39,11 @@ class CompilerPass implements CompilerPassInterface {
));
$tokenFactoryDefinition->addMethodCall('addTokenOutputType', ['participant_token']);
$factoryDefinition->addMethodCall('addOutput', array(
'case_token', 'Civi\DataProcessorTokenOutput\Output\CaseToken', E::ts('Case Tokens')
));
$tokenFactoryDefinition->addMethodCall('addTokenOutputType', ['case_token']);
$factoryDefinition->addMethodCall('addOutput', array(
'event_token', 'Civi\DataProcessorTokenOutput\Output\EventToken', E::ts('Event Tokens')
));
......
......@@ -6,9 +6,11 @@
namespace Civi\DataProcessorTokenOutput\Output;
use Civi\DataProcessor\DataFlow\CombinedDataFlow\CombinedSqlDataFlow;
use Civi\DataProcessor\DataFlow\EndOfFlowException;
use Civi\DataProcessor\DataFlow\Sort\SortCompareFactory;
use Civi\DataProcessor\DataFlow\SqlDataFlow;
use Civi\DataProcessor\DataFlow\SqlTableDataFlow;
use Civi\DataProcessor\Exception\DataSourceNotFoundException;
use Civi\DataProcessor\Exception\FieldNotFoundException;
use Civi\DataProcessor\Output\OutputInterface;
......@@ -348,7 +350,7 @@ abstract class AbstractToken implements OutputInterface, TokenOutput {
* @throws \Civi\DataProcessor\Exception\FieldNotFoundException
*/
protected function initializeDataProcessorClass($idsToUse, AbstractProcessorType $dataProcessorClass, $configuration) {
list($datasource_name, $field_name) = explode('::', $configuration[$this->getIdFieldName()], 2);
[$datasource_name, $field_name] = explode('::', $configuration[$this->getIdFieldName()], 2);
$dataSource = $dataProcessorClass->getDataSourceByName($datasource_name);
if (!$dataSource) {
throw new DataSourceNotFoundException(E::ts("Requires data source '%1' which could not be found. Did you rename or deleted the data source?", [1 => $datasource_name]));
......@@ -368,7 +370,8 @@ abstract class AbstractToken implements OutputInterface, TokenOutput {
if (is_array($idsToUse)) {
$operator = 'IN';
}
$whereClause = new SqlDataFlow\SimpleWhereClause($dataFlow->getName(), $fieldSpecification->name, $operator, $idsToUse, $fieldSpecification->type);
$tableAlias = $this->getTableAlias($dataFlow);
$whereClause = new SqlDataFlow\SimpleWhereClause($tableAlias, $fieldSpecification->name, $operator, $idsToUse, $fieldSpecification->type, FALSE);
$dataFlow->addWhereClause($whereClause);
}
......@@ -383,5 +386,21 @@ abstract class AbstractToken implements OutputInterface, TokenOutput {
$dataProcessorClass->getDataFlow()->setOffset(0);
}
/**
* Returns the table alias of a sql data flow.
*
* @param \Civi\DataProcessor\DataFlow\SqlDataFlow $dataFlow
* @return string|null
*/
protected function getTableAlias(SqlDataFlow $dataFlow) {
$tableAlias = $dataFlow->getName();
if ($dataFlow instanceof SqlTableDataFlow) {
$tableAlias = $dataFlow->getTableAlias();
} elseif ($dataFlow instanceof CombinedSqlDataFlow) {
$tableAlias = $dataFlow->getPrimaryTableAlias();
}
return $tableAlias;
}
}
<?php
/**
* @author Jaap Jansma <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
namespace Civi\DataProcessorTokenOutput\Output;
use CRM_DataprocessorTokenOutput_ExtensionUtil as E;
class CaseToken extends AbstractToken {
/**
* Array containing all the related participant ids
*
* This property is set when executed from an participant search action.
*
* @var array
*/
private static $_caseIds = null;
/**
* Function to set a different contact ID to be used in the data processor.
* This function is here so child classes can override it.
*
* @param $contactId
* @param $configuration
*
* @return mixed
*/
protected function getIdForToken($contactId, $values, $configuration) {
if (isset($values['caseId'])) {
return $values['caseId'];
} elseif (isset($values['case_id'])) {
return $values['case_id'];
} elseif (isset($values['extra_data']['case']['id'])) {
// Coming from CiviRules
return $values['extra_data']['case']['id'];
}
return false;
}
/**
* Returns the title of the ID field.
*
* @return String
*/
protected function getIdFieldTitle() {
return E::ts('Case ID Field');
}
/**
* @return string
*/
protected function getIdFieldName() {
return 'case_id_field';
}
}
......@@ -13,8 +13,8 @@
<url desc="Documentation">https://lab.civicrm.org/extensions/dataprocessor-token-output/blob/master/README.md</url>
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate>2021-03-24</releaseDate>
<version>1.7</version>
<releaseDate>2021-10-08</releaseDate>
<version>1.8</version>
<develStage>stable</develStage>
<compatibility>
<ver>5.13</ver>
......
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