$stractivitymodule = get_string("activitymodule");
$strshowmodulecourse = get_string('showmodulecourse');
$haseditsettingscapability = has_capability('local/contextadmin:editowncatsettings', $context);
$haseditvisibilitycapability = has_capability('local/contextadmin:changevisibilty', $context);
// If data submitted, then process and store.
if (!empty($parammodulename) and confirm_sesskey() && ($haseditvisibilitycapability or $haseditsettingscapability) && !is_plugin_locked($catid, $parammodulename, 'modules')) {
    if ($DB->record_exists("modules", array("name" => $parammodulename))) {
        if (!is_plugin_locked($catid, $parammodulename, 'modules')) {
            if ($paramvisible !== null) {
                set_context_module_settings($catid, $parammodulename, array('visible' => $paramvisible, 'search' => ''));
            }
            if ($paramoverride !== null) {
                set_context_module_settings($catid, $parammodulename, array('override' => $paramoverride, 'search' => ''));
            }
            if ($paramlocked !== null) {
                set_context_module_settings($catid, $parammodulename, array('locked' => $paramlocked, 'search' => ''));
            }
            if ($paramclear !== null) {
                remove_category_module_values($catid, $parammodulename);
            }
        } else {
            print_error('modulelocked', 'local_contextadmin');
        }
    } else {
        print_error('moduledoesnotexist', 'error');
    }
}
// Category is our primary source of context.  This is important.
$category = $PAGE->category;
$site = get_site();
$PAGE->set_title("{$site->shortname}: {$category->name}");
 public function test_category_module_exists()
 {
     global $COURSE;
     // Setup.
     // Test Set.
     $COURSE->category = 2;
     set_context_module_settings($COURSE->category, 'assignment', array('visible' => 0));
     $result = category_module_exists($COURSE->category, 'assignment', 'modules');
     $this->assertTrue((bool) $result);
     $COURSE->category = 3;
     remove_category_module_values($COURSE->category, 'assignment');
     $result = category_module_exists($COURSE->category, 'assignment', 'modules');
     $this->assertFalse((bool) $result);
     // Teardown.
 }