by Patrick Pollet.
Hello,
Within your function getUserId() you must add
global $USER;
to access tthe global variable setup for you by config.php
Cheers
edit : when developing for Moodle you should set your server to full debug mode (see http://docs.moodle.org/23/en/Debugging )
you will have seen immediately a PHP notice for unset variable $USER