Mwalker has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/115558

Change subject: Allow special parameters to thank you templates
......................................................................

Allow special parameters to thank you templates

Optional extras will be presented to the template in a 'specials'
dictionary. On the backennd, these should be saved in a new wmf
column, thank_you_options which is a JSON encoded string.

Change-Id: I54afc6918017aebfca744776936109dc1593cd6c
---
M sites/all/modules/thank_you/thank_you.module
M sites/all/modules/wmf_civicrm/wmf_civicrm.install
M sites/all/modules/wmf_civicrm/wmf_civicrm.module
3 files changed, 69 insertions(+), 26 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm 
refs/changes/58/115558/1

diff --git a/sites/all/modules/thank_you/thank_you.module 
b/sites/all/modules/thank_you/thank_you.module
index 47a4d86..c93c879 100644
--- a/sites/all/modules/thank_you/thank_you.module
+++ b/sites/all/modules/thank_you/thank_you.module
@@ -175,6 +175,20 @@
     list( $params['first_name'], $params['last_name'] ) = preg_split( '/ +/', 
$params['name'], 2, PREG_SPLIT_NO_EMPTY );
     $params['unsubscribe_link'] = build_unsub_link( -1, 
$params['recipient_address'], $params['locale'] );
 
+    // Turn a comma space separated list into an array
+    if ( array_key_exists( 'specials', $params ) ) {
+        $specials = preg_split('/[\s,]+/', $params['specials']);
+        $params['specials'] = array();
+        foreach ($specials as $special) {
+            $parts = explode('=', $special);
+            if (count($parts) != 2) {
+                $params['specials'][$parts[0]] = true;
+            } else {
+                $params['specials'][$parts[0]] = $parts[1];
+            }
+        }
+    }
+
        if ( $params['locale'] === "all" ) {
                $langs = array();
                foreach( glob( __DIR__ . "/templates/html/thank_you.*.html") as 
$lang ){
@@ -209,7 +223,7 @@
  * Send a TY letter, and do bookkeeping on the Civi records
  * TODO: rewrite the civi api stuff to work like other code
  */
-function thank_you_for_contribution( $contribution_id, $test = false ) {
+function thank_you_for_contribution( $contribution_id ) {
        civicrm_initialize( true );
        $contribution = civicrm_api("Contribution","get",
                array (
@@ -264,28 +278,26 @@
 
     $custom_values = wmf_civicrm_contribution_get_custom_values( 
$contribution_id, array(
         'no_thank_you',
+        'thank_you_options',
         'original_amount',
         'original_currency',
     ) );
 
-       // only check the following if this is not a test
-       if ( !$test ){
-               // don't send a Thank You email if one has already been sent
-               if ( !empty($contribution['thankyou_date']) ) {
-                       watchdog('thank_you', 'Thank you email already sent for 
this transaction.', array(), WATCHDOG_INFO);
-                       return false;
-               }
-               // only send a Thank You email if we are within the specified 
window
-               if (strtotime($contribution['receive_date']) < time() - 86400 * 
variable_get('thank_you_days', 14)) {
-                       watchdog('thank_you', 'Contribution is older than 
limit, ignoring.', array(), WATCHDOG_INFO);
-                       return false;
-               }
+    // don't send a Thank You email if one has already been sent
+    if ( !empty($contribution['thankyou_date']) ) {
+        watchdog('thank_you', 'Thank you email already sent for this 
transaction.', array(), WATCHDOG_INFO);
+        return false;
+    }
+    // only send a Thank You email if we are within the specified window
+    if (strtotime($contribution['receive_date']) < time() - 86400 * 
variable_get('thank_you_days', 14)) {
+        watchdog('thank_you', 'Contribution is older than limit, ignoring.', 
array(), WATCHDOG_INFO);
+        return false;
+    }
 
-        if ( $custom_values['no_thank_you'] ) {
-                       watchdog('thank_you', "Contribution has been marked 
no_thank_you={$custom_values['no_thank_you']}, skipping.", array(), 
WATCHDOG_INFO);
-                       return false;
-        }
-       }
+    if ( $custom_values['no_thank_you'] ) {
+        watchdog('thank_you', "Contribution has been marked 
no_thank_you={$custom_values['no_thank_you']}, skipping.", array(), 
WATCHDOG_INFO);
+        return false;
+    }
 
     $transaction = WmfTransaction::from_unique_id( $contribution['trxn_id'] );
 
@@ -303,22 +315,17 @@
         'recurring' => $transaction->is_recurring,
         'transaction_id' => "CNTCT-{$contact['id']}",
         'unsubscribe_link' => build_unsub_link( $contribution['id'], 
$contact['email'], $contact['preferred_language'] ),
-        # TODO
-        'specials' => array(),
+        'specials' => json_decode($custom_values['thank_you_options'], true),
     );
 
     $success = thank_you_send_mail( $params );
 
     if ( $success ) {
                watchdog('thank_you', "Thank you mail sent successfully for 
contribution id: $contribution_id to " . $email['to_address'], array(), 
WATCHDOG_INFO);
-        if ( !$test ) {
-            thank_you_update_ty_date( $contribution );
-               }
+        thank_you_update_ty_date( $contribution );
     } else {
                watchdog('thank_you', "Thank you mail failed for contribution 
id: $contribution_id to " . $email['to_address'], array(), WATCHDOG_ERROR);
-        if ( !$test ) {
-            wmf_civicrm_set_no_thank_you( $contribution_id, 'failed' );
-        }
+        wmf_civicrm_set_no_thank_you( $contribution_id, 'failed' );
     }
 }
 
@@ -348,6 +355,10 @@
 
 /**
  * Just send the letter
+ *
+ * There is a list of required parameters in this function. All other 
parameters
+ * are considered optional and should be passed in a 'special' key with an 
array
+ * of values.
  */
 function thank_you_send_mail( $params ) {
     $require_params = array(
diff --git a/sites/all/modules/wmf_civicrm/wmf_civicrm.install 
b/sites/all/modules/wmf_civicrm/wmf_civicrm.install
index 02ede0d..623ca40 100644
--- a/sites/all/modules/wmf_civicrm/wmf_civicrm.install
+++ b/sites/all/modules/wmf_civicrm/wmf_civicrm.install
@@ -693,6 +693,7 @@
  */
 function wmf_civicrm_update_7014()
 {
+    $ret = array();
     $api = wmf_civicrm_bootstrap_civi();
     $api->CustomGroup->get(array(
         'name' => 'contribution_extra',
@@ -741,3 +742,33 @@
     db_query("ALTER TABLE civicrm_contact
             MODIFY preferred_language varchar(32) DEFAULT NULL");
 }
+
+/**
+ * Add column for custom thank you template options
+ */
+function wmf_civicrm_update_7016()
+{
+    $ret = array();
+    $api = wmf_civicrm_bootstrap_civi();
+    $api->CustomGroup->get(array(
+            'name' => 'contribution_extra',
+        ));
+    $values = $api->values();
+    $custom_group = array_pop($values);
+
+    $success = $api->CustomField->create(array(
+            'custom_group_id' => $custom_group->id,
+            'name' => 'thank_you_options',
+            'column_name' => 'thank_you_options',
+            'label' => ts('Special parameters to pass to thank you'),
+            'data_type' => 'String',
+            'html_type' => 'Text',
+            'is_active' => 1,
+            'is_searchable' => 1,
+            'is_view' => 1,
+        ));
+    if (!$success) {
+        $ret[] = $api->errorMsg();
+    }
+    return $ret;
+}
diff --git a/sites/all/modules/wmf_civicrm/wmf_civicrm.module 
b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
index dda15cd..3b0608d 100644
--- a/sites/all/modules/wmf_civicrm/wmf_civicrm.module
+++ b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
@@ -315,6 +315,7 @@
         'gateway_account',
         'import_batch_number',
         'no_thank_you',
+        'thank_you_options',
         'source_name',
         'source_type',
         'source_host',

-- 
To view, visit https://gerrit.wikimedia.org/r/115558
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I54afc6918017aebfca744776936109dc1593cd6c
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: Mwalker <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to