Category: php

FogBugz “Active Project” notification tool

At Turboweb we’ve recently subscribed to a 5-user on-demand license for an awesome case tracking system called FogBugz.  For us it means that we have controlled workflow of cases (bugs, features, enquiries etc.) along with awesome estimation reporting and time tracking.  FogBugz was built with development teams in mind and it’s a very nice tool.

Anyway, one of the things it has is a nice API which you can use to interrogate the product (read and write) and this got me thinking about how I could use the API to remind me what I should currently be working on.  Thus was created the “FogBugz Notification Tool”.

This script does the following:

  1. Connects to your FogBugz installation
  2. Runs a query to see what things have been worked on today
  3. If there are any items that don’t have an end date, then it’s the case that’s currently being worked on
  4. Get the details of the case
  5. Use notify-send to pop up a notification bubble showing case number, title, estimated time and time remaining.

FogBugz Active Case Notification

I have found this most effective if I put it in my crontab to run every 5 minutes.

Requirements:

  • Ubuntu Linux (or any version of Linux that supports the “notify-send” command)
  • PHP5 CLI (simply because this script is written with PHP)
  • The “libnotify-bin” package (this provides the “notify-send” command, try “sudo apt-get install libnotify-bin”)

The script requires a little configuration for your circumstances, but this is easily done by editing the defined constants in the script:

	// Adjust these defines to suit your installation
	define( 'FBBASEURL', 'https://mywebsite.fogbugz.com/' );
	define( 'FBUSERNAME', 'my@email.address.com' );
	define( 'FBPASSWORD', 'mypassword' );

And to add it to your crontab, simply add this line (note the */5 means every time the current number of minutes in the hour is evenly divisible by 5)

*/5 * * * * DISPLAY=:0.0 /usr/bin/php /home/bob/fogbugz-notify.php

Of course, adjust the path appropriately.

CodeIgniter – Form Validation and Optional Fields

I’ve been doing a bit of work lately with CodeIgniter.  It’s been OK but the framework seems quite wrong in most places.  My main gripe is that the “helpers” define themselves as functions in the global namespace (rather than as objects that hook into the CodeIgniter object) which results in some stupidity like a function called “set_value” which just happens to retrieve the value as validated by the form validation “helper”.  Anyway, that’s a lesson learnt.

I’ve been trying to get the form validation to allow me to use set_value for fields that aren’t required, but unless your rules specify the field and a validation rule for it the value won’t be available when set_value is called.  The trick here is to use “echo” as the rule which means that the validation passes and you get back what you put in.  This is not documented in the CodeIgniter manual (it’s implied by the fact that you can use any PHP function as a “rule”).

Example:

$rules = array(
  array(
    'field' => 'name',
    'label' => 'Name',
    'rules' => 'required'
  ),
  array(
    'field' => 'nickname',
    'label' => 'Nickname',
    'rules' => 'echo'
  )
);
 
$this->form_validation->set_rules( $rules );

In this case any calls to set_value(‘nickname’) will return the correct value, rather than an empty string.

PHP tutorial – introduction to classes

You might have noticed that I’ve migrated this blog to WordPress – the main reason for doing so was to give me the ability to easily add pages to the blog so that I could keep my web dev tutorials in one place.

I’ve also just added the introduction to classes tutorial so go and check it out.

WordPress Themes