コード例 #1
0
ファイル: tagservice.php プロジェクト: evanjt/core
 /**
  * Updates the tags of the specified file path.
  * The passed tags are absolute, which means they will
  * replace the actual tag selection.
  *
  * @param string $path path
  * @param array  $tags array of tags
  * @return array list of tags
  * @throws \OCP\Files\NotFoundException if the file does not exist
  */
 public function updateFileTags($path, $tags)
 {
     $fileId = $this->homeFolder->get($path)->getId();
     $currentTags = $this->tagger->getTagsForObjects(array($fileId));
     if (!empty($currentTags)) {
         $currentTags = current($currentTags);
     }
     $newTags = array_diff($tags, $currentTags);
     foreach ($newTags as $tag) {
         $this->tagger->tagAs($fileId, $tag);
     }
     $deletedTags = array_diff($currentTags, $tags);
     foreach ($deletedTags as $tag) {
         $this->tagger->unTag($fileId, $tag);
     }
     // TODO: re-read from tagger to make sure the
     // list is up to date, in case of concurrent changes ?
     return $tags;
 }
コード例 #2
0
ファイル: cache.php プロジェクト: sunblade/core
 /**
  * Checks whether the given file has the given tag.
  *
  * @param \OCP\ITags $tagger
  * @param array $fileData file data
  * @param string $tag tag to check for
  * @return boolean true if the given file has the expected tag,
  * false otherwise
  */
 private function hasTag($tagger, $fileData, $tag)
 {
     $tags = $tagger->getTagsForObjects(array((int) $fileData['fileid']));
     return !empty($tags) && in_array($tag, current($tags));
 }