|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Joas Schilling <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
6
|
|
|
* @license AGPL-3.0 |
|
7
|
|
|
* |
|
8
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
9
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
10
|
|
|
* as published by the Free Software Foundation. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU Affero General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
19
|
|
|
* |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
namespace OCA\Activity; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Class Api |
|
26
|
|
|
* |
|
27
|
|
|
* @package OCA\Activity |
|
28
|
|
|
*/ |
|
29
|
|
|
class Api { |
|
30
|
|
|
const DEFAULT_LIMIT = 30; |
|
31
|
|
|
|
|
32
|
5 |
|
public static function get() { |
|
33
|
5 |
|
$app = new AppInfo\Application(); |
|
34
|
|
|
/** @var Data $data */ |
|
35
|
5 |
|
$data = $app->getContainer()->query('ActivityData'); |
|
36
|
|
|
|
|
37
|
5 |
|
$start = isset($_GET['start']) ? (int) $_GET['start'] : 0; |
|
38
|
5 |
|
$count = isset($_GET['count']) ? (int) $_GET['count'] : self::DEFAULT_LIMIT; |
|
39
|
5 |
|
$user = $app->getContainer()->getServer()->getUserSession()->getUser()->getUID(); |
|
40
|
|
|
|
|
41
|
5 |
|
if ($start !== 0) { |
|
42
|
2 |
|
$start = self::getSinceFromOffset($user, $start); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
5 |
|
$activities = $data->get( |
|
46
|
5 |
|
$app->getContainer()->query('GroupHelper'), |
|
47
|
5 |
|
$app->getContainer()->query('UserSettings'), |
|
48
|
5 |
|
$user, $start, $count, 'desc', 'all' |
|
49
|
|
|
); |
|
50
|
5 |
|
$parser = new PlainTextParser(\OC::$server->getL10NFactory()->get('activity')); |
|
51
|
|
|
|
|
52
|
5 |
|
$entries = []; |
|
53
|
5 |
|
foreach ($activities['data'] as $entry) { |
|
54
|
4 |
|
$entries[] = [ |
|
55
|
4 |
|
'id' => $entry['activity_id'], |
|
56
|
4 |
|
'subject' => $parser->parseMessage($entry['subject_prepared']), |
|
57
|
4 |
|
'message' => $parser->parseMessage($entry['message_prepared']), |
|
58
|
4 |
|
'file' => $entry['object_name'], |
|
59
|
4 |
|
'link' => $entry['link'], |
|
60
|
4 |
|
'date' => \date('c', $entry['timestamp']), |
|
61
|
|
|
]; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
5 |
|
return new \OC_OCS_Result($entries); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @param string $user |
|
69
|
|
|
* @param int $offset |
|
70
|
|
|
* @return int |
|
71
|
|
|
*/ |
|
72
|
2 |
|
protected static function getSinceFromOffset($user, $offset) { |
|
73
|
2 |
|
$query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
74
|
2 |
|
$query->select('activity_id') |
|
75
|
2 |
|
->from('activity') |
|
76
|
2 |
|
->where($query->expr()->eq('affecteduser', $query->createNamedParameter($user))) |
|
77
|
2 |
|
->orderBy('activity_id', 'desc') |
|
78
|
2 |
|
->setFirstResult($offset - 1) |
|
79
|
2 |
|
->setMaxResults(1); |
|
80
|
|
|
|
|
81
|
2 |
|
$result = $query->execute(); |
|
82
|
2 |
|
$row = $result->fetch(); |
|
83
|
2 |
|
$result->closeCursor(); |
|
84
|
|
|
|
|
85
|
2 |
|
if ($row) { |
|
86
|
1 |
|
return (int) $row['activity_id']; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
1 |
|
return 0; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|