diff --git a/src/Controller/InstanceController.php b/src/Controller/InstanceController.php index c5a9556..2df7bb5 100644 --- a/src/Controller/InstanceController.php +++ b/src/Controller/InstanceController.php @@ -19,7 +19,9 @@ class InstanceController extends AppController public function home() { - $this->set('md', file_get_contents(ROOT . '/README.md')); + // $this->set('md', file_get_contents(ROOT . '/README.md')); + $statistics = $this->Instance->getStatistics(); + $this->set('statistics', $statistics); } public function status() diff --git a/src/Model/Table/InstanceTable.php b/src/Model/Table/InstanceTable.php index dd935b8..50bc925 100644 --- a/src/Model/Table/InstanceTable.php +++ b/src/Model/Table/InstanceTable.php @@ -4,6 +4,7 @@ namespace App\Model\Table; use App\Model\Table\AppTable; use Cake\ORM\Table; +use Cake\ORM\TableRegistry; use Cake\Validation\Validator; use Migrations\Migrations; @@ -21,6 +22,47 @@ class InstanceTable extends AppTable return $validator; } + public function getStatistics($days=7): array + { + $models = ['Individuals', 'Organisations', 'Alignments', 'EncryptionKeys', 'SharingGroups', 'Users', 'Tags.Tags']; + foreach ($models as $model) { + $table = TableRegistry::getTableLocator()->get($model); + $statistics[$model]['amount'] = $table->find()->all()->count(); + if ($table->behaviors()->has('Timestamp')) { + $query = $table->find(); + $query->select([ + 'count' => $query->func()->count('id'), + 'date' => 'DATE(modified)', + ]) + ->where(['modified >' => new \DateTime("-{$days} days")]) + ->group(['date']) + ->order(['date']); + $data = $query->toArray(); + $interval = new \DateInterval('P1D'); + $period = new \DatePeriod(new \DateTime("-{$days} days"), $interval ,new \DateTime()); + $timeline = []; + foreach($period as $date){ + $timeline[$date->format("Y-m-d")] = [ + 'time' => $date->format("Y-m-d"), + 'count' => 0 + ]; + } + foreach ($data as $entry) { + $timeline[$entry->date]['count'] = $entry->count; + } + $statistics[$model]['timeline'] = array_values($timeline); + + $startCount = $table->find()->where(['modified <' => new \DateTime("-{$days} days")])->all()->count(); + $endCount = $statistics[$model]['amount']; + $statistics[$model]['variation'] = $endCount - $startCount; + } else { + $statistics[$model]['timeline'] = []; + $statistics[$model]['variation'] = 0; + } + } + return $statistics; + } + public function getMigrationStatus() { $migrations = new Migrations(); diff --git a/src/View/Helper/BootstrapHelper.php b/src/View/Helper/BootstrapHelper.php index 83cd7f1..47d8a3a 100644 --- a/src/View/Helper/BootstrapHelper.php +++ b/src/View/Helper/BootstrapHelper.php @@ -979,6 +979,7 @@ class BoostrapCard extends BootstrapGeneric 'headerHTML' => '', 'footerHTML' => '', 'bodyHTML' => '', + 'class' => '', 'headerClass' => '', 'bodyClass' => '', 'footerClass' => '', @@ -1010,6 +1011,7 @@ class BoostrapCard extends BootstrapGeneric 'card', !empty($this->options['variant']) ? "bg-{$this->options['variant']}" : '', !empty($this->options['variant']) ? $this->getTextClassForVariant($this->options['variant']) : '', + h($this->options['class']), ], ], implode('', [$this->genHeader(), $this->genBody(), $this->genFooter()])); return $card; diff --git a/templates/Instance/home.php b/templates/Instance/home.php index 74eb85a..20e3460 100644 --- a/templates/Instance/home.php +++ b/templates/Instance/home.php @@ -1,3 +1,22 @@ text($md); +// $Parsedown = new Parsedown(); +// echo $Parsedown->text($md); + +?> + +