Ejemplo n.º 1
0
 /**
  * Get all shares by the given user. Sharetype and path can be used to filter.
  *
  * @param string $userId
  * @param int $shareType
  * @param \OCP\Files\File|\OCP\Files\Folder $node
  * @param bool $reshares Also get the shares where $user is the owner instead of just the shares where $user is the initiator
  * @param int $limit The maximum number of shares to be returned, -1 for all shares
  * @param int $offset
  * @return Share[]
  */
 public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset)
 {
     $qb = $this->dbConn->getQueryBuilder();
     $qb->select('*')->from('share');
     $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter($shareType)));
     /**
      * Reshares for this user are shares where they are the owner.
      */
     if ($reshares === false) {
         //Special case for old shares created via the web UI
         $or1 = $qb->expr()->andX($qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), $qb->expr()->isNull('uid_initiator'));
         $qb->andWhere($qb->expr()->orX($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)), $or1));
     } else {
         $qb->andWhere($qb->expr()->orX($qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))));
     }
     if ($node !== null) {
         $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
     }
     if ($limit !== -1) {
         $qb->setMaxResults($limit);
     }
     $qb->setFirstResult($offset);
     $qb->orderBy('id');
     $cursor = $qb->execute();
     $shares = [];
     while ($data = $cursor->fetch()) {
         $shares[] = $this->createShare($data);
     }
     $cursor->closeCursor();
     return $shares;
 }