diff --git a/analytics/meta/embed.php b/analytics/meta/embed.php deleted file mode 100644 index e2c2def2..00000000 --- a/analytics/meta/embed.php +++ /dev/null @@ -1,16 +0,0 @@ - 'past26weeks']; - -$metabase = new \Metabase\Embed($metabaseUrl, $metabaseKey); -// Generate the HTML to create an iframe with the embedded dashboard -echo $metabase->dashboardIframe($dashboardId, $params); -?> \ No newline at end of file diff --git a/analytics/meta/metabase.php b/analytics/meta/metabase.php deleted file mode 100644 index 8ba1218b..00000000 --- a/analytics/meta/metabase.php +++ /dev/null @@ -1,188 +0,0 @@ -url = $url; - $this->key = $key; - $this->border = $border; - $this->title = $title; - $this->width = $width; - $this->height = $height; - $this->expirationSeconds = $expirationSeconds; - - $this->jwtConfig = Configuration::forSymmetricSigner(new Sha256(), InMemory::plainText($this->key)); - } - - /** - * Get the embed URL for a Metabase question - * - * @param int $questionId The id of the question to embed - * @param array $params An associate array with variables to be passed to the question - * - * @return string Embed URL - */ - public function questionUrl($questionId, $params = []) - { - return $this->url('question', $questionId, $params); - } - - /** - * Get the embed URL for a Metabase dashboard - * - * @param int $dashboardId The id of the dashboard to embed - * @param array $params An associate array with variables to be passed to the dashboard - * - * @return string Embed URL - */ - public function dashboardUrl($dashboardId, $params = []) - { - return $this->url('dashboard', $dashboardId, $params); - } - - /** - * Use JWT to encode tokens - * - * @param array $resource Resource to encode (question or dashboard) - * @param array $params An associate array with variables to be passed to the dashboard - * - * @return string Token - */ - private function encode($resource, $params) - { - $jwt = $this->jwtConfig->builder(); - $jwt->withClaim('resource', $resource); - if (empty($params)) { - $jwt->withClaim('params', (object)[]); - } else { - $jwt->withClaim('params', $params); - } - if (!is_null($this->expirationSeconds)) { - $jwt->expiresAt((new DateTimeImmutable())->modify('+' . $this->expirationSeconds . ' seconds')); - } - - return $jwt->getToken($this->jwtConfig->signer(), $this->jwtConfig->signingKey()); - } - - protected function url($resource, $id, $params) - { - // Generate auth token, using JWT - $token = $this->encode([$resource => $id], $params); - - // Generate embed URL - $url = $this->url . '/embed/' . $resource . '/' . $token->toString() . '#'; - - // Should border be included - if ($this->border) { - $url .= 'bordered=true&'; - } else { - $url .= 'bordered=false&'; - } - - // Should title be included - if ($this->title) { - $url .= 'titled=true&'; - } else { - $url .= 'titled=false&'; - } - - // Set selected theme (if any) - if (!empty($this->theme)) { - $url .= 'theme=' . $this->theme . '&'; - } - - // Remove trailing & - $url = rtrim($url, '&'); - - return $url; - } - - /** - * Generate the HTML to embed a question iframe with a given question id. - * It assumes no iframe border. Size can be manipulated via - * class $width/$height - * - * @param int $questionId The id of the question to embed - * @param array $params An associate array with variables to be passed to the question - * - * @return string Code to embed - */ - public function questionIFrame($questionId, $params = []) - { - $url = $this->questionUrl($questionId, $params); - return $this->iframe($url); - } - - /** - * Generate the HTML to embed a dashboard iframe with a given dashboard id. - * It assumes no iframe border. Size can be manipulated via - * class $width/$height - * - * @param int $dashboardId The id of the dashboard to embed - * @param array $params An associate array with variables to be passed to the dashboard - * - * @return string Code to embed - */ - public function dashboardIFrame($dashboardId, $params = []) - { - $url = $this->dashboardUrl($dashboardId, $params); - return $this->iframe($url); - } - - /** - * Generate the HTML to embed an iframe with a given URL. - * It assumes no iframe border. Size can be manipulated via - * class $width/$height - * - * @param string $iframeUrl The URL to create an iframe for - * - * @return string Code to embed - */ - protected function iframe($iframeUrl) - { - return ''; - } -} \ No newline at end of file diff --git a/analytics/tests/dashboard.html b/analytics/tests/dashboard.html new file mode 100644 index 00000000..6056ce48 --- /dev/null +++ b/analytics/tests/dashboard.html @@ -0,0 +1,44 @@ + + + +
+ + +