r78637 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78636‎ | r78637 | r78638 >
Date:21:34, 20 December 2010
Author:awjrichards
Status:deferred
Tags:
Comment:
Added code to handle and test tracking of premiums in CiviCRM
Modified paths:
  • /civicrm/trunk/sites/all/modules/wmf_premiums/wmf_premiums.module (modified) (history)

Diff [purge]

Index: civicrm/trunk/sites/all/modules/wmf_premiums/wmf_premiums.module
@@ -2,24 +2,73 @@
33 /**
44 * Implementation of hook_perm().
55 */
6 -function wmf_owa_perm() {
7 - return array('administer wmf_premiums');
 6+function wmf_premiums_perm() {
 7+ return array('administer wmf premiums');
88 }
99
1010 /**
11 - * Implementation of hook_civicrm_post
 11+ * Implementation of hook_menu()
 12+ */
 13+function wmf_premiums_menu() {
 14+ $items = array();
 15+
 16+ $items['admin/settings/wmf_premiums/test'] = array(
 17+ 'title' => 'Premium insert test',
 18+ 'access arguments' => array('administer wmf premiums'),
 19+ 'page_callback' => 'wmf_premiums_test_insert',
 20+ 'type' => MENU_DEFAULT_LOCAL_TASK,
 21+ );
 22+
 23+ return $items;
 24+}
 25+
 26+/**
 27+ * Invocation of hook queue2civicrm_import
1228 *
13 - * @param unknown_type $op
14 - * @param unknown_type $objectName
15 - * @param unknown_type $objectId
16 - * @param unknown_type $objectRef
 29+ * NOTE: this should probably really be done with CiviCRM's database
 30+ * stuff. However, it's a total pain in the ass, so I hacked it using
 31+ * Drupal's db stuff. This then REQUIRES that your drupal db user have
 32+ * insert/select access to the CiviCRM database.
 33+ *
 34+ * @param $contribution_info
1735 */
18 -function wmf_premiums_civicrm_post( $op, $objectName, $objectId, &$objectRef ) {
19 - // only continue if we're handling an updated contribution - a contrib also gets 'updated' upon creation
20 - if ( $objectName != 'Contribution' || ( $objectName == 'Contribution' && $op != 'edit' ) ) {
 36+function wmf_premiums_queue2civicrm_import( $contribution_info ) {
 37+ // make sure that we have premiums to deal with
 38+ if ( !$contribution_info[ 'msg' ][ 'size' ] ) {
 39+ watchdog( 'wmf_premiums', 'No premium selection for contribution id: %contrib_id', array('%contrib_id' => $contribution_info['contribution_id'] ), WATCHDOG_DEBUG);
2140 return;
2241 }
2342
24 - return;
25 -
 43+ $query = "INSERT INTO civicrm.premiums (tracking_id, contact_id, contribution_id, shirt, shirt_size)
 44+ VALUES ( %1, %2, %3, %4, '%5' )";
 45+
 46+ watchdog( 'wmf_premiums', 'Preparing to insert premium data with the following contribution info: %contrib_info', array( '%contrib_info' => print_r( $contribution_info, true )), WATCHDOG_DEBUG );
 47+ $result = db_query( $query,
 48+ $contribution_info['msg']['contribution_tracking_id'],
 49+ $contribution_info['contact_id'],
 50+ $contribution_info['contribution_id'],
 51+ 1,
 52+ $contribution_info['msg']['size']);
 53+ if ( !$result ) {
 54+ watchdog( 'wmf_premiums', 'There was an error inserting with the following contrib info: %contribution_info', array( '%contribution_info' => print_r( $contribution_info, true)), WATCHDOG_ERROR );
 55+ return false;
 56+ } else {
 57+ $insert_id = db_last_insert_id( 'civicrm.premiums', 'id' );
 58+ watchdog( 'wmf_premiums', 'Created new premiums record with id: %insert_id', array( '%insert_id' => $insert_id ), WATCHDOG_DEBUG );
 59+ }
 60+ return $insert_id;
 61+}
 62+
 63+function wmf_premiums_test_insert() {
 64+ $contribution_info = array(
 65+ 'msg' => array( 'size' => 'large', 'contribution_tracking_id' => 31337 ),
 66+ 'contact_id' => 1234,
 67+ 'contribution_id' => 4321
 68+ );
 69+ $insert_id = wmf_premiums_queue2civicrm_import( $contribution_info );
 70+ if ( !$insert_id ) {
 71+ drupal_set_message( 'There was a problem inserting your premium test :(', 'error' );
 72+ } else {
 73+ drupal_set_message( 'You succesfully inserted your premium test with id: ' . $insert_id );
 74+ }
2675 }
\ No newline at end of file

Status & tagging log