MDL-62029 core_privacy: context aware provider creation.
authorAdrian Greeve <adrian@moodle.com>
Tue, 1 May 2018 03:18:29 +0000 (11:18 +0800)
committerJake Dallimore <jake@moodle.com>
Wed, 9 May 2018 02:11:47 +0000 (10:11 +0800)
privacy/classes/local/request/context_aware_provider.php [new file with mode: 0644]
privacy/classes/manager.php

diff --git a/privacy/classes/local/request/context_aware_provider.php b/privacy/classes/local/request/context_aware_provider.php
new file mode 100644 (file)
index 0000000..bc5a4b3
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * This file contains the \core_privacy\local\request\plugin\provider interface to describe
+ * a class which provides data in some form for a plugin.
+ *
+ * Plugins should implement this if they need access to all approved contexts.
+ *
+ * @package core_privacy
+ * @copyright 2018 Adrian Greeve <adriangreeve.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+namespace core_privacy\local\request;
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * The provider interface for plugins which need access to all approved contexts to fill in user data.
+ *
+ * @copyright  2018 Adrian Greeve <adriangreeve.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+interface context_aware_provider extends \core_privacy\local\request\core_data_provider {
+
+    /**
+     * Export context information based on the whole approved context list collection.
+     *
+     * @param  \core_privacy\local\request\contextlist_collection $contextcollection The collection of approved context lists.
+     */
+    public static function export_complete_context_data(\core_privacy\local\request\contextlist_collection $contextcollection);
+}
index 922930a..14f20c7 100644 (file)
@@ -216,7 +216,7 @@ class manager {
                     // told to export.
                     $this->get_provider_classname($component)::export_user_data($approvedcontextlist);
                 }
-            } else {
+            } else if (!$this->component_implements($component, \core_privacy\local\request\context_aware_provider::class)) {
                 // This plugin does not know that it has data - export the shared data it doesn't know about.
                 local\request\helper::export_data_for_null_provider($approvedcontextlist);
             }
@@ -230,6 +230,14 @@ class manager {
             }
         }
 
+        // Check each component for context aware providers.
+        foreach ($this->get_component_list() as $component) {
+            // Core user preference providers.
+            if ($this->component_implements($component, \core_privacy\local\request\context_aware_provider::class)) {
+                $this->get_provider_classname($component)::export_complete_context_data($contextlistcollection);
+            }
+        }
+
         return local\request\writer::with_context(\context_system::instance())->finalise_content();
     }