This would require a close to real-time implementation. You could have a table that has all the rooms / chat sessions created. Then in your users table you could have a moderators column as well as a current room id column.
Rooms Table
Columns: ID, USER_ID, CREATED_AT, UPDATED_AT, NAME, PASSWORD, HAS_MODERATOR (bool) ....
When a moderator joins a room, you could update the "HAS_MODERATOR" field to true or 1. Then you could write a simple long-polling script that would simply make an ajax request to a php page or route and return a value of true or false. If it returns true, then a moderator is still in the room, otherwise you can close the room and force a redirect through javascript or something. The php script would simply check if has_moderator is true, AND you would go through the users table, retrieve all the moderators, and check what room they are in. Match the current room the moderator is in with the room your checking for. This will ensure that a moderator is in the room.
This might help you out: Notify Ajax/Javascript that background PHP has completed