From 69843bc98185612f431622a6b6dd6323f47d6618 Mon Sep 17 00:00:00 2001 From: Jens Schuppe Date: Mon, 25 Mar 2024 14:58:51 +0100 Subject: [PATCH] PHP Code Beautifier fixes --- CRM/Twingle/Config.php | 7 +- CRM/Twingle/Form/Profile.php | 285 +++++++++++++++--------- CRM/Twingle/Form/Settings.php | 78 +++---- CRM/Twingle/Page/Profiles.php | 2 +- CRM/Twingle/Submission.php | 74 +++--- CRM/Twingle/Tools.php | 96 +++++--- CRM/Twingle/Upgrader.php | 15 +- CRM/Twingle/Upgrader/Base.php | 48 ++-- api/v3/TwingleDonation/Cancel.php | 39 ++-- api/v3/TwingleDonation/Endrecurring.php | 37 +-- 10 files changed, 389 insertions(+), 292 deletions(-) diff --git a/CRM/Twingle/Config.php b/CRM/Twingle/Config.php index 81f4647..557a572 100644 --- a/CRM/Twingle/Config.php +++ b/CRM/Twingle/Config.php @@ -29,9 +29,10 @@ class CRM_Twingle_Config { */ public static function getRecurringProtectionOptions() { return [ - self::RCUR_PROTECTION_OFF => E::ts("No"), - self::RCUR_PROTECTION_EXCEPTION => E::ts("Raise Exception"), - self::RCUR_PROTECTION_ACTIVITY => E::ts("Create Activity"), + self::RCUR_PROTECTION_OFF => E::ts('No'), + self::RCUR_PROTECTION_EXCEPTION => E::ts('Raise Exception'), + self::RCUR_PROTECTION_ACTIVITY => E::ts('Create Activity'), ]; } + } diff --git a/CRM/Twingle/Form/Profile.php b/CRM/Twingle/Form/Profile.php index ba542eb..e1fc67a 100644 --- a/CRM/Twingle/Form/Profile.php +++ b/CRM/Twingle/Form/Profile.php @@ -23,7 +23,7 @@ use CRM_Twingle_ExtensionUtil as E; 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. */ @@ -151,25 +151,27 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { switch ($this->_op) { case 'delete': if ($profile_name) { - CRM_Utils_System::setTitle(E::ts('Delete Twingle API profile %1', array(1 => $profile_name))); - $this->addButtons(array( - array( + CRM_Utils_System::setTitle(E::ts('Delete Twingle API profile %1', [1 => $profile_name])); + $this->addButtons([ + [ 'type' => 'submit', 'name' => ($profile_name == 'default' ? E::ts('Reset') : E::ts('Delete')), 'isDefault' => TRUE, - ), - )); + ], + ]); } parent::buildQuickForm(); return; + case 'edit': // When editing without a valid profile name, edit the default profile. if (!$profile_name) { $profile_name = 'default'; $this->profile = CRM_Twingle_Profile::getProfile($profile_name); } - CRM_Utils_System::setTitle(E::ts('Edit Twingle API profile %1', array(1 => $this->profile->getName()))); + CRM_Utils_System::setTitle(E::ts('Edit Twingle API profile %1', [1 => $this->profile->getName()])); break; + case 'copy': // Retrieve the source profile name. $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); CRM_Utils_System::setTitle(E::ts('New Twingle API profile')); break; + case 'create': // Load factory default profile values. $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'), 'name', E::ts('Profile name'), - array(), + [], !$is_default ); $this->add( - 'text', // field type - 'selector', // field name - E::ts('Project IDs'), // field label + // field type + 'text', + // field name + 'selector', + // field label + E::ts('Project IDs'), ['class' => 'huge'], - TRUE // is required + // is required + TRUE ); $this->add( @@ -238,18 +245,28 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { ); $this->add( - 'select', // field type - 'financial_type_id', // field name - E::ts('Financial type'), // field label - static::getFinancialTypes(), // list of options - TRUE // is required + // field type + 'select', + // field name + 'financial_type_id', + // field label + E::ts('Financial type'), + // list of options + static::getFinancialTypes(), + // is required + TRUE ); $this->add( - 'select', // field type - 'financial_type_id_recur', // field name - E::ts('Financial type (recurring)'), // field label - static::getFinancialTypes(), // list of options - TRUE // is required + // field type + 'select', + // field name + 'financial_type_id_recur', + // field label + E::ts('Financial type (recurring)'), + // list of options + static::getFinancialTypes(), + // is required + TRUE ); $this->add( @@ -297,11 +314,16 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { $this->assign('payment_instruments', $payment_instruments); foreach ($payment_instruments as $pi_name => $pi_label) { $this->add( - 'select', // field type - $pi_name, // field name - E::ts('Record %1 as', [1 => $pi_label]), // field label - static::getPaymentInstruments(), // list of options - TRUE // is required + // field type + 'select', + // field name + $pi_name, + // field label + E::ts('Record %1 as', [1 => $pi_label]), + // list of options + static::getPaymentInstruments(), + // is required + TRUE ); $this->add( @@ -324,46 +346,70 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { } $this->add( - 'checkbox', // field type - 'newsletter_double_opt_in', // field name - E::ts('Use Double-Opt-In for newsletter'), // field label - FALSE, // is not required + // field type + 'checkbox', + // field name + 'newsletter_double_opt_in', + // field label + E::ts('Use Double-Opt-In for newsletter'), + // is not required + FALSE, [] ); $this->add( - 'select', // field type - 'newsletter_groups', // field name - E::ts('Sign up for newsletter groups'), // field label - static::getNewsletterGroups(), // list of options - FALSE, // is not required + // field type + 'select', + // field name + 'newsletter_groups', + // field label + E::ts('Sign up for newsletter groups'), + // list of options + static::getNewsletterGroups(), + // is not required + FALSE, ['class' => 'crm-select2 huge', 'multiple' => 'multiple'] ); $this->add( - 'select', // field type - 'postinfo_groups', // field name - E::ts('Sign up for postal mail groups'), // field label - static::getPostinfoGroups(), // list of options - FALSE, // is not required + // field type + 'select', + // field name + 'postinfo_groups', + // 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'] ); $this->add( - 'select', // field type - 'donation_receipt_groups', // field name - E::ts('Sign up for Donation receipt groups'), // field label - static::getDonationReceiptGroups(), // list of options - FALSE, // is not required + // field type + 'select', + // field name + 'donation_receipt_groups', + // 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'] ); $this->add( - 'select', // field type - 'campaign', // field name - E::ts('Default Campaign'), // field label - ['' => E::ts('- none -')] + static::getCampaigns(), // list of options - FALSE, // is not required + // field type + 'select', + // field name + 'campaign', + // field label + E::ts('Default Campaign'), + // list of options + ['' => E::ts('- none -')] + static::getCampaigns(), + // is not required + FALSE, ['class' => 'crm-select2 huge'] ); @@ -372,30 +418,41 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { 'campaign_targets', E::ts('Set Campaign for'), [ - 'contribution' => E::ts("Contribution"), - 'recurring' => E::ts("Recurring Contribution"), - 'membership' => E::ts("Membership"), - 'mandate' => E::ts("SEPA Mandate"), - 'contact' => E::ts("Contacts (XCM)"), + 'contribution' => E::ts('Contribution'), + 'recurring' => E::ts('Recurring Contribution'), + 'membership' => E::ts('Membership'), + 'mandate' => E::ts('SEPA Mandate'), + 'contact' => E::ts('Contacts (XCM)'), ], - FALSE, // is not required + // is not required + FALSE, ['class' => 'crm-select2 huge', 'multiple' => 'multiple'] ); $this->add( - 'select', // field type - 'membership_type_id', // field name - E::ts('Create membership of type'), // field label - ['' => E::ts('- none -')] + static::getMembershipTypes(), // list of options - FALSE, // is not required + // field type + 'select', + // field name + 'membership_type_id', + // field label + E::ts('Create membership of type'), + // list of options + ['' => E::ts('- none -')] + static::getMembershipTypes(), + // is not required + FALSE, ['class' => 'crm-select2 huge'] ); $this->add( - 'select', // field type - 'membership_type_id_recur', // field name - E::ts('Create membership of type (recurring)'), // field label - ['' => E::ts('- none -')] + static::getMembershipTypes(), // list of options - FALSE, // is not required + // field type + 'select', + // field name + 'membership_type_id_recur', + // 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'] ); $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->add( - 'text', // field type - 'contribution_source', // field name - E::ts('Contribution source'), // field label + // field type + 'text', + // 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', E::ts('Required address components'), [ - 'street_address' => E::ts("Street"), - 'postal_code' => E::ts("Postal Code"), - 'city' => E::ts("City"), - 'country' => E::ts("Country"), + 'street_address' => E::ts('Street'), + 'postal_code' => E::ts('Postal Code'), + 'city' => E::ts('City'), + 'country' => E::ts('Country'), ], - FALSE, // is not required + // is not required + FALSE, ['class' => 'crm-select2 huge', 'multiple' => 'multiple'] ); $this->add( - 'textarea', // field type - 'custom_field_mapping', // field name - E::ts('Custom field mapping'), // field label + // field type + 'textarea', + // 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. - 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.'); } @@ -483,7 +547,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { ); } 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) { throw new Exception( E::ts('Could not parse custom field mapping.') @@ -494,40 +558,41 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { // Check for custom field existence try { - $custom_field = civicrm_api3('CustomField', 'getsingle', array( + $custom_field = civicrm_api3('CustomField', 'getsingle', [ 'id' => $custom_field_id, - )); + ]); } catch (CiviCRM_API3_Exception $exception) { throw new Exception( E::ts( 'Custom field custom_%1 does not exist.', - array(1 => $custom_field_id) + [1 => $custom_field_id] ) ); } // Only allow custom fields on relevant entities. try { - $custom_group = civicrm_api3('CustomGroup', 'getsingle', array( + $custom_group = civicrm_api3('CustomGroup', 'getsingle', [ 'id' => $custom_field['custom_group_id'], - 'extends' => array( - 'IN' => array( + 'extends' => [ + 'IN' => [ 'Contact', 'Individual', 'Organization', 'Contribution', 'ContributionRecur', - ), - ), - )); - } catch (CiviCRM_API3_Exception $exception) { + ], + ], + ]); + } + catch (CiviCRM_API3_Exception $exception) { throw new Exception( E::ts( '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() { $values = $this->exportValues(); - if (in_array($this->_op, array('create', 'edit', 'copy'))) { + if (in_array($this->_op, ['create', 'edit', 'copy'])) { if (empty($values['name'])) { $values['name'] = 'default'; } @@ -614,9 +679,9 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { public static function getXCMProfiles() { if (!isset(static::$_xcm_profiles)) { if (method_exists('CRM_Xcm_Configuration', 'getProfileList')) { - static::$_xcm_profiles = array( - '' => E::ts("<select profile>"), - ); + static::$_xcm_profiles = [ + '' => E::ts('<select profile>'), + ]; $profiles = CRM_Xcm_Configuration::getProfileList(); foreach ($profiles as $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', [ 'option.limit' => 0, 'is_active' => 1, - 'return' => 'id,name' + 'return' => 'id,name', ]); foreach ($query['values'] as $type) { static::$_financialTypes[$type['id']] = $type['name']; @@ -663,7 +728,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { $query = civicrm_api3('MembershipType', 'get', [ 'option.limit' => 0, 'is_active' => 1, - 'return' => 'id,name' + 'return' => 'id,name', ]); foreach ($query['values'] as $type) { static::$_membershipTypes[$type['id']] = $type['name']; @@ -711,13 +776,13 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { if (!isset(static::$_prefixOptions)) { static::$_prefixOptions = ['' => E::ts('none')]; $query = civicrm_api3('OptionValue', 'get', [ - 'option.limit' => 0, - 'option_group_id' => 'individual_prefix', - 'is_active' => 1, - 'return' => [ - 'value', - 'label', - ], + 'option.limit' => 0, + 'option_group_id' => 'individual_prefix', + 'is_active' => 1, + 'return' => [ + 'value', + 'label', + ], ]); foreach ($query['values'] as $prefix) { static::$_prefixOptions[$prefix['value']] = $prefix['label']; @@ -763,7 +828,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { 'option.limit' => 0, 'option_group_id' => 'payment_instrument', 'is_active' => 1, - 'return' => 'value,label' + 'return' => 'value,label', ]); foreach ($query['values'] as $payment_instrument) { // 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' => [ 'value', 'label', - ] + ], ] ); @@ -837,7 +902,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { 'is_active' => 1, 'group_type' => ['LIKE' => '%' . CRM_Utils_Array::implodePadded($group_type['value']) . '%'], 'option.limit' => 0, - 'return' => 'id,name' + 'return' => 'id,name', ]); foreach ($query['values'] as $group) { static::$_newsletterGroups[$group['id']] = $group['name']; @@ -863,7 +928,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { $query = civicrm_api3('Group', 'get', [ 'option.limit' => 0, 'is_active' => 1, - 'return' => 'id,name' + 'return' => 'id,name', ]); foreach ($query['values'] as $group) { static::$_groups[$group['id']] = $group['name']; @@ -911,7 +976,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { 'return' => [ 'id', 'title', - ] + ], ]); foreach ($query['values'] as $campaign) { static::$_campaigns[$campaign['id']] = $campaign['title']; diff --git a/CRM/Twingle/Form/Settings.php b/CRM/Twingle/Form/Settings.php index 631fb05..a359588 100644 --- a/CRM/Twingle/Form/Settings.php +++ b/CRM/Twingle/Form/Settings.php @@ -23,69 +23,69 @@ use CRM_Twingle_ExtensionUtil as E; class CRM_Twingle_Form_Settings extends CRM_Core_Form { /** - * @var array list of all settings options + * @var arraylistofallsettingsoptions */ public static $SETTINGS_LIST = [ - 'twingle_prefix', - 'twingle_use_sepa', - 'twingle_dont_use_reference', - 'twingle_protect_recurring', - 'twingle_protect_recurring_activity_type', - 'twingle_protect_recurring_activity_subject', - 'twingle_protect_recurring_activity_status', - 'twingle_protect_recurring_activity_assignee', + 'twingle_prefix', + 'twingle_use_sepa', + 'twingle_dont_use_reference', + 'twingle_protect_recurring', + 'twingle_protect_recurring_activity_type', + 'twingle_protect_recurring_activity_subject', + 'twingle_protect_recurring_activity_status', + 'twingle_protect_recurring_activity_assignee', ]; /** * @inheritdoc */ - function buildQuickForm() { + public function buildQuickForm() { // Set redirect destination. $this->controller->_destination = CRM_Utils_System::url('civicrm/admin/settings/twingle', 'reset=1'); $this->add( 'text', 'twingle_prefix', - E::ts("Twingle ID Prefix") + E::ts('Twingle ID Prefix') ); $this->add( 'checkbox', 'twingle_use_sepa', - E::ts("Use CiviSEPA") + E::ts('Use CiviSEPA') ); $this->add( 'checkbox', 'twingle_dont_use_reference', - E::ts("Use CiviSEPA generated reference") + E::ts('Use CiviSEPA generated reference') ); $this->add( 'select', 'twingle_protect_recurring', - E::ts("Protect Recurring Contributions"), + E::ts('Protect Recurring Contributions'), CRM_Twingle_Config::getRecurringProtectionOptions() ); $this->add( 'select', 'twingle_protect_recurring_activity_type', - E::ts("Activity Type"), + E::ts('Activity Type'), $this->getOptionValueList('activity_type', [0]) ); $this->add( 'text', 'twingle_protect_recurring_activity_subject', - E::ts("Subject"), + E::ts('Subject'), ['class' => 'huge'] ); $this->add( 'select', 'twingle_protect_recurring_activity_status', - E::ts("Status"), + E::ts('Status'), $this->getOptionValueList('activity_status') ); @@ -102,18 +102,18 @@ class CRM_Twingle_Form_Settings extends CRM_Core_Form { ] ); - $this->addButtons(array( - array ( - 'type' => 'submit', - 'name' => E::ts('Save'), - 'isDefault' => TRUE, - ) - )); + $this->addButtons([ + [ + 'type' => 'submit', + 'name' => E::ts('Save'), + 'isDefault' => TRUE, + ], + ]); // set defaults foreach (self::$SETTINGS_LIST as $setting) { $this->setDefaults([ - $setting => Civi::settings()->get($setting) + $setting => Civi::settings()->get($setting), ]); } @@ -132,12 +132,13 @@ class CRM_Twingle_Form_Settings extends CRM_Core_Form { $protection_mode = CRM_Utils_Array::value('twingle_protect_recurring', $this->_submitValues); if ($protection_mode == CRM_Twingle_Config::RCUR_PROTECTION_ACTIVITY) { foreach (['twingle_protect_recurring_activity_type', - 'twingle_protect_recurring_activity_subject', - 'twingle_protect_recurring_activity_status', - 'twingle_protect_recurring_activity_assignee',] as $activity_field) { + 'twingle_protect_recurring_activity_subject', + 'twingle_protect_recurring_activity_status', + 'twingle_protect_recurring_activity_assignee', + ] as $activity_field) { $current_value = CRM_Utils_Array::value($activity_field, $this->_submitValues); 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)); } - /** * @inheritdoc */ - function postProcess() { + public function postProcess() { $values = $this->exportValues(); // store settings @@ -160,25 +160,25 @@ class CRM_Twingle_Form_Settings extends CRM_Core_Form { parent::postProcess(); } - /** * Get a list of option group items * @param $group_id string group ID or name * @return array list of ID(value) => label * @throws CiviCRM_API3_Exception */ - protected function getOptionValueList($group_id, $reserved = [0,1]) { - $list = ['' => E::ts("-select-")]; + protected function getOptionValueList($group_id, $reserved = [0, 1]) { + $list = ['' => E::ts('-select-')]; $query = civicrm_api3('OptionValue', 'get', [ - 'option_group_id' => $group_id, - 'option.limit' => 0, - 'is_active' => 1, - 'is_reserved' => ['IN' => $reserved], - 'return' => 'value,label', + 'option_group_id' => $group_id, + 'option.limit' => 0, + 'is_active' => 1, + 'is_reserved' => ['IN' => $reserved], + 'return' => 'value,label', ]); foreach ($query['values'] as $value) { $list[$value['value']] = $value['label']; } return $list; } + } diff --git a/CRM/Twingle/Page/Profiles.php b/CRM/Twingle/Page/Profiles.php index eb5bf0c..f042e81 100644 --- a/CRM/Twingle/Page/Profiles.php +++ b/CRM/Twingle/Page/Profiles.php @@ -18,7 +18,7 @@ use CRM_Twingle_ExtensionUtil as E; class CRM_Twingle_Page_Profiles extends CRM_Core_Page { public function run() { - CRM_Utils_System::setTitle(E::ts("Twingle API Profiles")); + CRM_Utils_System::setTitle(E::ts('Twingle API Profiles')); $profiles = []; foreach (CRM_Twingle_Profile::getProfiles() as $profile_name => $profile) { $profiles[$profile_name]['name'] = $profile_name; diff --git a/CRM/Twingle/Submission.php b/CRM/Twingle/Submission.php index 2c2a282..342e2be 100644 --- a/CRM/Twingle/Submission.php +++ b/CRM/Twingle/Submission.php @@ -54,13 +54,13 @@ class CRM_Twingle_Submission { } // Validate donation rhythm. - if (!in_array($params['donation_rhythm'], array( + if (!in_array($params['donation_rhythm'], [ 'one_time', 'halfyearly', 'quarterly', 'yearly', 'monthly', - ))) { + ])) { throw new CiviCRM_API3_Exception( E::ts('Invalid donation rhythm.'), 'invalid_format' @@ -108,7 +108,7 @@ class CRM_Twingle_Submission { // Validate custom fields parameter, if given. if (!empty($params['custom_fields'])) { if (is_string($params['custom_fields'])) { - $params['custom_fields'] = json_decode($params['custom_fields'], TRUE); + $params['custom_fields'] = json_decode($params['custom_fields'], TRUE); } if (!is_array($params['custom_fields'])) { throw new CiviCRM_API3_Exception( @@ -137,7 +137,8 @@ class CRM_Twingle_Submission { 'getsingle', ['id' => $params['campaign_id']] ); - } catch (CiviCRM_API3_Exception $e) { + } + catch (CiviCRM_API3_Exception $e) { unset($params['campaign_id']); } } @@ -186,14 +187,14 @@ class CRM_Twingle_Submission { } else { // 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'])) { $contact_data['country_id'] = $country['id']; unset($contact_data['country']); } else { 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' ); } @@ -241,18 +242,20 @@ class CRM_Twingle_Submission { } // 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, - 'location_type_id' => $location_type_id)); + 'location_type_id' => $location_type_id, + ]); if ($existing_org_addresses['count'] <= 0) { // Organisation does not have a WORK address. return FALSE; } // 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, - 'location_type_id' => $location_type_id)); + 'location_type_id' => $location_type_id, + ]); if ($existing_contact_addresses['count'] > 0) { // Contact already has a WORK address. return FALSE; @@ -284,21 +287,21 @@ class CRM_Twingle_Submission { } // 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, 'contact_id_a' => $contact_id, 'contact_id_b' => $organisation_id, 'is_active' => 1, - )); + ]); if ($existing_relationship['count'] == 0) { // There is currently no (active) relationship between these contacts. - $new_relationship_data = array( + $new_relationship_data = [ 'relationship_type_id' => self::EMPLOYER_RELATIONSHIP_TYPE_ID, 'contact_id_a' => $contact_id, 'contact_id_b' => $organisation_id, 'is_active' => 1, - ); + ]; civicrm_api3('Relationship', 'create', $new_relationship_data); } @@ -312,12 +315,11 @@ class CRM_Twingle_Submission { * @throws \CiviCRM_API3_Exception */ public static function civiSepaEnabled() { - $sepa_extension = civicrm_api3('Extension', 'get', array( + $sepa_extension = civicrm_api3('Extension', 'get', [ 'full_name' => 'org.project60.sepa', 'is_active' => 1, - )); - return - Civi::settings()->get('twingle_use_sepa') + ]); + return Civi::settings()->get('twingle_use_sepa') && $sepa_extension['count']; } @@ -334,25 +336,25 @@ class CRM_Twingle_Submission { * to contribution parameter arrays. */ public static function getFrequencyMapping($donation_rhythm) { - $mapping = array( - 'halfyearly' => array( + $mapping = [ + 'halfyearly' => [ 'frequency_unit' => 'month', 'frequency_interval' => 6, - ), - 'quarterly' => array( + ], + 'quarterly' => [ 'frequency_unit' => 'month', 'frequency_interval' => 3, - ), - 'yearly' => array( + ], + 'yearly' => [ 'frequency_unit' => 'month', 'frequency_interval' => 12, - ), - 'monthly' => array( + ], + 'monthly' => [ 'frequency_unit' => 'month', 'frequency_interval' => 1, - ), - 'one_time' => array(), - ); + ], + 'one_time' => [], + ]; 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. */ public static function getSEPACycleDay($start_date, $creditor_id) { - $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); + $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); $earliest_rcur_date = strtotime("$start_date + $frst_notice_days days + $buffer_days days"); // 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; 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); @@ -406,7 +408,7 @@ class CRM_Twingle_Submission { // then: check if campaign should be set it this context $enabled_contexts = $profile->getAttribute('campaign_targets'); - if ($enabled_contexts === null || !is_array($enabled_contexts)) { + if ($enabled_contexts === NULL || !is_array($enabled_contexts)) { // backward compatibility: $enabled_contexts = ['contribution', 'contact']; } @@ -414,10 +416,12 @@ class CRM_Twingle_Submission { // use the submitted campaign if set if (!empty($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'))) { $entity_data['campaign_id'] = $campaign; } } } + } diff --git a/CRM/Twingle/Tools.php b/CRM/Twingle/Tools.php index 86cd828..52e9789 100644 --- a/CRM/Twingle/Tools.php +++ b/CRM/Twingle/Tools.php @@ -33,25 +33,36 @@ class CRM_Twingle_Tools { */ public static function checkRecurringContributionChange($recurring_contribution_id, $change) { // 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 - 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 - if (self::$protection_suspended) return; + if (self::$protection_suspended) { + return; + } // check if protection is turned on $protection_on = Civi::settings()->get('twingle_protect_recurring'); - if (empty($protection_on)) return; + if (empty($protection_on)) { + return; + } // load the recurring contribution $recurring_contribution = civicrm_api3('ContributionRecur', 'getsingle', [ - 'return' => 'trxn_id,contribution_status_id,payment_instrument_id,contact_id', - 'id' => $recurring_contribution_id]); + 'return' => 'trxn_id,contribution_status_id,payment_instrument_id,contact_id', + 'id' => $recurring_contribution_id, + ]); // 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 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) - 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: 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) { // this currently only works with prefixes $prefix = Civi::settings()->get('twingle_prefix'); - if (empty($prefix)) return null; + if (empty($prefix)) { + return NULL; + } // load recurring contribution if necessary if (empty($recurring_contribution['trxn_id'])) { @@ -95,7 +110,9 @@ class CRM_Twingle_Tools { */ public static function processRecurringContributionTermination($recurring_contribution_id, $recurring_contribution) { // check if we're suspended - if (self::$protection_suspended) return; + if (self::$protection_suspended) { + return; + } $protection_mode = Civi::settings()->get('twingle_protect_recurring'); switch ($protection_mode) { @@ -104,39 +121,44 @@ class CRM_Twingle_Tools { break; 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: // create contact source activity // first: get the contact ID if (!empty($recurring_contribution['contact_id'])) { $target_id = (int) $recurring_contribution['contact_id']; - } else { + } + else { $target_id = (int) civicrm_api3('ContributionRecur', 'getvalue', [ - 'id' => $recurring_contribution_id, - 'return' => 'contact_id']); + 'id' => $recurring_contribution_id, + 'return' => 'contact_id', + ]); } if (!empty($recurring_contribution['trxn_id'])) { $trxn_id = $recurring_contribution['trxn_id']; - } else { + } + else { $trxn_id = civicrm_api3('ContributionRecur', 'getvalue', [ - 'id' => $recurring_contribution_id, - 'return' => 'trxn_id']); + 'id' => $recurring_contribution_id, + 'return' => 'trxn_id', + ]); } try { civicrm_api3('Activity', 'create', [ - 'activity_type_id' => Civi::settings()->get('twingle_protect_recurring_activity_type'), - 'subject' => Civi::settings()->get('twingle_protect_recurring_activity_subject'), - 'activity_date_time' => date('YmdHis'), - 'target_id' => $target_id, - 'assignee_id' => Civi::settings()->get('twingle_protect_recurring_activity_assignee'), - 'status_id' => Civi::settings()->get('twingle_protect_recurring_activity_status'), - 'details' => E::ts("Recurring contribution [%1] (Transaction ID '%2') was terminated by a user. You need to end the corresponding record in Twingle as well, or it will still be collected.", + 'activity_type_id' => Civi::settings()->get('twingle_protect_recurring_activity_type'), + 'subject' => Civi::settings()->get('twingle_protect_recurring_activity_subject'), + 'activity_date_time' => date('YmdHis'), + 'target_id' => $target_id, + 'assignee_id' => Civi::settings()->get('twingle_protect_recurring_activity_assignee'), + 'status_id' => Civi::settings()->get('twingle_protect_recurring_activity_status'), + 'details' => E::ts("Recurring contribution [%1] (Transaction ID '%2') was terminated by a user. You need to end the corresponding record in Twingle as well, or it will still be collected.", [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()); } break; @@ -161,9 +183,9 @@ class CRM_Twingle_Tools { // lookup and add instrument IDs $lookup = civicrm_api3('OptionValue', 'get', [ - 'option_group_id' => 'payment_instrument', - 'name' => ['IN' => $sepa_payment_instruments], - 'return' => 'value' + 'option_group_id' => 'payment_instrument', + 'name' => ['IN' => $sepa_payment_instruments], + 'return' => 'value', ]); foreach ($lookup['values'] as $payment_instrument) { $sepa_payment_instruments[] = $payment_instrument['value']; @@ -184,9 +206,9 @@ class CRM_Twingle_Tools { try { // try recurring mandate $rcur_mandate = civicrm_api3('SepaMandate', 'get', [ - 'entity_id' => $contribution_id, - 'entity_table' => 'civicrm_contribution_recur', - 'type' => 'RCUR', + 'entity_id' => $contribution_id, + 'entity_table' => 'civicrm_contribution_recur', + 'type' => 'RCUR', ]); if ($rcur_mandate['count'] == 1) { return reset($rcur_mandate['values']); @@ -195,17 +217,19 @@ class CRM_Twingle_Tools { // try OOFF mandate // try recurring mandate $ooff_mandate = civicrm_api3('SepaMandate', 'get', [ - 'entity_id' => $contribution_id, - 'entity_table' => 'civicrm_contribution', - 'type' => 'OOFF', + 'entity_id' => $contribution_id, + 'entity_table' => 'civicrm_contribution', + 'type' => 'OOFF', ]); if ($ooff_mandate['count'] == 1) { return reset($ooff_mandate['values']); } - } catch (Exception $ex) { + } + catch (Exception $ex) { Civi::log()->warning("CRM_Twingle_Tools::getMandate failed for [{$contribution_id}]: " . $ex->getMessage()); } } return NULL; } + } diff --git a/CRM/Twingle/Upgrader.php b/CRM/Twingle/Upgrader.php index 9b3af0c..98d956b 100644 --- a/CRM/Twingle/Upgrader.php +++ b/CRM/Twingle/Upgrader.php @@ -20,11 +20,11 @@ class CRM_Twingle_Upgrader extends CRM_Twingle_Upgrader_Base { /** * Example: Run an external SQL script when the module is uninstalled. * - public function uninstall() { - $this->executeSqlFile('sql/myuninstall.sql'); - } - - /** + * public function uninstall() { + * $this->executeSqlFile('sql/myuninstall.sql'); + * } + * + * /** * Copy financial_type_id setting to new setting financial_type_id_recur. */ 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); $data = json_encode($profile->getData()); 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'], - 2 => [$data, 'String'] + 2 => [$data, 'String'], ]); } } return TRUE; } + } diff --git a/CRM/Twingle/Upgrader/Base.php b/CRM/Twingle/Upgrader/Base.php index 07e9629..1ffe718 100644 --- a/CRM/Twingle/Upgrader/Base.php +++ b/CRM/Twingle/Upgrader/Base.php @@ -9,7 +9,7 @@ use CRM_Twingle_ExtensionUtil as E; class CRM_Twingle_Upgrader_Base { /** - * @var varies, subclass of this + * @var variessubclassofthis */ static $instance; @@ -19,22 +19,22 @@ class CRM_Twingle_Upgrader_Base { protected $ctx; /** - * @var string, eg 'com.example.myextension' + * @var stringegcomexamplemyextension */ protected $extensionName; /** - * @var string, full path to the extension's source tree + * @var stringfullpathtotheextensionssourcetree */ protected $extensionDir; /** - * @var array(revisionNumber) sorted numerically + * @var arrayrevisionNumbersortednumerically */ private $revisions; /** - * @var boolean + * @var bool * Flag to clean up extension revision data in civicrm_setting */ private $revisionStorageIsDeprecated = FALSE; @@ -42,7 +42,7 @@ class CRM_Twingle_Upgrader_Base { /** * Obtain a reference to the active upgrade handler. */ - static public function instance() { + public static function instance() { if (!self::$instance) { // FIXME auto-generate self::$instance = new CRM_Twingle_Upgrader( @@ -63,13 +63,13 @@ class CRM_Twingle_Upgrader_Base { * CRM_Twingle_Upgrader_Base::_queueAdapter($ctx, 'methodName', 'arg1', 'arg2'); * @endcode */ - static public function _queueAdapter() { + public static function _queueAdapter() { $instance = self::instance(); $args = func_get_args(); $instance->ctx = array_shift($args); $instance->queue = $instance->ctx->queue; $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) { @@ -144,7 +144,7 @@ class CRM_Twingle_Upgrader_Base { * provides syntatic sugar for queueing several tasks that * run different queries */ - public function executeSql($query, $params = array()) { + public function executeSql($query, $params = []) { // FIXME verify that we raise an exception on error CRM_Core_DAO::executeQuery($query, $params); return TRUE; @@ -163,11 +163,11 @@ class CRM_Twingle_Upgrader_Base { $args = func_get_args(); $title = array_shift($args); $task = new CRM_Queue_Task( - array(get_class($this), '_queueAdapter'), + [get_class($this), '_queueAdapter'], $args, $title ); - return $this->queue->createItem($task, array('weight' => -1)); + return $this->queue->createItem($task, ['weight' => -1]); } // ******** Revision-tracking helpers ******** @@ -200,23 +200,23 @@ class CRM_Twingle_Upgrader_Base { $currentRevision = $this->getCurrentRevision(); foreach ($this->getRevisions() as $revision) { if ($revision > $currentRevision) { - $title = ts('Upgrade %1 to revision %2', array( + $title = ts('Upgrade %1 to revision %2', [ 1 => $this->extensionName, 2 => $revision, - )); + ]); // note: don't use addTask() because it sets weight=-1 $task = new CRM_Queue_Task( - array(get_class($this), '_queueAdapter'), - array('upgrade_' . $revision), + [get_class($this), '_queueAdapter'], + ['upgrade_' . $revision], $title ); $this->queue->createItem($task); $task = new CRM_Queue_Task( - array(get_class($this), '_queueAdapter'), - array('setCurrentRevision', $revision), + [get_class($this), '_queueAdapter'], + ['setCurrentRevision', $revision], $title ); $this->queue->createItem($task); @@ -231,7 +231,7 @@ class CRM_Twingle_Upgrader_Base { */ public function getRevisions() { if (!is_array($this->revisions)) { - $this->revisions = array(); + $this->revisions = []; $clazz = new ReflectionClass(get_class($this)); $methods = $clazz->getMethods(); @@ -302,7 +302,7 @@ class CRM_Twingle_Upgrader_Base { $this->executeCustomDataFileByAbsPath($file); } } - if (is_callable(array($this, 'install'))) { + if (is_callable([$this, 'install'])) { $this->install(); } } @@ -315,7 +315,7 @@ class CRM_Twingle_Upgrader_Base { if (!empty($revisions)) { $this->setCurrentRevision(max($revisions)); } - if (is_callable(array($this, 'postInstall'))) { + if (is_callable([$this, 'postInstall'])) { $this->postInstall(); } } @@ -330,7 +330,7 @@ class CRM_Twingle_Upgrader_Base { $this->executeSqlTemplate($file); } } - if (is_callable(array($this, 'uninstall'))) { + if (is_callable([$this, 'uninstall'])) { $this->uninstall(); } $files = glob($this->extensionDir . '/sql/*_uninstall.sql'); @@ -346,7 +346,7 @@ class CRM_Twingle_Upgrader_Base { */ public function onEnable() { // stub for possible future use - if (is_callable(array($this, 'enable'))) { + if (is_callable([$this, 'enable'])) { $this->enable(); } } @@ -356,7 +356,7 @@ class CRM_Twingle_Upgrader_Base { */ public function onDisable() { // stub for possible future use - if (is_callable(array($this, 'disable'))) { + if (is_callable([$this, 'disable'])) { $this->disable(); } } @@ -364,7 +364,7 @@ class CRM_Twingle_Upgrader_Base { public function onUpgrade($op, CRM_Queue_Queue $queue = NULL) { switch ($op) { case 'check': - return array($this->hasPendingRevisions()); + return [$this->hasPendingRevisions()]; case 'enqueue': return $this->enqueuePendingRevisions($queue); diff --git a/api/v3/TwingleDonation/Cancel.php b/api/v3/TwingleDonation/Cancel.php index e007059..37ac700 100644 --- a/api/v3/TwingleDonation/Cancel.php +++ b/api/v3/TwingleDonation/Cancel.php @@ -26,34 +26,34 @@ use CRM_Twingle_ExtensionUtil as E; * @see http://wiki.civicrm.org/confluence/display/CRMDOC/API+Architecture+Standards */ function _civicrm_api3_twingle_donation_Cancel_spec(&$params) { - $params['project_id'] = array( + $params['project_id'] = [ 'name' => 'project_id', 'title' => E::ts('Project ID'), 'type' => CRM_Utils_Type::T_STRING, 'api.required' => 1, 'description' => E::ts('The Twingle project ID.'), - ); - $params['trx_id'] = array( + ]; + $params['trx_id'] = [ 'name' => 'trx_id', 'title' => E::ts('Transaction ID'), 'type' => CRM_Utils_Type::T_STRING, 'api.required' => 1, 'description' => E::ts('The unique transaction ID of the donation'), - ); - $params['cancelled_at'] = array( + ]; + $params['cancelled_at'] = [ 'name' => 'cancelled_at', 'title' => E::ts('Cancelled at'), 'type' => CRM_Utils_Type::T_INT, 'api.required' => 1, 'description' => E::ts('The date when the donation was cancelled, format: YmdHis.'), - ); - $params['cancel_reason'] = array( + ]; + $params['cancel_reason'] = [ 'name' => 'cancel_reason', 'title' => E::ts('Cancel reason'), 'type' => CRM_Utils_Type::T_STRING, 'api.required' => 1, 'description' => E::ts('The reason for the donation being cancelled.'), - ); + ]; } /** @@ -82,15 +82,15 @@ function civicrm_api3_twingle_donation_Cancel($params) { // Retrieve (recurring) contribution. $default_profile = CRM_Twingle_Profile::getProfile('default'); try { - $contribution = civicrm_api3('Contribution', 'getsingle', array( + $contribution = civicrm_api3('Contribution', 'getsingle', [ 'trxn_id' => $default_profile->getTransactionID($params['trx_id']), - )); + ]); $contribution_type = 'Contribution'; } catch (CiviCRM_API3_Exception $exception) { - $contribution = civicrm_api3('ContributionRecur', 'getsingle', array( - 'trxn_id' => $default_profile->getTransactionID($params['trx_id']), - )); + $contribution = civicrm_api3('ContributionRecur', 'getsingle', [ + 'trxn_id' => $default_profile->getTransactionID($params['trx_id']), + ]); $contribution_type = 'ContributionRecur'; } @@ -102,7 +102,7 @@ function civicrm_api3_twingle_donation_Cancel($params) { $mandate = CRM_Twingle_Tools::getMandateFor($contribution['id']); if (!$mandate) { 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' ); } @@ -115,7 +115,8 @@ function civicrm_api3_twingle_donation_Cancel($params) { $end_date = date('Ymd', max( time(), $end_date->getTimestamp())); - } else { + } + else { // end date couldn't be parsed, use 'now' $end_date = date('Ymd'); } @@ -132,19 +133,19 @@ function civicrm_api3_twingle_donation_Cancel($params) { } // Retrieve updated contribution for return value. - $contribution = civicrm_api3($contribution_type, 'getsingle', array( + $contribution = civicrm_api3($contribution_type, 'getsingle', [ 'id' => $contribution['id'], - )); + ]); } else { // regular contribution CRM_Twingle_Tools::$protection_suspended = TRUE; - $contribution = civicrm_api3($contribution_type, 'create', array( + $contribution = civicrm_api3($contribution_type, 'create', [ 'id' => $contribution['id'], 'cancel_date' => $params['cancelled_at'], 'contribution_status_id' => 'Cancelled', 'cancel_reason' => $params['cancel_reason'], - )); + ]); CRM_Twingle_Tools::$protection_suspended = FALSE; } diff --git a/api/v3/TwingleDonation/Endrecurring.php b/api/v3/TwingleDonation/Endrecurring.php index 9daa59b..95804ef 100644 --- a/api/v3/TwingleDonation/Endrecurring.php +++ b/api/v3/TwingleDonation/Endrecurring.php @@ -26,27 +26,27 @@ use CRM_Twingle_ExtensionUtil as E; * @see http://wiki.civicrm.org/confluence/display/CRMDOC/API+Architecture+Standards */ function _civicrm_api3_twingle_donation_endrecurring_spec(&$params) { - $params['project_id'] = array( + $params['project_id'] = [ 'name' => 'project_id', 'title' => E::ts('Project ID'), 'type' => CRM_Utils_Type::T_STRING, 'api.required' => 1, 'description' => E::ts('The Twingle project ID.'), - ); - $params['trx_id'] = array( + ]; + $params['trx_id'] = [ 'name' => 'trx_id', 'title' => E::ts('Transaction ID'), 'type' => CRM_Utils_Type::T_STRING, 'api.required' => 1, 'description' => E::ts('The unique transaction ID of the donation'), - ); - $params['ended_at'] = array( + ]; + $params['ended_at'] = [ 'name' => 'ended_at', 'title' => E::ts('Ended at'), 'type' => CRM_Utils_Type::T_INT, 'api.required' => 1, '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'); - $contribution = civicrm_api3('ContributionRecur', 'getsingle', array( + $contribution = civicrm_api3('ContributionRecur', 'getsingle', [ 'trxn_id' => $default_profile->getTransactionID($params['trx_id']), - )); + ]); // End SEPA mandate (which ends the associated recurring contribution) or // recurring contributions. @@ -87,7 +87,7 @@ function civicrm_api3_twingle_donation_endrecurring($params) { $mandate = CRM_Twingle_Tools::getMandateFor($contribution['id']); if (!$mandate) { 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' ); } @@ -99,7 +99,8 @@ function civicrm_api3_twingle_donation_endrecurring($params) { $end_date = date('Ymd', max( time(), $end_date->getTimestamp())); - } else { + } + else { // end date couldn't be parsed, use 'now' $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 if ($mandate['status'] != 'FRST' && $mandate['status'] != 'RCUR') { 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' ); } @@ -122,18 +123,18 @@ function civicrm_api3_twingle_donation_endrecurring($params) { 'api_error' ); } - $contribution = civicrm_api3('ContributionRecur', 'getsingle', array( + $contribution = civicrm_api3('ContributionRecur', 'getsingle', [ 'id' => $contribution['id'], - )); + ]); } else { // END RECURRING CONTRIBUTION CRM_Twingle_Tools::$protection_suspended = TRUE; - $contribution = civicrm_api3('ContributionRecur', 'create', array( - 'id' => $contribution['id'], - 'end_date' => $params['ended_at'], - 'contribution_status_id' => CRM_Twingle_Submission::CONTRIBUTION_STATUS_COMPLETED, - )); + $contribution = civicrm_api3('ContributionRecur', 'create', [ + 'id' => $contribution['id'], + 'end_date' => $params['ended_at'], + 'contribution_status_id' => CRM_Twingle_Submission::CONTRIBUTION_STATUS_COMPLETED, + ]); CRM_Twingle_Tools::$protection_suspended = FALSE; }