Building a Bug Tracker: Filtering by Assignment
Within a bug tracker, it can often be helpful to see who the bug is assigned to. For this reason, we set up the bug_tracker_assignment custom field. Now we’re going to implement filtering by that custom field.
In fact, the structure is already in place, so this will be extremely easy to add; it is just a matter of a few conditionals and a few links. Ready?
Open up the bug_tracker/filter_by template.
Locate this line:
{if segment_3 == "severity"}
We’re going to make this conditional handle assignments, as well. So update the line to look like so:
{if segment_3 == "severity" OR segment_3 == "assignment"}
As you can see here, our links will pass what we’re filtering by in the URL. We continue here, then, creating our own semantics. The best part is that we’ve already considered this need, and the code is already in place:
search:bug_tracker_{segment_3}="={segment_4}"
is already present in our weblog entries tag. Nothing else needs to be done here.
Because ExpressionEngine gains a lot of flexibility through segments; all that is left to do for this feature is to add our links.
Open up inc/.leftnav, and find this line:
<li><a href="#">Assigned To</a></li>
Now, replace it with this:
<ul>
<li><a href="{path="{bug_tracker_template_group}/filter_by"}assignment/Bob">Bob</a></li>
<li><a href="{path="{bug_tracker_template_group}/filter_by"}assignment/Jane">Jane</a></li>
<li><a href="{path="{bug_tracker_template_group}/filter_by"}assignment/Andrew">Andrew</a></li>
<li><a href="{path="{bug_tracker_template_group}/filter_by"}assignment/Chris">Chris</a></li>
</ul>
This works, but it is going to give us some strange language in our headers. The language differences are easily handled by a few more conditionals.
Open up bug_tracker/filter_by and locate these lines:
{if no_results}
{if segment_3 != "assignment"}
No bugs of {segment_4} {segment_3}.
{if:elseif segment_3 == "assignment"}
There are no bugs assigned to {segment_4}.
{/if}
{/if}
That will update the headers if there are no results; now to change the headers if there are results. Locate this line:
<h3>Filtering by {segment_4} {segment_3}</h3>
and replace it with this code, similar to above:
{if segment_3 != "assignment"}
<h3>Filtering by {segment_4} {segment_3}</h3>
{if:elseif segment_3 == "assignment"}
<h3>Bugs assigned to {segment_4}</h3>
{/if}
As you can see from the above prcess, adding new filters and information takes a very short time. The reason for this is ExpressionEngine’s power of using URL segments in combination with the template tags. Rolling out new website features becomes a simple matter of a few minor template updates, and creating the appropriate links.


