Commit e370c570 authored by Christian Wach's avatar Christian Wach
Browse files

Create custom Activity Status on install/enable

parent 0307d9c8
......@@ -168,6 +168,9 @@ function callnext_civicrm_install() {
// Create the dashlet if it doesn't exist.
callnext_dashlet_get();
// Create the Activity Status if it doesn't exist.
callnext_activity_status_get();
_callnext_civix_civicrm_install();
}
......@@ -207,6 +210,9 @@ function callnext_civicrm_enable() {
// Create the dashlet if it doesn't exist.
callnext_dashlet_get();
// Create the Activity Status if it doesn't exist.
callnext_activity_status_get();
_callnext_civix_civicrm_enable();
}
......@@ -295,6 +301,160 @@ function callnext_civicrm_entityTypes(&$entityTypes) {
_callnext_civix_civicrm_entityTypes($entityTypes);
}
/**
* Get our Activity Status Type Option Group.
*
* @since 2.0.1
*
* @return int|bool $group_id Numeric ID of Option Group, or FALSE if not found.
*/
function callnext_activity_status_group_id_get() {
try {
// Get the "Activity Status Type" option group.
$result = civicrm_api3('OptionGroup', 'get', [
'sequential' => 1,
'name' => "activity_status",
]);
}
catch (CiviCRM_API3_Exception $e) {
// Do something if API call fails.
error_log(print_r([
'method' => __METHOD__,
'message' => $e->getMessage(),
], TRUE));
// Show a message.
CRM_Core_Error::debug_log_message($e->getMessage());
return FALSE;
}
// There should be only one entry, so return its ID.
if (!empty($result['values'])) {
$group = array_pop($result['values']);
return $group['id'];
}
// Fallback.
return FALSE;
}
/**
* Get our custom Activity Status.
*
* @since 2.0.1
*
* @return array|bool $status Array of status data, or FALSE if not found.
*/
function callnext_activity_status_get() {
// Get the Option Group ID.
$option_group_id = callnext_activity_status_group_id_get();
// Bail on error.
if ($option_group_id === FALSE) {
return FALSE;
}
try {
// Get the custom Activity Status.
$result = civicrm_api3('OptionValue', 'get', [
'sequential' => 1,
'option_group_id' => $option_group_id,
'name' => 'Awaiting Response',
]);
}
catch (CiviCRM_API3_Exception $e) {
// Do something if API call fails.
error_log(print_r([
'method' => __METHOD__,
'message' => $e->getMessage(),
], TRUE));
// Show a message.
CRM_Core_Error::debug_log_message($e->getMessage());
return FALSE;
}
// Create it if it isn't there.
if (empty($result['values'])) {
$option_value = callnext_activity_status_create();
}
// It's already there.
else {
$option_value = array_pop($result['values']);
}
// --<
return $option_value;
}
/**
* Create our custom Activity Status.
*
* @since 2.0.1
*
* @return array|bool $status Array of status data, or FALSE on failure.
*/
function callnext_activity_status_create() {
// Get the Option Group ID.
$option_group_id = callnext_activity_status_group_id_get();
// Bail on error.
if ($option_group_id === FALSE) {
return FALSE;
}
try {
// Create the custom Activity Status.
$result = civicrm_api3('OptionValue', 'create', [
'option_group_id' => $option_group_id,
'name' => 'Awaiting Response',
'label' => 'Awaiting Response',
'is_active' => 1,
]);
}
catch (CiviCRM_API3_Exception $e) {
// Do something if API call fails.
error_log(print_r([
'method' => __METHOD__,
'message' => $e->getMessage(),
], TRUE));
// Show a message.
CRM_Core_Error::debug_log_message($e->getMessage());
return FALSE;
}
// There should be only one entry, so return it.
if (!empty($result['values'])) {
return array_pop($result['values']);
}
// Fallback.
return FALSE;
}
/**
* Get our dashlet.
*
......
Supports Markdown
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