MDL-61407 privacy: Track changes in any context
authorAndrew Nicols <andrew@nicols.co.uk>
Sun, 15 Apr 2018 09:33:03 +0000 (17:33 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Wed, 2 May 2018 11:13:30 +0000 (19:13 +0800)
privacy/classes/tests/request/content_writer.php

index bc7f497..3bd7e9d 100644 (file)
@@ -73,6 +73,8 @@ class content_writer implements \core_privacy\local\request\content_writer {
 
     /**
      * Whether any data has been exported at all within the current context.
+     *
+     * @return  bool
      */
     public function has_any_data() {
         $hasdata = !empty($this->data->{$this->context->id});
@@ -96,6 +98,32 @@ class content_writer implements \core_privacy\local\request\content_writer {
         return $hasanydata;
     }
 
+    /**
+     * Whether any data has been exported for any context.
+     *
+     * @return  bool
+     */
+    public function has_any_data_in_any_context() {
+        $checkfordata = function($location) {
+            foreach ($location as $context => $data) {
+                if (!empty($data)) {
+                    return true;
+                }
+            }
+
+            return false;
+        };
+
+        $hasanydata = $checkfordata($this->data);
+        $hasanydata = $hasanydata || $checkfordata($this->relateddata);
+        $hasanydata = $hasanydata || $checkfordata($this->metadata);
+        $hasanydata = $hasanydata || $checkfordata($this->files);
+        $hasanydata = $hasanydata || $checkfordata($this->customfiles);
+        $hasanydata = $hasanydata || $checkfordata($this->userprefs);
+
+        return $hasanydata;
+    }
+
     /**
      * Constructor for the content writer.
      *