Completed
Push — master ( d79a20...4b5696 )
by Sander
10s
created

SharingACLMapper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * Nextcloud - passman
4
 *
5
 * @copyright Copyright (c) 2016, Sander Brand ([email protected])
6
 * @copyright Copyright (c) 2016, Marcos Zuriaga Miguel ([email protected])
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\Passman\Db;
25
26
27
use OCP\AppFramework\Db\Mapper;
28
use OCP\IDBConnection;
29
use OCP\IUser;
30
use OCA\Passman\Utility\Utils;
31
32
class SharingACLMapper extends Mapper {
33
    const TABLE_NAME = '*PREFIX*passman_sharing_acl';
34
35
    public function __construct(IDBConnection $db) {
36
        parent::__construct($db, 'passman_sharing_acl');
37
    }
38
39
    public function createACLEntry(SharingACL $acl){
40
        return $this->insert($acl);
41
    }
42
43
    /**
44
     * Gets the currently accepted share requests from the given user for the given vault guid
45
     * @param $user_id
46
     * @param $vault_guid
47
     * @return SharingACL[]
48
     */
49 1
    public function getVaultEntries($user_id, $vault_guid) {
50 1
        $q = "SELECT * FROM ". self::TABLE_NAME ." WHERE user_id = ? AND vault_guid = ?";
51 1
        return $this->findEntities($q, [$user_id, $vault_guid]);
52
    }
53
54
    /**
55
     * Gets the acl for a given item guid
56
     * @param $user_id
57
     * @param $item_guid
58
     * @return SharingACL
59
     */
60 1
    public function getItemACL($user_id, $item_guid) {
61 1
        $q = "SELECT * FROM " . self::TABLE_NAME . " WHERE item_guid = ? AND ";
62 1
        $filter = [$item_guid];
63 1
        if ($user_id === null){
64
            $q .= 'user_id is null';
65
        }
66
        else {
67 1
            $q .= 'user_id = ? ';
68 1
            $filter[] = $user_id;
69
        }
70 1
        return $this->findEntity($q, $filter);
71
    }
72
73
    /**
74
     * Update the acl for a given item guid
75
     * @param $user_id
76
     * @param $item_guid
77
     * @return SharingACL
78
     */
79 1
    public function updateCredentialACL(SharingACL $sharingACL) {
80 1
        return $this->update($sharingACL);
81
    }
82
83
    /**
84
     * Gets the currently accepted share requests from the given user for the given vault guid
85
     * @param $user_id
86
     * @param $vault_id
87
     * @return SharingACL[]
88
     */
89 1
    public function getCredentialAclList($item_guid) {
90 1
        $q = "SELECT * FROM ". self::TABLE_NAME ." WHERE item_guid = ?";
91 1
        return $this->findEntities($q, [$item_guid]);
92
    }
93
94 1
    public function deleteShareACL(SharingACL $ACL){
95 1
    	return $this->delete($ACL);
96
	}
97
}