From: Christian Weiske Date: Thu, 24 Nov 2016 22:11:52 +0000 (+0100) Subject: show subscriptions on status page X-Git-Tag: v0.2.0~1 X-Git-Url: https://git.cweiske.de/phinde.git/commitdiff_plain/dd3e0698a71ca2746166f006135aeace83dfeb20 show subscriptions on status page --- diff --git a/data/templates/status.htm b/data/templates/status.htm index 86c39fe..fb8daf3 100644 --- a/data/templates/status.htm +++ b/data/templates/status.htm @@ -30,6 +30,7 @@ Index size {{esStatus.size_human}} + Gearman Open tasks @@ -43,6 +44,18 @@ Task workers {{gearStatus.workers}} + + + Subscriptions + Total + {{subSum}} + + {% for key, number in subCount %} + + {{key}} + {{number}} + + {% endfor %} diff --git a/src/phinde/Subscriptions.php b/src/phinde/Subscriptions.php index 4d00ab8..5aac9b2 100644 --- a/src/phinde/Subscriptions.php +++ b/src/phinde/Subscriptions.php @@ -37,6 +37,28 @@ class Subscriptions return $stmt->fetchObject(); } + /** + * Count number of subscriptions + * + * @return array Array of keys with different status, number as value + */ + public function count() + { + $stmt = $this->db->prepare( + 'SELECT COUNT(*) as count, sub_status FROM subscriptions' + . ' GROUP BY sub_status' + . ' ORDER BY sub_status' + ); + $stmt->execute(); + + $res = []; + foreach ($stmt as $row) { + $res[$row['sub_status']] = $row['count']; + } + + return $res; + } + /** * Create a new subscription entry in database. * Automatically generates secret, capkey and lease seconds. diff --git a/www/status.php b/www/status.php index 4118c9c..a57c121 100644 --- a/www/status.php +++ b/www/status.php @@ -8,6 +8,9 @@ $esStatus = $es->getIndexStatus(); $queue = new Queue(); $gearStatus = $queue->getServerStatus(); +$subDb = new Subscriptions(); +$subCount = $subDb->count(); + /** * @link http://jeffreysambells.com/2012/10/25/human-readable-filesize-php */ @@ -29,6 +32,8 @@ render( array( 'esStatus' => $esStatus, 'gearStatus' => $gearStatus, + 'subCount' => $subCount, + 'subSum' => array_sum($subCount), ) ); ?>