diff --git a/admin/roles/check.php b/admin/roles/check.php index 0c2c822351f..47311020b84 100644 --- a/admin/roles/check.php +++ b/admin/roles/check.php @@ -24,7 +24,7 @@ require_once(dirname(__FILE__) . '/../../config.php'); -$contextid = required_param('contextid',PARAM_INT); +$contextid = required_param('contextid', PARAM_INT); list($context, $course, $cm) = get_context_info_array($contextid); @@ -44,7 +44,7 @@ if ($course) { } } -// security first +// Security first. require_login($course, false, $cm); if (!has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride', 'moodle/role:override', 'moodle/role:manage'), $context)) { print_error('nopermissions', 'error', '', get_string('checkpermissions', 'role')); diff --git a/admin/roles/classes/capability_table_base.php b/admin/roles/classes/capability_table_base.php index df442751390..9c9d7f9029b 100644 --- a/admin/roles/classes/capability_table_base.php +++ b/admin/roles/classes/capability_table_base.php @@ -15,7 +15,7 @@ // along with Moodle. If not, see . /** - * Library code used by the roles administration interfaces. + * Base capability table. * * @package core_role * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com) @@ -49,13 +49,13 @@ abstract class core_role_capability_table_base { const NUM_CAPS_FOR_SEARCH = 12; /** - * Constructor - * @param object $context the context this table relates to. + * Constructor. + * @param context $context the context this table relates to. * @param string $id what to put in the id="" attribute. */ - public function __construct($context, $id) { + public function __construct(context $context, $id) { $this->context = $context; - $this->capabilities = fetch_context_capabilities($context); + $this->capabilities = $context->get_capabilities(); $this->id = $id; } @@ -74,15 +74,15 @@ abstract class core_role_capability_table_base { public function display() { if (count($this->capabilities) > self::NUM_CAPS_FOR_SEARCH) { global $PAGE; - $PAGE->requires->strings_for_js(array('filter','clear'),'moodle'); + $PAGE->requires->strings_for_js(array('filter', 'clear'), 'moodle'); $PAGE->requires->js_init_call('M.core_role.init_cap_table_filter', array($this->id, $this->context->id)); } echo '' . "\n\n"; - echo ''; + echo ''; $this->add_header_cells(); echo "\n\n\n"; - /// Loop over capabilities. + // Loop over capabilities. $contextlevel = 0; $component = ''; foreach ($this->capabilities as $capability) { @@ -90,35 +90,35 @@ abstract class core_role_capability_table_base { continue; } - /// Prints a breaker if component or name or context level has changed + // Prints a breaker if component or name or context level has changed. if (component_level_changed($capability, $component, $contextlevel)) { $this->print_heading_row($capability); } $contextlevel = $capability->contextlevel; $component = $capability->component; - /// Start the row. + // Start the row. echo ''; - /// Table cell for the capability name. + // Table cell for the capability name. echo ''; - /// Add the cells specific to this table. + // Add the cells specific to this table. $this->add_row_cells($capability); - /// End the row. + // End the row. echo "\n"; } - /// End of the table. + // End of the table. echo "\n
' . get_string('capability','role') . '
' . get_string('capability', 'core_role') . '
' . get_capability_docs_link($capability) . '' . $capability->name . '
\n"; } /** * Used to output a heading rows when the context level or component changes. - * @param object $capability gives the new component and contextlevel. + * @param stdClass $capability gives the new component and contextlevel. */ protected function print_heading_row($capability) { echo '' . @@ -127,10 +127,14 @@ abstract class core_role_capability_table_base { } - /** For subclasses to override, output header cells, after the initial capability one. */ + /** + * For subclasses to override, output header cells, after the initial capability one. + */ protected abstract function add_header_cells(); - /** For subclasses to override, return the number of cells that add_header_cells/add_row_cells output. */ + /** + * For subclasses to override, return the number of cells that add_header_cells/add_row_cells output. + */ protected abstract function num_extra_columns(); /** @@ -148,7 +152,7 @@ abstract class core_role_capability_table_base { * For subclasses to override. A change to reaturn class names that are added * to the class="" attribute on the <tr> for this capability. * - * @param object $capability the capability this row relates to. + * @param stdClass $capability the capability this row relates to. * @return array of class name strings. */ protected function get_row_classes($capability) { @@ -161,7 +165,7 @@ abstract class core_role_capability_table_base { * * You can rely on get_row_classes always being called before add_row_cells. * - * @param object $capability the capability this row relates to. + * @param stdClass $capability the capability this row relates to. */ protected abstract function add_row_cells($capability); } diff --git a/admin/roles/classes/capability_table_with_risks.php b/admin/roles/classes/capability_table_with_risks.php index 01625632ba7..b759b896b5f 100644 --- a/admin/roles/classes/capability_table_with_risks.php +++ b/admin/roles/classes/capability_table_with_risks.php @@ -15,7 +15,7 @@ // along with Moodle. If not, see . /** - * Library code used by the roles administration interfaces. + * Capabilities table with risks. * * @package core_role * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com) @@ -47,7 +47,7 @@ abstract class core_role_capability_table_with_risks extends core_role_capabilit parent::__construct($context, $id); $this->allrisks = get_all_risks(); - $this->risksurl = get_docs_url(s(get_string('risks', 'role'))); + $this->risksurl = get_docs_url(s(get_string('risks', 'core_role'))); $this->allpermissions = array( CAP_INHERIT => 'inherit', @@ -64,7 +64,7 @@ abstract class core_role_capability_table_with_risks extends core_role_capabilit $this->roleid = $roleid; $this->load_current_permissions(); - /// Fill in any blank permissions with an explicit CAP_INHERIT, and init a locked field. + // Fill in any blank permissions with an explicit CAP_INHERIT, and init a locked field. foreach ($this->capabilities as $capid => $cap) { if (!isset($this->permissions[$cap->name])) { $this->permissions[$cap->name] = CAP_INHERIT; @@ -76,7 +76,7 @@ abstract class core_role_capability_table_with_risks extends core_role_capabilit protected function load_current_permissions() { global $DB; - /// Load the overrides/definition in this context. + // Load the overrides/definition in this context. if ($this->roleid) { $this->permissions = $DB->get_records_menu('role_capabilities', array('roleid' => $this->roleid, 'contextid' => $this->context->id), '', 'capability,permission'); @@ -96,18 +96,18 @@ abstract class core_role_capability_table_with_risks extends core_role_capabilit foreach ($this->capabilities as $cap) { if ($cap->locked || $this->skip_row($cap)) { - /// The user is not allowed to change the permission for this capability + // The user is not allowed to change the permission for this capability. continue; } $permission = optional_param($cap->name, null, PARAM_PERMISSION); if (is_null($permission)) { - /// A permission was not specified in submitted data. + // A permission was not specified in submitted data. continue; } - /// If the permission has changed, update $this->permissions and - /// Record the fact there is data to save. + // If the permission has changed, update $this->permissions and + // Record the fact there is data to save. if ($this->permissions[$cap->name] != $permission) { $this->permissions[$cap->name] = $permission; $this->changed[] = $cap->name; @@ -119,14 +119,14 @@ abstract class core_role_capability_table_with_risks extends core_role_capabilit * Save the new values of any permissions that have been changed. */ public function save_changes() { - /// Set the permissions. + // Set the permissions. foreach ($this->changed as $changedcap) { assign_capability($changedcap, $this->permissions[$changedcap], $this->roleid, $this->context->id, true); } - /// Force accessinfo refresh for users visiting this context. - mark_context_dirty($this->context->path); + // Force accessinfo refresh for users visiting this context. + $this->context->mark_dirty(); } public function display() { @@ -143,7 +143,7 @@ abstract class core_role_capability_table_with_risks extends core_role_capabilit global $OUTPUT; echo '' . get_string('permission', 'role') . ' ' . $OUTPUT->help_icon('permission', 'role') . ''; - echo '' . get_string('risks','role') . ''; + echo '' . get_string('risks', 'core_role') . ''; } protected function num_extra_columns() { @@ -164,7 +164,7 @@ abstract class core_role_capability_table_with_risks extends core_role_capabilit protected function add_row_cells($capability) { $this->add_permission_cells($capability); - /// One cell for each possible risk. + // One cell for each possible risk. foreach ($this->allrisks as $riskname => $risk) { echo ''; if ($risk & (int)$capability->riskbitmask) { @@ -180,7 +180,7 @@ abstract class core_role_capability_table_with_risks extends core_role_capabilit * @param string $type the type of risk, will be one of the keys from the * get_all_risks array. Must start with 'risk'. */ - function get_risk_icon($type) { + public function get_risk_icon($type) { global $OUTPUT; if (!isset($this->riskicons[$type])) { $iconurl = $OUTPUT->pix_url('i/' . str_replace('risk', 'risk_', $type)); diff --git a/admin/roles/classes/check_users_selector.php b/admin/roles/classes/check_users_selector.php index b899106a409..f30df0dbefe 100644 --- a/admin/roles/classes/check_users_selector.php +++ b/admin/roles/classes/check_users_selector.php @@ -15,12 +15,7 @@ // along with Moodle. If not, see . /** - * Library code used by the roles administration interfaces. - * - * Responds to actions: - * add - add a new role - * edit - edit the definition of a role - * view - view the definition of a role + * User selector. * * @package core_role * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com) @@ -38,7 +33,7 @@ require_once($CFG->dirroot.'/user/selector/lib.php'); */ class core_role_check_users_selector extends user_selector_base { /** @var bool limit listing of users to enrolled only */ - var $onlyenrolled; + protected $onlyenrolled; /** * Constructor.