]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Nodeinfo/classes/Usage_stats.php
Fix undefined variables on Favorite plugin by XRevan86
[quix0rs-gnu-social.git] / plugins / Nodeinfo / classes / Usage_stats.php
1 <?php
2 /**
3  * GNU social - a federating social network
4  *
5  * LICENCE: This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 if (!defined('GNUSOCIAL')) {
20     exit(1);
21 }
22
23 /**
24  * Table Definition for Usage_stats
25  */
26 class Usage_stats extends Managed_DataObject
27 {
28     ###START_AUTOCODE
29     /* the code below is auto generated do not remove the above tag */
30
31     public $__table = 'usage_stats';         // table name
32     public $type;                            // varchar(191)  unique_key   not 255 because utf8mb4 takes more space
33     public $count;                           // int(4)
34     public $modified;                        // timestamp()   not_null default_CURRENT_TIMESTAMP
35
36     /* the code above is auto generated do not remove the tag below */
37     ###END_AUTOCODE
38
39     public static function schemaDef()
40     {
41         return [
42             'description' => 'node stats',
43             'fields' => [
44                 'type' => ['type' => 'varchar', 'length' => 191, 'description' => 'Type of countable entity'],
45                 'count' => ['type' => 'int', 'size' => 'int', 'default' => 0, 'description' => 'Number of entities of this type'],
46
47                 'modified' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
48             ],
49             'primary key' => ['type'],
50             'unique keys' => [
51                 'usage_stats_key' => ['type'],
52             ],
53             'indexes' => [
54                 'user_stats_idx' => ['type'],
55             ],
56         ];
57     }
58
59     public function getUserCount()
60     {
61         return intval(Usage_stats::getKV('type', 'users')->count);
62     }
63
64     public function getPostCount()
65     {
66         return intval(Usage_stats::getKV('type', 'posts')->count);
67     }
68
69     public function getCommentCount()
70     {
71         return intval(Usage_stats::getKV('type', 'comments')->count);
72     }
73 }