XF 2.2 Want to do a simple SQL lookup and display result via Add-on?

I'm trying to add a link to my staff bar, that has a badge with a counter on it. I've created an add-on and have modified the templates, but I'm unsure of where I can write the PHP/SQL code to retrieve the count I want to display in the badge. I know I can extend controllers, but I'm not sure what one I should be extending exactly since the staff bar is part of PAGE_CONTAINER.

Don't really need any additional complexities either really, all I need is a single function where I can do a SQL query and pass the result back to the template modification basically, but failing to find anything in the docs or anywhere really, so hopefully someone can help. The link isn't it's own page, it's a link that points to an app offsite of the forum.
 
Under the development section of the ACP, go to code event listeners and create one for tenplater_template_pre_render with hint PAGE_CONTAINER.
 
Top Bottom