Commit 143f3f49 authored by jaapjansma's avatar jaapjansma
Browse files

Added filtering on Contact (sub) type on the contact filter.

parent 7ed3194a
......@@ -3,6 +3,7 @@
* Search tasks (eg. Export) work with Member,Contribute,Participant,Case...
* Added source to retrieve the owner membership, when owner membership is not set (meaning it is already the primary) then it will return itself.
* Added date filter to filter date with the PHP Date Format.
* Added filtering on Contact (sub) type on the contact filter.
# Version 1.3.0
......
......@@ -72,6 +72,22 @@ class ContactFilter extends AbstractFieldFilterHandler {
'multiple' => true,
));
$contactTypesApi = civicrm_api3('ContactType', 'get',array('is_active' => 1, 'options' => array('limit' => 0)));
$contactTypes = array();
foreach($contactTypesApi['values'] as $contactType) {
$contactTypeName = $contactType['name'];
if (isset($contactType['parent_id']) && $contactType['parent_id']) {
$contactTypeName = 'sub_'. $contactTypeName;
}
$contactTypes[$contactTypeName] = $contactType['label'];
}
$form->add('select', 'limit_contact_types', E::ts('Limit to Contact Type(s)'), $contactTypes, false, array(
'style' => 'min-width:250px',
'class' => 'crm-select2 huge',
'placeholder' => E::ts('- All contact types -'),
'multiple' => true,
));
if (isset($filter['configuration'])) {
$configuration = $filter['configuration'];
$defaults = array();
......@@ -81,6 +97,9 @@ class ContactFilter extends AbstractFieldFilterHandler {
if (isset($configuration['limit_groups'])) {
$defaults['limit_groups'] = $configuration['limit_groups'];
}
if (isset($configuration['limit_contact_types'])) {
$defaults['limit_contact_types'] = $configuration['limit_contact_types'];
}
$form->setDefaults($defaults);
}
}
......@@ -107,6 +126,7 @@ class ContactFilter extends AbstractFieldFilterHandler {
$configuration['field'] = $field;
$configuration['datasource'] = $datasource;
$configuration['limit_groups'] = isset($submittedValues['limit_groups']) ? $submittedValues['limit_groups'] : false;
$configuration['limit_contact_types'] = isset($submittedValues['limit_contact_types']) ? $submittedValues['limit_contact_types'] : false;
return $configuration;
}
......@@ -145,17 +165,37 @@ class ContactFilter extends AbstractFieldFilterHandler {
'placeholder' => E::ts('- select -'),
]);
$api_params = array();
if (!empty($this->configuration['limit_groups'])) {
$api_params['group'] = ['IN' => $this->configuration['limit_groups']];
}
$limitContactTypes = array();
$limitContactSubTypes = array();
if (isset($this->configuration['limit_contact_types']) && is_array($this->configuration['limit_contact_types'])) {
foreach($this->configuration['limit_contact_types'] as $limit_contact_type) {
if (stripos($limit_contact_type, 'sub_') === 0) {
// This is a subtype
$limitContactSubTypes[] = substr($limit_contact_type, 4);
} else {
$limitContactTypes[] = $limit_contact_type;
}
}
}
if (count($limitContactTypes)) {
$api_params['contact_type'] = ['IN' => $limitContactTypes];
}
if (count($limitContactSubTypes)) {
$api_params['contact_sub_type'] = ['IN' => $limitContactSubTypes];
}
$props = array(
'placeholder' => E::ts('Select a contact'),
'entity' => 'Contact',
'api' => array('params' => $api_params),
'create' => false,
'multiple' => true,
'style' => $minWidth,
'class' => $sizeClass,
);
if (!empty($this->configuration['limit_groups'])) {
$props['api'] = ['params' => ['group' => ['IN' => $this->configuration['limit_groups']]]];
}
$form->addEntityRef( "{$alias}_value", '', $props);
if (isset($defaultFilterValue['op'])) {
......
......@@ -9,4 +9,9 @@
<div class="content">{$form.limit_groups.html}</div>
<div class="clear"></div>
</div>
{/crmScope}
\ No newline at end of file
<div class="crm-section">
<div class="label">{$form.limit_contact_types.label}</div>
<div class="content">{$form.limit_contact_types.html}</div>
<div class="clear"></div>
</div>
{/crmScope}
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