Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
extensions
Call Next Dashlet
Commits
e370c570
Commit
e370c570
authored
Apr 16, 2021
by
Christian Wach
⚽
Browse files
Create custom Activity Status on install/enable
parent
0307d9c8
Changes
1
Hide whitespace changes
Inline
Side-by-side
callnext.php
View file @
e370c570
...
...
@@ -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.
*
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment