Posts

Showing posts with the label config. lib. auth

Assigning roles to users in Moodle based on their profile data using php script

In case you want to allow some particular blocks to be seen only by a particular group of users in your Moodle, you can do as below: Note: assuming you've already created all the user accounts in your Moodle. 1. Categorize your users using some fields like department or description: For example, I have Middle School Students and High School Students. Each of the students has Graduation Year information stored in the department field of the user profile. I will then use that field to determine which school they are studying now: Student Number 1's department: 2015 class => High School Student Number 2's department: 2021 class => Middle School The below snippet is pretty handy to identify which school a student is studying based on her graduation year: <?php function class_to_grade_level ($class_of) { // you may want to change the timezone date_default_timezone_set('Asia/Ho_Chi_Minh'); $grad_year = intval($class_of); $curr...