Skip to content
Snippets Groups Projects
Commit 775a747f authored by jaapjansma's avatar jaapjansma
Browse files

Added tag as a field and data source

parent 8f1f343e
No related branches found
No related tags found
No related merge requests found
# Version 1.21 (not yet released)
# Version 1.21
* Added contribution ID to the participant data source so that you can link a contribution and an event registration.
* Added a field for contact tags.
* Added a data source for entity tag and tag.
# Version 1.20
......
......@@ -102,6 +102,8 @@ class Factory {
$this->addDataSource('group', new Definition('Civi\DataProcessor\Source\Group\GroupSource'), E::ts('Group'));
$this->addDataSource('group_contact', new Definition('Civi\DataProcessor\Source\Group\GroupContactSource'), E::ts('Contacts in a group'));
$this->addDataSource('group_contact_cache', new Definition('Civi\DataProcessor\Source\Group\SmartGroupContactSource'), E::ts('Contacts in a smart group'));
$this->addDataSource('tag', new Definition('Civi\DataProcessor\Source\Tag\TagSource'), E::ts('Tag'));
$this->addDataSource('entity_tag', new Definition('Civi\DataProcessor\Source\Tag\EntityTagSource'), E::ts('Entity Tag (Link between an entity and a tag)'));
$this->addDataSource('email', new Definition('Civi\DataProcessor\Source\Contact\EmailSource'), E::ts('E-mail'));
$this->addDataSource('address', new Definition('Civi\DataProcessor\Source\Contact\AddressSource'), E::ts('Address'));
$this->addDataSource('phone', new Definition('Civi\DataProcessor\Source\Contact\PhoneSource'), E::ts('Phone'));
......@@ -176,6 +178,7 @@ class Factory {
$this->addOutputHandler('case_roles', new Definition('Civi\DataProcessor\FieldOutputHandler\CaseRolesFieldOutputHandler'), E::ts('Case Roles'));
$this->addOutputHandler('manage_case_link', new Definition('Civi\DataProcessor\FieldOutputHandler\ManageCaseLinkFieldOutputHandler'), E::ts('Link to manage case'));
$this->addOutputHandler('groups_of_contact', new Definition('Civi\DataProcessor\FieldOutputHandler\GroupsOfContactFieldOutputHandler'), E::ts('Display the groups of a contact'));
$this->addOutputHandler('tags_of_contact', new Definition('Civi\DataProcessor\FieldOutputHandler\TagsOfContactFieldOutputHandler'), E::ts('Display the tags of a contact'));
$this->addOutputHandler('event_repeating_info', new Definition('Civi\DataProcessor\FieldOutputHandler\EventRepeatingInfoFieldOutputHandler'), E::ts('Display info about repeating event'));
$this->addOutputHandler('event_participants', new Definition('Civi\DataProcessor\FieldOutputHandler\EventParticipantsFieldOutputHandler'), E::ts('List participants'));
$this->addOutputHandler('event_participant_count', new Definition('Civi\DataProcessor\FieldOutputHandler\EventParticipantsCountFieldOutputHandler'), E::ts('Participant Count'));
......
<?php
/**
* @author Jaap Jansma <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
namespace Civi\DataProcessor\FieldOutputHandler;
use Civi\DataProcessor\ProcessorType\AbstractProcessorType;
use CRM_Dataprocessor_ExtensionUtil as E;
use Civi\DataProcessor\Source\SourceInterface;
use Civi\DataProcessor\DataSpecification\FieldSpecification;
use Civi\DataProcessor\FieldOutputHandler\FieldOutput;
use Civi\DataProcessor\Exception\DataSourceNotFoundException;
use Civi\DataProcessor\Exception\FieldNotFoundException;
class TagsOfContactFieldOutputHandler extends AbstractFieldOutputHandler {
/**
* @var \Civi\DataProcessor\Source\SourceInterface
*/
protected $dataSource;
/**
* @var SourceInterface
*/
protected $contactIdSource;
/**
* @var FieldSpecification
*/
protected $contactIdField;
/**
* @var FieldSpecification
*/
protected $outputFieldSpecification;
/**
* @return \Civi\DataProcessor\DataSpecification\FieldSpecification
*/
public function getOutputFieldSpecification() {
return $this->outputFieldSpecification;
}
/**
* Returns the data type of this field
*
* @return String
*/
protected function getType() {
return 'String';
}
/**
* Initialize the processor
*
* @param String $alias
* @param String $title
* @param array $configuration
* @param \Civi\DataProcessor\ProcessorType\AbstractProcessorType $processorType
*/
public function initialize($alias, $title, $configuration) {
list($this->contactIdSource, $this->contactIdField) = $this->initializeField($configuration['field'], $configuration['datasource'], $alias);
$this->outputFieldSpecification = new FieldSpecification($this->contactIdField->name, 'String', $title, null, $alias);
}
/**
* Returns the formatted value
*
* @param $rawRecord
* @param $formattedRecord
*
* @return \Civi\DataProcessor\FieldOutputHandler\FieldOutput
*/
public function formatField($rawRecord, $formattedRecord) {
$contactId = $rawRecord[$this->contactIdField->alias];
$contactTags = \CRM_Core_BAO_EntityTag::getContactTags($contactId);
$allTags = \CRM_Core_BAO_Tag::getTagsUsedFor('civicrm_contact', FALSE);
$rawValues = array();
$formattedValues = array();
if (!empty($contactTags) && is_array($contactTags)) {
foreach($contactTags as $tagId => $tagName) {
$rawValues[] = $tagName;
$color = "";
if (isset($allTags[$tagId]['color'])) {
$color = "background-color: ".$allTags[$tagId]['color']."; color: ".\CRM_Utils_Color::getContrast($allTags[$tagId]['color']);
}
$formattedValues[] = "<span class=\"crm-tag-item\" style=\"{$color}\" title=\"{$allTags[$tagId]['description']}\">{$tagName}</span>";
}
}
$output = new HTMLFieldOutput($rawValues);
$output->formattedValue = implode(", ", $rawValues);
$output->setHtmlOutput(implode(" ", $formattedValues));
return $output;
}
/**
* Returns true when this handler has additional configuration.
*
* @return bool
*/
public function hasConfiguration() {
return true;
}
/**
* When this handler has additional configuration you can add
* the fields on the form with this function.
*
* @param \CRM_Core_Form $form
* @param array $field
*/
public function buildConfigurationForm(\CRM_Core_Form $form, $field=array()) {
$fieldSelect = \CRM_Dataprocessor_Utils_DataSourceFields::getAvailableFieldsInDataSources($field['data_processor_id']);
$form->add('select', 'contact_id_field', E::ts('Contact ID Field'), $fieldSelect, true, array(
'style' => 'min-width:250px',
'class' => 'crm-select2 huge',
'placeholder' => E::ts('- select -'),
));
if (isset($field['configuration'])) {
$configuration = $field['configuration'];
$defaults = array();
if (isset($configuration['field']) && isset($configuration['datasource'])) {
$defaults['contact_id_field'] = $configuration['datasource'] . '::' . $configuration['field'];
}
$form->setDefaults($defaults);
}
}
/**
* When this handler has configuration specify the template file name
* for the configuration form.
*
* @return false|string
*/
public function getConfigurationTemplateFileName() {
return "CRM/Dataprocessor/Form/Field/Configuration/TagsOfContactFieldOutputHandler.tpl";
}
/**
* Process the submitted values and create a configuration array
*
* @param $submittedValues
* @return array
*/
public function processConfiguration($submittedValues) {
list($datasource, $field) = explode('::', $submittedValues['contact_id_field'], 2);
$configuration['field'] = $field;
$configuration['datasource'] = $datasource;
return $configuration;
}
}
<?php
/**
* @author Jaap Jansma <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
namespace Civi\DataProcessor\Source\Tag;
use Civi\DataProcessor\Source\AbstractCivicrmEntitySource;
use CRM_Dataprocessor_ExtensionUtil as E;
class EntityTagSource extends AbstractCivicrmEntitySource {
/**
* Returns the entity name
*
* @return String
*/
protected function getEntity() {
return 'EntityTag';
}
/**
* Returns the table name of this entity
*
* @return String
*/
protected function getTable() {
return 'civicrm_entity_tag';
}
}
<?php
/**
* @author Jaap Jansma <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
namespace Civi\DataProcessor\Source\Tag;
use Civi\DataProcessor\Source\AbstractCivicrmEntitySource;
use CRM_Dataprocessor_ExtensionUtil as E;
class TagSource extends AbstractCivicrmEntitySource {
/**
* Returns the entity name
*
* @return String
*/
protected function getEntity() {
return 'Tag';
}
/**
* Returns the table name of this entity
*
* @return String
*/
protected function getTable() {
return 'civicrm_tag';
}
}
......@@ -14,8 +14,8 @@
<url desc="Documentation">https://lab.civicrm.org/extensions/dataprocessor/blob/master/README.md</url>
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate>2020-10-29</releaseDate>
<version>1.21-dev</version>
<releaseDate>2020-11-27</releaseDate>
<version>1.21</version>
<develStage>stable</develStage>
<compatibility>
<ver>4.7</ver>
......
{crmScope extensionKey='dataprocessor'}
<div class="crm-section">
<div class="label">{$form.contact_id_field.label}</div>
<div class="content">{$form.contact_id_field.html}</div>
<div class="clear"></div>
</div>
{/crmScope}
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