-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hide folders without photos (fix #163)
- Loading branch information
Showing
8 changed files
with
125 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace OCA\Memories\Controller; | ||
|
||
use OCP\Files\FileInfo; | ||
use OCP\Files\Folder; | ||
use OCA\Memories\Db\TimelineQuery; | ||
|
||
trait FoldersTrait { | ||
protected TimelineQuery $timelineQuery; | ||
|
||
private function getFolderPreviews(Folder &$parent, FileInfo &$fileInfo) { | ||
$folder = $parent->getById($fileInfo->getId()); | ||
if (count($folder) === 0) { | ||
return []; | ||
} | ||
return $this->timelineQuery->getFolderPreviews($folder[0]); | ||
} | ||
|
||
/** | ||
* Get subfolders entry for days response. | ||
*/ | ||
public function getSubfoldersEntry(Folder &$folder) | ||
{ | ||
// Ugly: get the view of the folder with reflection | ||
// This is unfortunately the only way to get the contents of a folder | ||
// matching a MIME type without using SEARCH, which is deep | ||
$rp = new \ReflectionProperty('\OC\Files\Node\Node', 'view'); | ||
$rp->setAccessible(true); | ||
$view = $rp->getValue($folder); | ||
|
||
// Get the subfolders | ||
$folders = $view->getDirectoryContent($folder->getPath(), FileInfo::MIMETYPE_FOLDER, $folder); | ||
|
||
// Sort by name | ||
usort($folders, function ($a, $b) { | ||
return strnatcmp($a->getName(), $b->getName()); | ||
}); | ||
|
||
// Process to response type | ||
return [ | ||
'dayid' => \OCA\Memories\Util::$TAG_DAYID_FOLDERS, | ||
'count' => \count($folders), | ||
'detail' => array_map(function (&$node) use (&$folder) { | ||
return [ | ||
'fileid' => $node->getId(), | ||
'name' => $node->getName(), | ||
'isfolder' => 1, | ||
'path' => $node->getPath(), | ||
'previews' => $this->getFolderPreviews($folder, $node), | ||
]; | ||
}, $folders, []), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OCA\Memories\Db; | ||
|
||
use OCP\DB\QueryBuilder\IQueryBuilder; | ||
use OCP\Files\Folder; | ||
use OCP\IDBConnection; | ||
|
||
trait TimelineQueryFolders | ||
{ | ||
protected IDBConnection $connection; | ||
|
||
public function getFolderPreviews(Folder &$folder) | ||
{ | ||
$query = $this->connection->getQueryBuilder(); | ||
|
||
// SELECT all photos | ||
$query->select('f.fileid', 'f.etag')->from('memories', 'm'); | ||
|
||
// WHERE these photos are in the user's requested folder recursively | ||
$query = $this->joinFilecache($query, $folder, true, false); | ||
|
||
// ORDER descending by fileid | ||
$query->orderBy('f.fileid', 'DESC'); | ||
|
||
// MAX 4 | ||
$query->setMaxResults(4); | ||
|
||
// FETCH tag previews | ||
$cursor = $this->executeQueryWithCTEs($query); | ||
$ans = $cursor->fetchAll(); | ||
|
||
// Post-process | ||
foreach ($ans as &$row) { | ||
$row['fileid'] = (int) $row['fileid']; | ||
} | ||
|
||
return $ans; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters