Tuesday, October 30, 2007

How to create an Alumni directory


public


group: Alumni


jwolf - Thu, 2007-03-15 01:17



I have been involved with creating several Drupal-based alumni websites. One of the most requested feature, by clients, is an alumni directory; a tabular listing of all registered alumni with links to the alumni's profile(s).


Below is a basic how to implemented an alumni directory using contributed modules. This howto is based on Drupal 5.x, however, you can use the same approach with Drupal 4.7.x.

I hope this is helpful for others who are building Drupal-based alumni websites.


Modules used


• Profile (part of core)

• Usernode


• Views


Putting it all together


Profile Module


The profile module, which is part of Drupal core, should be enabled to allow you to define custom fields (e.g., Year of Graduation, First Name, Last Name, etc...). These custom fields are then used as part of the site's registration process and ultimately used for the alumni directory. More information about extending user account information can be found at http://drupal.org/handbook/modules/profile/


The custom fields that I have created for several sites are shown in the screenshot below.


Profile Fields


As you can see in the above screenshot there are several custom fields that have been created, you may not need to create the same exact fields, as your project's needs may vary. The custom fields that will be used in the alumni directory are:



• Graduation Year (profile_grad_year);

• First Name (profile_first_name);

• Last Name (profile_last_name);

and

• Maiden Name (profile_maiden_name)


Each of the custom fields above has a "field type" which defines what type of form the user will interact with (e.g., single-line textfield and list selection). As for the Graduation Year field, I created a selection list "field type" which creates a drop down list of the graduation years to choose from. It is very simple to add additional years when needed. The first, last, and maiden names "field types" are single-line textfields. All the above custom fields, with the exception of Maiden Name, are required fields to be filled out by the alumni during the registration process.


Graduation Year field type


Another field that will be shown in the alumni directory, username, will be covered later when we get into the Views module. The benefit of adding the username field to the alumni directory is that it will provide a link to the alumni's profile.



Now that the custom fields have been created, it's time to move on to the Usernode module.


Usernode Module


Usernode creates a content page for each user. The usernode is automatically created with the user account. One of the great benefits of using the Usernode module is that Usernodes can be used in user listings with the views module; it makes available the custom fields, created by the profile module, to the Views module.


Enabling the Usernode module is all that needs to be done. There is no additional configuration needed for Usernode.


Views Module


Views is a powerful query builder for Drupal that allows you to fetch and present lists of content (posts/nodes) to the user in ways that are tailored to your site and your content.


Using Views, an administrator can create pages and blocks that list new posts of a particular type (such as forum or blog posts), create alphabetical lists by taxonomy, create weekly, monthly or yearly archive pages, create a table of posts that are flagged as unread, and much much more!


I must say, this module kicks ass. A mighty big thanks to Earl Miles (merlinofchaos) for this module. Views surely is a piece of art.


If you're not familiar with the Views module I strongly suggest that you spend some time to get to know Views, it will make you a happier Drupaler.


The Views documentation can be found at http://drupal.org/node/109604


First, you'll need to enable the Views module. You should also enable the Views UI which allows you to create and edit views. Once the module(s) have been enabled you can create a new view.


To create and administer Views, navigate to admin/build/views (Drupal 5.x), here you will be presented with a list of "Default Views" - system default views.


Creating a new view


The following steps are how you'll create the alumni directory view.


Basic Information


1) Click on the "Add" button/link (admin/build/views/add)

2) Give the view a name: alumni_directory


3) Assign who has access to the view. If you assign access to anonymous users, anyone who visits the site will be able to view the alumni directory. However, anonymous users will not be able to view the individual profiles of alumni unless you allow access to users' profiles in the "Access control" section. I usually do not allow anonymous users to access users' profiles and restrict access to profiles only to authenticated user (registered alumni).

4) Description. Give the view a description (e.g., Alumni Directory).


Page

The alumni directory view will be provided as a page.


5) Check "Provide Page View";

6) URL of the alumni directory = alumni-directory;

7) View Type is a "Table View";

8) Title. This is the title that will be shown at the top of the view (page) = Alumni Directory;

9) Check "Use Pager" so that the alumni directory will be pagenated;


10) Nodes per Page. How many alumni do you want to show per page?

11) Header. This will be shown at the top of the alumni directory. I usually put a message about the alumni directory and a link to the registration page for those who are not yet registered;

12) Footer. This will be shown at the bottom of the alumni directory;

13) Empty Text. This is where you can put text to display if a view returns no nodes;

14) Input format = Filtered HTML;


Fields

Skip down to the "Fields" section.


Here at the fields section is where you define what fields you want the ("Table View") view to display.


15) Add Field. Select the "Usernode: Name" field. This is the username link that was mentioned earlier. This will provide a direct link to the alumni's profile;


15b) Label. What is the name you want to give this filed? = "Username";

15c) Handler. Select the "themed userlink" option. This will make the username a link to the alumni's profile;

15d) Sortable. If you'd like to make the usernames' sortable, than choose "Yes";

15e) Default Sort = None;



16) Add Field. Select the "Profile: Graduation Year". This is the custom field (profile_grad_year) that was created using the profile module as mentioned in the "Profile Module" section above;

16b) Label. What is the name you want to give this filed? = "Class";

16c) Sortable = Yes;

16d) Default Sort = Ascending. This will sort the alumni directory by class year in ascending order;



17) Add Field. "Profile: First Name". Again, this is the custom field (profile_first_name) that was created using the profile module as mentioned in the "Profile Module" section above;

17b) Label = "First Name";

17c) Sortable = Yes;

17d) Default Sort = None;



18) Add Field. "Profile: Last Name" - this is the custom field (profile_last_name);

18b) Label = "Last Name";

18c) Sortable = Yes;

18d) Default Sort = None;



19) Add Field. Select the "Profile: Maiden Name" - this is the custom field (profile_maiden_name);

19b) Label = "Maiden Name";

19c) Sortable = Yes;

19d) Default Sort = None;



Views Field


Filter

Skip down to the "Filters" section.


Here at the filter section is where you define how you want to filter the view. I created three filters that will filter the view so that only active alumni are listed, therefore filtering out any alumni that are either pending registration approval or blocked from access to the site.

The second filter that I created displays alumni who are registered with the site and are part of a graduation class. In other words, I'm filtering out non-alumni users from the alumni directory (e.g., site ops, administrators, etc).

The third filter is filtering by role. I only want members of the "alumni" role to be in my alumni directory. This third filter is a little over kill, but it gets the job done.


20) Add Filter. Select the "Usernode: Active" field;


20b) Operator. Select the "Is Equal To" operator;

20c) Value. Select the "active" value;


21) Add Filter. Select the "Profile: Graduation Year" field;

21b) Operator. Select the "Is One Of" operator;

21c) Value. Multiple select all the years.



Views Filter


Exposed Filers

To view by a individual class, I created a "Exposed Filter" which will allow visitors to select, from a drop down list, a specific class to view.

To create a selection list of classes, you'll need to create an "exposed filter" as follows:


22) Back in the "Filters" section click on the "Expose" button for the "Profile: Graduation Year". In the "Exposed Filters" section, you should now see the newly created exposed filter for the profile "Graduation Year".

22b) In the "exposed Filters" section, give the exposed filter a "Label" - I labeled my exposed filter "Select a Class to view";

22c) Check the "Optional", "Force Single", and "Lock Operator" boxes



At this point it's now time to save the view by clicking the "Save" button.


You will then be redirected back to the Views administration page and you should now see the newly created alumni directory view in the "Existing Views" list.

You can go to the alumni directory by clicking on the URL link (for the alumni directory view). If all went well you should be brought to the alumni directory.


The Alumni Directory


Attached is the exported view of the alumni directory that I created.







AttachmentSize
alumni-directory-view.txt4.01 KB



Original Post: http://groups.drupal.org/node/3172

3 comments:

Anonymous said...

excellent article Stephen,
Have you had to import any user profiles from a CSV file? Do you know if there is an easy way to have user fields imported?

Anonymous said...

Great article! I used your step by step instructions for an association's membership directory, and it's working great. A bit of a long-shot question: After installing Profile Privacy module (to allow members to hide profile fields if they like), profile fields are hidden correctly in profiles, but still show up in my Membership Directory table view. Do you know how I can hide these fields?

Oleksandr Berezko said...

Great article! Thanks a lot!! What about Drupal 6?