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
|
|
|
{ |
31
|
|
|
const DEFAULT_LIMIT = 30; |
32
|
|
|
|
33
|
1 |
|
static public function get() { |
34
|
1 |
|
$app = new AppInfo\Application(); |
35
|
|
|
/** @var Data $data */ |
36
|
1 |
|
$data = $app->getContainer()->query('ActivityData'); |
37
|
|
|
|
38
|
1 |
|
$start = isset($_GET['start']) ? (int) $_GET['start'] : 0; |
39
|
1 |
|
$count = isset($_GET['count']) ? (int) $_GET['count'] : self::DEFAULT_LIMIT; |
40
|
1 |
|
$user = $app->getContainer()->getServer()->getUserSession()->getUser()->getUID(); |
41
|
|
|
|
42
|
1 |
|
if ($start !== 0) { |
43
|
|
|
$start = self::getSinceFromOffset($user, $start); |
44
|
|
|
} |
45
|
|
|
|
46
|
1 |
|
$activities = $data->get( |
47
|
1 |
|
$app->getContainer()->query('GroupHelper'), |
48
|
1 |
|
$app->getContainer()->query('UserSettings'), |
49
|
1 |
|
$user, $start, $count, 'desc', 'all' |
50
|
1 |
|
); |
51
|
1 |
|
$parser = new PlainTextParser(\OC::$server->getL10NFactory()->get('activity')); |
52
|
|
|
|
53
|
1 |
|
$entries = array(); |
54
|
1 |
|
foreach($activities['data'] as $entry) { |
55
|
|
|
$entries[] = array( |
56
|
|
|
'id' => $entry['activity_id'], |
57
|
|
|
'subject' => $parser->parseMessage($entry['subject_prepared']), |
58
|
|
|
'message' => $parser->parseMessage($entry['message_prepared']), |
59
|
|
|
'file' => $entry['object_name'], |
60
|
|
|
'link' => $entry['link'], |
61
|
|
|
'date' => date('c', $entry['timestamp']), |
62
|
|
|
); |
63
|
1 |
|
} |
64
|
|
|
|
65
|
1 |
|
return new \OC_OCS_Result($entries); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param string $user |
70
|
|
|
* @param int $offset |
71
|
|
|
* @return int |
72
|
|
|
*/ |
73
|
|
|
protected static function getSinceFromOffset($user, $offset) { |
74
|
|
|
$query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
75
|
|
|
$query->select('activity_id') |
76
|
|
|
->from('activity') |
77
|
|
|
->where($query->expr()->eq('affecteduser', $query->createNamedParameter($user))) |
78
|
|
|
->orderBy('activity_id', 'desc') |
79
|
|
|
->setFirstResult($offset - 1) |
80
|
|
|
->setMaxResults(1); |
81
|
|
|
|
82
|
|
|
$result = $query->execute(); |
83
|
|
|
$row = $result->fetch(); |
84
|
|
|
$result->closeCursor(); |
85
|
|
|
|
86
|
|
|
if ($row) { |
87
|
|
|
return (int) $row['activity_id']; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
return 0; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|