Have you looked at this excellent documentation:
http://docs.moodle.org/en/Development:Roles#Programming_Interface
For example, you may use something like that:
$context = get_context_instance(CONTEXT_SYSTEM)) if (has_capability('moodle/legacy:admin', $context)||has_capability('moodle/legacy:teacher', $context)) { }Hope this helps?
Arnaud