Usage_stats.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Table for storing Nodeinfo statistics
  18. *
  19. * @package NodeInfo
  20. * @author Diogo Cordeiro <diogo@fc.up.pt>
  21. * @copyright 2018-2019 Free Software Foundation, Inc http://www.fsf.org
  22. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  23. */
  24. defined('GNUSOCIAL') || die();
  25. /**
  26. * Table Definition for usage_stats and some getters
  27. *
  28. * @copyright 2018-2019 Free Software Foundation, Inc http://www.fsf.org
  29. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  30. */
  31. class Usage_stats extends Managed_DataObject
  32. {
  33. public $__table = 'usage_stats'; // table name
  34. public $type; // varchar(191) unique_key not 255 because utf8mb4 takes more space
  35. public $count; // int(4)
  36. public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
  37. /**
  38. * Table Definition for usage_stats
  39. *
  40. * @return array
  41. */
  42. public static function schemaDef(): array
  43. {
  44. return [
  45. 'description' => 'node stats',
  46. 'fields' => [
  47. 'type' => ['type' => 'varchar', 'not null' => true, 'length' => 191, 'description' => 'Type of countable entity'],
  48. 'count' => ['type' => 'int', 'size' => 'int', 'default' => 0, 'description' => 'Number of entities of this type'],
  49. 'modified' => ['type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'],
  50. ],
  51. 'primary key' => ['type'],
  52. ];
  53. }
  54. /**
  55. * Total number of users
  56. *
  57. * @return int
  58. */
  59. public function getUserCount(): int
  60. {
  61. return Usage_stats::getKV('type', 'users')->count;
  62. }
  63. /**
  64. * Total number of dents
  65. *
  66. * @return int
  67. */
  68. public function getPostCount(): int
  69. {
  70. return Usage_stats::getKV('type', 'posts')->count;
  71. }
  72. /**
  73. * Total number of replies
  74. *
  75. * @return int
  76. */
  77. public function getCommentCount(): int
  78. {
  79. return Usage_stats::getKV('type', 'comments')->count;
  80. }
  81. }