Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AdminUI - Add Administer Scheduled Reminders page #26896

Merged
merged 4 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions CRM/ACL/BAO/ACL.php
Original file line number Diff line number Diff line change
Expand Up @@ -540,12 +540,16 @@ public static function getObjectTableOptions(): array {
];
}

public static function getObjectIdOptions($context, $params): array {
$tableName = $params['values']['object_table'] ?? NULL;
// Look up object_table if not known
if (!$tableName && !empty($params['values']['id'])) {
$tableName = CRM_Core_DAO::getFieldValue('CRM_ACL_DAO_ACL', $params['values']['id'], 'object_table');
}
/**
* Provides pseudoconstant list for `object_id` field.
*
* @param string $fieldName
* @param array $params
* @return array
*/
public static function getObjectIdOptions(string $fieldName, array $params): array {
$values = self::fillValues($params['values'], ['object_table']);
$tableName = $values['object_table'];
if (!$tableName) {
return [];
}
Expand Down
60 changes: 59 additions & 1 deletion CRM/Core/BAO/ActionSchedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,61 @@ public static function getMapping($identifier) {
return self::getMappings()[$identifier] ?? NULL;
}

/**
* Provides the pseudoconstant list for `mapping_id` field.
* @return array
*/
public static function getMappingOptions(): array {
return CRM_Utils_Array::collectMethod('getLabel', self::getMappings());
}

/**
* Provides pseudoconstant list for `entity_value` field.
* @return array
*/
public static function getEntityValueOptions(string $fieldName, array $params): array {
$values = self::fillValues($params['values'], ['mapping_id']);
if (!$values['mapping_id']) {
return [];
}
return self::getMapping($values['mapping_id'])->getValueLabels();
}

/**
* Provides pseudoconstant list for `entity_status` field.
* @return array
*/
public static function getEntityStatusOptions(string $fieldName, array $params): array {
$values = self::fillValues($params['values'], ['mapping_id', 'entity_value']);
if (!$values['mapping_id']) {
return [];
}
return self::getMapping($values['mapping_id'])->getStatusLabels($values['entity_value']);
}

/**
* Provides pseudoconstant list for `start_action_date` & `end_date` fields.
* @return array
*/
public static function getActionDateOptions(string $fieldName, array $params): array {
$values = self::fillValues($params['values'], ['mapping_id', 'entity_value']);
if (!$values['mapping_id']) {
return [];
}
return self::getMapping($values['mapping_id'])->getDateFields($values['entity_value']);
}

/**
* Provides pseudoconstant lists for `start_action_unit`, `repetition_frequency_unit` & `end_frequency_unit`.
* @return array
*/
public static function getDateUnits(string $fieldName, array $params): array {
$controlField = self::fields()[$fieldName]['html']['controlField'];
$values = self::fillValues($params['values'], [$controlField]);
$count = $values[$controlField] ?? 0;
return CRM_Core_SelectValues::getRecurringFrequencyUnits($count);
}

/**
* For each entity, get a list of entity-value labels.
*
Expand Down Expand Up @@ -137,7 +192,10 @@ public static function getList($filterMapping = NULL, $filterValue = NULL): arra
$list[$dao->id]['start_action_offset'] = $dao->start_action_offset;
$list[$dao->id]['start_action_unit'] = $dao->start_action_unit;
$list[$dao->id]['start_action_condition'] = $dao->start_action_condition;
$list[$dao->id]['entityDate'] = ucwords(str_replace('_', ' ', $dao->entityDate));
$list[$dao->id]['mapping_id'] = $dao->mapping_id;
$list[$dao->id]['entity_value'] = explode(CRM_Core_DAO::VALUE_SEPARATOR, $dao->entityValueIds);
$dateOptions = self::getActionDateOptions('start_action_date', ['values' => $list[$dao->id]]);
$list[$dao->id]['entityDate'] = $dateOptions[$dao->entityDate] ?? '';
$list[$dao->id]['absolute_date'] = $dao->absolute_date;
$list[$dao->id]['entity'] = $filterMapping->getLabel();
$list[$dao->id]['value'] = implode(', ', CRM_Utils_Array::subset(
Expand Down
4 changes: 2 additions & 2 deletions CRM/Core/BAO/CustomGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -2145,11 +2145,11 @@ public static function getExtendsEntityColumnValueOptions($context, $params) {
/**
* Loads pseudoconstant option values for the `extends_entity_column_id` field.
*
* @param string $context
* @param string $fieldName
* @param array $params
* @return array
*/
public static function getExtendsEntityColumnIdOptions($context = NULL, $params = []) {
public static function getExtendsEntityColumnIdOptions(string $fieldName = NULL, array $params = []) {
$props = $params['values'] ?? [];
$ogId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'custom_data_type', 'id', 'name');
$optionValues = CRM_Core_BAO_OptionValue::getOptionValuesArray($ogId);
Expand Down
42 changes: 42 additions & 0 deletions CRM/Core/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -3354,4 +3354,46 @@ public static function isComponentEnabled(): bool {
return !defined("$daoName::COMPONENT") || CRM_Core_Component::isEnabled($daoName::COMPONENT);
}

/**
* Given an incomplete record, attempt to fill missing field values from the database
*/
public static function fillValues(array $existingValues, $fieldsToRetrieve): array {
$idField = static::$_primaryKey[0];
// Ensure primary key is set
$existingValues += [$idField => NULL];
// It's hard to look things up without an ID! Check for another unique field to use:
if (!$existingValues[$idField] && is_callable([static::class, 'indices'])) {
foreach (static::indices(FALSE) as $index) {
if (!empty($index['unique']) && count($index['field']) === 1 && !empty($existingValues[$index['field'][0]])) {
$idField = $index['field'][0];
}
}
}
$idValue = $existingValues[$idField] ?? NULL;
foreach ($fieldsToRetrieve as $fieldName) {
if (!array_key_exists($fieldName, $existingValues)) {
$fieldMeta = static::getSupportedFields()[$fieldName] ?? ['type' => NULL];
$existingValues[$fieldName] = NULL;
if ($idValue) {
$existingValues[$fieldName] = self::getFieldValue(static::class, $idValue, $fieldName, $idField);
}
if (isset($existingValues[$fieldName])) {
if (!empty($fieldMeta['serialize'])) {
self::unSerializeField($existingValues[$fieldName], $fieldMeta['serialize']);
}
elseif ($fieldMeta['type'] === CRM_Utils_Type::T_BOOLEAN) {
$existingValues[$fieldName] = (bool) $existingValues[$fieldName];
}
elseif ($fieldMeta['type'] === CRM_Utils_Type::T_INT) {
$existingValues[$fieldName] = (int) $existingValues[$fieldName];
}
elseif ($fieldMeta['type'] === CRM_Utils_Type::T_FLOAT) {
$existingValues[$fieldName] = (float) $existingValues[$fieldName];
}
}
}
}
return $existingValues;
}

}
52 changes: 43 additions & 9 deletions CRM/Core/DAO/ActionSchedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Core/ActionSchedule.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:0c18fcc2d83152d208ffb128cf3b0e32)
* (GenCodeChecksum:98aa9bf4539e598e9d7d0d5da203717d)
*/

/**
Expand Down Expand Up @@ -594,7 +594,12 @@ public static function &fields() {
'localizable' => 0,
'serialize' => self::SERIALIZE_SEPARATOR_TRIMMED,
'html' => [
'label' => ts("Entity value"),
'type' => 'Select',
'label' => ts("Entity Value"),
'controlField' => 'mapping_id',
],
'pseudoconstant' => [
'callback' => 'CRM_Core_BAO_ActionSchedule::getEntityValueOptions',
],
'add' => '3.4',
],
Expand All @@ -618,7 +623,12 @@ public static function &fields() {
'localizable' => 0,
'serialize' => self::SERIALIZE_SEPARATOR_TRIMMED,
'html' => [
'type' => 'Select',
'label' => ts("Entity Status"),
'controlField' => 'entity_value',
],
'pseudoconstant' => [
'callback' => 'CRM_Core_BAO_ActionSchedule::getEntityStatusOptions',
],
'add' => '3.4',
],
Expand Down Expand Up @@ -665,9 +675,10 @@ public static function &fields() {
'html' => [
'type' => 'Select',
'label' => ts("Start Action Unit"),
'controlField' => 'start_action_offset',
],
'pseudoconstant' => [
'callback' => 'CRM_Core_SelectValues::getRecurringFrequencyUnits',
'callback' => 'CRM_Core_BAO_ActionSchedule::getDateUnits',
],
'add' => '3.4',
],
Expand Down Expand Up @@ -713,14 +724,19 @@ public static function &fields() {
'bao' => 'CRM_Core_BAO_ActionSchedule',
'localizable' => 0,
'html' => [
'label' => ts("Start Action Date"),
'type' => 'Select',
'label' => ts("Start Date"),
'controlField' => 'entity_value',
],
'pseudoconstant' => [
'callback' => 'CRM_Core_BAO_ActionSchedule::getActionDateOptions',
],
'add' => '3.4',
],
'is_repeat' => [
'name' => 'is_repeat',
'type' => CRM_Utils_Type::T_BOOLEAN,
'title' => ts('Repeat?'),
'title' => ts('Repeat'),
'required' => TRUE,
'usage' => [
'import' => FALSE,
Expand All @@ -734,6 +750,9 @@ public static function &fields() {
'entity' => 'ActionSchedule',
'bao' => 'CRM_Core_BAO_ActionSchedule',
'localizable' => 0,
'html' => [
'type' => 'CheckBox',
],
'add' => '3.4',
],
'repetition_frequency_unit' => [
Expand All @@ -757,9 +776,10 @@ public static function &fields() {
'html' => [
'type' => 'Select',
'label' => ts("Repetition Frequency Unit"),
'controlField' => 'repetition_frequency_interval',
],
'pseudoconstant' => [
'callback' => 'CRM_Core_SelectValues::getRecurringFrequencyUnits',
'callback' => 'CRM_Core_BAO_ActionSchedule::getDateUnits',
],
'add' => '3.4',
],
Expand Down Expand Up @@ -806,9 +826,10 @@ public static function &fields() {
'html' => [
'type' => 'Select',
'label' => ts("End Frequency Unit"),
'controlField' => 'end_frequency_interval',
],
'pseudoconstant' => [
'callback' => 'CRM_Core_SelectValues::getRecurringFrequencyUnits',
'callback' => 'CRM_Core_BAO_ActionSchedule::getDateUnits',
],
'add' => '3.4',
],
Expand Down Expand Up @@ -876,7 +897,12 @@ public static function &fields() {
'bao' => 'CRM_Core_BAO_ActionSchedule',
'localizable' => 0,
'html' => [
'type' => 'Select',
'label' => ts("End Date"),
'controlField' => 'entity_value',
],
'pseudoconstant' => [
'callback' => 'CRM_Core_BAO_ActionSchedule::getActionDateOptions',
],
'add' => '3.4',
],
Expand Down Expand Up @@ -1042,7 +1068,7 @@ public static function &fields() {
'mapping_id' => [
'name' => 'mapping_id',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Reminder Mapping'),
'title' => ts('Reminder For'),
'description' => ts('Name/ID of the mapping to use on this table'),
'maxlength' => 64,
'size' => CRM_Utils_Type::BIG,
Expand All @@ -1057,6 +1083,13 @@ public static function &fields() {
'entity' => 'ActionSchedule',
'bao' => 'CRM_Core_BAO_ActionSchedule',
'localizable' => 0,
'html' => [
'type' => 'Select',
'label' => ts("Used For"),
],
'pseudoconstant' => [
'callback' => 'CRM_Core_BAO_ActionSchedule::getMappingOptions',
],
'add' => '3.4',
],
'group_id' => [
Expand All @@ -1077,13 +1110,14 @@ public static function &fields() {
'localizable' => 0,
'FKClassName' => 'CRM_Contact_DAO_Group',
'html' => [
'type' => 'Select',
'type' => 'EntityRef',
'label' => ts("Group"),
],
'pseudoconstant' => [
'table' => 'civicrm_group',
'keyColumn' => 'id',
'labelColumn' => 'title',
'prefetch' => 'FALSE',
],
'add' => '3.4',
],
Expand Down
3 changes: 2 additions & 1 deletion CRM/Core/PseudoConstant.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ public static function get($daoName, $fieldName, $params = [], $context = NULL)
'fresh' => FALSE,
'context' => $context,
'condition' => [],
'values' => [],
];
$entity = CRM_Core_DAO_AllCoreTables::getBriefName($daoName);

Expand Down Expand Up @@ -224,7 +225,7 @@ public static function get($daoName, $fieldName, $params = [], $context = NULL)

// if callback is specified..
if (!empty($pseudoconstant['callback'])) {
$fieldOptions = call_user_func(Civi\Core\Resolver::singleton()->get($pseudoconstant['callback']), $context, $params);
$fieldOptions = call_user_func(Civi\Core\Resolver::singleton()->get($pseudoconstant['callback']), $fieldName, $params);
$fieldOptions = self::formatArrayOptions($context, $fieldOptions);
//CRM-18223: Allow additions to field options via hook.
CRM_Utils_Hook::fieldOptions($entity, $fieldName, $fieldOptions, $params);
Expand Down
10 changes: 4 additions & 6 deletions Civi/Api4/ActionSchedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
namespace Civi\Api4;

/**
* ActionSchedule Entity.
* Scheduled Reminders.
*
* This entity exposes CiviCRM schedule reminders, which allows us to send messages (through email or SMS)
* to contacts when certain criteria are met. Using this API you can create schedule reminder for
* Scheduled reminders send messages (through email or SMS) to contacts when
* certain criteria are met. Using this API you can create schedule reminders for
* supported entities like Contact, Activity, Event, Membership or Contribution.
*
* Creating a new ActionSchedule requires at minimum a title, mapping_id and entity_value.
*
* @searchable none
* @searchable secondary
* @see https://docs.civicrm.org/user/en/latest/email/scheduled-reminders/
* @since 5.19
* @package Civi\Api4
Expand Down
2 changes: 1 addition & 1 deletion Civi/Api4/Generic/BasicGetFieldsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private function formatOptionList(&$field) {
$field['options'] = self::pseudoconstantOptions($field['pseudoconstant']['optionGroupName']);
}
elseif (!empty($field['pseudoconstant']['callback'])) {
$field['options'] = call_user_func(\Civi\Core\Resolver::singleton()->get($field['pseudoconstant']['callback']));
$field['options'] = call_user_func(\Civi\Core\Resolver::singleton()->get($field['pseudoconstant']['callback']), $field['name'], []);
}
else {
throw new \CRM_Core_Exception('Unsupported pseudoconstant type for field "' . $field['name'] . '"');
Expand Down
2 changes: 1 addition & 1 deletion Civi/Api4/Service/Spec/SpecFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ private static function addOptionProps(&$options, $spec, $baoName, $fieldName, $
}
}
elseif ($returnFormat && !empty($pseudoconstant['callback'])) {
$callbackOptions = call_user_func(\Civi\Core\Resolver::singleton()->get($pseudoconstant['callback']), NULL, [], $values);
$callbackOptions = call_user_func(\Civi\Core\Resolver::singleton()->get($pseudoconstant['callback']), $fieldName, ['values' => $values]);
foreach ($callbackOptions as $callbackOption) {
if (is_array($callbackOption) && !empty($callbackOption['id']) && isset($optionIndex[$callbackOption['id']])) {
$options[$optionIndex[$callbackOption['id']]] += $callbackOption;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div af-fieldset="">
<div class="af-markup">
<div class="help">
{{:: ts('Scheduled reminders allow you to automatically send messages to contacts regarding their memberships, participation in events, or other activities.') }}
<a href="https://docs.civicrm.org/user/en/latest/email/scheduled-reminders/" target="_blank" class="crm-doc-link no-popup">{{:: ts('Learn more...') }}</a>
</div>
</div>
<crm-search-display-table search-name="Administer_Scheduled_Reminders" display-name="Administer_Scheduled_Reminders_Table"></crm-search-display-table>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "search",
"title": "Scheduled Reminders",
"description": "Administer scheduled reminders",
"icon": "fa-list-alt",
"server_route": "civicrm/admin/scheduleReminders",
"permission": "administer CiviCRM data"
}
Loading