diff --git a/Web/Models/Repositories/Clubs.php b/Web/Models/Repositories/Clubs.php index 17ae58f2..bea73cef 100644 --- a/Web/Models/Repositories/Clubs.php +++ b/Web/Models/Repositories/Clubs.php @@ -37,6 +37,24 @@ class Clubs return new Util\EntityStream("Club", $result); } + + function getCount(): int + { + return sizeof(clone $this->clubs); + } + + function getPopularClubs(): \Traversable + { + $query = "SELECT ROW_NUMBER() OVER (ORDER BY `subscriptions` DESC) as `place`, `target` as `id`, COUNT(`follower`) as `subscriptions` FROM `subscriptions` WHERE `model` = \"openvk\\\Web\\\Models\\\Entities\\\Club\" GROUP BY `target` ORDER BY `subscriptions` DESC, `id` LIMIT 10;"; + $entries = DatabaseConnection::i()->getConnection()->query($query); + + foreach($entries as $entry) + yield (object) [ + "place" => $entry["place"], + "club" => $this->get($entry["id"]), + "subscriptions" => $entry["subscriptions"], + ]; + } use \Nette\SmartObject; } diff --git a/Web/Models/Repositories/Posts.php b/Web/Models/Repositories/Posts.php index 0e7aed80..ba590baf 100644 --- a/Web/Models/Repositories/Posts.php +++ b/Web/Models/Repositories/Posts.php @@ -105,4 +105,9 @@ class Posts { return sizeof($this->posts->where(["wall" => $user, "deleted" => 0])); } + + function getCount(): int + { + return sizeof(clone $this->posts); + } } diff --git a/Web/Models/Repositories/Users.php b/Web/Models/Repositories/Users.php index 9342b647..e99611b2 100644 --- a/Web/Models/Repositories/Users.php +++ b/Web/Models/Repositories/Users.php @@ -69,6 +69,24 @@ class Users return $this->getByShortUrl($address); } + + /** + * If you need to check if the user is an instance administrator, use `$user->getChandlerUser()->can("access")->model("admin")->whichBelongsTo(NULL)`. + * This method is more suitable for instance administrators lists + */ + function getInstanceAdmins(bool $excludeHidden = true): \Traversable + { + $query = "SELECT DISTINCT(`profiles`.`id`) FROM `ChandlerACLRelations` JOIN `profiles` ON `ChandlerACLRelations`.`user` = `profiles`.`user` COLLATE utf8mb4_unicode_520_ci WHERE `ChandlerACLRelations`.`group` IN (SELECT `group` FROM `ChandlerACLGroupsPermissions` WHERE `model` = \"admin\" AND `permission` = \"access\")"; + + if($excludeHidden) + $query .= " AND `ChandlerACLRelations`.`user` NOT IN (SELECT `user` FROM `ChandlerACLRelations` WHERE `group` IN (SELECT `group` FROM `ChandlerACLGroupsPermissions` WHERE `model` = \"hidden_admin\" AND `permission` = \"be\"))"; + + $query .= " ORDER BY `profiles`.`id`;"; + + $result = DatabaseConnection::i()->getConnection()->query($query); + foreach($result as $entry) + yield $this->get($entry->id); + } use \Nette\SmartObject; } diff --git a/Web/Presenters/AboutPresenter.php b/Web/Presenters/AboutPresenter.php index 550fc8f0..f7131772 100644 --- a/Web/Presenters/AboutPresenter.php +++ b/Web/Presenters/AboutPresenter.php @@ -1,7 +1,7 @@ template->themes = Themepacks::i()->getAllThemes(); $this->template->languages = getLanguages(); } + + function renderAboutInstance(): void + { + $this->template->usersStats = (new Users)->getStatistics(); + $this->template->clubsCount = (new Clubs)->getCount(); + $this->template->postsCount = (new Posts)->getCount(); + $this->template->popularClubs = (new Clubs)->getPopularClubs(); + $this->template->admins = iterator_to_array((new Users)->getInstanceAdmins()); + } function renderLanguage(): void { diff --git a/Web/Presenters/templates/@layout.xml b/Web/Presenters/templates/@layout.xml index ffd9b6a0..5eeff060 100644 --- a/Web/Presenters/templates/@layout.xml +++ b/Web/Presenters/templates/@layout.xml @@ -267,6 +267,7 @@ {var dbVersion = \Chandler\Database\DatabaseConnection::i()->getConnection()->getPdo()->getAttribute(\PDO::ATTR_SERVER_VERSION)}