/** * Comparator function to sort files alphabetically and have * the directories appear first * * @param \OCP\Files\FileInfo $a file * @param \OCP\Files\FileInfo $b file * @return int -1 if $a must come before $b, 1 otherwise */ public static function compareFileNames(FileInfo $a, FileInfo $b) { $aType = $a->getType(); $bType = $b->getType(); if ($aType === 'dir' and $bType !== 'dir') { return -1; } elseif ($aType !== 'dir' and $bType === 'dir') { return 1; } else { return \OCP\Util::naturalSortCompare($a->getName(), $b->getName()); } }
/** * Comparator function to sort files alphabetically and have * the directories appear first * * @param \OCP\Files\FileInfo $a file * @param \OCP\Files\FileInfo $b file * @return int -1 if $a must come before $b, 1 otherwise */ public static function compareFileNames($a, $b) { $aType = $a->getType(); $bType = $b->getType(); if ($aType === 'dir' and $bType !== 'dir') { return -1; } elseif ($aType !== 'dir' and $bType === 'dir') { return 1; } else { return strnatcasecmp($a->getName(), $b->getName()); } }
/** * Formats the file info to be returned as OPDS to the client * * @param \OCP\Files\FileInfo $i * @return array formatted file info */ public static function formatFileInfo(\OCP\Files\FileInfo $i) { $entry = array(); $entry['id'] = $i['fileid']; $entry['mtime'] = $i['mtime']; $entry['name'] = $i->getName(); $entry['type'] = $i['type']; if ($i['type'] === 'file') { $entry['mimetype'] = $i['mimetype']; $entry['humansize'] = \OC_Helper::humanFileSize($i['size']); $entry['meta'] = Meta::get($i['fileid']); } return $entry; }
/** * Returns the name of the node * * @return string */ public function getName() { return $this->info->getName(); }
/** * Formats the file info to be returned as JSON to the client. * * @param \OCP\Files\FileInfo $i * @return array formatted file info */ public static function formatFileInfo(FileInfo $i) { $entry = array(); $entry['id'] = $i['fileid']; $entry['parentId'] = $i['parent']; $entry['mtime'] = $i['mtime'] * 1000; // only pick out the needed attributes $entry['name'] = $i->getName(); $entry['permissions'] = $i['permissions']; $entry['mimetype'] = $i['mimetype']; $entry['size'] = $i['size']; $entry['type'] = $i['type']; $entry['etag'] = $i['etag']; if (isset($i['tags'])) { $entry['tags'] = $i['tags']; } if (isset($i['displayname_owner'])) { $entry['shareOwner'] = $i['displayname_owner']; } if (isset($i['is_share_mount_point'])) { $entry['isShareMountPoint'] = $i['is_share_mount_point']; } $mountType = null; if ($i->isShared()) { $mountType = 'shared'; } else { if ($i->isMounted()) { $mountType = 'external'; } } if ($mountType !== null) { if ($i->getInternalPath() === '') { $mountType .= '-root'; } $entry['mountType'] = $mountType; } if (isset($i['extraData'])) { $entry['extraData'] = $i['extraData']; } return $entry; }