Commit 842593ea authored by jaapjansma's avatar jaapjansma
Browse files

Added XCM Profiles

parent 77e2aa2a
......@@ -59,6 +59,9 @@ class CRM_Civiconfig_Config {
if (CRM_Civiconfig_Utils::isExtensionInstalled('de.systopia.identitytracker')) {
$supportedEntities[] = 'IdentityTrackerMapping';
}
if (CRM_Civiconfig_Utils::isExtensionInstalled('de.systopia.xcm')) {
$supportedEntities[] = 'XcmProfile';
}
return $supportedEntities;
}
......
<?php
/**
* Class for XcmProfile configuration
*
* @author Erik Hommel (CiviCooP) <erik.hommel@civicoop.org>
* @date 3 Feb 2016
* @license AGPL-3.0
*/
class CRM_Civiconfig_Entity_XcmProfile extends CRM_Civiconfig_Entity {
/**
* CRM_Civiconfig_RuleGroup constructor.
*/
public function __construct() {
parent::__construct('XcmProfile');
}
/**
* Function to find an existing entity based on the entity's parameters.
*
* If no existing entity is found, an empty array is returned.
* This default implementation searches on the name, but you can override it.
*
* @param array $params
* @return array
* @access public
* @static
*/
public function getExisting(array $params) {
try {
$name = $params['name'];
$profiles = \Civi::settings()->get('xcm_config_profiles');
if (isset($profiles[$name])) {
return $profiles[$name];
}
} catch (\CiviCRM_API3_Exception $ex) {
// Do nothing
}
return [];
}
/**
* Method to create or update any entity
*
* @param array $params Parameters
* @return int id of created/updated entity
* @throws Exception when error from API Entity Create
*/
public function create(array $params) {
$existingEntity = $this->getExisting($params);
// First prepare, then validate, because for e.g. event types, the
// option_group_id (which should be set) is set by the prepare function.
$this->prepareParams($params, $existingEntity);
$this->validateCreateParams($params);
try {
$name = $params['name'];
$profiles = \Civi::settings()->get('xcm_config_profiles');
$profiles[$name] = $params;
\Civi::settings()->set('xcm_config_profiles', $profiles);
} catch (\Exception $ex) {
throw new \CRM_Civiconfig_EntityException("Could not create or update {$this->entity} type with name "
.$params['name'].". Error from API {$this->entity}.Create: " . $ex->getMessage() . '. Params: '.json_encode($params));
}
return $params['name'];
}
/**
* Manipulate $params before entity creation.
*
* @param array $params params that will be used for entity creation
* @param array $existing existing entity (if available)
*/
protected function prepareParams(array &$params, array $existing = []) {
if (!isset($params['title'])) {
$params['title'] = ucfirst($params['name']);
}
$params['options']['default_location_type'] = $this->getLocationType($params['options']['default_location_type'], $params['name']);
$params['options']['diff_current_location_type'] = $this->getLocationType($params['options']['diff_current_location_type'], $params['name']);
$params['options']['diff_old_location_type'] = $this->getLocationType($params['options']['diff_old_location_type'], $params['name']);
$params['options']['primary_phone_type'] = $this->getPhoneType($params['options']['primary_phone_type'], $params['name']);
$params['options']['secondary_phone_type'] = $this->getPhoneType($params['options']['secondary_phone_type'], $params['name']);
$params['options']['duplicates_activity'] = $this->getActivityType($params['options']['duplicates_activity'], $params['name']);
$params['options']['diff_activity'] = $this->getActivityType($params['options']['diff_activity'], $params['name']);
$params['postprocessing']['matched_add_activity'] = $this->getActivityType($params['postprocessing']['matched_add_activity'], $params['name']);
$params['postprocessing']['matched_add_activity_status'] = $this->getActivityStatus($params['postprocessing']['matched_add_activity_status'], $params['name']);
$params['postprocessing']['created_add_activity'] = $this->getActivityType($params['postprocessing']['created_add_activity'], $params['name']);
$params['postprocessing']['created_add_activity_status'] = $this->getActivityStatus($params['postprocessing']['created_add_activity_status'], $params['name']);
foreach($params['rules'] as $rule_name => $rule) {
$params['rules'][$rule_name] = $this->getDeduleRule($rule, $params['name']);
}
return $params;
}
/**
* Return the dedupe rule id
*
* @param $dedupe_rule
* @param $name
*
* @return array
* @throws \CRM_Civiconfig_EntityException
*/
protected function getDeduleRule($dedupe_rule, $name) {
if (!is_numeric($dedupe_rule) && $dedupe_rule && stripos($dedupe_rule, 'DEDUPE_')===0) {
try {
$dedupe_rule_name = substr($dedupe_rule, 7);
$dedupe_rule_id = civicrm_api3('RuleGroup', 'getvalue', [
'name' => $dedupe_rule_name,
'return' => 'id'
]);
$dedupe_rule = 'DEDUPE_'.$dedupe_rule_id;
} catch (\CiviCRM_API3_Exception $ex) {
throw new \CRM_Civiconfig_EntityException("Could not create or update {$this->entity} type with name "
.$name.". Error from API {$this->entity}.Create: " . $ex->getMessage() . '.');
}
}
return $dedupe_rule;
}
/**
* Return the location type id
*
* @param $location_type
* @param $name
*
* @return array
* @throws \CRM_Civiconfig_EntityException
*/
protected function getLocationType($location_type, $name) {
if (!is_numeric($location_type) && $location_type) {
try {
$location_type = civicrm_api3('LocationType', 'getvalue', [
'name' => $location_type,
'return' => 'id'
]);
} catch (\CiviCRM_API3_Exception $ex) {
throw new \CRM_Civiconfig_EntityException("Could not create or update {$this->entity} type with name "
.$name.". Error from API {$this->entity}.Create: " . $ex->getMessage() . '.');
}
}
return $location_type;
}
/**
* Return the phone type id
*
* @param $phone_type
* @param $name
*
* @return array
* @throws \CRM_Civiconfig_EntityException
*/
protected function getPhoneType($phone_type, $name) {
if (!is_numeric($phone_type) && $phone_type) {
try {
$phone_type = civicrm_api3('OptionValue', 'getvalue', [
'name' => $phone_type,
'option_group_id' => 'phone_type',
'return' => 'value'
]);
} catch (\CiviCRM_API3_Exception $ex) {
throw new \CRM_Civiconfig_EntityException("Could not create or update {$this->entity} type with name "
.$name.". Error from API {$this->entity}.Create: " . $ex->getMessage() . '.');
}
}
return $phone_type;
}
/**
* Return the activity type id
*
* @param $activity_type
* @param $name
*
* @return array
* @throws \CRM_Civiconfig_EntityException
*/
protected function getActivityType($activity_type, $name) {
if (!is_numeric($activity_type) && $activity_type) {
try {
$activity_type = civicrm_api3('OptionValue', 'getvalue', [
'name' => $activity_type,
'option_group_id' => 'activity_type',
'return' => 'value'
]);
} catch (\CiviCRM_API3_Exception $ex) {
throw new \CRM_Civiconfig_EntityException("Could not create or update {$this->entity} type with name "
.$name.". Error from API {$this->entity}.Create: " . $ex->getMessage() . '.');
}
}
return $activity_type;
}
/**
* Return the activity status id
*
* @param $activity_status
* @param $name
*
* @return array
* @throws \CRM_Civiconfig_EntityException
*/
protected function getActivityStatus($activity_status, $name) {
if (!is_numeric($activity_status) && $activity_status) {
try {
$activity_status = civicrm_api3('OptionValue', 'getvalue', [
'name' => $activity_status,
'option_group_id' => 'activity_status',
'return' => 'value'
]);
} catch (\CiviCRM_API3_Exception $ex) {
throw new \CRM_Civiconfig_EntityException("Could not create or update {$this->entity} type with name "
.$name.". Error from API {$this->entity}.Create: " . $ex->getMessage() . '.');
}
}
return $activity_status;
}
/**
* Method to validate params for create.
*
* Override this method if you want custom validation for the entity params.
*
* @param array $params
* @throws Exception when mandatory param not found
*/
public function validateCreateParams($params) {
parent::validateCreateParams($params);
}
}
{
"event_registration": {
"name": "event_registration",
"label": "Event Registration",
"options": {
"fill_address": "2",
"fill_fields_multivalue": "",
"fill_details": [],
"fill_details_primary": "",
"override_details": [],
"override_details_primary": "",
"default_location_type": "Home",
"primary_phone_type": "Phone",
"secondary_phone_type": "Mobile",
"picker": "min",
"duplicates_activity": "check_contact",
"duplicates_subject": "Duplicate contact",
"diff_handler": "diff",
"diff_activity": "check_contact",
"diff_activity_subject": "",
"diff_processing": "1",
"diff_current_location_type": "1",
"diff_old_location_type": "0",
"fill_fields": [
"first_name",
"last_name"
],
"override_fields": [],
"case_insensitive": "1",
"match_contact_id": ""
},
"rules": {
"rule_1": "DEDUPE_Matricule",
"rule_2": "0",
"rule_3": "0",
"rule_4": "0",
"rule_5": "0",
"rule_6": "0",
"rule_7": "0",
"rule_8": "0",
"rule_9": "0"
},
"postprocessing": {
"matched_add_group": "0",
"matched_add_tag": "0",
"matched_add_activity": "0",
"matched_add_activity_subject": "",
"matched_add_activity_template": "0",
"matched_add_activity_status": "Completed",
"matched_add_activity_campaign": "",
"created_add_group": "0",
"created_add_tag": "0",
"created_add_activity": "0",
"created_add_activity_subject": "",
"created_add_activity_template": "0",
"created_add_activity_status": "Completed",
"created_add_activity_campaign": ""
}
}
}
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