Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
55.56% |
10 / 18 |
|
33.33% |
1 / 3 |
CRAP | |
0.00% |
0 / 1 |
ProjectMapper | |
55.56% |
10 / 18 |
|
33.33% |
1 / 3 |
5.40 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
find | |
90.00% |
9 / 10 |
|
0.00% |
0 / 1 |
2.00 | |||
getProjects | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * Nextcloud - cospend |
5 | * |
6 | * This file is licensed under the Affero General Public License version 3 or |
7 | * later. See the COPYING file. |
8 | * |
9 | * @author Julien Veyssier <eneiluj@posteo.net> |
10 | * @copyright Julien Veyssier 2019 |
11 | */ |
12 | |
13 | namespace OCA\Cospend\Db; |
14 | |
15 | use Exception; |
16 | use OCP\AppFramework\Db\QBMapper; |
17 | use OCP\DB\QueryBuilder\IQueryBuilder; |
18 | use OCP\IDBConnection; |
19 | |
20 | class ProjectMapper extends QBMapper { |
21 | const TABLENAME = 'cospend_projects'; |
22 | |
23 | public function __construct(IDBConnection $db) { |
24 | parent::__construct($db, self::TABLENAME, Project::class); |
25 | } |
26 | |
27 | public function find(string $id): Project { |
28 | $qb = $this->db->getQueryBuilder(); |
29 | $qb->select('*') |
30 | ->from(self::TABLENAME) |
31 | ->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_STR))); |
32 | $result = $qb->executeQuery(); |
33 | $row = $result->fetch(); |
34 | $result->closeCursor(); |
35 | |
36 | if ($row === false) { |
37 | throw new Exception('Project ' . $id . ' not found'); |
38 | } |
39 | |
40 | return $this->mapRowToEntity($row); |
41 | } |
42 | |
43 | /** |
44 | * @param string $userId |
45 | * @return array |
46 | * @throws \OCP\DB\Exception |
47 | */ |
48 | public function getProjects(string $userId): array { |
49 | $qb = $this->db->getQueryBuilder(); |
50 | |
51 | $qb->select('*') |
52 | ->from($this->getTableName()) |
53 | ->where( |
54 | $qb->expr()->eq('userid', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR)) |
55 | ); |
56 | |
57 | return $this->findEntities($qb); |
58 | } |
59 | } |