Measure node completion in Drupal, part 1
Introducing Content Complete, A CCK-based Drupal module
Ever needed to measure the completeness of your Drupal nodes? Or wanted to motivate your users to complete their content until it reaches a 100%? In this post, I'll outline the basic configuration of Content Complete, a new Drupal module that does exactly that. Content Complete started as a simple module to show completeness of nodes, but over time has included Rules support to manage complex user flows, dynamic caching and Views integration. In this first post, I'll guide you through the steps to configure the module, output the percentage of completeness and show you how to theme the percentage bar. In the second post of this series, I'll show you how to output all this data using Views.
To start, you need to download and install the module from the download page or directly via Drush.
Configuring the module
Completeness of nodes is measured per content type. For each content type, you need to select the fields you want to be included in the percentage. For example, you have a content type "Artist" with the fields "Title", "Release Date", "Label" and "Website". You want all of those fields to be completed by your users, such that the node is at 100%. If, for example, a user only fills in a value for "Title" and "Website", the completeness will be at 50%.
To activate content completion checks, go to Administer > Content Management > Content types, and click 'edit' on the content type you wish to have checked. Enable the checks, save the content type and reload the page to find the fields you can check for completeness, as shown in Figure 1.
If you are using the Content Profile module to manage user profiles, the module will figure out the profile node that belongs to the logged in user.
Displaying completeness
Content Complete provides various ways to display data like the percentage, a percentage bar and the next field to be completed. These are the different blocks provided by the module:
Content Complete: current node
: show completeness for the current node. Can be shown only at the node page.Content Complete: Album (first node)
: show completeness for the first node it finds of the specified content type and for which the logged in user has edit permissions. Can be shown at any page. Use this only if you have one node of that content type, for example, the associated profile node of that user.- Views. Will be reviewed in the next post of this series.
To enable a block, go to Administer > Site building > Blocks and drag and drop Content Complete: current node
to the region you want to display the block at. Then, navigate to your node to see the block appear (see Figure 2). You can also configure the block to be hidden when 100% is reached.
Who gets to see what: configuring permissions
The completeness block will be shown to every user including the anonymous user. Often, you will want to provide this block only to users who can edit the content. You can change the
permissions at Administer > User management > Permissions.
Theming
The module provides several CSS classes and ids for the themer. For example, you can use '.cck-complete-percent-bar-leq-25'
to style the appearance of the percent bar if the
percent is lower or equal (leq) to 25. Likewise, there are classes for leq-50
, leq-75
and leq-100
. Absolute numbers can be styled using .cck-complete-percent-bar-x
(with x replacing the actual percentage). Here is an example we used in one of our projects:
.content-complete-percent-bar-wrapper {<br> background: #333333;<br> border:1px solid #666666;<br> padding:1px;<br> margin: .5em 0;<br>}<br>.content-complete-percent-bar {<br> height: 5px;<br> background-color: #8CC101;<br>}
What's next
In the second part of this series, I will show you how to use Views to set up different views on the completeness of your nodes.
Tags: Drupal Planet