Case Study: Social Networking with ExpressionEngine, Part 1
by Ryan Irelan
Last week Greg posted to the Airbag blog detailing some recent projects that were hatched by Team Airbag. I thought I would point out (again, as Greg did mention this in the comments of his write-up) that three of those projects were developed on ExpressionEngine. However, I’d like to talk about just one of them right now: Clinician1.
Clinician1 came to Airbag with the task of building a community website for Physician Assistants. A large part of the site is based around content from members of the community, comments on that content and responses to polls.
ExpressionEngine is a great tool to manage content, allow commenting on content and dozens of other ways of interacting with the content (ratings, saving or favoriting, tagging) using third party add-ons. But the client also wanted some more traditional social networking features: groups and friends. Every user had to have the ability to join a topical group and add other users as friends (in the case of Clinician1, they were called “colleagues”).
I pondered all of the ways I could implement this by cobbling together existing ExpressionEngine functionality and ultimately decided it would be easier to write both of the social networking tools from scratch, as custom modules. It was time consuming but proved easier in the long run because I have exact control over how these features act. Another benefit of going custom is that I maintain the ability to add new features to the modules and refine existing ones, based on client needs. This wouldn’t have been the case if I hacked together existing add-ons.
I created two modules: a Networks module and a Friends module. These modules are not available for download (but maybe one day), but I do want to walk through a few examples of how they are used in the templates. This part of the series we will talk about the Networks module.
Let’s start with some EE code, shall we?
{exp:networks:show type="all"} Network name: {name} Network Description: {description} {join} {/exp:networks:show}
This is the basic networks tag pair that lists out all of the networks in the system. It displays the name, the description and then a button to join the network. The tag pair accepts the “type” parameter, which can have the value of “all” or “user.” If you give it the “user” value, the module will only return networks of which the currently logged-in user is a member.
For a list of groups or networks that the user is already a member of, we use the “user” parameter and a single variable to create a button to leave the group.
{exp:networks:show type="user"} Network name: {name} {leave} {/exp:networks:show}
There’s also the option of adding the count of network members using the {count}
variable inside of the networks:show tag pair, as well as creating a permalink ({permalink}
) to view the network detail page.
I also created the functionality to display a list of all members from a certain group:
{exp:networks:member_list network="1"} {/exp:networks:member_list}
as well as a way for users to create their own groups (and automatically join the new group they just created). Group creation in Clinician1 is currently restricted to the control panel and admin users, but the functionality was built to allow anyone to create a new group.
In the ExpressionEngine control panel, the networks are accessible, allowing the administrator to create new networks, edit existing networks (just the name and description) and delete networks.
Finally, I also added simple search functionality, so the users could search for groups to join. This isn’t part of the initial Clinician1 website, but the ability is there should it ever be needed.
This brief look at the Networks module ends Part 1 of this case study on social networking with ExpressionEngine. Next up is the Friends module, which allows users to create one-on-one connections with other members of the community.