PHP Code Beautifier fixes

This commit is contained in:
Jens Schuppe 2024-03-25 14:58:51 +01:00
parent fad228315d
commit 69843bc981
10 changed files with 389 additions and 292 deletions

View file

@ -29,9 +29,10 @@ class CRM_Twingle_Config {
*/ */
public static function getRecurringProtectionOptions() { public static function getRecurringProtectionOptions() {
return [ return [
self::RCUR_PROTECTION_OFF => E::ts("No"), self::RCUR_PROTECTION_OFF => E::ts('No'),
self::RCUR_PROTECTION_EXCEPTION => E::ts("Raise Exception"), self::RCUR_PROTECTION_EXCEPTION => E::ts('Raise Exception'),
self::RCUR_PROTECTION_ACTIVITY => E::ts("Create Activity"), self::RCUR_PROTECTION_ACTIVITY => E::ts('Create Activity'),
]; ];
} }
} }

View file

@ -23,7 +23,7 @@ use CRM_Twingle_ExtensionUtil as E;
class CRM_Twingle_Form_Profile extends CRM_Core_Form { class CRM_Twingle_Form_Profile extends CRM_Core_Form {
/** /**
* @var CRM_Twingle_Profile $profile * @var CRM_Twingle_Profile
* *
* The profile object the form is acting on. * The profile object the form is acting on.
*/ */
@ -151,25 +151,27 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
switch ($this->_op) { switch ($this->_op) {
case 'delete': case 'delete':
if ($profile_name) { if ($profile_name) {
CRM_Utils_System::setTitle(E::ts('Delete Twingle API profile <em>%1</em>', array(1 => $profile_name))); CRM_Utils_System::setTitle(E::ts('Delete Twingle API profile <em>%1</em>', [1 => $profile_name]));
$this->addButtons(array( $this->addButtons([
array( [
'type' => 'submit', 'type' => 'submit',
'name' => ($profile_name == 'default' ? E::ts('Reset') : E::ts('Delete')), 'name' => ($profile_name == 'default' ? E::ts('Reset') : E::ts('Delete')),
'isDefault' => TRUE, 'isDefault' => TRUE,
), ],
)); ]);
} }
parent::buildQuickForm(); parent::buildQuickForm();
return; return;
case 'edit': case 'edit':
// When editing without a valid profile name, edit the default profile. // When editing without a valid profile name, edit the default profile.
if (!$profile_name) { if (!$profile_name) {
$profile_name = 'default'; $profile_name = 'default';
$this->profile = CRM_Twingle_Profile::getProfile($profile_name); $this->profile = CRM_Twingle_Profile::getProfile($profile_name);
} }
CRM_Utils_System::setTitle(E::ts('Edit Twingle API profile <em>%1</em>', array(1 => $this->profile->getName()))); CRM_Utils_System::setTitle(E::ts('Edit Twingle API profile <em>%1</em>', [1 => $this->profile->getName()]));
break; break;
case 'copy': case 'copy':
// Retrieve the source profile name. // Retrieve the source profile name.
$profile_name = CRM_Utils_Request::retrieve('source_name', 'String', $this); $profile_name = CRM_Utils_Request::retrieve('source_name', 'String', $this);
@ -184,6 +186,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
$this->profile->setName($profile_name); $this->profile->setName($profile_name);
CRM_Utils_System::setTitle(E::ts('New Twingle API profile')); CRM_Utils_System::setTitle(E::ts('New Twingle API profile'));
break; break;
case 'create': case 'create':
// Load factory default profile values. // Load factory default profile values.
$this->profile = CRM_Twingle_Profile::createDefaultProfile($profile_name); $this->profile = CRM_Twingle_Profile::createDefaultProfile($profile_name);
@ -201,16 +204,20 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
($is_default ? 'static' : 'text'), ($is_default ? 'static' : 'text'),
'name', 'name',
E::ts('Profile name'), E::ts('Profile name'),
array(), [],
!$is_default !$is_default
); );
$this->add( $this->add(
'text', // field type // field type
'selector', // field name 'text',
E::ts('Project IDs'), // field label // field name
'selector',
// field label
E::ts('Project IDs'),
['class' => 'huge'], ['class' => 'huge'],
TRUE // is required // is required
TRUE
); );
$this->add( $this->add(
@ -238,18 +245,28 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
); );
$this->add( $this->add(
'select', // field type // field type
'financial_type_id', // field name 'select',
E::ts('Financial type'), // field label // field name
static::getFinancialTypes(), // list of options 'financial_type_id',
TRUE // is required // field label
E::ts('Financial type'),
// list of options
static::getFinancialTypes(),
// is required
TRUE
); );
$this->add( $this->add(
'select', // field type // field type
'financial_type_id_recur', // field name 'select',
E::ts('Financial type (recurring)'), // field label // field name
static::getFinancialTypes(), // list of options 'financial_type_id_recur',
TRUE // is required // field label
E::ts('Financial type (recurring)'),
// list of options
static::getFinancialTypes(),
// is required
TRUE
); );
$this->add( $this->add(
@ -297,11 +314,16 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
$this->assign('payment_instruments', $payment_instruments); $this->assign('payment_instruments', $payment_instruments);
foreach ($payment_instruments as $pi_name => $pi_label) { foreach ($payment_instruments as $pi_name => $pi_label) {
$this->add( $this->add(
'select', // field type // field type
$pi_name, // field name 'select',
E::ts('Record %1 as', [1 => $pi_label]), // field label // field name
static::getPaymentInstruments(), // list of options $pi_name,
TRUE // is required // field label
E::ts('Record %1 as', [1 => $pi_label]),
// list of options
static::getPaymentInstruments(),
// is required
TRUE
); );
$this->add( $this->add(
@ -324,46 +346,70 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
} }
$this->add( $this->add(
'checkbox', // field type // field type
'newsletter_double_opt_in', // field name 'checkbox',
E::ts('Use Double-Opt-In for newsletter'), // field label // field name
FALSE, // is not required 'newsletter_double_opt_in',
// field label
E::ts('Use Double-Opt-In for newsletter'),
// is not required
FALSE,
[] []
); );
$this->add( $this->add(
'select', // field type // field type
'newsletter_groups', // field name 'select',
E::ts('Sign up for newsletter groups'), // field label // field name
static::getNewsletterGroups(), // list of options 'newsletter_groups',
FALSE, // is not required // field label
E::ts('Sign up for newsletter groups'),
// list of options
static::getNewsletterGroups(),
// is not required
FALSE,
['class' => 'crm-select2 huge', 'multiple' => 'multiple'] ['class' => 'crm-select2 huge', 'multiple' => 'multiple']
); );
$this->add( $this->add(
'select', // field type // field type
'postinfo_groups', // field name 'select',
E::ts('Sign up for postal mail groups'), // field label // field name
static::getPostinfoGroups(), // list of options 'postinfo_groups',
FALSE, // is not required // field label
E::ts('Sign up for postal mail groups'),
// list of options
static::getPostinfoGroups(),
// is not required
FALSE,
['class' => 'crm-select2 huge', 'multiple' => 'multiple'] ['class' => 'crm-select2 huge', 'multiple' => 'multiple']
); );
$this->add( $this->add(
'select', // field type // field type
'donation_receipt_groups', // field name 'select',
E::ts('Sign up for Donation receipt groups'), // field label // field name
static::getDonationReceiptGroups(), // list of options 'donation_receipt_groups',
FALSE, // is not required // field label
E::ts('Sign up for Donation receipt groups'),
// list of options
static::getDonationReceiptGroups(),
// is not required
FALSE,
['class' => 'crm-select2 huge', 'multiple' => 'multiple'] ['class' => 'crm-select2 huge', 'multiple' => 'multiple']
); );
$this->add( $this->add(
'select', // field type // field type
'campaign', // field name 'select',
E::ts('Default Campaign'), // field label // field name
['' => E::ts('- none -')] + static::getCampaigns(), // list of options 'campaign',
FALSE, // is not required // field label
E::ts('Default Campaign'),
// list of options
['' => E::ts('- none -')] + static::getCampaigns(),
// is not required
FALSE,
['class' => 'crm-select2 huge'] ['class' => 'crm-select2 huge']
); );
@ -372,30 +418,41 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
'campaign_targets', 'campaign_targets',
E::ts('Set Campaign for'), E::ts('Set Campaign for'),
[ [
'contribution' => E::ts("Contribution"), 'contribution' => E::ts('Contribution'),
'recurring' => E::ts("Recurring Contribution"), 'recurring' => E::ts('Recurring Contribution'),
'membership' => E::ts("Membership"), 'membership' => E::ts('Membership'),
'mandate' => E::ts("SEPA Mandate"), 'mandate' => E::ts('SEPA Mandate'),
'contact' => E::ts("Contacts (XCM)"), 'contact' => E::ts('Contacts (XCM)'),
], ],
FALSE, // is not required // is not required
FALSE,
['class' => 'crm-select2 huge', 'multiple' => 'multiple'] ['class' => 'crm-select2 huge', 'multiple' => 'multiple']
); );
$this->add( $this->add(
'select', // field type // field type
'membership_type_id', // field name 'select',
E::ts('Create membership of type'), // field label // field name
['' => E::ts('- none -')] + static::getMembershipTypes(), // list of options 'membership_type_id',
FALSE, // is not required // field label
E::ts('Create membership of type'),
// list of options
['' => E::ts('- none -')] + static::getMembershipTypes(),
// is not required
FALSE,
['class' => 'crm-select2 huge'] ['class' => 'crm-select2 huge']
); );
$this->add( $this->add(
'select', // field type // field type
'membership_type_id_recur', // field name 'select',
E::ts('Create membership of type (recurring)'), // field label // field name
['' => E::ts('- none -')] + static::getMembershipTypes(), // list of options 'membership_type_id_recur',
FALSE, // is not required // field label
E::ts('Create membership of type (recurring)'),
// list of options
['' => E::ts('- none -')] + static::getMembershipTypes(),
// is not required
FALSE,
['class' => 'crm-select2 huge'] ['class' => 'crm-select2 huge']
); );
$this->add( $this->add(
@ -407,9 +464,12 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
$this->addRule('membership_postprocess_call', E::ts("The API call must have the form 'Entity.Action'."), 'regex', '/^[A-Za-z_]+[.][A-Za-z_]+$/'); $this->addRule('membership_postprocess_call', E::ts("The API call must have the form 'Entity.Action'."), 'regex', '/^[A-Za-z_]+[.][A-Za-z_]+$/');
$this->add( $this->add(
'text', // field type // field type
'contribution_source', // field name 'text',
E::ts('Contribution source'), // field label // field name
'contribution_source',
// field label
E::ts('Contribution source'),
[] []
); );
@ -418,19 +478,23 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
'required_address_components', 'required_address_components',
E::ts('Required address components'), E::ts('Required address components'),
[ [
'street_address' => E::ts("Street"), 'street_address' => E::ts('Street'),
'postal_code' => E::ts("Postal Code"), 'postal_code' => E::ts('Postal Code'),
'city' => E::ts("City"), 'city' => E::ts('City'),
'country' => E::ts("Country"), 'country' => E::ts('Country'),
], ],
FALSE, // is not required // is not required
FALSE,
['class' => 'crm-select2 huge', 'multiple' => 'multiple'] ['class' => 'crm-select2 huge', 'multiple' => 'multiple']
); );
$this->add( $this->add(
'textarea', // field type // field type
'custom_field_mapping', // field name 'textarea',
E::ts('Custom field mapping'), // field label // field name
'custom_field_mapping',
// field label
E::ts('Custom field mapping'),
[] []
); );
@ -469,7 +533,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
} }
// Restrict profile names to alphanumeric characters and the underscore. // Restrict profile names to alphanumeric characters and the underscore.
if (isset($values['name']) && preg_match("/[^A-Za-z0-9\_]/", $values['name'])) { if (isset($values['name']) && preg_match('/[^A-Za-z0-9\_]/', $values['name'])) {
$this->_errors['name'] = E::ts('Only alphanumeric characters and the underscore (_) are allowed for profile names.'); $this->_errors['name'] = E::ts('Only alphanumeric characters and the underscore (_) are allowed for profile names.');
} }
@ -483,7 +547,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
); );
} }
foreach ($custom_field_mapping as $custom_field_map) { foreach ($custom_field_mapping as $custom_field_map) {
$custom_field_map = explode("=", $custom_field_map); $custom_field_map = explode('=', $custom_field_map);
if (count($custom_field_map) !== 2) { if (count($custom_field_map) !== 2) {
throw new Exception( throw new Exception(
E::ts('Could not parse custom field mapping.') E::ts('Could not parse custom field mapping.')
@ -494,38 +558,39 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
// Check for custom field existence // Check for custom field existence
try { try {
$custom_field = civicrm_api3('CustomField', 'getsingle', array( $custom_field = civicrm_api3('CustomField', 'getsingle', [
'id' => $custom_field_id, 'id' => $custom_field_id,
)); ]);
} }
catch (CiviCRM_API3_Exception $exception) { catch (CiviCRM_API3_Exception $exception) {
throw new Exception( throw new Exception(
E::ts( E::ts(
'Custom field custom_%1 does not exist.', 'Custom field custom_%1 does not exist.',
array(1 => $custom_field_id) [1 => $custom_field_id]
) )
); );
} }
// Only allow custom fields on relevant entities. // Only allow custom fields on relevant entities.
try { try {
$custom_group = civicrm_api3('CustomGroup', 'getsingle', array( $custom_group = civicrm_api3('CustomGroup', 'getsingle', [
'id' => $custom_field['custom_group_id'], 'id' => $custom_field['custom_group_id'],
'extends' => array( 'extends' => [
'IN' => array( 'IN' => [
'Contact', 'Contact',
'Individual', 'Individual',
'Organization', 'Organization',
'Contribution', 'Contribution',
'ContributionRecur', 'ContributionRecur',
), ],
), ],
)); ]);
} catch (CiviCRM_API3_Exception $exception) { }
catch (CiviCRM_API3_Exception $exception) {
throw new Exception( throw new Exception(
E::ts( E::ts(
'Custom field custom_%1 is not in a CustomGroup that extends one of the supported CiviCRM entities.', 'Custom field custom_%1 is not in a CustomGroup that extends one of the supported CiviCRM entities.',
array(1 => $custom_field['id']) [1 => $custom_field['id']]
) )
); );
} }
@ -563,7 +628,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
*/ */
public function postProcess() { public function postProcess() {
$values = $this->exportValues(); $values = $this->exportValues();
if (in_array($this->_op, array('create', 'edit', 'copy'))) { if (in_array($this->_op, ['create', 'edit', 'copy'])) {
if (empty($values['name'])) { if (empty($values['name'])) {
$values['name'] = 'default'; $values['name'] = 'default';
} }
@ -614,9 +679,9 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
public static function getXCMProfiles() { public static function getXCMProfiles() {
if (!isset(static::$_xcm_profiles)) { if (!isset(static::$_xcm_profiles)) {
if (method_exists('CRM_Xcm_Configuration', 'getProfileList')) { if (method_exists('CRM_Xcm_Configuration', 'getProfileList')) {
static::$_xcm_profiles = array( static::$_xcm_profiles = [
'' => E::ts("&lt;select profile&gt;"), '' => E::ts('&lt;select profile&gt;'),
); ];
$profiles = CRM_Xcm_Configuration::getProfileList(); $profiles = CRM_Xcm_Configuration::getProfileList();
foreach ($profiles as $profile_key => $profile_name) { foreach ($profiles as $profile_key => $profile_name) {
static::$_xcm_profiles[$profile_key] = $profile_name; static::$_xcm_profiles[$profile_key] = $profile_name;
@ -640,7 +705,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
$query = civicrm_api3('FinancialType', 'get', [ $query = civicrm_api3('FinancialType', 'get', [
'option.limit' => 0, 'option.limit' => 0,
'is_active' => 1, 'is_active' => 1,
'return' => 'id,name' 'return' => 'id,name',
]); ]);
foreach ($query['values'] as $type) { foreach ($query['values'] as $type) {
static::$_financialTypes[$type['id']] = $type['name']; static::$_financialTypes[$type['id']] = $type['name'];
@ -663,7 +728,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
$query = civicrm_api3('MembershipType', 'get', [ $query = civicrm_api3('MembershipType', 'get', [
'option.limit' => 0, 'option.limit' => 0,
'is_active' => 1, 'is_active' => 1,
'return' => 'id,name' 'return' => 'id,name',
]); ]);
foreach ($query['values'] as $type) { foreach ($query['values'] as $type) {
static::$_membershipTypes[$type['id']] = $type['name']; static::$_membershipTypes[$type['id']] = $type['name'];
@ -763,7 +828,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
'option.limit' => 0, 'option.limit' => 0,
'option_group_id' => 'payment_instrument', 'option_group_id' => 'payment_instrument',
'is_active' => 1, 'is_active' => 1,
'return' => 'value,label' 'return' => 'value,label',
]); ]);
foreach ($query['values'] as $payment_instrument) { foreach ($query['values'] as $payment_instrument) {
// Do not include CiviSEPA payment instruments, but add a SEPA option if // Do not include CiviSEPA payment instruments, but add a SEPA option if
@ -802,7 +867,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
'return' => [ 'return' => [
'value', 'value',
'label', 'label',
] ],
] ]
); );
@ -837,7 +902,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
'is_active' => 1, 'is_active' => 1,
'group_type' => ['LIKE' => '%' . CRM_Utils_Array::implodePadded($group_type['value']) . '%'], 'group_type' => ['LIKE' => '%' . CRM_Utils_Array::implodePadded($group_type['value']) . '%'],
'option.limit' => 0, 'option.limit' => 0,
'return' => 'id,name' 'return' => 'id,name',
]); ]);
foreach ($query['values'] as $group) { foreach ($query['values'] as $group) {
static::$_newsletterGroups[$group['id']] = $group['name']; static::$_newsletterGroups[$group['id']] = $group['name'];
@ -863,7 +928,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
$query = civicrm_api3('Group', 'get', [ $query = civicrm_api3('Group', 'get', [
'option.limit' => 0, 'option.limit' => 0,
'is_active' => 1, 'is_active' => 1,
'return' => 'id,name' 'return' => 'id,name',
]); ]);
foreach ($query['values'] as $group) { foreach ($query['values'] as $group) {
static::$_groups[$group['id']] = $group['name']; static::$_groups[$group['id']] = $group['name'];
@ -911,7 +976,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
'return' => [ 'return' => [
'id', 'id',
'title', 'title',
] ],
]); ]);
foreach ($query['values'] as $campaign) { foreach ($query['values'] as $campaign) {
static::$_campaigns[$campaign['id']] = $campaign['title']; static::$_campaigns[$campaign['id']] = $campaign['title'];

View file

@ -23,7 +23,7 @@ use CRM_Twingle_ExtensionUtil as E;
class CRM_Twingle_Form_Settings extends CRM_Core_Form { class CRM_Twingle_Form_Settings extends CRM_Core_Form {
/** /**
* @var array list of all settings options * @var arraylistofallsettingsoptions
*/ */
public static $SETTINGS_LIST = [ public static $SETTINGS_LIST = [
'twingle_prefix', 'twingle_prefix',
@ -39,53 +39,53 @@ class CRM_Twingle_Form_Settings extends CRM_Core_Form {
/** /**
* @inheritdoc * @inheritdoc
*/ */
function buildQuickForm() { public function buildQuickForm() {
// Set redirect destination. // Set redirect destination.
$this->controller->_destination = CRM_Utils_System::url('civicrm/admin/settings/twingle', 'reset=1'); $this->controller->_destination = CRM_Utils_System::url('civicrm/admin/settings/twingle', 'reset=1');
$this->add( $this->add(
'text', 'text',
'twingle_prefix', 'twingle_prefix',
E::ts("Twingle ID Prefix") E::ts('Twingle ID Prefix')
); );
$this->add( $this->add(
'checkbox', 'checkbox',
'twingle_use_sepa', 'twingle_use_sepa',
E::ts("Use CiviSEPA") E::ts('Use CiviSEPA')
); );
$this->add( $this->add(
'checkbox', 'checkbox',
'twingle_dont_use_reference', 'twingle_dont_use_reference',
E::ts("Use CiviSEPA generated reference") E::ts('Use CiviSEPA generated reference')
); );
$this->add( $this->add(
'select', 'select',
'twingle_protect_recurring', 'twingle_protect_recurring',
E::ts("Protect Recurring Contributions"), E::ts('Protect Recurring Contributions'),
CRM_Twingle_Config::getRecurringProtectionOptions() CRM_Twingle_Config::getRecurringProtectionOptions()
); );
$this->add( $this->add(
'select', 'select',
'twingle_protect_recurring_activity_type', 'twingle_protect_recurring_activity_type',
E::ts("Activity Type"), E::ts('Activity Type'),
$this->getOptionValueList('activity_type', [0]) $this->getOptionValueList('activity_type', [0])
); );
$this->add( $this->add(
'text', 'text',
'twingle_protect_recurring_activity_subject', 'twingle_protect_recurring_activity_subject',
E::ts("Subject"), E::ts('Subject'),
['class' => 'huge'] ['class' => 'huge']
); );
$this->add( $this->add(
'select', 'select',
'twingle_protect_recurring_activity_status', 'twingle_protect_recurring_activity_status',
E::ts("Status"), E::ts('Status'),
$this->getOptionValueList('activity_status') $this->getOptionValueList('activity_status')
); );
@ -102,18 +102,18 @@ class CRM_Twingle_Form_Settings extends CRM_Core_Form {
] ]
); );
$this->addButtons(array( $this->addButtons([
array ( [
'type' => 'submit', 'type' => 'submit',
'name' => E::ts('Save'), 'name' => E::ts('Save'),
'isDefault' => TRUE, 'isDefault' => TRUE,
) ],
)); ]);
// set defaults // set defaults
foreach (self::$SETTINGS_LIST as $setting) { foreach (self::$SETTINGS_LIST as $setting) {
$this->setDefaults([ $this->setDefaults([
$setting => Civi::settings()->get($setting) $setting => Civi::settings()->get($setting),
]); ]);
} }
@ -134,10 +134,11 @@ class CRM_Twingle_Form_Settings extends CRM_Core_Form {
foreach (['twingle_protect_recurring_activity_type', foreach (['twingle_protect_recurring_activity_type',
'twingle_protect_recurring_activity_subject', 'twingle_protect_recurring_activity_subject',
'twingle_protect_recurring_activity_status', 'twingle_protect_recurring_activity_status',
'twingle_protect_recurring_activity_assignee',] as $activity_field) { 'twingle_protect_recurring_activity_assignee',
] as $activity_field) {
$current_value = CRM_Utils_Array::value($activity_field, $this->_submitValues); $current_value = CRM_Utils_Array::value($activity_field, $this->_submitValues);
if (empty($current_value)) { if (empty($current_value)) {
$this->_errors[$activity_field] = E::ts("This is required for activity creation"); $this->_errors[$activity_field] = E::ts('This is required for activity creation');
} }
} }
} }
@ -145,11 +146,10 @@ class CRM_Twingle_Form_Settings extends CRM_Core_Form {
return (0 == count($this->_errors)); return (0 == count($this->_errors));
} }
/** /**
* @inheritdoc * @inheritdoc
*/ */
function postProcess() { public function postProcess() {
$values = $this->exportValues(); $values = $this->exportValues();
// store settings // store settings
@ -160,15 +160,14 @@ class CRM_Twingle_Form_Settings extends CRM_Core_Form {
parent::postProcess(); parent::postProcess();
} }
/** /**
* Get a list of option group items * Get a list of option group items
* @param $group_id string group ID or name * @param $group_id string group ID or name
* @return array list of ID(value) => label * @return array list of ID(value) => label
* @throws CiviCRM_API3_Exception * @throws CiviCRM_API3_Exception
*/ */
protected function getOptionValueList($group_id, $reserved = [0,1]) { protected function getOptionValueList($group_id, $reserved = [0, 1]) {
$list = ['' => E::ts("-select-")]; $list = ['' => E::ts('-select-')];
$query = civicrm_api3('OptionValue', 'get', [ $query = civicrm_api3('OptionValue', 'get', [
'option_group_id' => $group_id, 'option_group_id' => $group_id,
'option.limit' => 0, 'option.limit' => 0,
@ -181,4 +180,5 @@ class CRM_Twingle_Form_Settings extends CRM_Core_Form {
} }
return $list; return $list;
} }
} }

View file

@ -18,7 +18,7 @@ use CRM_Twingle_ExtensionUtil as E;
class CRM_Twingle_Page_Profiles extends CRM_Core_Page { class CRM_Twingle_Page_Profiles extends CRM_Core_Page {
public function run() { public function run() {
CRM_Utils_System::setTitle(E::ts("Twingle API Profiles")); CRM_Utils_System::setTitle(E::ts('Twingle API Profiles'));
$profiles = []; $profiles = [];
foreach (CRM_Twingle_Profile::getProfiles() as $profile_name => $profile) { foreach (CRM_Twingle_Profile::getProfiles() as $profile_name => $profile) {
$profiles[$profile_name]['name'] = $profile_name; $profiles[$profile_name]['name'] = $profile_name;

View file

@ -54,13 +54,13 @@ class CRM_Twingle_Submission {
} }
// Validate donation rhythm. // Validate donation rhythm.
if (!in_array($params['donation_rhythm'], array( if (!in_array($params['donation_rhythm'], [
'one_time', 'one_time',
'halfyearly', 'halfyearly',
'quarterly', 'quarterly',
'yearly', 'yearly',
'monthly', 'monthly',
))) { ])) {
throw new CiviCRM_API3_Exception( throw new CiviCRM_API3_Exception(
E::ts('Invalid donation rhythm.'), E::ts('Invalid donation rhythm.'),
'invalid_format' 'invalid_format'
@ -137,7 +137,8 @@ class CRM_Twingle_Submission {
'getsingle', 'getsingle',
['id' => $params['campaign_id']] ['id' => $params['campaign_id']]
); );
} catch (CiviCRM_API3_Exception $e) { }
catch (CiviCRM_API3_Exception $e) {
unset($params['campaign_id']); unset($params['campaign_id']);
} }
} }
@ -186,14 +187,14 @@ class CRM_Twingle_Submission {
} }
else { else {
// Look up the country depending on the given ISO code. // Look up the country depending on the given ISO code.
$country = civicrm_api3('Country', 'get', array('iso_code' => $contact_data['country'])); $country = civicrm_api3('Country', 'get', ['iso_code' => $contact_data['country']]);
if (!empty($country['id'])) { if (!empty($country['id'])) {
$contact_data['country_id'] = $country['id']; $contact_data['country_id'] = $country['id'];
unset($contact_data['country']); unset($contact_data['country']);
} }
else { else {
throw new \CiviCRM_API3_Exception( throw new \CiviCRM_API3_Exception(
E::ts('Unknown country %1.', array(1 => $contact_data['country'])), E::ts('Unknown country %1.', [1 => $contact_data['country']]),
'invalid_format' 'invalid_format'
); );
} }
@ -241,18 +242,20 @@ class CRM_Twingle_Submission {
} }
// Check whether organisation has a WORK address. // Check whether organisation has a WORK address.
$existing_org_addresses = civicrm_api3('Address', 'get', array( $existing_org_addresses = civicrm_api3('Address', 'get', [
'contact_id' => $organisation_id, 'contact_id' => $organisation_id,
'location_type_id' => $location_type_id)); 'location_type_id' => $location_type_id,
]);
if ($existing_org_addresses['count'] <= 0) { if ($existing_org_addresses['count'] <= 0) {
// Organisation does not have a WORK address. // Organisation does not have a WORK address.
return FALSE; return FALSE;
} }
// Check whether contact already has a WORK address. // Check whether contact already has a WORK address.
$existing_contact_addresses = civicrm_api3('Address', 'get', array( $existing_contact_addresses = civicrm_api3('Address', 'get', [
'contact_id' => $contact_id, 'contact_id' => $contact_id,
'location_type_id' => $location_type_id)); 'location_type_id' => $location_type_id,
]);
if ($existing_contact_addresses['count'] > 0) { if ($existing_contact_addresses['count'] > 0) {
// Contact already has a WORK address. // Contact already has a WORK address.
return FALSE; return FALSE;
@ -284,21 +287,21 @@ class CRM_Twingle_Submission {
} }
// see if there is already one // see if there is already one
$existing_relationship = civicrm_api3('Relationship', 'get', array( $existing_relationship = civicrm_api3('Relationship', 'get', [
'relationship_type_id' => self::EMPLOYER_RELATIONSHIP_TYPE_ID, 'relationship_type_id' => self::EMPLOYER_RELATIONSHIP_TYPE_ID,
'contact_id_a' => $contact_id, 'contact_id_a' => $contact_id,
'contact_id_b' => $organisation_id, 'contact_id_b' => $organisation_id,
'is_active' => 1, 'is_active' => 1,
)); ]);
if ($existing_relationship['count'] == 0) { if ($existing_relationship['count'] == 0) {
// There is currently no (active) relationship between these contacts. // There is currently no (active) relationship between these contacts.
$new_relationship_data = array( $new_relationship_data = [
'relationship_type_id' => self::EMPLOYER_RELATIONSHIP_TYPE_ID, 'relationship_type_id' => self::EMPLOYER_RELATIONSHIP_TYPE_ID,
'contact_id_a' => $contact_id, 'contact_id_a' => $contact_id,
'contact_id_b' => $organisation_id, 'contact_id_b' => $organisation_id,
'is_active' => 1, 'is_active' => 1,
); ];
civicrm_api3('Relationship', 'create', $new_relationship_data); civicrm_api3('Relationship', 'create', $new_relationship_data);
} }
@ -312,12 +315,11 @@ class CRM_Twingle_Submission {
* @throws \CiviCRM_API3_Exception * @throws \CiviCRM_API3_Exception
*/ */
public static function civiSepaEnabled() { public static function civiSepaEnabled() {
$sepa_extension = civicrm_api3('Extension', 'get', array( $sepa_extension = civicrm_api3('Extension', 'get', [
'full_name' => 'org.project60.sepa', 'full_name' => 'org.project60.sepa',
'is_active' => 1, 'is_active' => 1,
)); ]);
return return Civi::settings()->get('twingle_use_sepa')
Civi::settings()->get('twingle_use_sepa')
&& $sepa_extension['count']; && $sepa_extension['count'];
} }
@ -334,25 +336,25 @@ class CRM_Twingle_Submission {
* to contribution parameter arrays. * to contribution parameter arrays.
*/ */
public static function getFrequencyMapping($donation_rhythm) { public static function getFrequencyMapping($donation_rhythm) {
$mapping = array( $mapping = [
'halfyearly' => array( 'halfyearly' => [
'frequency_unit' => 'month', 'frequency_unit' => 'month',
'frequency_interval' => 6, 'frequency_interval' => 6,
), ],
'quarterly' => array( 'quarterly' => [
'frequency_unit' => 'month', 'frequency_unit' => 'month',
'frequency_interval' => 3, 'frequency_interval' => 3,
), ],
'yearly' => array( 'yearly' => [
'frequency_unit' => 'month', 'frequency_unit' => 'month',
'frequency_interval' => 12, 'frequency_interval' => 12,
), ],
'monthly' => array( 'monthly' => [
'frequency_unit' => 'month', 'frequency_unit' => 'month',
'frequency_interval' => 1, 'frequency_interval' => 1,
), ],
'one_time' => array(), 'one_time' => [],
); ];
return $mapping[$donation_rhythm]; return $mapping[$donation_rhythm];
} }
@ -371,15 +373,15 @@ class CRM_Twingle_Submission {
* The next possible day of this or the next month to start collecting. * The next possible day of this or the next month to start collecting.
*/ */
public static function getSEPACycleDay($start_date, $creditor_id) { public static function getSEPACycleDay($start_date, $creditor_id) {
$buffer_days = (int) CRM_Sepa_Logic_Settings::getSetting("pp_buffer_days"); $buffer_days = (int) CRM_Sepa_Logic_Settings::getSetting('pp_buffer_days');
$frst_notice_days = (int) CRM_Sepa_Logic_Settings::getSetting("batching.FRST.notice", $creditor_id); $frst_notice_days = (int) CRM_Sepa_Logic_Settings::getSetting('batching.FRST.notice', $creditor_id);
$earliest_rcur_date = strtotime("$start_date + $frst_notice_days days + $buffer_days days"); $earliest_rcur_date = strtotime("$start_date + $frst_notice_days days + $buffer_days days");
// Find the next cycle day // Find the next cycle day
$cycle_days = CRM_Sepa_Logic_Settings::getListSetting("cycledays", range(1, 28), $creditor_id); $cycle_days = CRM_Sepa_Logic_Settings::getListSetting('cycledays', range(1, 28), $creditor_id);
$earliest_cycle_day = $earliest_rcur_date; $earliest_cycle_day = $earliest_rcur_date;
while (!in_array(date('j', $earliest_cycle_day), $cycle_days)) { while (!in_array(date('j', $earliest_cycle_day), $cycle_days)) {
$earliest_cycle_day = strtotime("+ 1 day", $earliest_cycle_day); $earliest_cycle_day = strtotime('+ 1 day', $earliest_cycle_day);
} }
return date('j', $earliest_cycle_day); return date('j', $earliest_cycle_day);
@ -406,7 +408,7 @@ class CRM_Twingle_Submission {
// then: check if campaign should be set it this context // then: check if campaign should be set it this context
$enabled_contexts = $profile->getAttribute('campaign_targets'); $enabled_contexts = $profile->getAttribute('campaign_targets');
if ($enabled_contexts === null || !is_array($enabled_contexts)) { if ($enabled_contexts === NULL || !is_array($enabled_contexts)) {
// backward compatibility: // backward compatibility:
$enabled_contexts = ['contribution', 'contact']; $enabled_contexts = ['contribution', 'contact'];
} }
@ -414,10 +416,12 @@ class CRM_Twingle_Submission {
// use the submitted campaign if set // use the submitted campaign if set
if (!empty($submission['campaign_id'])) { if (!empty($submission['campaign_id'])) {
$entity_data['campaign_id'] = $submission['campaign_id']; $entity_data['campaign_id'] = $submission['campaign_id'];
} // otherwise use the profile's }
// otherwise use the profile's
elseif (!empty($campaign = $profile->getAttribute('campaign'))) { elseif (!empty($campaign = $profile->getAttribute('campaign'))) {
$entity_data['campaign_id'] = $campaign; $entity_data['campaign_id'] = $campaign;
} }
} }
} }
} }

View file

@ -33,25 +33,36 @@ class CRM_Twingle_Tools {
*/ */
public static function checkRecurringContributionChange($recurring_contribution_id, $change) { public static function checkRecurringContributionChange($recurring_contribution_id, $change) {
// check if a change to the status is planned // check if a change to the status is planned
if (empty($change['contribution_status_id'])) return; if (empty($change['contribution_status_id'])) {
return;
}
// check if the target status is not closed // check if the target status is not closed
if (in_array($change['contribution_status_id'], [2,5])) return; if (in_array($change['contribution_status_id'], [2, 5])) {
return;
}
// check if we're suspended // check if we're suspended
if (self::$protection_suspended) return; if (self::$protection_suspended) {
return;
}
// check if protection is turned on // check if protection is turned on
$protection_on = Civi::settings()->get('twingle_protect_recurring'); $protection_on = Civi::settings()->get('twingle_protect_recurring');
if (empty($protection_on)) return; if (empty($protection_on)) {
return;
}
// load the recurring contribution // load the recurring contribution
$recurring_contribution = civicrm_api3('ContributionRecur', 'getsingle', [ $recurring_contribution = civicrm_api3('ContributionRecur', 'getsingle', [
'return' => 'trxn_id,contribution_status_id,payment_instrument_id,contact_id', 'return' => 'trxn_id,contribution_status_id,payment_instrument_id,contact_id',
'id' => $recurring_contribution_id]); 'id' => $recurring_contribution_id,
]);
// check if this is a SEPA transaction (doesn't concern us) // check if this is a SEPA transaction (doesn't concern us)
if (self::isSDD($recurring_contribution['payment_instrument_id'])) return; if (self::isSDD($recurring_contribution['payment_instrument_id'])) {
return;
}
// see if this recurring contribution is from Twingle // see if this recurring contribution is from Twingle
if (!self::isTwingleRecurringContribution($recurring_contribution_id, $recurring_contribution)) { if (!self::isTwingleRecurringContribution($recurring_contribution_id, $recurring_contribution)) {
@ -59,7 +70,9 @@ class CRM_Twingle_Tools {
} }
// check if it's really a termination (i.e. current status is 2 or 5) // check if it's really a termination (i.e. current status is 2 or 5)
if (!in_array($recurring_contribution['contribution_status_id'], [2,5])) return; if (!in_array($recurring_contribution['contribution_status_id'], [2, 5])) {
return;
}
// this _IS_ on of the cases where we should step in: // this _IS_ on of the cases where we should step in:
CRM_Twingle_Tools::processRecurringContributionTermination($recurring_contribution_id, $recurring_contribution); CRM_Twingle_Tools::processRecurringContributionTermination($recurring_contribution_id, $recurring_contribution);
@ -74,7 +87,9 @@ class CRM_Twingle_Tools {
public static function isTwingleRecurringContribution($recurring_contribution_id, $recurring_contribution = NULL) { public static function isTwingleRecurringContribution($recurring_contribution_id, $recurring_contribution = NULL) {
// this currently only works with prefixes // this currently only works with prefixes
$prefix = Civi::settings()->get('twingle_prefix'); $prefix = Civi::settings()->get('twingle_prefix');
if (empty($prefix)) return null; if (empty($prefix)) {
return NULL;
}
// load recurring contribution if necessary // load recurring contribution if necessary
if (empty($recurring_contribution['trxn_id'])) { if (empty($recurring_contribution['trxn_id'])) {
@ -95,7 +110,9 @@ class CRM_Twingle_Tools {
*/ */
public static function processRecurringContributionTermination($recurring_contribution_id, $recurring_contribution) { public static function processRecurringContributionTermination($recurring_contribution_id, $recurring_contribution) {
// check if we're suspended // check if we're suspended
if (self::$protection_suspended) return; if (self::$protection_suspended) {
return;
}
$protection_mode = Civi::settings()->get('twingle_protect_recurring'); $protection_mode = Civi::settings()->get('twingle_protect_recurring');
switch ($protection_mode) { switch ($protection_mode) {
@ -104,24 +121,28 @@ class CRM_Twingle_Tools {
break; break;
case CRM_Twingle_Config::RCUR_PROTECTION_EXCEPTION: case CRM_Twingle_Config::RCUR_PROTECTION_EXCEPTION:
throw new Exception(E::ts("This is a Twingle recurring contribution. It should be terminated through the Twingle interface, otherwise it will still be collected.")); throw new Exception(E::ts('This is a Twingle recurring contribution. It should be terminated through the Twingle interface, otherwise it will still be collected.'));
case CRM_Twingle_Config::RCUR_PROTECTION_ACTIVITY: case CRM_Twingle_Config::RCUR_PROTECTION_ACTIVITY:
// create contact source activity // create contact source activity
// first: get the contact ID // first: get the contact ID
if (!empty($recurring_contribution['contact_id'])) { if (!empty($recurring_contribution['contact_id'])) {
$target_id = (int) $recurring_contribution['contact_id']; $target_id = (int) $recurring_contribution['contact_id'];
} else { }
else {
$target_id = (int) civicrm_api3('ContributionRecur', 'getvalue', [ $target_id = (int) civicrm_api3('ContributionRecur', 'getvalue', [
'id' => $recurring_contribution_id, 'id' => $recurring_contribution_id,
'return' => 'contact_id']); 'return' => 'contact_id',
]);
} }
if (!empty($recurring_contribution['trxn_id'])) { if (!empty($recurring_contribution['trxn_id'])) {
$trxn_id = $recurring_contribution['trxn_id']; $trxn_id = $recurring_contribution['trxn_id'];
} else { }
else {
$trxn_id = civicrm_api3('ContributionRecur', 'getvalue', [ $trxn_id = civicrm_api3('ContributionRecur', 'getvalue', [
'id' => $recurring_contribution_id, 'id' => $recurring_contribution_id,
'return' => 'trxn_id']); 'return' => 'trxn_id',
]);
} }
try { try {
@ -136,7 +157,8 @@ class CRM_Twingle_Tools {
[1 => $recurring_contribution_id, 2 => $trxn_id]), [1 => $recurring_contribution_id, 2 => $trxn_id]),
'source_contact_id' => CRM_Core_Session::getLoggedInContactID(), 'source_contact_id' => CRM_Core_Session::getLoggedInContactID(),
]); ]);
} catch (Exception $ex) { }
catch (Exception $ex) {
Civi::log()->warning("TwingleAPI: Couldn't create recurring protection activity: " . $ex->getMessage()); Civi::log()->warning("TwingleAPI: Couldn't create recurring protection activity: " . $ex->getMessage());
} }
break; break;
@ -163,7 +185,7 @@ class CRM_Twingle_Tools {
$lookup = civicrm_api3('OptionValue', 'get', [ $lookup = civicrm_api3('OptionValue', 'get', [
'option_group_id' => 'payment_instrument', 'option_group_id' => 'payment_instrument',
'name' => ['IN' => $sepa_payment_instruments], 'name' => ['IN' => $sepa_payment_instruments],
'return' => 'value' 'return' => 'value',
]); ]);
foreach ($lookup['values'] as $payment_instrument) { foreach ($lookup['values'] as $payment_instrument) {
$sepa_payment_instruments[] = $payment_instrument['value']; $sepa_payment_instruments[] = $payment_instrument['value'];
@ -202,10 +224,12 @@ class CRM_Twingle_Tools {
if ($ooff_mandate['count'] == 1) { if ($ooff_mandate['count'] == 1) {
return reset($ooff_mandate['values']); return reset($ooff_mandate['values']);
} }
} catch (Exception $ex) { }
catch (Exception $ex) {
Civi::log()->warning("CRM_Twingle_Tools::getMandate failed for [{$contribution_id}]: " . $ex->getMessage()); Civi::log()->warning("CRM_Twingle_Tools::getMandate failed for [{$contribution_id}]: " . $ex->getMessage());
} }
} }
return NULL; return NULL;
} }
} }

View file

@ -20,11 +20,11 @@ class CRM_Twingle_Upgrader extends CRM_Twingle_Upgrader_Base {
/** /**
* Example: Run an external SQL script when the module is uninstalled. * Example: Run an external SQL script when the module is uninstalled.
* *
public function uninstall() { * public function uninstall() {
$this->executeSqlFile('sql/myuninstall.sql'); * $this->executeSqlFile('sql/myuninstall.sql');
} * }
*
/** * /**
* Copy financial_type_id setting to new setting financial_type_id_recur. * Copy financial_type_id setting to new setting financial_type_id_recur.
*/ */
public function upgrade_4000() { public function upgrade_4000() {
@ -74,14 +74,15 @@ class CRM_Twingle_Upgrader extends CRM_Twingle_Upgrader_Base {
$profile = new CRM_Twingle_Profile($profile_name, $profile_data); $profile = new CRM_Twingle_Profile($profile_name, $profile_data);
$data = json_encode($profile->getData()); $data = json_encode($profile->getData());
CRM_Core_DAO::executeQuery( CRM_Core_DAO::executeQuery(
"INSERT IGNORE INTO civicrm_twingle_profile(name,config,last_access,access_counter) VALUES (%1, %2, NOW(), 0)", 'INSERT IGNORE INTO civicrm_twingle_profile(name,config,last_access,access_counter) VALUES (%1, %2, NOW(), 0)',
[ [
1 => [$profile_name, 'String'], 1 => [$profile_name, 'String'],
2 => [$data, 'String'] 2 => [$data, 'String'],
]); ]);
} }
} }
return TRUE; return TRUE;
} }
} }

View file

@ -9,7 +9,7 @@ use CRM_Twingle_ExtensionUtil as E;
class CRM_Twingle_Upgrader_Base { class CRM_Twingle_Upgrader_Base {
/** /**
* @var varies, subclass of this * @var variessubclassofthis
*/ */
static $instance; static $instance;
@ -19,22 +19,22 @@ class CRM_Twingle_Upgrader_Base {
protected $ctx; protected $ctx;
/** /**
* @var string, eg 'com.example.myextension' * @var stringegcomexamplemyextension
*/ */
protected $extensionName; protected $extensionName;
/** /**
* @var string, full path to the extension's source tree * @var stringfullpathtotheextensionssourcetree
*/ */
protected $extensionDir; protected $extensionDir;
/** /**
* @var array(revisionNumber) sorted numerically * @var arrayrevisionNumbersortednumerically
*/ */
private $revisions; private $revisions;
/** /**
* @var boolean * @var bool
* Flag to clean up extension revision data in civicrm_setting * Flag to clean up extension revision data in civicrm_setting
*/ */
private $revisionStorageIsDeprecated = FALSE; private $revisionStorageIsDeprecated = FALSE;
@ -42,7 +42,7 @@ class CRM_Twingle_Upgrader_Base {
/** /**
* Obtain a reference to the active upgrade handler. * Obtain a reference to the active upgrade handler.
*/ */
static public function instance() { public static function instance() {
if (!self::$instance) { if (!self::$instance) {
// FIXME auto-generate // FIXME auto-generate
self::$instance = new CRM_Twingle_Upgrader( self::$instance = new CRM_Twingle_Upgrader(
@ -63,13 +63,13 @@ class CRM_Twingle_Upgrader_Base {
* CRM_Twingle_Upgrader_Base::_queueAdapter($ctx, 'methodName', 'arg1', 'arg2'); * CRM_Twingle_Upgrader_Base::_queueAdapter($ctx, 'methodName', 'arg1', 'arg2');
* @endcode * @endcode
*/ */
static public function _queueAdapter() { public static function _queueAdapter() {
$instance = self::instance(); $instance = self::instance();
$args = func_get_args(); $args = func_get_args();
$instance->ctx = array_shift($args); $instance->ctx = array_shift($args);
$instance->queue = $instance->ctx->queue; $instance->queue = $instance->ctx->queue;
$method = array_shift($args); $method = array_shift($args);
return call_user_func_array(array($instance, $method), $args); return call_user_func_array([$instance, $method], $args);
} }
public function __construct($extensionName, $extensionDir) { public function __construct($extensionName, $extensionDir) {
@ -144,7 +144,7 @@ class CRM_Twingle_Upgrader_Base {
* provides syntatic sugar for queueing several tasks that * provides syntatic sugar for queueing several tasks that
* run different queries * run different queries
*/ */
public function executeSql($query, $params = array()) { public function executeSql($query, $params = []) {
// FIXME verify that we raise an exception on error // FIXME verify that we raise an exception on error
CRM_Core_DAO::executeQuery($query, $params); CRM_Core_DAO::executeQuery($query, $params);
return TRUE; return TRUE;
@ -163,11 +163,11 @@ class CRM_Twingle_Upgrader_Base {
$args = func_get_args(); $args = func_get_args();
$title = array_shift($args); $title = array_shift($args);
$task = new CRM_Queue_Task( $task = new CRM_Queue_Task(
array(get_class($this), '_queueAdapter'), [get_class($this), '_queueAdapter'],
$args, $args,
$title $title
); );
return $this->queue->createItem($task, array('weight' => -1)); return $this->queue->createItem($task, ['weight' => -1]);
} }
// ******** Revision-tracking helpers ******** // ******** Revision-tracking helpers ********
@ -200,23 +200,23 @@ class CRM_Twingle_Upgrader_Base {
$currentRevision = $this->getCurrentRevision(); $currentRevision = $this->getCurrentRevision();
foreach ($this->getRevisions() as $revision) { foreach ($this->getRevisions() as $revision) {
if ($revision > $currentRevision) { if ($revision > $currentRevision) {
$title = ts('Upgrade %1 to revision %2', array( $title = ts('Upgrade %1 to revision %2', [
1 => $this->extensionName, 1 => $this->extensionName,
2 => $revision, 2 => $revision,
)); ]);
// note: don't use addTask() because it sets weight=-1 // note: don't use addTask() because it sets weight=-1
$task = new CRM_Queue_Task( $task = new CRM_Queue_Task(
array(get_class($this), '_queueAdapter'), [get_class($this), '_queueAdapter'],
array('upgrade_' . $revision), ['upgrade_' . $revision],
$title $title
); );
$this->queue->createItem($task); $this->queue->createItem($task);
$task = new CRM_Queue_Task( $task = new CRM_Queue_Task(
array(get_class($this), '_queueAdapter'), [get_class($this), '_queueAdapter'],
array('setCurrentRevision', $revision), ['setCurrentRevision', $revision],
$title $title
); );
$this->queue->createItem($task); $this->queue->createItem($task);
@ -231,7 +231,7 @@ class CRM_Twingle_Upgrader_Base {
*/ */
public function getRevisions() { public function getRevisions() {
if (!is_array($this->revisions)) { if (!is_array($this->revisions)) {
$this->revisions = array(); $this->revisions = [];
$clazz = new ReflectionClass(get_class($this)); $clazz = new ReflectionClass(get_class($this));
$methods = $clazz->getMethods(); $methods = $clazz->getMethods();
@ -302,7 +302,7 @@ class CRM_Twingle_Upgrader_Base {
$this->executeCustomDataFileByAbsPath($file); $this->executeCustomDataFileByAbsPath($file);
} }
} }
if (is_callable(array($this, 'install'))) { if (is_callable([$this, 'install'])) {
$this->install(); $this->install();
} }
} }
@ -315,7 +315,7 @@ class CRM_Twingle_Upgrader_Base {
if (!empty($revisions)) { if (!empty($revisions)) {
$this->setCurrentRevision(max($revisions)); $this->setCurrentRevision(max($revisions));
} }
if (is_callable(array($this, 'postInstall'))) { if (is_callable([$this, 'postInstall'])) {
$this->postInstall(); $this->postInstall();
} }
} }
@ -330,7 +330,7 @@ class CRM_Twingle_Upgrader_Base {
$this->executeSqlTemplate($file); $this->executeSqlTemplate($file);
} }
} }
if (is_callable(array($this, 'uninstall'))) { if (is_callable([$this, 'uninstall'])) {
$this->uninstall(); $this->uninstall();
} }
$files = glob($this->extensionDir . '/sql/*_uninstall.sql'); $files = glob($this->extensionDir . '/sql/*_uninstall.sql');
@ -346,7 +346,7 @@ class CRM_Twingle_Upgrader_Base {
*/ */
public function onEnable() { public function onEnable() {
// stub for possible future use // stub for possible future use
if (is_callable(array($this, 'enable'))) { if (is_callable([$this, 'enable'])) {
$this->enable(); $this->enable();
} }
} }
@ -356,7 +356,7 @@ class CRM_Twingle_Upgrader_Base {
*/ */
public function onDisable() { public function onDisable() {
// stub for possible future use // stub for possible future use
if (is_callable(array($this, 'disable'))) { if (is_callable([$this, 'disable'])) {
$this->disable(); $this->disable();
} }
} }
@ -364,7 +364,7 @@ class CRM_Twingle_Upgrader_Base {
public function onUpgrade($op, CRM_Queue_Queue $queue = NULL) { public function onUpgrade($op, CRM_Queue_Queue $queue = NULL) {
switch ($op) { switch ($op) {
case 'check': case 'check':
return array($this->hasPendingRevisions()); return [$this->hasPendingRevisions()];
case 'enqueue': case 'enqueue':
return $this->enqueuePendingRevisions($queue); return $this->enqueuePendingRevisions($queue);

View file

@ -26,34 +26,34 @@ use CRM_Twingle_ExtensionUtil as E;
* @see http://wiki.civicrm.org/confluence/display/CRMDOC/API+Architecture+Standards * @see http://wiki.civicrm.org/confluence/display/CRMDOC/API+Architecture+Standards
*/ */
function _civicrm_api3_twingle_donation_Cancel_spec(&$params) { function _civicrm_api3_twingle_donation_Cancel_spec(&$params) {
$params['project_id'] = array( $params['project_id'] = [
'name' => 'project_id', 'name' => 'project_id',
'title' => E::ts('Project ID'), 'title' => E::ts('Project ID'),
'type' => CRM_Utils_Type::T_STRING, 'type' => CRM_Utils_Type::T_STRING,
'api.required' => 1, 'api.required' => 1,
'description' => E::ts('The Twingle project ID.'), 'description' => E::ts('The Twingle project ID.'),
); ];
$params['trx_id'] = array( $params['trx_id'] = [
'name' => 'trx_id', 'name' => 'trx_id',
'title' => E::ts('Transaction ID'), 'title' => E::ts('Transaction ID'),
'type' => CRM_Utils_Type::T_STRING, 'type' => CRM_Utils_Type::T_STRING,
'api.required' => 1, 'api.required' => 1,
'description' => E::ts('The unique transaction ID of the donation'), 'description' => E::ts('The unique transaction ID of the donation'),
); ];
$params['cancelled_at'] = array( $params['cancelled_at'] = [
'name' => 'cancelled_at', 'name' => 'cancelled_at',
'title' => E::ts('Cancelled at'), 'title' => E::ts('Cancelled at'),
'type' => CRM_Utils_Type::T_INT, 'type' => CRM_Utils_Type::T_INT,
'api.required' => 1, 'api.required' => 1,
'description' => E::ts('The date when the donation was cancelled, format: YmdHis.'), 'description' => E::ts('The date when the donation was cancelled, format: YmdHis.'),
); ];
$params['cancel_reason'] = array( $params['cancel_reason'] = [
'name' => 'cancel_reason', 'name' => 'cancel_reason',
'title' => E::ts('Cancel reason'), 'title' => E::ts('Cancel reason'),
'type' => CRM_Utils_Type::T_STRING, 'type' => CRM_Utils_Type::T_STRING,
'api.required' => 1, 'api.required' => 1,
'description' => E::ts('The reason for the donation being cancelled.'), 'description' => E::ts('The reason for the donation being cancelled.'),
); ];
} }
/** /**
@ -82,15 +82,15 @@ function civicrm_api3_twingle_donation_Cancel($params) {
// Retrieve (recurring) contribution. // Retrieve (recurring) contribution.
$default_profile = CRM_Twingle_Profile::getProfile('default'); $default_profile = CRM_Twingle_Profile::getProfile('default');
try { try {
$contribution = civicrm_api3('Contribution', 'getsingle', array( $contribution = civicrm_api3('Contribution', 'getsingle', [
'trxn_id' => $default_profile->getTransactionID($params['trx_id']), 'trxn_id' => $default_profile->getTransactionID($params['trx_id']),
)); ]);
$contribution_type = 'Contribution'; $contribution_type = 'Contribution';
} }
catch (CiviCRM_API3_Exception $exception) { catch (CiviCRM_API3_Exception $exception) {
$contribution = civicrm_api3('ContributionRecur', 'getsingle', array( $contribution = civicrm_api3('ContributionRecur', 'getsingle', [
'trxn_id' => $default_profile->getTransactionID($params['trx_id']), 'trxn_id' => $default_profile->getTransactionID($params['trx_id']),
)); ]);
$contribution_type = 'ContributionRecur'; $contribution_type = 'ContributionRecur';
} }
@ -102,7 +102,7 @@ function civicrm_api3_twingle_donation_Cancel($params) {
$mandate = CRM_Twingle_Tools::getMandateFor($contribution['id']); $mandate = CRM_Twingle_Tools::getMandateFor($contribution['id']);
if (!$mandate) { if (!$mandate) {
throw new CiviCRM_API3_Exception( throw new CiviCRM_API3_Exception(
E::ts("SEPA Mandate for contribution [%1 not found.", [1 => $contribution['id']]), E::ts('SEPA Mandate for contribution [%1 not found.', [1 => $contribution['id']]),
'api_error' 'api_error'
); );
} }
@ -115,7 +115,8 @@ function civicrm_api3_twingle_donation_Cancel($params) {
$end_date = date('Ymd', max( $end_date = date('Ymd', max(
time(), time(),
$end_date->getTimestamp())); $end_date->getTimestamp()));
} else { }
else {
// end date couldn't be parsed, use 'now' // end date couldn't be parsed, use 'now'
$end_date = date('Ymd'); $end_date = date('Ymd');
} }
@ -132,19 +133,19 @@ function civicrm_api3_twingle_donation_Cancel($params) {
} }
// Retrieve updated contribution for return value. // Retrieve updated contribution for return value.
$contribution = civicrm_api3($contribution_type, 'getsingle', array( $contribution = civicrm_api3($contribution_type, 'getsingle', [
'id' => $contribution['id'], 'id' => $contribution['id'],
)); ]);
} }
else { else {
// regular contribution // regular contribution
CRM_Twingle_Tools::$protection_suspended = TRUE; CRM_Twingle_Tools::$protection_suspended = TRUE;
$contribution = civicrm_api3($contribution_type, 'create', array( $contribution = civicrm_api3($contribution_type, 'create', [
'id' => $contribution['id'], 'id' => $contribution['id'],
'cancel_date' => $params['cancelled_at'], 'cancel_date' => $params['cancelled_at'],
'contribution_status_id' => 'Cancelled', 'contribution_status_id' => 'Cancelled',
'cancel_reason' => $params['cancel_reason'], 'cancel_reason' => $params['cancel_reason'],
)); ]);
CRM_Twingle_Tools::$protection_suspended = FALSE; CRM_Twingle_Tools::$protection_suspended = FALSE;
} }

View file

@ -26,27 +26,27 @@ use CRM_Twingle_ExtensionUtil as E;
* @see http://wiki.civicrm.org/confluence/display/CRMDOC/API+Architecture+Standards * @see http://wiki.civicrm.org/confluence/display/CRMDOC/API+Architecture+Standards
*/ */
function _civicrm_api3_twingle_donation_endrecurring_spec(&$params) { function _civicrm_api3_twingle_donation_endrecurring_spec(&$params) {
$params['project_id'] = array( $params['project_id'] = [
'name' => 'project_id', 'name' => 'project_id',
'title' => E::ts('Project ID'), 'title' => E::ts('Project ID'),
'type' => CRM_Utils_Type::T_STRING, 'type' => CRM_Utils_Type::T_STRING,
'api.required' => 1, 'api.required' => 1,
'description' => E::ts('The Twingle project ID.'), 'description' => E::ts('The Twingle project ID.'),
); ];
$params['trx_id'] = array( $params['trx_id'] = [
'name' => 'trx_id', 'name' => 'trx_id',
'title' => E::ts('Transaction ID'), 'title' => E::ts('Transaction ID'),
'type' => CRM_Utils_Type::T_STRING, 'type' => CRM_Utils_Type::T_STRING,
'api.required' => 1, 'api.required' => 1,
'description' => E::ts('The unique transaction ID of the donation'), 'description' => E::ts('The unique transaction ID of the donation'),
); ];
$params['ended_at'] = array( $params['ended_at'] = [
'name' => 'ended_at', 'name' => 'ended_at',
'title' => E::ts('Ended at'), 'title' => E::ts('Ended at'),
'type' => CRM_Utils_Type::T_INT, 'type' => CRM_Utils_Type::T_INT,
'api.required' => 1, 'api.required' => 1,
'description' => E::ts('The date when the recurring donation was ended, format: YmdHis.'), 'description' => E::ts('The date when the recurring donation was ended, format: YmdHis.'),
); ];
} }
/** /**
@ -73,9 +73,9 @@ function civicrm_api3_twingle_donation_endrecurring($params) {
} }
$default_profile = CRM_Twingle_Profile::getProfile('default'); $default_profile = CRM_Twingle_Profile::getProfile('default');
$contribution = civicrm_api3('ContributionRecur', 'getsingle', array( $contribution = civicrm_api3('ContributionRecur', 'getsingle', [
'trxn_id' => $default_profile->getTransactionID($params['trx_id']), 'trxn_id' => $default_profile->getTransactionID($params['trx_id']),
)); ]);
// End SEPA mandate (which ends the associated recurring contribution) or // End SEPA mandate (which ends the associated recurring contribution) or
// recurring contributions. // recurring contributions.
@ -87,7 +87,7 @@ function civicrm_api3_twingle_donation_endrecurring($params) {
$mandate = CRM_Twingle_Tools::getMandateFor($contribution['id']); $mandate = CRM_Twingle_Tools::getMandateFor($contribution['id']);
if (!$mandate) { if (!$mandate) {
throw new CiviCRM_API3_Exception( throw new CiviCRM_API3_Exception(
E::ts("SEPA Mandate for recurring contribution [%1 not found.", [1 => $contribution['id']]), E::ts('SEPA Mandate for recurring contribution [%1 not found.', [1 => $contribution['id']]),
'api_error' 'api_error'
); );
} }
@ -99,7 +99,8 @@ function civicrm_api3_twingle_donation_endrecurring($params) {
$end_date = date('Ymd', max( $end_date = date('Ymd', max(
time(), time(),
$end_date->getTimestamp())); $end_date->getTimestamp()));
} else { }
else {
// end date couldn't be parsed, use 'now' // end date couldn't be parsed, use 'now'
$end_date = date('Ymd'); $end_date = date('Ymd');
} }
@ -107,7 +108,7 @@ function civicrm_api3_twingle_donation_endrecurring($params) {
// verify that the mandate has not been terminated in the past // verify that the mandate has not been terminated in the past
if ($mandate['status'] != 'FRST' && $mandate['status'] != 'RCUR') { if ($mandate['status'] != 'FRST' && $mandate['status'] != 'RCUR') {
throw new CiviCRM_API3_Exception( throw new CiviCRM_API3_Exception(
E::ts("SEPA Mandate [%1] already terminated.", [1 => $mandate_id]), E::ts('SEPA Mandate [%1] already terminated.', [1 => $mandate_id]),
'api_error' 'api_error'
); );
} }
@ -122,18 +123,18 @@ function civicrm_api3_twingle_donation_endrecurring($params) {
'api_error' 'api_error'
); );
} }
$contribution = civicrm_api3('ContributionRecur', 'getsingle', array( $contribution = civicrm_api3('ContributionRecur', 'getsingle', [
'id' => $contribution['id'], 'id' => $contribution['id'],
)); ]);
} }
else { else {
// END RECURRING CONTRIBUTION // END RECURRING CONTRIBUTION
CRM_Twingle_Tools::$protection_suspended = TRUE; CRM_Twingle_Tools::$protection_suspended = TRUE;
$contribution = civicrm_api3('ContributionRecur', 'create', array( $contribution = civicrm_api3('ContributionRecur', 'create', [
'id' => $contribution['id'], 'id' => $contribution['id'],
'end_date' => $params['ended_at'], 'end_date' => $params['ended_at'],
'contribution_status_id' => CRM_Twingle_Submission::CONTRIBUTION_STATUS_COMPLETED, 'contribution_status_id' => CRM_Twingle_Submission::CONTRIBUTION_STATUS_COMPLETED,
)); ]);
CRM_Twingle_Tools::$protection_suspended = FALSE; CRM_Twingle_Tools::$protection_suspended = FALSE;
} }