Notifier


as of: January 17, 2014

Notifer modules are displayed on the right side of the screen below the scale weight. They can display information constantly or conditionally. Notifiers have the following methods:

string draw()
void transactionReset()

The draw method should return an HTML string containing the informtion to display. This should almost always include some block-level HTML tag like a <div;> so that different notifiers don't run together. Return the empty string if there's nothing to display currently. The transactionReset method does not have to do anything. This method is simply called after the end of each transaction. It is provided as a convenience in case your Notifier is keeping track of any state that needs to be reliably reset after a transaction.

Developers should be aware that Notifiers will only be refreshed when a) the whole page reloads or b) a parser triggers a redraw of that section. Setting a parser's return value for scale to any non-false value will redraw that section. This could be refactored if it bothers anyone sufficiently.

Example: display the current member's IOU balance

class MemBalanceNotifier extends Notifier 
{
	public function draw(){
        global $CORE_LOCAL;

        if ($CORE_LOCAL->get('memberID') == 0 || $CORE_LOCAL->get('memberID') == $CORE_LOCAL->get('defaultNonMem')) {
            return '';
        }

		$db = Database::pDataConnect();

        $query = $db->prepare_statement('SELECT Balance FROM custdata WHERE CardNo=?');
        $result = $db->exec_statement($query, array($CORE_LOCAL->get('memberID')));

        // non-valid member number apparently
        if ($db->num_rows($result) == 0) {
            return '';
        }

        $row = $db->fetch_row($result);

        return sprintf('<div style="border:1px solid black;">Balance $%.2f</div>',
                        $row['Balance']);

	}
}