1 | <?php |
||
33 | class ShareRequestMapper extends Mapper { |
||
34 | const TABLE_NAME = 'passman_share_request'; |
||
35 | |||
36 | public function __construct(IDBConnection $db) { |
||
37 | parent::__construct($db, self::TABLE_NAME); |
||
38 | } |
||
39 | |||
40 | 1 | public function createRequest(ShareRequest $request){ |
|
43 | |||
44 | /** |
||
45 | * Obtains a request by the given item and vault GUID pair |
||
46 | * @param $item_guid |
||
47 | * @param $target_vault_guid |
||
48 | * @return ShareRequest |
||
49 | */ |
||
50 | 1 | public function getRequestByItemAndVaultGuid($item_guid, $target_vault_guid){ |
|
54 | |||
55 | /** |
||
56 | * Get shared items for the given item_guid |
||
57 | * @param $item_guid |
||
58 | * @return ShareRequest[] |
||
59 | */ |
||
60 | 1 | public function getRequestsByItemGuidGroupedByUser($item_guid){ |
|
61 | 1 | if (strtolower($this->db->getDatabasePlatform()->getName()) === 'mysql'){ |
|
62 | 1 | $this->db->executeQuery("SET sql_mode = '';"); |
|
63 | } |
||
64 | 1 | $q = "SELECT *, target_user_id FROM *PREFIX*" . self::TABLE_NAME . " WHERE item_guid = ? GROUP BY target_user_id;"; |
|
65 | 1 | return $this->findEntities($q, [$item_guid]); |
|
66 | } |
||
67 | |||
68 | /** |
||
69 | * Deletes all pending requests for the given user to the given item |
||
70 | * @param $item_id The item ID |
||
71 | * @param $target_user_id The target user |
||
72 | * @return \PDOStatement The result of running the db query |
||
73 | */ |
||
74 | 1 | public function cleanItemRequestsForUser($item_id, $target_user_id){ |
|
79 | |||
80 | /** |
||
81 | * Obtains all pending share requests for the given user ID |
||
82 | * @param $user_id |
||
83 | * @return ShareRequest[] |
||
84 | */ |
||
85 | 1 | public function getUserPendingRequests($user_id){ |
|
89 | |||
90 | /** |
||
91 | * Deletes the given share request |
||
92 | * @param ShareRequest $shareRequest Request to delete |
||
93 | * @return ShareRequest The deleted request |
||
94 | */ |
||
95 | 1 | public function deleteShareRequest(ShareRequest $shareRequest){ |
|
98 | |||
99 | /** |
||
100 | * Gets a share request by it's unique incremental id |
||
101 | * @param $id |
||
102 | * @return ShareRequest |
||
103 | * @throws DoesNotExistException |
||
104 | */ |
||
105 | 1 | public function getShareRequestById($id){ |
|
109 | |||
110 | /** |
||
111 | * Gets all share requests by a given item GUID |
||
112 | * @param $item_guid |
||
113 | * @return ShareRequest[] |
||
114 | */ |
||
115 | 1 | public function getShareRequestsByItemGuid($item_guid){ |
|
119 | |||
120 | /** |
||
121 | * Updates the given share request, |
||
122 | * @param ShareRequest $shareRequest |
||
123 | * @return ShareRequest |
||
124 | */ |
||
125 | 1 | public function updateShareRequest(ShareRequest $shareRequest){ |
|
128 | |||
129 | /** |
||
130 | * Finds pending requests sent to the given user to the given item. |
||
131 | * @param $item_guid |
||
132 | * @param $user_id |
||
133 | * @return ShareRequest[] |
||
134 | */ |
||
135 | 1 | public function getPendingShareRequests($item_guid, $user_id){ |
|
139 | |||
140 | /** |
||
141 | * Updates all pending requests with the given permissions |
||
142 | * @param $item_guid The item for which to update the requests |
||
143 | * @param $user_id The user for which to update the requests |
||
144 | * @param $permissions The new permissions to apply |
||
145 | * @return \PDOStatement The result of the operation |
||
146 | */ |
||
147 | 1 | public function updatePendingRequestPermissions($item_guid, $user_id, $permissions){ |
|
151 | |||
152 | } |