Skip to content

Commit

Permalink
[#3] added option to enable/disable source injection
Browse files Browse the repository at this point in the history
  • Loading branch information
bjendres committed Jun 23, 2020
1 parent 6e816d3 commit 28ec4f8
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
17 changes: 17 additions & 0 deletions CRM/Contactsource/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,21 @@ public static function getContactSourceSyncMode()
return $value;
}
}

/**
* Get the mode to sync the contact source activities to the
* contact's source field
*
* @return string
* '' => "disabled"
* 'first_campaign' => "First contact (campaign)"
* 'first_subject' => "First contact (subject)"
* 'all_campaign' => "All contacts (campaign)"
* 'all_subject' => "All contacts (subject)"
*
*/
public static function sourceInjectionEnabled()
{
return !empty(Civi::settings()->get('contact_source_inject'));
}
}
20 changes: 11 additions & 9 deletions CRM/Contactsource/Contactsource.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@ class CRM_Contactsource_Contactsource
*/
public static function injectInPage($page)
{
$pageName = $page->getVar('_name');
// only if contact summary
if ($pageName == 'CRM_Contact_Page_View_Summary') {
$contact_id = $page->getVar('_contactId');
$contact_source_string = self::getContactSourceString($contact_id, 2);
if ($contact_source_string) {
$page->assign('contact_source_string', $contact_source_string);
CRM_Core_Region::instance('page-body')->add(array(
'template' => 'CRM/Contactsource/Contactsource.tpl'));
if (CRM_Contactsource_Configuration::sourceInjectionEnabled()) {
$pageName = $page->getVar('_name');
// only if contact summary
if ($pageName == 'CRM_Contact_Page_View_Summary') {
$contact_id = $page->getVar('_contactId');
$contact_source_string = self::getContactSourceString($contact_id, 2);
if ($contact_source_string) {
$page->assign('contact_source_string', $contact_source_string);
CRM_Core_Region::instance('page-body')->add(array(
'template' => 'CRM/Contactsource/Contactsource.tpl'));
}
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions CRM/Contactsource/Form/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class CRM_Contactsource_Form_Settings extends CRM_Core_Form
public function buildQuickForm()
{
// synchronise contact source
$this->add(
'checkbox',
'contact_source_inject',
E::ts("Inject additional source field")
);
$this->add(
'select',
'contact_source_sync',
Expand Down Expand Up @@ -72,6 +77,7 @@ public function buildQuickForm()

// set current values
$this->setDefaults([
'contact_source_inject' => CRM_Contactsource_Configuration::sourceInjectionEnabled(),
'contact_source_sync' => Civi::settings()->get('contact_source_sync'),
'contact_source_subject' => CRM_Contactsource_Configuration::getDefaultActivitySubject(),
]);
Expand All @@ -83,6 +89,7 @@ public function postProcess()
{
// first: store values
$values = $this->exportValues();
Civi::settings()->set('contact_source_inject', CRM_Utils_Array::value('contact_source_inject', $values, 0));
Civi::settings()->set('contact_source_sync', CRM_Utils_Array::value('contact_source_sync', $values, ''));
Civi::settings()->set('contact_source_subject', CRM_Utils_Array::value('contact_source_subject', $values, ''));

Expand Down
8 changes: 7 additions & 1 deletion templates/CRM/Contactsource/Form/Settings.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@

{crmScope extensionKey='de.systopia.contactsource'}
<h3>{ts}Fill Contact's Source Field{/ts}</h3>
<div class="crm-section">
<div class="crm-section">
<div class="label">{$form.contact_source_inject.label}</div>
<div class="content">{$form.contact_source_inject.html}</div>
<div class="clear"></div>
</div>

<div class="crm-section">
<div class="label">{$form.contact_source_sync.label}</div>
<div class="content">{$form.contact_source_sync.html}</div>
<div class="clear"></div>
Expand Down

0 comments on commit 28ec4f8

Please sign in to comment.