|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Circles - Bring cloud-users closer together. |
|
4
|
|
|
* |
|
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
6
|
|
|
* later. See the COPYING file. |
|
7
|
|
|
* |
|
8
|
|
|
* @author Maxence Lange <[email protected]> |
|
9
|
|
|
* @copyright 2017 |
|
10
|
|
|
* @license GNU AGPL version 3 or any later version |
|
11
|
|
|
* |
|
12
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
13
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
14
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
15
|
|
|
* License, or (at your option) any later version. |
|
16
|
|
|
* |
|
17
|
|
|
* This program is distributed in the hope that it will be useful, |
|
18
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20
|
|
|
* GNU Affero General Public License for more details. |
|
21
|
|
|
* |
|
22
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
23
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
24
|
|
|
* |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
namespace OCA\Circles\Db; |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
use daita\MySmallPhpTools\Traits\TStringTools; |
|
32
|
|
|
use Exception; |
|
33
|
|
|
use OCA\Circles\Exceptions\JsonException; |
|
34
|
|
|
use OCA\Circles\Exceptions\ModelException; |
|
35
|
|
|
use OCA\Circles\Exceptions\TokenDoesNotExistException; |
|
36
|
|
|
use OCA\Circles\Model\GlobalScale\GSEvent; |
|
37
|
|
|
use OCA\Circles\Model\GlobalScale\GSWrapper; |
|
38
|
|
|
use OCA\Circles\Model\Member; |
|
39
|
|
|
use OCA\Circles\Model\SharesToken; |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Class TokensRequest |
|
44
|
|
|
* |
|
45
|
|
|
* @package OCA\Circles\Db |
|
46
|
|
|
*/ |
|
47
|
|
|
class GSEventsRequest extends GSEventsRequestBuilder { |
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
use TStringTools; |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param GSEvent $event |
|
55
|
|
|
* @param array $instances |
|
56
|
|
|
* |
|
57
|
|
|
* @return GSWrapper |
|
58
|
|
|
*/ |
|
59
|
|
|
public function create(GSevent $event, array $instances): GSWrapper { |
|
60
|
|
|
$wrapper = new GSWrapper(); |
|
61
|
|
|
$wrapper->setToken($this->uuid()); |
|
62
|
|
|
$wrapper->setEvent($event); |
|
63
|
|
|
$wrapper->setInstances($instances); |
|
64
|
|
|
$wrapper->setCreation(time()); |
|
65
|
|
|
|
|
66
|
|
|
$qb = $this->getGSEventsInsertSql(); |
|
67
|
|
|
$qb->setValue('token', $qb->createNamedParameter($wrapper->getToken())) |
|
68
|
|
|
->setValue('event', $qb->createNamedParameter(json_encode($wrapper->getEvent()))) |
|
69
|
|
|
->setValue('instances', $qb->createNamedParameter(json_encode($wrapper->getInstances()))) |
|
70
|
|
|
->setValue('creation', $qb->createNamedParameter($wrapper->getCreation())); |
|
71
|
|
|
|
|
72
|
|
|
$qb->execute(); |
|
73
|
|
|
|
|
74
|
|
|
return $wrapper; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param string $token |
|
81
|
|
|
* |
|
82
|
|
|
* @return GSWrapper |
|
83
|
|
|
* @throws TokenDoesNotExistException |
|
84
|
|
|
* @throws JsonException |
|
85
|
|
|
* @throws ModelException |
|
86
|
|
|
*/ |
|
87
|
|
|
public function getByToken(string $token): GSWrapper { |
|
88
|
|
|
$qb = $this->getGSEventsSelectSql(); |
|
89
|
|
|
$this->limitToToken($qb, $token); |
|
90
|
|
|
|
|
91
|
|
|
$cursor = $qb->execute(); |
|
92
|
|
|
$data = $cursor->fetch(); |
|
93
|
|
|
$cursor->closeCursor(); |
|
94
|
|
|
if ($data === false) { |
|
95
|
|
|
throw new TokenDoesNotExistException('Unknown share token'); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
return $this->parseGSEventsSelectSql($data); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
|