示例#1
0
 /**
  * Get the a list if items tagged with $tag.
  *
  * Throws an exception if the tag could not be found.
  *
  * @param string $tag Tag id or name.
  * @return array|false An array of object ids or false on error.
  * @throws \Exception
  */
 public function getIdsForTag($tag)
 {
     $result = null;
     $tagId = false;
     if (is_numeric($tag)) {
         $tagId = $tag;
     } elseif (is_string($tag)) {
         $tag = trim($tag);
         if ($tag === '') {
             \OCP\Util::writeLog('core', __METHOD__ . ', Cannot use empty tag names', \OCP\Util::DEBUG);
             return false;
         }
         $tagId = $this->getTagId($tag);
     }
     if ($tagId === false) {
         $l10n = \OC::$server->getL10N('core');
         throw new \Exception($l10n->t('Could not find category "%s"', $tag));
     }
     $ids = array();
     $sql = 'SELECT `objid` FROM `' . self::RELATION_TABLE . '` WHERE `categoryid` = ?';
     try {
         $stmt = \OCP\DB::prepare($sql);
         $result = $stmt->execute(array($tagId));
         if (\OCP\DB::isError($result)) {
             \OCP\Util::writeLog('core', __METHOD__ . 'DB error: ' . \OCP\DB::getErrorMessage(), \OCP\Util::ERROR);
             return false;
         }
     } catch (\Exception $e) {
         \OCP\Util::writeLog('core', __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR);
         return false;
     }
     if (!is_null($result)) {
         while ($row = $result->fetchRow()) {
             $id = (int) $row['objid'];
             if ($this->includeShared) {
                 // We have to check if we are really allowed to access the
                 // items that are tagged with $tag. To that end, we ask the
                 // corresponding sharing backend if the item identified by $id
                 // is owned by any of $this->owners.
                 foreach ($this->owners as $owner) {
                     if ($this->backend->isValidSource($id, $owner)) {
                         $ids[] = $id;
                         break;
                     }
                 }
             } else {
                 $ids[] = $id;
             }
         }
     }
     return $ids;
 }
示例#2
0
文件: share.php 项目: evanjt/core
 /**
  * format result
  * @param array $items result
  * @param string $column is it a file share or a general share ('file_target' or 'item_target')
  * @param \OCP\Share_Backend $backend sharing backend
  * @param int $format
  * @param array $parameters additional format parameters
  * @return array format result
  */
 private static function formatResult($items, $column, $backend, $format = self::FORMAT_NONE, $parameters = null)
 {
     if ($format === self::FORMAT_NONE) {
         return $items;
     } else {
         if ($format === self::FORMAT_STATUSES) {
             $statuses = array();
             foreach ($items as $item) {
                 if ($item['share_type'] === self::SHARE_TYPE_LINK) {
                     $statuses[$item[$column]]['link'] = true;
                 } else {
                     if (!isset($statuses[$item[$column]])) {
                         $statuses[$item[$column]]['link'] = false;
                     }
                 }
                 if (!empty($item['file_target'])) {
                     $statuses[$item[$column]]['path'] = $item['path'];
                 }
             }
             return $statuses;
         } else {
             return $backend->formatItems($items, $format, $parameters);
         }
     }
 }