MDL-36060: Remove anonymous functions in mod/lti
authorMark Nielsen <mark@moodlerooms.com>
Tue, 12 Mar 2013 22:28:23 +0000 (15:28 -0700)
committerDan Poltawski <dan@moodle.com>
Tue, 30 Apr 2013 16:50:36 +0000 (17:50 +0100)
This was breaking eaccelerator because it doesn't
support anonymous functions.

mod/lti/locallib.php
mod/lti/settings.php

index 645ec15..63eaacb 100644 (file)
@@ -563,6 +563,23 @@ function lti_filter_get_types($course) {
     return $DB->get_records('lti_types', $filter);
 }
 
+/**
+ * Given an array of tools, filter them based on their state
+ *
+ * @param array $tools An array of lti_types records
+ * @param int $state One of the LTI_TOOL_STATE_* constants
+ * @return array
+ */
+function lti_filter_tool_types(array $tools, $state) {
+    $return = array();
+    foreach ($tools as $key => $tool) {
+        if ($tool->state == $state) {
+            $return[$key] = $tool;
+        }
+    }
+    return $return;
+}
+
 function lti_get_types_for_add_instance() {
     global $DB, $SITE, $COURSE;
 
index b7d4f2c..a36a7c7 100644 (file)
@@ -66,21 +66,15 @@ if ($ADMIN->fulltree) {
 
     $types = lti_filter_get_types(get_site()->id);
 
-    $configuredtools = array_filter($types, function($value) {
-        return $value->state == LTI_TOOL_STATE_CONFIGURED;
-    });
+    $configuredtools = lti_filter_tool_types($types, LTI_TOOL_STATE_CONFIGURED);
 
     $configuredtoolshtml = lti_get_tool_table($configuredtools, 'lti_configured');
 
-    $pendingtools = array_filter($types, function($value) {
-        return $value->state == LTI_TOOL_STATE_PENDING;
-    });
+    $pendingtools = lti_filter_tool_types($types, LTI_TOOL_STATE_PENDING);
 
     $pendingtoolshtml = lti_get_tool_table($pendingtools, 'lti_pending');
 
-    $rejectedtools = array_filter($types, function($value) {
-        return $value->state == LTI_TOOL_STATE_REJECTED;
-    });
+    $rejectedtools = lti_filter_tool_types($types, LTI_TOOL_STATE_REJECTED);
 
     $rejectedtoolshtml = lti_get_tool_table($rejectedtools, 'lti_rejected');