. /** * Base capability table. * * @package core_role * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); /** * This class represents a table with one row for each of a list of capabilities * where the first cell in the row contains the capability name, and there is * arbitrary stuff in the rest of the row. This class is used by * admin/roles/manage.php, override.php and check.php. * * An ajaxy search UI shown at the top, if JavaScript is on. */ abstract class core_role_capability_table_base { /** The context this table relates to. */ protected $context; /** The capabilities to display. Initialised as $context->get_capabilities(). */ protected $capabilities = array(); /** Added as an id="" attribute to the table on output. */ protected $id; /** Added to the class="" attribute on output. */ protected $classes = array('rolecap'); /** Default number of capabilities in the table for the search UI to be shown. */ const NUM_CAPS_FOR_SEARCH = 12; /** * Constructor. * @param context $context the context this table relates to. * @param string $id what to put in the id="" attribute. */ public function __construct(context $context, $id) { $this->context = $context; $this->capabilities = $context->get_capabilities(); $this->id = $id; } /** * Use this to add class="" attributes to the table. You get the rolecap by * default. * @param array $classnames of class names. */ public function add_classes($classnames) { $this->classes = array_unique(array_merge($this->classes, $classnames)); } /** * Display the table. */ public function display() { if (count($this->capabilities) > self::NUM_CAPS_FOR_SEARCH) { global $PAGE; $jsmodule = array( 'name' => 'rolescapfilter', 'fullpath' => '/admin/roles/module.js', 'strings' => array( array('filter', 'moodle'), array('clear', 'moodle'), ), 'requires' => array('node', 'cookie', 'escape') ); $PAGE->requires->js_init_call('M.core_role.init_cap_table_filter', array($this->id, $this->context->id), false, $jsmodule); } echo '
' . get_string('capability', 'core_role') . ' | '; $this->add_header_cells(); echo "
---|
' . get_capability_docs_link($capability) . '' . $capability->name . ' | '; // Add the cells specific to this table. $this->add_row_cells($capability); // End the row. echo "