CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • Modifying civicrm_themekey to include Events
Pages: [1]

Author Topic: Modifying civicrm_themekey to include Events  (Read 664 times)

kharding

  • I post occasionally
  • **
  • Posts: 75
  • Karma: 4
  • CiviCRM version: 4.2.7
  • CMS version: Drupal 7
  • MySQL version: Recent
  • PHP version: 5.3.16
Modifying civicrm_themekey to include Events
October 12, 2012, 11:24:35 am
Hi all,

I've managed, through some sort of trickery, to get cicivrm_themekey to work with 4.2 and Drupal 7. (Moderate hurrays for me, I suppose?).

Thankfully, civicrm_themekey works across all aspects of a contribution - from the initial page, to the contribution confirmation, to the thank-you.

Now, I want to get it to work somehow for events.  I just need to find a way to programmatically expose the event ID throughout all stages of the event registration.

Here's the relevant code in civicrm_themekey:

Code: [Select]


function themekey_civicrm_dummy2contribution_page_id($dummy) {
  if (!civicrm_initialize()) {
    return NULL;
  }
  if (arg(0) == 'civicrm' && arg(1) == 'contribute' && arg(2) == 'transact') {
    if (!empty($_GET['id'])) {
      $contribution_page_id = $_GET['id'];
    }
    /*elseif (($qfKey = $_REQUEST['qfKey']) && ($data = $_SESSION['CiviCRM']['CRM_Contribute_Controller_Contribution_' . $qfKey])) {
      if (!empty($data['id'])) {
        $contribution_page_id = $data['id'];
      }
    }*/
    else {
      require_once DRUPAL_ROOT . '/sites/all/modules/civicrm/' . 'CRM/Core/Session.php';
      $session = CRM_Core_Session::singleton( );
      $contribution_page_id = $session->get('pastContributionID');
    }
  }
  return !empty($contribution_page_id) ? $contribution_page_id : NULL;
}


and:

Code: [Select]
function _themekey_civicrm_contribution_page_load($contribution_id) {
  if (!civicrm_initialize()) {
    return NULL;
  }
  require_once DRUPAL_ROOT . '/' . 'CRM/Core/DAO.php';
  $query = "SELECT contribution_type_id FROM civicrm_contribution_page WHERE id = %1 ORDER BY title asc;";
  $params = array(
    1 => array((int) $contribution_id, 'Integer'),
  );
  $dao = CRM_Core_DAO::executeQuery( $query, $params, true, 'CRM_Contribute_DAO_ContributionPage' );
  $dao->fetch();
  return $dao;
}

Any idea on how to duplicate this code to get the event ID exposed to Themekey?

I don't know how an event id is stored in #session, because that might be the easiest.

kharding

  • I post occasionally
  • **
  • Posts: 75
  • Karma: 4
  • CiviCRM version: 4.2.7
  • CMS version: Drupal 7
  • MySQL version: Recent
  • PHP version: 5.3.16
Re: Modifying themekey_civicrm to include Events
October 12, 2012, 12:20:53 pm
Hmmnm, okay - I seem to have found a way to do it.

However, it assumes that the first time that a user encounters an event registration page, they'll come at it via /civicrm/event/register?reset=1&id=1 (where id is the event number).  This should be how the user comes across an event page, no?

Anyways, the themekey_civicrm module first tries to get the contribution/event page ID via this code:

Code: [Select]
if (arg(0) == 'civicrm' && arg(1) == 'contribute' && arg(2) == 'transact') {
    if (!empty($_GET['id'])) {
      $contribution_page_id = $_GET['id'];
    }
...

Assuming that this is the first time that a user encounters an event registration page - and it probably should be - then I used that part of the function to store the event ID into the CiviCRM Session:

Code: [Select]

if (!empty($_GET['id'])) {
  require_once DRUPAL_ROOT . '/sites/all/modules/civicrm/' . 'CRM/Core/Session.php';
      $session = CRM_Core_Session::singleton( );
  $themekey_eventID = $_GET['id'];
  $session->set('themekey_eventID', $themekey_eventID);
      $contribution_page_id = $_GET['id'];
    }


And when the CiviCRM URL doesn't display an ID as part of its URL (like after you've submitted the registration form), then the themekey_civicrm module can then pull the event ID via the session:

Code: [Select]

else {
      require_once DRUPAL_ROOT . '/sites/all/modules/civicrm/' . 'CRM/Core/Session.php';
      $session = CRM_Core_Session::singleton( );
      $contribution_page_id = $session->get('themekey_eventID');
    }


I;ll note that I'm absolutely not skilled at what I'm doing here via PHP and other stuff; and this is kludgery of the worst sort.  It also assumes that anyone coming at an event registration form will have a URL that *first* includes an ID in it. If that doesn't happen, then this fix fails.

Maybe this will help someone!

kharding

  • I post occasionally
  • **
  • Posts: 75
  • Karma: 4
  • CiviCRM version: 4.2.7
  • CMS version: Drupal 7
  • MySQL version: Recent
  • PHP version: 5.3.16
Re: Modifying civicrm_themekey to include Events
October 12, 2012, 03:20:57 pm
Update: I edited the code that determines the event ID on first view to include people who landed on the event info page; this code will allow themekey_civicrm to detect if someone's landed on an Event Info page:

Code: [Select]
if (arg(0) == 'civicrm' && arg(1) == 'contribute' && arg(2) == 'transact' or arg(2) == 'info') {
    if (!empty($_GET['id'])) {
      $contribution_page_id = $_GET['id'];
    }
...

I'm going to see if I can post an alpha version of this module on drupal.org tonight or tomorrow.

First time! Whee.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • Modifying civicrm_themekey to include Events

This forum was archived on 2017-11-26.