Analyzing component data

The Webform module offers a standard set of basic statistics on components that receive user input data. For our IMEI component we will implement an analysis that shows how many blank and non-blank entries have been submitted to our component.

If we had access to a complete TAC (Type Allocation Code) database, we might have been able to report on the number of submissions we have received per mobile telephone manufacturer and global regions based on the first group of eight digits. Unfortunately the TAC data is not widely accessible, so we are somewhat limited.

How to do it...

Let's code the function that will perform the database analysis of our IMEI component:

/**
* Implements _webform_analysis_component().
*/
function _webform_analysis_imei($component, $sids = array()) {
$query = db_select('webform_submitted_data', 'wsd', array('fetch' => PDO::FETCH_ASSOC))
->fields('wsd', array('data'))
->condition('nid', $component['nid'])
->condition('cid', $component['cid']);
if (count($sids)) {
$query->condition('sid', $sids, 'IN'),
}
$nonblanks = 0;
$submissions = 0;
$result = $query->execute();
foreach ($result as $data) {
if (drupal_strlen(trim($data['data'])) > 0) {
$nonblanks++;
}
$submissions++;
}
$rows[0] = array(t('Left Blank'), ($submissions - $nonblanks));
$rows[1] = array(t('User entered value'), $nonblanks);
return $rows;
}

How it works...

This simple function runs a query against the data that has been submitted against our IMEI component. We iterate through the query result set, counting the total number of submissions as well as the number of non-blank submissions. When we have checked all the data we build our two analysis table rows showing the count of blank and non-blank entries we have received.

The following screenshot shows how our component output will render on the analysis page when we test the finished product:

How it works...
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset