From f5f89f23954ee8fce2e80632a502e24e09865515 Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Thu, 4 Feb 2016 14:13:59 +0100 Subject: [PATCH] Helper for storing events HFJ-1610 --- h5p-event-base.class.php | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/h5p-event-base.class.php b/h5p-event-base.class.php index 2398818..f8a9cac 100644 --- a/h5p-event-base.class.php +++ b/h5p-event-base.class.php @@ -19,7 +19,7 @@ class H5PEventBase { public static $log_time = 2592000; // 30 Days // Protected variables - protected $type, $sub_type, $content_id, $content_title, $library_name, $library_version, $time; + protected $id, $type, $sub_type, $content_id, $content_title, $library_name, $library_version, $time; /** * Adds event type, h5p library and timestamp to event before saving it. @@ -105,6 +105,36 @@ class H5PEventBase { } } + /** + * A helper which makes it easier for some systems to save the data. + * No NULL values, empty string or 0 used instead. + * Used in e.g. WordPress. + * + * @return array with two arrays: $data, $format + */ + protected function toArray() { + return array( + array( + 'created_at' => $this->time, + 'type' => $this->type, + 'sub_type' => empty($this->sub_type) ? '' : $this->sub_type, + 'content_id' => empty($this->content_id) ? 0 : $this->content_id, + 'content_title' => empty($this->content_title) ? '' : $this->content_title, + 'library_name' => empty($this->library_name) ? '' : $this->library_name, + 'library_version' => empty($this->library_version) ? '' : $this->library_version + ), + array( + '%d', + '%s', + '%s', + '%d', + '%s', + '%s', + '%s' + ) + ); + } + /** * Store the event. */