Posts Tagged ‘modules’

Drupal 6 module’s page unresponsive

Colin Calnan | Thursday, March 26th, 2009

Discovered a very upsetting scenario today while building out a Drupal 6 site. If you have the Update module enabled and drupal.org goes down your module admin page at www.example.com/admin/build/modules stops responding. Why? I think it’s because somewhere in the Update module is a call to updates.drupal.org.

The quick and dirty solution is to temporarily disable the module via the system table in your database.

How do I do that?

  • Using phpMyAdmin or some other GUI tool or via the command link
    1. View the system table contents
    2. Find the row where filename is modules/update/update.module
    3. Edit the row and set it’s status field to 0
    4. Refresh your modules page
  • Via SQL Query/command line

    UPDATE `system` SET `status` = 0 WHERE `filename` = 'modules/update/update.module'

I’m going to submit an issue about this and look into a possible solution. I was halted in my work for over an hour today because of this.
Disclaimer: I am not responsible for those of you who do not backup before making any changes to your database.

Displaying Webform results in a block

Colin Calnan | Wednesday, January 14th, 2009

We use the webform module for most of our form needs on our client sites. It’s a pretty good module that provides most of the functionality required. The most important part of the webforms module is the submission data. The reason for the form in the first place is to gather data that can be analyzed and then acted on. Webform has a results area where you can view all the submitted data, analyze it, download it and export it. It does this using some useful built in functions such as webform_get_submissions.

However, say you want to get the number of submissions to a particular field in a form and then display the most popular choices in a block, a little similar to a poll but the data is collected as part of a webform. For our example, the form is collecting a list of reasons for donating and then displaying the top 5 reasons in a block on the site.

One way to achieve this is via a module. We create a block using hook_block and then display the top 5 reasons in it (explanations are in comments in code):

function mymodule_block($op = 'list', $delta = 0, $edit = array()) {
  switch($op){
    // Create the block listing in the block admin page
    case 'list':
      $blocks[0]['info'] = t('Top 5 Reasons for donating');
      return $blocks;
      break;
 
    case 'view':
      switch($delta) {
        case 0:
          if (module_exists('webform')) {
 
            // Set the node id to the webform we require the results of
            $nid = 999;
 
            // Load the webform node
            $node = node_load($nid);
 
            // Retrieve the list of reason choices from the webform field, split at line breaks 
            // The choices are entered in a textarea when creating a form 
            // in the format "i_have_money|I have lots of money"
            $reason_key_pair = explode('', $node->;webform['components'][1]['extra']['items']);
 
            // Loop through the textarea to create an array in the form 
            // $submission['i_have_money']=>;I have lots of money.
            foreach($reason_key_pair as $key =>; $value) {
              $new_array = explode('|', $value);
              $submissions[trim($new_array[0])] = $new_array[1];
            }
 
            // Execute the query to return the top 5 reasons for donating from the webform_submitted_data table
            $result = db_query("SELECT sd.data reason, COUNT(sd.data) total
              FROM {webform_submissions} s
              LEFT JOIN webform_submitted_data sd ON sd.sid = s.sid
              WHERE sd.nid = %d AND sd.data != '%s'
              GROUP BY sd.data
              ORDER BY COUNT(sd.data) DESC
              LIMIT 0,5", $node->nid, '');          
 
              // Create an array which will hold the reasons - which we will then display in the block
              $reasons = array();
 
              // We run through the submissions and match them to the choices from the webform textarea values
              while ($row = db_fetch_array($result)) {
                $safe_key = $row['reason'];
 
                // If a user chosen option actually exists in the current options available, then display it
                if(array_key_exists($safe_key, $submissions)) {
                  $reasons[] = $submissions[$safe_key];
                }
              }
 
              // If there are no results we need to display a message
              if (count($reasons) == 0) {
                $reasons[] = array('data' => t('There are no reasons'));
              }
 
             // Theme the results as a list to be styled with CSS
             $block['content'] = theme('item_list', $reasons, NULL, 'ol', $attributes = NULL);
          }
        	break;
        }
      return $block;
      break;
  }
}

Enable the module, then go to the blocks admin page and your block will now be available. Simply set the title and position it where you want it.

An example of this block can be seen in the right sidebar on the BCNDP website.

 


t. 604.684.2498 | f. 604.721.4007 | e. turningheads [at] raisedeyebrow.com