Merge branch 'dev' into main
This commit is contained in:
commit
841028a435
4 changed files with 50 additions and 20 deletions
|
@ -205,15 +205,40 @@ class CRM_TwingleCampaign_BAO_CustomField {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
foreach ($options as $key => $value) {
|
foreach ($options as $key => $value) {
|
||||||
$result[] = civicrm_api3(
|
|
||||||
|
$option_value_exists = civicrm_api3(
|
||||||
'OptionValue',
|
'OptionValue',
|
||||||
'create',
|
'get',
|
||||||
[
|
[
|
||||||
|
'sequential' => 1,
|
||||||
'option_group_id' => $option_group_id,
|
'option_group_id' => $option_group_id,
|
||||||
'value' => $key,
|
'value' => $key,
|
||||||
'label' => $value,
|
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// If the option value does not yet exist, create it
|
||||||
|
if ($option_value_exists['count'] == 0) {
|
||||||
|
$result[] = civicrm_api3(
|
||||||
|
'OptionValue',
|
||||||
|
'create',
|
||||||
|
[
|
||||||
|
'option_group_id' => $option_group_id,
|
||||||
|
'value' => $key,
|
||||||
|
'label' => $value,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// If the option value already exist, update it
|
||||||
|
else {
|
||||||
|
$result[] = civicrm_api3(
|
||||||
|
'OptionValue',
|
||||||
|
'create',
|
||||||
|
[
|
||||||
|
'id' => $option_value_exists['values'][0]['id'],
|
||||||
|
'label' => $value,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (CiviCRM_API3_Exception $e) {
|
} catch (CiviCRM_API3_Exception $e) {
|
||||||
$errorMessage = $e->getMessage();
|
$errorMessage = $e->getMessage();
|
||||||
|
|
|
@ -158,7 +158,7 @@ class CRM_TwingleCampaign_BAO_OptionValue {
|
||||||
// If a specific option value is required
|
// If a specific option value is required
|
||||||
try {
|
try {
|
||||||
$option_value = civicrm_api3(
|
$option_value = civicrm_api3(
|
||||||
'CustomValue',
|
'OptionValue',
|
||||||
'get',
|
'get',
|
||||||
[
|
[
|
||||||
'sequential' => 1,
|
'sequential' => 1,
|
||||||
|
|
|
@ -31,6 +31,13 @@ class CRM_TwingleCampaign_BAO_TwingleProject extends Campaign {
|
||||||
'one_time',
|
'one_time',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// All fields for hex color codes
|
||||||
|
const colorFields = [
|
||||||
|
'design_background_color',
|
||||||
|
'design_primary_color',
|
||||||
|
'design_font_color',
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ## TwingleProject constructor
|
* ## TwingleProject constructor
|
||||||
*
|
*
|
||||||
|
@ -143,11 +150,13 @@ class CRM_TwingleCampaign_BAO_TwingleProject extends Campaign {
|
||||||
*/
|
*/
|
||||||
private function strToInt(array &$values) {
|
private function strToInt(array &$values) {
|
||||||
foreach ($values as $key => $value) {
|
foreach ($values as $key => $value) {
|
||||||
if (ctype_digit($value)) {
|
if (!in_array($key, self::colorFields)) {
|
||||||
$values[$key] = intval($value);
|
if (ctype_digit($value)) {
|
||||||
}
|
$values[$key] = intval($value);
|
||||||
elseif (is_array($value)) {
|
}
|
||||||
$this->strToInt($values[$key]);
|
elseif (is_array($value)) {
|
||||||
|
$this->strToInt($values[$key]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -298,21 +307,18 @@ class CRM_TwingleCampaign_BAO_TwingleProject extends Campaign {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate hexadecimal color fields
|
// Validate hexadecimal color fields
|
||||||
$colorFields =
|
foreach (self::colorFields as $colorField) {
|
||||||
[
|
|
||||||
'design_background_color',
|
|
||||||
'design_primary_color',
|
|
||||||
'design_font_color',
|
|
||||||
];
|
|
||||||
foreach ($colorFields as $colorField) {
|
|
||||||
if (
|
if (
|
||||||
!empty($this->values['project_options'][$colorField]) &&
|
(
|
||||||
|
!empty($this->values['project_options'][$colorField]) ||
|
||||||
|
$this->values['project_options'][$colorField] === "0"
|
||||||
|
) &&
|
||||||
(
|
(
|
||||||
!(
|
!(
|
||||||
ctype_xdigit($this->values['project_options'][$colorField]) ||
|
ctype_xdigit($this->values['project_options'][$colorField]) ||
|
||||||
is_integer($this->values['project_options'][$colorField])
|
is_integer($this->values['project_options'][$colorField])
|
||||||
) ||
|
) ||
|
||||||
strlen((string) $this->values['project_options'][$colorField]) > 6
|
strlen((string) $this->values['project_options'][$colorField]) != 6
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
$valid = FALSE;
|
$valid = FALSE;
|
||||||
|
|
|
@ -411,8 +411,7 @@ function _validateAndSendInput($id, $campaign_type_id): bool {
|
||||||
CRM_Core_Session::setStatus(
|
CRM_Core_Session::setStatus(
|
||||||
$errorMessage,
|
$errorMessage,
|
||||||
E::ts("Input validation failed"),
|
E::ts("Input validation failed"),
|
||||||
error,
|
error
|
||||||
[unique => TRUE]
|
|
||||||
);
|
);
|
||||||
// Validation failed
|
// Validation failed
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue