Restrictions on access to folders in Moodle

1

I am trying to create access restrictions to a folder within a Moodle course using a Script . This restriction must be for groups of users and if you do not belong to that group, you can not see the existing resources in that folder.

The operation I want to do through programming is like the following:

I have searched for information and it is very scarce and in the documentation just shows how to do it from the web link .

I know how to create groups, folders and sections programmatically from a script, but I can not identify the tables that must be used to make these restrictions or what are the steps to follow.

If someone knows how to do it or has an example or documentation that can help me, it will be a great help for me.

    
asked by Joacer 10.10.2016 в 16:32
source

1 answer

0

After looking for and trying some things, I found a solution that works, and it consists of modifying the field availavility of the table mdl_course_modules to add the access restriction.

I have created a function that is responsible for creating this permission, and it is as follows:

 /**
 * Se crean las restricciones de acceso a las seccion para solo usuarios que pertenezcan al grupo
 *
 * @param $course curso en que esta la seccion a restringir acceso
 * @param $sectionid id de la seccion a restringir acceso
 * @param $groupid id del grupo que tendra acceso
 * @param $module id del modulo a restringir de la tabla mdl_modules
 *
 */
    function grantPermission($course, $sectionid, $groupid, $module ){

        global $DB;

        $restriction = '{"op":"&","c":[{"type":"group","id":'. $groupid .'}],"showc":[true]}';

        $cm= $DB->get_record('course_modules', array('course' => $course , 'section' => $sectionid, 'module' => $module ), '*', MUST_EXIST);

        $course_module = new stdClass();
        $course_module->id = $cm->id;
        $course_module->course = $course;
        $course_module->section = $sectionid;
        $course_module->availability = $restriction;

        $res = $DB->update_record('course_modules', $course_module);

        if($res)
            rebuild_course_cache($course, true);    

        return $res;
    }
    
answered by 14.10.2016 / 12:57
source