2016-10-02 07:56:36 +08:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Created by PhpStorm.
|
|
|
|
* User: wolfi
|
|
|
|
* Date: 1/10/16
|
|
|
|
* Time: 23:15
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Passman\Db;
|
|
|
|
|
|
|
|
|
|
|
|
use OCA\Passman\Utility\Utils;
|
|
|
|
use OCP\AppFramework\Db\Mapper;
|
|
|
|
use OCP\IDBConnection;
|
|
|
|
|
|
|
|
class ShareRequestMapper extends Mapper {
|
2016-10-02 17:22:19 +08:00
|
|
|
const TABLE_NAME = 'passman_share_request';
|
2016-10-02 07:56:36 +08:00
|
|
|
|
|
|
|
public function __construct(IDBConnection $db, Utils $utils) {
|
|
|
|
parent::__construct($db, self::TABLE_NAME);
|
|
|
|
$this->utils = $utils;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function createRequest(ShareRequest $request){
|
2016-10-02 17:43:31 +08:00
|
|
|
return $this->insert($request);
|
2016-10-02 07:56:36 +08:00
|
|
|
}
|
2016-10-02 19:48:23 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtains a request by the given item and vault GUID pair
|
|
|
|
* @param $item_guid
|
|
|
|
* @param $target_vault_guid
|
|
|
|
* @return ShareRequest
|
|
|
|
*/
|
|
|
|
public function getRequestByGuid($item_guid, $target_vault_guid){
|
|
|
|
$q = "SELECT * FROM *PREFIX*" . self::TABLE_NAME . " WHERE item_guid = ? AND target_vault_guid = ?";
|
|
|
|
return $this->findEntity($q, [$item_guid, $target_vault_guid]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function cleanItemRequestsForUser($item_id, $target_user_id){
|
|
|
|
$req = new ShareRequest();
|
|
|
|
$req->setItemId($item_id);
|
|
|
|
$req->setTargetUserId($target_user_id);
|
|
|
|
return $this->delete($req);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtains all pending share requests for the given user ID
|
|
|
|
* @param $user_id
|
|
|
|
* @return ShareRequest[]
|
|
|
|
*/
|
|
|
|
public function getUserPendingRequests($user_id){
|
|
|
|
$q = "SELECT * FROM *PREFIX*{{self::TABLE_NAME }} WHERE user_id = ?";
|
|
|
|
return $this->findEntities($q, [$user_id]);
|
|
|
|
}
|
2016-10-02 07:56:36 +08:00
|
|
|
}
|