Example #1
0
 /**
  * Function that is called after a user is added to a group.
  * TODO what does it do?
  * @param array $arguments
  */
 public static function post_addToGroup($arguments)
 {
     // Find the group shares and check if the user needs a unique target
     $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share` WHERE `share_type` = ? AND `share_with` = ?');
     $result = $query->execute(array(self::SHARE_TYPE_GROUP, $arguments['gid']));
     $query = \OC_DB::prepare('INSERT INTO `*PREFIX*share` (`item_type`, `item_source`,' . ' `item_target`, `parent`, `share_type`, `share_with`, `uid_owner`, `permissions`,' . ' `stime`, `file_source`, `file_target`) VALUES (?,?,?,?,?,?,?,?,?,?,?)');
     while ($item = $result->fetchRow()) {
         $sourceExists = \OC\Share\Share::getItemSharedWithBySource($item['item_type'], $item['item_source'], self::FORMAT_NONE, null, true, $arguments['uid']);
         if ($sourceExists) {
             $fileTarget = $sourceExists['file_target'];
             $itemTarget = $sourceExists['item_target'];
         } else {
             $itemTarget = Helper::generateTarget($item['item_type'], $item['item_source'], self::SHARE_TYPE_USER, $arguments['uid'], $item['owner'], null, $item['parent']);
             // do we also need a file target
             if ($item['item_type'] === 'file' || $item['item_type'] === 'folder') {
                 $fileTarget = Helper::generateTarget('file', $item['file_target'], self::SHARE_TYPE_USER, $arguments['uid'], $item['owner'], null, $item['parent']);
             } else {
                 $fileTarget = null;
             }
         }
         // Insert an extra row for the group share if the item or file target is unique for this user
         if ($itemTarget != $item['item_target'] || $fileTarget != $item['file_target']) {
             $query->execute(array($item['item_type'], $item['item_source'], $itemTarget, $item['id'], self::$shareTypeGroupUserUnique, $arguments['uid'], $item['uid_owner'], $item['permissions'], $item['stime'], $item['file_source'], $fileTarget));
             \OC_DB::insertid('*PREFIX*share');
         }
     }
 }
Example #2
0
 /**
  * Get the item of item type shared with the current user by source
  * @param string $itemType
  * @param string $itemSource
  * @param int $format (optional) Format type must be defined by the backend
  * @param mixed $parameters
  * @param bool $includeCollections
  * @return array
  */
 public static function getItemSharedWithBySource($itemType, $itemSource, $format = self::FORMAT_NONE, $parameters = null, $includeCollections = false)
 {
     return \OC\Share\Share::getItemSharedWithBySource($itemType, $itemSource, $format, $parameters, $includeCollections);
 }