1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2016 Julius Härtl <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @author Julius Härtl <[email protected]> |
6
|
|
|
* |
7
|
|
|
* @license GNU AGPL version 3 or any later version |
8
|
|
|
* |
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
12
|
|
|
* License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU Affero General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
21
|
|
|
* |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace OCA\Deck\Db; |
25
|
|
|
|
26
|
|
|
use OCP\AppFramework\Db\Entity; |
27
|
|
|
use OCP\IDBConnection; |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
class StackMapper extends DeckMapper implements IPermissionMapper { |
31
|
|
|
|
32
|
|
|
private $cardMapper; |
33
|
|
|
|
34
|
|
|
public function __construct(IDBConnection $db, CardMapper $cardMapper) { |
35
|
|
|
parent::__construct($db, 'deck_stacks', Stack::class); |
|
|
|
|
36
|
|
|
$this->cardMapper = $cardMapper; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param $id |
42
|
|
|
* @return \OCP\AppFramework\Db\Entity if not found |
43
|
|
|
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException |
44
|
|
|
* @throws \OCP\AppFramework\Db\DoesNotExistException |
45
|
|
|
*/ |
46
|
|
|
public function find($id) { |
47
|
|
|
$sql = 'SELECT * FROM `*PREFIX*deck_stacks` ' . |
48
|
|
|
'WHERE `id` = ?'; |
49
|
|
|
return $this->findEntity($sql, [$id]); |
|
|
|
|
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
public function findAll($boardId, $limit = null, $offset = null) { |
54
|
|
|
$sql = 'SELECT * FROM `*PREFIX*deck_stacks` WHERE `board_id` = ? AND deleted_at = 0 ORDER BY `order`'; |
55
|
|
|
return $this->findEntities($sql, [$boardId], $limit, $offset); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
public function findDeleted($boardId, $limit = null, $offset = null) { |
60
|
|
|
$sql = 'SELECT * FROM `*PREFIX*deck_stacks` s |
61
|
|
|
WHERE `s`.`board_id` = ? AND NOT s.deleted_at = 0'; |
62
|
|
|
return $this->findEntities($sql, [$boardId], $limit, $offset); |
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
public function delete(Entity $entity) { |
67
|
|
|
// delete cards on stack |
68
|
|
|
$this->cardMapper->deleteByStack($entity->getId()); |
69
|
|
|
return parent::delete($entity); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
View Code Duplication |
public function isOwner($userId, $stackId) { |
|
|
|
|
73
|
|
|
$sql = 'SELECT owner FROM `*PREFIX*deck_boards` WHERE `id` IN (SELECT board_id FROM `*PREFIX*deck_stacks` WHERE id = ?)'; |
74
|
|
|
$stmt = $this->execute($sql, [$stackId]); |
75
|
|
|
$row = $stmt->fetch(); |
76
|
|
|
return ($row['owner'] === $userId); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function findBoardId($stackId) { |
80
|
|
|
$entity = $this->find($stackId); |
81
|
|
|
return $entity->getBoardId(); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.