[icinga-checkins] icinga.org: icingaweb2/feature/translation-catalog-statistics-object-13013 : Introduce class CatalogStatistics

git at icinga.org git at icinga.org
Wed Dec 14 11:44:59 CET 2016


Module: icingaweb2
Branch: feature/translation-catalog-statistics-object-13013
Commit: 8694a13fea9ccd6700cea63523fd40115a07dbc4
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=8694a13fea9ccd6700cea63523fd40115a07dbc4

Author: Johannes Meyer <johannes.meyer at netways.de>
Date:   Mon Nov 21 12:10:58 2016 +0100

Introduce class CatalogStatistics

refs #13013

---

 .../Translation/Catalog/CatalogStatistics.php      |  172 ++++++++++++++++++++
 1 file changed, 172 insertions(+)

diff --git a/modules/translation/library/Translation/Catalog/CatalogStatistics.php b/modules/translation/library/Translation/Catalog/CatalogStatistics.php
new file mode 100644
index 0000000..e3ac86e
--- /dev/null
+++ b/modules/translation/library/Translation/Catalog/CatalogStatistics.php
@@ -0,0 +1,172 @@
+<?php
+/* Icinga Web 2 | (c) 2016 Icinga Development Team | GPLv2+ */
+
+namespace Icinga\Module\Translation\Catalog;
+
+/**
+ * Class CatalogStatistics
+ *
+ * Provides Catalog statistics.
+ *
+ * @package Icinga\Module\Translation\Catalog
+ */
+class CatalogStatistics
+{
+    /**
+     * The Catalog for which to produce the statistics
+     *
+     * @var Catalog
+     */
+    protected $catalog;
+
+    /**
+     * The amount of entries
+     *
+     * @var int
+     */
+    protected $entryCount;
+
+    /**
+     * The amount of obsolete entries
+     *
+     * @var int
+     */
+    protected $obsoleteEntryCount;
+
+    /**
+     * The amount of translated entries
+     *
+     * @var int
+     */
+    protected $translatedEntryCount;
+
+    /**
+     * The amount of fuzzy entries
+     *
+     * @var int
+     */
+    protected $fuzzyEntryCount;
+
+    /**
+     * The amount of faulty entries
+     *
+     * @var int
+     */
+    protected $faultyEntryCount;
+
+    /**
+     * Create new CatalogStatistics
+     *
+     * @param   Catalog     $catalog
+     */
+    public function __construct(Catalog $catalog)
+    {
+        $this->catalog = $catalog;
+    }
+
+    /**
+     * Return the amount of entries
+     *
+     * @return int
+     */
+    public function countEntries()
+    {
+        if ($this->entryCount === null) {
+            $this->refresh();
+        }
+
+        return $this->entryCount;
+    }
+
+    /**
+     * Return the amount of obsolete entries
+     *
+     * @return int
+     */
+    public function countObsoleteEntries()
+    {
+        if ($this->obsoleteEntryCount === null) {
+            $this->refresh();
+        }
+
+        return $this->obsoleteEntryCount;
+    }
+
+    /**
+     * Return the amount of translated entries
+     *
+     * @return int
+     */
+    public function countTranslatedEntries()
+    {
+        if ($this->translatedEntryCount === null) {
+            $this->refresh();
+        }
+
+        return $this->translatedEntryCount;
+    }
+
+    /**
+     * Return the amount of fuzzy entries
+     *
+     * @return int
+     */
+    public function countFuzzyEntries()
+    {
+        if ($this->fuzzyEntryCount === null) {
+            $this->refresh();
+        }
+
+        return $this->fuzzyEntryCount;
+    }
+
+    /**
+     * Return the amount of faulty entries
+     *
+     * @return int
+     */
+    public function countFaultyEntries()
+    {
+        if ($this->faultyEntryCount === null) {
+            $this->refresh();
+        }
+
+        return $this->faultyEntryCount;
+    }
+
+    /**
+     * Refresh statistic counters
+     *
+     * @return  $this
+     */
+    public function refresh()
+    {
+        $this->entryCount = 0;
+        $this->obsoleteEntryCount = 0;
+        $this->translatedEntryCount = 0;
+        $this->fuzzyEntryCount = 0;
+        $this->faultyEntryCount = 0;
+        /** @var CatalogEntry $entry */
+        foreach ($this->catalog as $entry) {
+            $this->entryCount++;
+
+            if ($entry->isObsolete()) {
+                $this->obsoleteEntryCount++;
+            }
+
+            if ($entry->isTranslated()) {
+                $this->translatedEntryCount++;
+            }
+
+            if ($entry->isFuzzy()) {
+                $this->fuzzyEntryCount++;
+            }
+
+            if ($entry->isFaulty()) {
+                $this->faultyEntryCount++;
+            }
+        }
+
+        return $this;
+    }
+}



More information about the icinga-checkins mailing list