Drupal - How to create a list of users who did not submit some webform?

Step 1 - Introduce a webform submission flag

Install/enable the Flag module. Navigate to /admin/structure/flags/add/node and create a flag (do not check the "global" checkbox). Let's assume you label it something like "Webform submission". For "Bundles" (on the same form), check "Webform".

Here is such Flag definition (in export format) you could use for it (just import it in your own site):

$flags = array();
// Exported flag: "Webform submission".
$flags['webform_submission'] = array (
  'entity_type' => 'node',
  'title' => 'Webform submission',
  'global' => '0',
  'types' => 
  array (
    0 => 'webform',
  ),
  'flag_short' => 'Webform submitted',
  'flag_long' => 'Indication that the Webform was submitted already',
  'flag_message' => 'Webform submission recorded',
  'unflag_short' => 'Webform NOT submitted',
  'unflag_long' => 'Indication that the Webform is not yet submitted',
  'unflag_message' => 'Webform submission recording removed',
  'unflag_denied_text' => '',
  'link_type' => 'toggle',
  'weight' => 0,
  'show_in_links' => 
  array (
    'full' => 0,
    'teaser' => 0,
    'rss' => 0,
    'search_index' => 0,
    'search_result' => 0,
    'answers_full_node' => 0,
    'print' => 0,
  ),
  'show_as_field' => 0,
  'show_on_form' => 0,
  'access_author' => '',
  'show_contextual_link' => 0,
  'i18n' => 0,
  'api_version' => 3,
);
return $flags;

Step 2 - Register webform submissions

Install/enable the Rules module and create a Rule to flag the webform when it is submitted (by the user who submitted the webform and using the flag "Webform submission" (from Step 1).

Here is such Rule definition (in export format) you could use for it (just import it in your own site, which you can do if you have the 'Rules UI' enabled):

{ "rules_flag_a_submitted_webform" : {
    "LABEL" : "Flag a submitted webform",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "flag", "webform_rules" ],
    "ON" : { "webform_rules_submit" : [] },
    "IF" : [
      { "data_is" : { "data" : [ "node:nid" ], "value" : "5" } },
      { "user_has_role" : { "account" : [ "user" ], "roles" : { "value" : { "2" : "2" } } } }
    ],
    "DO" : [
      { "flag_flagnode" : {
          "flag" : "webform_submission",
          "node" : [ "node" ],
          "flagging_user" : [ "user" ],
          "permission_check" : "1"
        }
      }
    ]
  }
}

Step 3 - List the webform submissions

Create a view (using the Views module), to list the user who have yes or no flagged the webform with the "Webform submission"-flag from Step 1).

Here is such Views definition (in export format) you could use for it (just import it in your own site, which you can do if you have the 'Views UI' enabled):

$view = new view();
$view->name = 'webform_submissions_by_users';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'users';
$view->human_name = 'Webform submissions by users';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Webform submissions by users';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['access']['perm'] = 'access user profiles';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'table';
/* Relationship: Flags: User's flaggings */
$handler->display->display_options['relationships']['flag_user_content_rel']['id'] = 'flag_user_content_rel';
$handler->display->display_options['relationships']['flag_user_content_rel']['table'] = 'users';
$handler->display->display_options['relationships']['flag_user_content_rel']['field'] = 'flag_user_content_rel';
$handler->display->display_options['relationships']['flag_user_content_rel']['required'] = 0;
$handler->display->display_options['relationships']['flag_user_content_rel']['flag'] = 'webform_submission';
/* Field: User: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'users';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['name']['alter']['ellipsis'] = FALSE;
/* Field: Flags: User uid */
$handler->display->display_options['fields']['uid']['id'] = 'uid';
$handler->display->display_options['fields']['uid']['table'] = 'flagging';
$handler->display->display_options['fields']['uid']['field'] = 'uid';
$handler->display->display_options['fields']['uid']['relationship'] = 'flag_user_content_rel';
/* Field: Flags: Flagged time */
$handler->display->display_options['fields']['timestamp']['id'] = 'timestamp';
$handler->display->display_options['fields']['timestamp']['table'] = 'flagging';
$handler->display->display_options['fields']['timestamp']['field'] = 'timestamp';
$handler->display->display_options['fields']['timestamp']['relationship'] = 'flag_user_content_rel';
$handler->display->display_options['fields']['timestamp']['date_format'] = 'long';
$handler->display->display_options['fields']['timestamp']['second_date_format'] = 'long';
/* Sort criterion: User: Uid */
$handler->display->display_options['sorts']['uid']['id'] = 'uid';
$handler->display->display_options['sorts']['uid']['table'] = 'users';
$handler->display->display_options['sorts']['uid']['field'] = 'uid';
/* Filter criterion: Flags: User uid */
$handler->display->display_options['filters']['uid']['id'] = 'uid';
$handler->display->display_options['filters']['uid']['table'] = 'flagging';
$handler->display->display_options['filters']['uid']['field'] = 'uid';
$handler->display->display_options['filters']['uid']['relationship'] = 'flag_user_content_rel';
$handler->display->display_options['filters']['uid']['value'] = '';
$handler->display->display_options['filters']['uid']['exposed'] = TRUE;
$handler->display->display_options['filters']['uid']['expose']['operator_id'] = 'uid_op';
$handler->display->display_options['filters']['uid']['expose']['label'] = 'User uid';
$handler->display->display_options['filters']['uid']['expose']['use_operator'] = TRUE;
$handler->display->display_options['filters']['uid']['expose']['operator'] = 'uid_op';
$handler->display->display_options['filters']['uid']['expose']['identifier'] = 'uid';
$handler->display->display_options['filters']['uid']['expose']['remember_roles'] = array(
  2 => '2',
  1 => 0,
  3 => 0,
  4 => 0,
  5 => 0,
  6 => 0,
);
/* Filter criterion: User: Active */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'users';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = '1';

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'webform-submissions-by-users';

Fruit of your labor

If you import the above definitions of the flag, the rule and the view, and you have a few users submit the webform (= record their data), you can visit the relative path in your own site, which should then display a table that looks similar to this example:

Name            User uid   Flagged time
--------------+----------+--------------------------------
Demo.User     !          !                                
Famous.Dries  ! 8        ! Wednesday, May 11, 2016 - 19:13
Pierre.Vriens ! 19       ! Wednesday, May 11, 2016 - 18:07 

For the above example, user "Demo.User" had not yet submitted the webform. The view contains an exposed filter so that you can limit the display to only those who submitted the form, or those who did not yet submit the form.

Start nagging users

If you would enhance your view from Step 3 with the Views Bulk Operations module, and you'd create a Rules Component (using the Rules module) to send an eMail, you could use it to eMail all those users in that view with some type of nagging eMail like "Please record your data...".

What's next?

The above doesn't take into account any webform submissions from before the above logic is implement. However it should be pretty forward to use a mixture of the above (4) modules, including VBO, to perform such one time only update (to also flag the users who already submitted the webform in the past). Anybody interested in knowing about that: Ask (a followup) Question ...

Tags:

Webforms

Views