You can use a conditional statement based on capabilities to determine what code is run
if (has capability 'mark assignments' in context 'this course') then run code to generate teachers' view else run code to generate students' view
https://docs.moodle.org/dev/Access_API#Determining_that_a_user_has_a_given_capability
if (has capability 'mark assignments' in context 'this course') then run code to generate teachers' view else run code to generate students' view
https://docs.moodle.org/dev/Access_API#Determining_that_a_user_has_a_given_capability