Tarakan Design Blog

OpenCamp was a HUGE success

File 39OpenCamp (with DrupalCamp Dallas 2010) was this past weekend and all indications are that it was a tremendous success.  We worked long and hard putting it together.  We featured 30 Drupal sessions and nearly 100 sessions in all.  Over 600 people attended the Camp.  We had a spectacular evening pyrotechnic jump by the Army Golden Knights.  We had parties Fri and Sat night with live musical entertainment.  We gave away thousands of dollars in various prizes.

A few of us Dallas Drupal cyclists were able to take Jay Batson, the co-founder of Acquia out for a couple laps around White Rock lake (and why didn't we take a picture - Jay was wearing Drupal bikle shorts and jersey!).  All in all it was a great weekend.

Check out the Flickr pool for pictures from OpenCamp (some of them are from the photography contest).  And look for DrupalCamp 2011 sometime this spring.

OpenCamp in Dallas

File 32 Tarakan Design is proud to help bring OpenCamp to Dallas on Aug 27-29, 2010.  It's a new idea in community-driven camps, bring developers and users of Drupal, Wordpress and Joomla! together, as well as those involved in community building, social media and podcasting. Tarakan help put together DrupalCamp Dallas last year, and it was a huge success.

 

File 33We're going to have some great Drupal, Wordpress, Joomla!, and social & new media speakers there, as well as local community experts in various areas of Drupal there to give sessions and help answer questions.  We have an incredible venue - the Crowne Plaza in Addison.  We have a dozen rooms dedicated to the camp.

Well-known Geek Girl and OpenCamp co-organizer Cali Lewis (of geekbrief.tv) was shooting videos at the Crowne Plaza on Sunday- be sure to check the OpenCamp site soon for those videos and lots of pictures.

And sign up soon- it's only $99 until June 1, then it goes up.  That includes everything, include breakfast and lunch each day.   Reserve a room for the weekend too- we have great parties planned for both nights, with live entertainment.

Quick and Easy "Or Admin" Filter for Views

Prerequisites: Drupal 6, Views2, PHP

Recently, we had the need to create an Organic Groups view that filtered nodes based on group membership or, if the current user was admin, to show nodes from all groups.  We needed something like the "Published Or Admin" node filter, only applied to Organic Groups membership.

My first instinct was, "No problem! Organic Groups considers users with the administer nodes permission to be members of all groups." Unfortunately, this membership test does not apply to Views filters.

My second instinct was, "That's OK, we'll just use the user:roles filter". Unfortunately, the user:roles filter acts on the node owner rather the current user.

Contribs to the Rescue

Fortunately, there is a simple way around this using the contribs Views Or and Views PHP Filter. As you are probably aware, views filters are normally combined with logical ANDs, meaning that a node is included only if it satisfies the requirements of all the included filters. Views Or allows us to combine arbitrary filters with logical ORs instead, giving us a lot more flexibility.

Views PHP Filter allows us to execute arbitrary PHP code and return a list of node IDs as either an inclusive or an exclusive filter. For example, if you define a PHP filter that returns the nids (1, 2, 3) and then add a node:published filter, you'd get any of nodes 1, 2, and 3 that are also published. Of course, that wouldn't be particularly useful; however, since we can execute arbitrary PHP we can write some code that does this:

if (the current user is admin) then return (a list of all node ids), otherwise return nothing.

Combine that with Views Or and things start to get interesting. One fortunate thing is that if you have a null clause (like our "return nothing" case), Views Or does not generate anything in the resulting query.

Combining Views PHP Filter and Views Or

With that combination we can effectively get this kind of filter logic: 

If the current user is not admin: if (the current user is a member of the node's group) ← no OR clause since we returned nothing

If the current user is admin: if (the current user is a member of the node's group OR the nid is IN (set of all nids))

Now the problem with this approach is that it incurs an extra database call every time the page is viewed (to get a list of all nids), plus the set of all nids could potentially get really large. If you remember, though, we can configure our PHP filter to be exclusive instead of inclusive.

Using Negative Logic

Now, armed also with the knowledge that nids start at 1, we use negative logic for our PHP code:

if (the current user is admin) then return (nid 0) 

or

global $user;
if (in_array('admin', $user->roles)) {
  return array(0);
}

You see where I'm going with this. Combined with the exclusive PHP filter option, we're saying "nodes that do not have nid = 0", which is to say, all nodes in the system.

File 30

So we end up with the following filters (of course, substitute your own node type):

File 31

 That's it. With just a few lines of code and a couple of modules, you've created an "Or Admin" filter.

 

Our Philosophy

 

  • Customer centered, Agile development
  • Clear and open communication
  • Solid software engineering principles

 

Drupal

Drupal

 

We use the Drupal Content Management Framework for secure and reliable websites.
Learn More