From f7ecfa21088175bc236b1136c1a4b2aa2488f37c Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 22 Aug 2014 17:17:01 +0200 Subject: [PATCH] show some statistics on the index page --- controller/guicontroller.php | 21 +++++++++++++++++++ lib/tokenstorage.php | 24 ++++++++++++++++++++++ templates/index.php | 40 ++++++++++++++++++++++++++++++++---- templates/indexStats.php | 11 ++++++++++ 4 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 templates/indexStats.php diff --git a/controller/guicontroller.php b/controller/guicontroller.php index 06ea681..2c05750 100644 --- a/controller/guicontroller.php +++ b/controller/guicontroller.php @@ -61,6 +61,7 @@ class GuiController extends Controller $res = new TemplateResponse('grauphel', 'index'); $res->setParams(array('apiurl' => $this->getApiUrl())); $this->addNavigation($res); + $this->addStats($res); return $res; } @@ -74,6 +75,26 @@ class GuiController extends Controller $res->setParams($params); } + protected function addStats(TemplateResponse $res) + { + if ($this->user === null) { + return; + } + + $username = $this->user->getUid(); + $notes = new \OCA\Grauphel\Lib\NoteStorage($this->urlGen); + $tokens = new \OCA\Grauphel\Lib\TokenStorage(); + + $nav = new \OCP\Template('grauphel', 'indexStats', ''); + $nav->assign('notes', count($notes->loadNotesOverview($username))); + $nav->assign('syncrev', $notes->loadSyncData($username)->latestSyncRevision); + $nav->assign('tokens', count($tokens->loadForUser($username, 'access'))); + + $params = $res->getParams(); + $params['stats'] = $nav; + $res->setParams($params); + } + protected function checkDeps() { if (!class_exists('OAuthProvider')) { diff --git a/lib/tokenstorage.php b/lib/tokenstorage.php index 9a173f5..f8f0806 100644 --- a/lib/tokenstorage.php +++ b/lib/tokenstorage.php @@ -106,6 +106,30 @@ class TokenStorage return $token; } + /** + * Load multiple tokens + * + * @param string $username User name + * @param string $type Token type: temp, access, verify + * + * @return array Array of Token objects + */ + public function loadForUser($username, $type) + { + $result = \OC_DB::executeAudited( + 'SELECT * FROM `*PREFIX*grauphel_oauth_tokens`' + . ' WHERE `token_user` = ? AND `token_type` = ?', + array($username, $type) + ); + + $tokens = array(); + while ($tokenRow = $result->fetchRow()) { + $tokens[] = $this->fromDb($tokenRow); + } + + return $tokens; + } + protected function fromDb($tokenRow) { $token = new Token(); diff --git a/templates/index.php b/templates/index.php index 7b7c6a6..e63df37 100644 --- a/templates/index.php +++ b/templates/index.php @@ -1,13 +1,45 @@ + + printPage(); ?>
-
-

Tomboy notes server

-

+

+

Tomboy notes server

+

Use the following sync server URL with tomboy/conboy/tomdroid:

-
+
+ printPage(); ?>
diff --git a/templates/indexStats.php b/templates/indexStats.php new file mode 100644 index 0000000..78274da --- /dev/null +++ b/templates/indexStats.php @@ -0,0 +1,11 @@ +

Stats

+
+
Number of notes
+
+ +
Number of registered apps
+
+ +
Sync revision
+
+
-- 2.30.2