Commit d75445ec authored by jaapjansma's avatar jaapjansma

Added formatted address field

parent d34fe798
......@@ -2,7 +2,8 @@
* Changed Age field so aggeragation is working correctly.
* Changed Field Specification to allow more advanced mysql functions.
* Added Event Filter
* Added Event Filter.
* Added Formatted Address field.
# Version 1.6.0
......
......@@ -152,6 +152,7 @@ class Factory {
$this->addjoinType('simple_join', new Definition('Civi\DataProcessor\DataFlow\MultipleDataFlows\SimpleJoin'), E::ts('Select fields to join on'));
$this->addjoinType('simple_non_required_join', new Definition('Civi\DataProcessor\DataFlow\MultipleDataFlows\SimpleNonRequiredJoin'), E::ts('Select fields to join on (not required)'));
$this->addOutputHandler('raw', new Definition('Civi\DataProcessor\FieldOutputHandler\RawFieldOutputHandler'), E::ts('Raw field value'));
$this->addOutputHandler('formatted_address', new Definition('Civi\DataProcessor\FieldOutputHandler\FormattedAddressFieldOutputHandler'), E::ts('Formatted Address'));
$this->addOutputHandler('number', new Definition('Civi\DataProcessor\FieldOutputHandler\NumberFieldOutputHandler'), E::ts('Formatted Number field value'));
$this->addOutputHandler('date', new Definition('Civi\DataProcessor\FieldOutputHandler\DateFieldOutputHandler'), E::ts('Date field value'));
$this->addOutputHandler('age', new Definition('Civi\DataProcessor\FieldOutputHandler\AgeFieldOutputHandler'), E::ts('Age field value'));
......
<?php
/**
* @author Jaap Jansma <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
namespace Civi\DataProcessor\FieldOutputHandler;
use CRM_Dataprocessor_ExtensionUtil as E;
class FormattedAddressFieldOutputHandler extends AbstractSimpleFieldOutputHandler {
/**
* Returns the label of the field for selecting a field.
*
* This could be override in a child class.
*
* @return string
*/
protected function getFieldTitle() {
return E::ts('Address ID Field');
}
/**
* Returns the data type of this field
*
* @return String
*/
protected function getType() {
return 'String';
}
/**
* Returns the formatted value
*
* @param $rawRecord
* @param $formattedRecord
*
* @return \Civi\DataProcessor\FieldOutputHandler\FieldOutput
*/
public function formatField($rawRecord, $formattedRecord) {
$addressId = $rawRecord[$this->inputFieldSpec->alias];
$formattedAddress = "";
try {
$address = civicrm_api3('Address', 'getsingle', ['id' => $addressId]);
$formattedAddress = \CRM_Utils_Address::format($address);
} catch (\Exception $e) {
// Do nothing
}
$formattedValue = new HTMLFieldOutput($addressId);
$formattedValue->formattedValue = strip_tags($formattedAddress);
$formattedValue->setHtmlOutput($formattedAddress);
return $formattedValue;
}
}
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