From 71daa4a6d678dab1822ad7d54ade02158e706641 Mon Sep 17 00:00:00 2001 From: Jerome Mouneyrac Date: Mon, 8 Oct 2012 10:58:43 +0800 Subject: [PATCH] MDL-35198 replace key_exists by array_key_exists --- admin/webservice/service_users.php | 2 +- blocks/community/forms.php | 2 +- course/externallib.php | 10 +++++----- enrol/externallib.php | 4 ++-- enrol/manual/externallib.php | 2 +- lib/adminlib.php | 2 +- lib/upgradelib.php | 4 ++-- webservice/lib.php | 2 +- webservice/simpletest/testwebservice.php | 6 +++--- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/admin/webservice/service_users.php b/admin/webservice/service_users.php index 12db2b0497f..ad67c6680e4 100644 --- a/admin/webservice/service_users.php +++ b/admin/webservice/service_users.php @@ -97,7 +97,7 @@ $usersmissingcaps = $webservicemanager->get_missing_capabilities_by_users($allow //add the missing capabilities to the allowed users object to be displayed by renderer foreach ($allowedusers as &$alloweduser) { - if (!is_siteadmin($alloweduser->id) and key_exists($alloweduser->id, $usersmissingcaps)) { + if (!is_siteadmin($alloweduser->id) and array_key_exists($alloweduser->id, $usersmissingcaps)) { $alloweduser->missingcapabilities = implode(', ', $usersmissingcaps[$alloweduser->id]); } } diff --git a/blocks/community/forms.php b/blocks/community/forms.php index fafab8a6035..5026d5b21af 100644 --- a/blocks/community/forms.php +++ b/blocks/community/forms.php @@ -140,7 +140,7 @@ class community_hub_search_form extends moodleform { $options = array(); $firsthub = false; foreach ($hubs as $hub) { - if (key_exists('id', $hub)) { + if (array_key_exists('id', $hub)) { $params = array('hubid' => $hub['id'], 'filetype' => HUB_HUBSCREENSHOT_FILE_TYPE); $imgurl = new moodle_url(HUB_HUBDIRECTORYURL . diff --git a/course/externallib.php b/course/externallib.php index c9bf881ee31..861ec2dc76d 100644 --- a/course/externallib.php +++ b/course/externallib.php @@ -267,7 +267,7 @@ class core_course_external extends external_api { array('options' => $options)); //retrieve courses - if (!key_exists('ids', $params['options']) + if (!array_key_exists('ids', $params['options']) or empty($params['options']['ids'])) { $courses = $DB->get_records('course'); } else { @@ -504,13 +504,13 @@ class core_course_external extends external_api { require_capability('moodle/course:create', $context); // Make sure lang is valid - if (key_exists('lang', $course) and empty($availablelangs[$course['lang']])) { + if (array_key_exists('lang', $course) and empty($availablelangs[$course['lang']])) { throw new moodle_exception( get_string('errorinvalidparam', 'webservice', 'lang')); } // Make sure theme is valid - if (key_exists('forcetheme', $course)) { + if (array_key_exists('forcetheme', $course)) { if (!empty($CFG->allowcoursethemes)) { if (empty($availablethemes[$course['forcetheme']])) { throw new moodle_exception( @@ -530,10 +530,10 @@ class core_course_external extends external_api { //set default value for completion $courseconfig = get_config('moodlecourse'); if (completion_info::is_enabled_for_site()) { - if (!key_exists('enablecompletion', $course)) { + if (!array_key_exists('enablecompletion', $course)) { $course['enablecompletion'] = $courseconfig->enablecompletion; } - if (!key_exists('completionstartonenrol', $course)) { + if (!array_key_exists('completionstartonenrol', $course)) { $course['completionstartonenrol'] = $courseconfig->completionstartonenrol; } } else { diff --git a/enrol/externallib.php b/enrol/externallib.php index b3b2b31414d..a13580a051d 100644 --- a/enrol/externallib.php +++ b/enrol/externallib.php @@ -371,7 +371,7 @@ class core_role_external extends external_api { // throw an exception if user is not able to assign the role in this context $roles = get_assignable_roles($context, ROLENAME_SHORT); - if (!key_exists($assignment['roleid'], $roles)) { + if (!array_key_exists($assignment['roleid'], $roles)) { throw new invalid_parameter_exception('Can not assign roleid='.$assignment['roleid'].' in contextid='.$assignment['contextid']); } @@ -433,7 +433,7 @@ class core_role_external extends external_api { // throw an exception if user is not able to unassign the role in this context $roles = get_assignable_roles($context, ROLENAME_SHORT); - if (!key_exists($unassignment['roleid'], $roles)) { + if (!array_key_exists($unassignment['roleid'], $roles)) { throw new invalid_parameter_exception('Can not unassign roleid='.$unassignment['roleid'].' in contextid='.$unassignment['contextid']); } diff --git a/enrol/manual/externallib.php b/enrol/manual/externallib.php index f2daf62773d..1804a19e117 100644 --- a/enrol/manual/externallib.php +++ b/enrol/manual/externallib.php @@ -90,7 +90,7 @@ class enrol_manual_external extends external_api { //throw an exception if user is not able to assign the role $roles = get_assignable_roles($context); - if (!key_exists($enrolment['roleid'], $roles)) { + if (!array_key_exists($enrolment['roleid'], $roles)) { $errorparams = new stdClass(); $errorparams->roleid = $enrolment['roleid']; $errorparams->courseid = $enrolment['courseid']; diff --git a/lib/adminlib.php b/lib/adminlib.php index 397bbf17107..64e645c8add 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -7584,7 +7584,7 @@ class admin_setting_managewebservicetokens extends admin_setting { array(array('id' => $token->userid)), $token->serviceid); if (!is_siteadmin($token->userid) and - key_exists($token->userid, $usermissingcaps)) { + array_key_exists($token->userid, $usermissingcaps)) { $missingcapabilities = implode(', ', $usermissingcaps[$token->userid]); if (!empty($missingcapabilities)) { diff --git a/lib/upgradelib.php b/lib/upgradelib.php index a81c98b9a8d..1f81de89bfa 100644 --- a/lib/upgradelib.php +++ b/lib/upgradelib.php @@ -877,7 +877,7 @@ function external_update_descriptions($component) { $dbfunction->classpath = $function['classpath']; $update = true; } - $functioncapabilities = key_exists('capabilities', $function)?$function['capabilities']:''; + $functioncapabilities = array_key_exists('capabilities', $function)?$function['capabilities']:''; if ($dbfunction->capabilities != $functioncapabilities) { $dbfunction->capabilities = $functioncapabilities; $update = true; @@ -893,7 +893,7 @@ function external_update_descriptions($component) { $dbfunction->methodname = $function['methodname']; $dbfunction->classpath = empty($function['classpath']) ? null : $function['classpath']; $dbfunction->component = $component; - $dbfunction->capabilities = key_exists('capabilities', $function)?$function['capabilities']:''; + $dbfunction->capabilities = array_key_exists('capabilities', $function)?$function['capabilities']:''; $dbfunction->id = $DB->insert_record('external_functions', $dbfunction); } unset($functions); diff --git a/webservice/lib.php b/webservice/lib.php index 4c475da0169..8d738379b48 100644 --- a/webservice/lib.php +++ b/webservice/lib.php @@ -511,7 +511,7 @@ class webservice { //detect the missing capabilities foreach ($servicecaps as $functioname => $functioncaps) { foreach ($functioncaps as $functioncap) { - if (!key_exists($functioncap, $usercaps)) { + if (!array_key_exists($functioncap, $usercaps)) { if (!isset($usersmissingcaps[$user->id]) or array_search($functioncap, $usersmissingcaps[$user->id]) === false) { $usersmissingcaps[$user->id][] = $functioncap; diff --git a/webservice/simpletest/testwebservice.php b/webservice/simpletest/testwebservice.php index 3bf0e86b1da..33e560c7051 100644 --- a/webservice/simpletest/testwebservice.php +++ b/webservice/simpletest/testwebservice.php @@ -448,15 +448,15 @@ class webservice_test extends UnitTestCase { $dbcourses[$course['id']]->timecreated); $this->assertEqual($course['timemodified'], $dbcourses[$course['id']]->timemodified); - if (key_exists('enablecompletion', $course)) { + if (array_key_exists('enablecompletion', $course)) { $this->assertEqual($course['enablecompletion'], $dbcourses[$course['id']]->enablecompletion); } - if (key_exists('completionstartonenrol', $course)) { + if (array_key_exists('completionstartonenrol', $course)) { $this->assertEqual($course['completionstartonenrol'], $dbcourses[$course['id']]->completionstartonenrol); } - if (key_exists('completionnotify', $course)) { + if (array_key_exists('completionnotify', $course)) { $this->assertEqual($course['completionnotify'], $dbcourses[$course['id']]->completionnotify); }