-
Notifications
You must be signed in to change notification settings - Fork 342
Expand file tree
/
Copy pathStats.php
More file actions
51 lines (41 loc) · 1.2 KB
/
Stats.php
File metadata and controls
51 lines (41 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
declare(strict_types=1);
namespace Selfoss\controllers\Items;
use Selfoss\daos;
use Selfoss\helpers\Authentication;
use Selfoss\helpers\View;
/**
* Controller for viewing item statistics
*/
final readonly class Stats {
public function __construct(
private Authentication $authentication,
private daos\Items $itemsDao,
private daos\Sources $sourcesDao,
private daos\Tags $tagsDao,
private View $view
) {
}
/**
* returns current basic stats
* json
*/
public function stats(): void {
$this->authentication->ensureCanRead();
$stats = $this->itemsDao->stats();
$tags = $this->tagsDao->getWithUnread();
foreach ($tags as $tag) {
if (!str_starts_with($tag['tag'], '#')) {
continue;
}
$stats['unread'] -= $tag['unread'];
}
if (array_key_exists('tags', $_GET) && $_GET['tags'] == 'true') {
$stats['tags'] = $tags;
}
if (array_key_exists('sources', $_GET) && $_GET['sources'] == 'true') {
$stats['sources'] = $this->sourcesDao->getWithUnread();
}
$this->view->jsonSuccess($stats);
}
}