예제 #1
0
 /**
  * Share an item with a user, group, or via private link
  * @param string $itemType
  * @param string $itemSource
  * @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
  * @param string $shareWith User or group the item is being shared with
  * @param int $permissions CRUDS
  * @param string $itemSourceName
  * @param \DateTime $expirationDate
  * @return bool|string Returns true on success or false on failure, Returns token on success for links
  * @throws \Exception
  */
 public static function shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions, $itemSourceName = null, \DateTime $expirationDate = null)
 {
     return \OC\Share\Share::shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions, $itemSourceName, $expirationDate);
 }
예제 #2
0
 /**
  * @param $fid
  * @param $uid
  * @param $wUid
  * @return bool|string
  * @throws \Exception
  * @throws \OC\HintException
  */
 public function shareFile($uid, $wUid, $fid, $permission = 1)
 {
     $isEnabled = \OCP\Share::isEnabled();
     $isAllowed = \OCP\Share::isResharingAllowed();
     $sharedWith = \OCP\Share::getUsersItemShared('file', $fid, $uid, false, true);
     //$file = $this->connect->files()->getInfoById($fid);
     if ($isEnabled && $isAllowed && !in_array($wUid, $sharedWith)) {
         // \OCP\Constants::PERMISSION_READ
         // \OCP\Constants::PERMISSION_ALL
         // \OCP\Share::SHARE_TYPE_LINK
         // \OCP\Share::SHARE_TYPE_USER,
         $shareIsSuccess = \OC\Share\Share::shareItem('file', $fid, \OCP\Share::SHARE_TYPE_USER, $wUid, $permission);
         if ($shareIsSuccess) {
             $this->connect->update('*PREFIX*share', ['uid_initiator' => $uid], 'share_with = :share_with AND uid_owner = :uid_owner AND file_source = :file_source', [':share_with' => $wUid, ':uid_owner' => $uid, ':file_source' => $fid]);
             $token = \OC\Share\Share::shareItem('file', $fid, \OCP\Share::SHARE_TYPE_LINK, $wUid, $permission);
             $this->connect->update('*PREFIX*share', ['uid_initiator' => $uid, 'share_with' => null], 'uid_owner = :uid_owner AND file_source = :file_source AND token = :token', [':uid_owner' => $uid, ':file_source' => $fid, ':token' => $token]);
             return $token;
         }
     }
 }