Code style

This commit is contained in:
Jens Schuppe 2024-06-12 14:35:42 +02:00
parent cf9483ca3e
commit ac1b08b775
4 changed files with 47 additions and 74 deletions

View file

@ -687,7 +687,10 @@ class CRM_Twingle_Profile {
return $default_profile;
}
else {
throw new ProfileException('Could not find default profile', ProfileException::ERROR_CODE_DEFAULT_PROFILE_NOT_FOUND);
throw new ProfileException(
'Could not find default profile',
ProfileException::ERROR_CODE_DEFAULT_PROFILE_NOT_FOUND
);
}
}

View file

@ -115,17 +115,17 @@ class CRM_Twingle_Upgrader extends CRM_Extension_Upgrader_Base {
public function upgrade_5150(): bool {
$this->ctx->log->info('Activate mapping of `purpose` and `user_extra_field` to notes in each existing profile.');
$profiles = CRM_Twingle_Profile::getProfiles();
if ($profiles) {
foreach ($profiles as $profile) {
foreach (CRM_Twingle_Profile::getProfiles() as $profile) {
$profile_changed = FALSE;
/** @phpstan-var array<string> $contribution_notes */
$contribution_notes = $profile->getAttribute('map_as_contribution_notes', []);
/** @phpstan-var array<string> $contact_notes */
$contact_notes = $profile->getAttribute('map_as_contact_notes', []);
if (!in_array('purpose', $contribution_notes)) {
if (!in_array('purpose', $contribution_notes, TRUE)) {
$profile->setAttribute('map_as_contribution_notes', array_merge($contribution_notes, ['purpose']));
$profile_changed = TRUE;
}
if (!in_array('user_extrafield', $contact_notes)) {
if (!in_array('user_extrafield', $contact_notes, TRUE)) {
$profile->setAttribute('map_as_contact_notes', array_merge($contact_notes, ['user_extrafield']));
$profile_changed = TRUE;
}
@ -133,7 +133,6 @@ class CRM_Twingle_Upgrader extends CRM_Extension_Upgrader_Base {
$profile->saveProfile();
}
}
}
return TRUE;
}

View file

@ -17,6 +17,7 @@ declare(strict_types = 1);
use CRM_Twingle_ExtensionUtil as E;
use Civi\Twingle\Exceptions\BaseException;
use Civi\Api4\Note;
/**
* TwingleDonation.Submit API specification
@ -485,20 +486,19 @@ function civicrm_api3_twingle_donation_Submit($params) {
}
// Create contact notes.
/** @phpstan-var array<string> $contact_note_mappings */
$contact_note_mappings = $profile->getAttribute('map_as_contact_notes', []);
foreach (['user_extrafield'] as $target) {
if (
isset($params[$target])
&& '' !== $params[$target]
&& in_array($target, $contact_note_mappings)
&& in_array($target, $contact_note_mappings, TRUE)
) {
civicrm_api4('Note', 'create', [
'values' => [
'entity_table' => 'civicrm_contact',
'entity_id' => $contact_id,
'note' => $params[$target],
],
]);
Note::create(FALSE)
->addValue('entity_table', 'civicrm_contact')
->addValue('entity_id', $contact_id)
->addValue('note', $params[$target])
->execute();
}
}
@ -803,27 +803,26 @@ function civicrm_api3_twingle_donation_Submit($params) {
);
}
$result_values['contribution'] = $contribution['values'];
}
// Add notes to the contribution.
$contribution_note_mappings = $profile->getAttribute("map_as_contribution_notes", []);
/** @phpstan-var array<string> $contribution_note_mappings */
$contribution_note_mappings = $profile->getAttribute('map_as_contribution_notes', []);
foreach (['purpose', 'remarks'] as $target) {
if (
in_array($target, $contribution_note_mappings)
in_array($target, $contribution_note_mappings, TRUE)
&& isset($params[$target])
&& '' !== $params[$target]
) {
civicrm_api4('Note', 'create', [
'values' => [
'entity_table' => 'civicrm_contribution',
'entity_id' => CRM_Utils_Array::first($result_values['contribution'])['id'],
'note' => $params[$target],
],
]);
Note::create(FALSE)
->addValue('entity_table', 'civicrm_contribution')
->addValue('entity_id', reset($contribution['values'])['id'])
->addValue('note', reset($params[$target]))
->execute();
}
}
$result_values['contribution'] = $contribution['values'];
}
// MEMBERSHIP CREATION
// CHECK whether a membership should be created (based on profile settings and data provided)

View file

@ -316,21 +316,7 @@
<tr class="crm-section">
<td class="label">
{$form.map_as_contribution_notes.label}
<a
onclick='
CRM.help(
"{ts domain="de.systopia.twingle"}Create contribution note for{/ts}",
{literal}{
"id": "id-map_as_contribution_notes",
"file": "CRM\/Twingle\/Form\/Profile"
}{/literal}
);
return false;
'
href="#"
title="{ts domain="de.systopia.twingle"}Help{/ts}"
class="helpicon"
></a>
{help id="id-map_as_contribution_notes" title=$form.map_as_contribution_notes.label}
</td>
<td class="content">{$form.map_as_contribution_notes.html}</td>
</tr>
@ -338,21 +324,7 @@
<tr class="crm-section">
<td class="label">
{$form.map_as_contact_notes.label}
<a
onclick='
CRM.help(
"{ts domain="de.systopia.twingle"}Create contact note for{/ts}",
{literal}{
"id": "id-map_as_contact_notes",
"file": "CRM\/Twingle\/Form\/Profile"
}{/literal}
);
return false;
'
href="#"
title="{ts domain="de.systopia.twingle"}Help{/ts}"
class="helpicon"
></a>
{help id="id-map_as_contact_notes" title=$form.map_as_contact_notes.label}
</td>
<td class="content">{$form.map_as_contact_notes.html}</td>
</tr>