Skip to content

Commit

Permalink
[#1][#3][#4] merged new developments
Browse files Browse the repository at this point in the history
  • Loading branch information
bjendres committed Jul 7, 2020
2 parents cc2bfc8 + c3bcdb5 commit a7d3172
Show file tree
Hide file tree
Showing 8 changed files with 705 additions and 177 deletions.
3 changes: 1 addition & 2 deletions CRM/Contactsource/ActivityCreation.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public static function shouldInject($form) {
return false;
}

// TODO: setting to turn it off?
return true;
return CRM_Contactsource_Configuration::formInjectionEnabled();
}


Expand Down
143 changes: 100 additions & 43 deletions CRM/Contactsource/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,56 +15,113 @@
+--------------------------------------------------------*/


use CRM_Contactsource_ExtensionUtil as E;

/**
* Collection of upgrade steps.
*/
class CRM_Contactsource_Configuration {
class CRM_Contactsource_Configuration
{

const CONTACT_SOURCE_ACTIVITY_TYPE = 'contact_source';
const CONTACT_SOURCE_FIELD_LENGTH = 255;

const CONTACT_SOURCE_ACTIVITY_TYPE = 'contact_source';
protected static $activity_type_id = NULL;

protected static $activity_type_id = NULL;
/**
* Get the extensions "First Contact" activity type ID
*/
public static function getActivityTypeID()
{
if (self::$activity_type_id === NULL) {
$activity_types = civicrm_api3('OptionValue', 'get', [
'option_group_id' => 'activity_type',
'name' => self::CONTACT_SOURCE_ACTIVITY_TYPE
]);
switch ($activity_types['count']) {
case 0:
// doesn't exit yet => create
civicrm_api3('OptionValue', 'create', [
'option_group_id' => 'activity_type',
'name' => self::CONTACT_SOURCE_ACTIVITY_TYPE,
'label' => E::ts("First Contact"),
'is_active' => 1,
'is_reserved' => 1,
'filter' => 0,
'icon' => 'fa-user-plus']);
return self::getActivityTypeID();

/**
* Get the extensions "First Contact" activity type ID
*/
public static function getActivityTypeID() {
if (self::$activity_type_id === NULL) {
$activity_types = civicrm_api3('OptionValue', 'get', [
'option_group_id' => 'activity_type',
'name' => self::CONTACT_SOURCE_ACTIVITY_TYPE
]);
switch ($activity_types['count']) {
case 0:
// doesn't exit yet => create
civicrm_api3('OptionValue', 'create', [
'option_group_id' => 'activity_type',
'name' => self::CONTACT_SOURCE_ACTIVITY_TYPE,
'label' => E::ts("First Contact"),
'is_active' => 1,
'is_reserved' => 1,
'filter' => 0,
'icon' => 'fa-user-plus']);
return self::getActivityTypeID();
case 1:
// found one
$activity_type = reset($activity_types['values']);
if (empty($activity_type['is_active'])) {
// still needs to be activated
civicrm_api3('OptionValue', 'create', [
'id' => $activity_type['id'],
'is_active' => 1]);
}
self::$activity_type_id = $activity_type['value'];
break;

case 1:
// found one
$activity_type = reset($activity_types['values']);
if (empty($activity_type['is_active'])) {
// still needs to be activated
civicrm_api3('OptionValue', 'create', [
'id' => $activity_type['id'],
'is_active' => 1]);
}
self::$activity_type_id = $activity_type['value'];
break;
default:
// found multiple ones
throw new Exception("Multiple activity types of name '" . self::CONTACT_SOURCE_ACTIVITY_TYPE . "' found. Please fix activity_type option group!");
}
}
return self::$activity_type_id;
}

/**
* Get the default contact source activity subject.
*
* @return string
* '': don't fill at all
* 'campaign_title': fill with campaign title
*
*/
public static function getDefaultActivitySubject()
{
$value = Civi::settings()->get('contact_source_subject');
if (empty($value)) {
return '';
} else {
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 getContactSourceSyncMode()
{
$value = Civi::settings()->get('contact_source_sync');
if (empty($value)) {
return '';
} else {
return $value;
}
}

/**
* Is the injection of the artificial source field in the contact summary activated?
*/
public static function sourceInjectionEnabled()
{
return !empty(Civi::settings()->get('contact_source_inject_field'));
}

default:
// found multiple ones
throw new Exception("Multiple activity types of name '" . self::CONTACT_SOURCE_ACTIVITY_TYPE . "' found. Please fix activity_type option group!");
}
/**
* Should the contact source be entered in the contact create form
*/
public static function formInjectionEnabled()
{
return !empty(Civi::settings()->get('contact_source_inject_form'));
}
return self::$activity_type_id;
}
}
Loading

0 comments on commit a7d3172

Please sign in to comment.