MDL-53451 competency: Improve performance by bypassing api::is_enabled()

This commit is contained in:
Frederic Massart 2016-04-22 11:34:39 +08:00
parent 86dd906aa7
commit 5592edb646
7 changed files with 21 additions and 13 deletions

View File

@ -32,7 +32,7 @@ defined('MOODLE_INTERNAL') || die();
* @param context $coursecontext The context of the course
*/
function tool_lp_extend_navigation_course($navigation, $course, $coursecontext) {
if (!\core_competency\api::is_enabled()) {
if (!get_config('core_competency', 'enabled')) {
return;
}
@ -61,7 +61,7 @@ function tool_lp_extend_navigation_course($navigation, $course, $coursecontext)
* @param context_course $coursecontext The context of the course
*/
function tool_lp_extend_navigation_user($navigation, $user, $usercontext, $course, $coursecontext) {
if (!\core_competency\api::is_enabled()) {
if (!get_config('core_competency', 'enabled')) {
return;
}
@ -88,7 +88,7 @@ function tool_lp_extend_navigation_user($navigation, $user, $usercontext, $cours
* @return bool
*/
function tool_lp_myprofile_navigation(core_user\output\myprofile\tree $tree, $user, $iscurrentuser, $course) {
if (!\core_competency\api::is_enabled()) {
if (!get_config('core_competency', 'enabled')) {
return false;
} else if (!\core_competency\plan::can_read_user($user->id)) {
return false;
@ -109,7 +109,7 @@ function tool_lp_myprofile_navigation(core_user\output\myprofile\tree $tree, $us
* @param context $coursecategorycontext The context of the course category
*/
function tool_lp_extend_navigation_category_settings($navigation, $coursecategorycontext) {
if (!\core_competency\api::is_enabled()) {
if (!get_config('core_competency', 'enabled')) {
return false;
}
@ -160,7 +160,7 @@ function tool_lp_extend_navigation_category_settings($navigation, $coursecategor
function tool_lp_coursemodule_standard_elements($formwrapper, $mform) {
global $CFG, $COURSE;
if (!\core_competency\api::is_enabled()) {
if (!get_config('core_competency', 'enabled')) {
return;
} else if (!has_capability('moodle/competency:coursecompetencymanage', $formwrapper->get_context())) {
return;
@ -195,7 +195,7 @@ function tool_lp_coursemodule_standard_elements($formwrapper, $mform) {
* @param stdClass $course The course.
*/
function tool_lp_coursemodule_edit_post_actions($data, $course) {
if (!\core_competency\api::is_enabled()) {
if (!get_config('core_competency', 'enabled')) {
return $data;
}

View File

@ -28,7 +28,7 @@ defined('MOODLE_INTERNAL') || die();
$parentname = 'competencies';
// If the plugin is enabled we add the pages.
if (\core_competency\api::is_enabled()) {
if (get_config('core_competency', 'enabled')) {
// Manage competency frameworks page.
$temp = new admin_externalpage(

View File

@ -23,7 +23,7 @@
*/
defined('MOODLE_INTERNAL') || die();
if (\core_competency\api::is_enabled()) {
if (get_config('core_competency', 'enabled')) {
$parentname = 'competencies';

View File

@ -62,7 +62,7 @@ class block_lp extends block_base {
}
$this->content = new stdClass();
if (!\core_competency\api::is_enabled()) {
if (!get_config('core_competency', 'enabled')) {
return $this->content;
}

View File

@ -49,6 +49,10 @@ class api {
/**
* Returns whether competencies are enabled.
*
* This method should never do more than checking the config setting, the reason
* being that some other code could be checking the config value directly
* to avoid having to load this entire file into memory.
*
* @return boolean True when enabled.
*/
public static function is_enabled() {

View File

@ -40,7 +40,7 @@ use core_competency\user_evidence;
function core_competency_comment_add($comment, $params) {
global $USER;
if (!api::is_enabled()) {
if (!get_config('core_competency', 'enabled')) {
return;
}
@ -215,7 +215,7 @@ function core_competency_comment_add($comment, $params) {
* @return array
*/
function core_competency_comment_permissions($params) {
if (!api::is_enabled()) {
if (!get_config('core_competency', 'enabled')) {
return array('post' => false, 'view' => false);
}
@ -241,7 +241,7 @@ function core_competency_comment_permissions($params) {
* @return bool
*/
function core_competency_comment_validate($params) {
if (!api::is_enabled()) {
if (!get_config('core_competency', 'enabled')) {
return false;
}
@ -274,7 +274,7 @@ function core_competency_comment_validate($params) {
function core_competency_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) {
global $CFG;
if (!api::is_enabled()) {
if (!get_config('core_competency', 'enabled')) {
return false;
}

View File

@ -34,6 +34,10 @@ defined('MOODLE_INTERNAL') || die;
* @param stdClass $context The context of the course
*/
function report_competency_extend_navigation_course($navigation, $course, $context) {
if (!get_config('core_competency', 'enabled')) {
return;
}
if (has_capability('moodle/competency:coursecompetencyview', $context)) {
$url = new moodle_url('/report/competency/index.php', array('id' => $course->id));
$name = get_string('pluginname', 'report_competency');