StackMapper::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 2
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);
0 ignored issues
show
Deprecated Code introduced by
The method OCP\AppFramework\Db\Mapper::__construct() has been deprecated with message: 14.0.0 Move over to QBMapper

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.

Loading history...
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]);
0 ignored issues
show
Deprecated Code introduced by
The method OCP\AppFramework\Db\Mapper::findEntity() has been deprecated with message: 14.0.0 Move over to QBMapper

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.

Loading history...
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);
0 ignored issues
show
Deprecated Code introduced by
The method OCP\AppFramework\Db\Mapper::findEntities() has been deprecated with message: 14.0.0 Move over to QBMapper

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.

Loading history...
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);
0 ignored issues
show
Deprecated Code introduced by
The method OCP\AppFramework\Db\Mapper::findEntities() has been deprecated with message: 14.0.0 Move over to QBMapper

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.

Loading history...
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);
0 ignored issues
show
Deprecated Code introduced by
The method OCP\AppFramework\Db\Mapper::delete() has been deprecated with message: 14.0.0 Move over to QBMapper

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.

Loading history...
70
	}
71
72 View Code Duplication
	public function isOwner($userId, $stackId) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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