Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

Feature request: sort by update or create time #42

Closed
AdriaandeJongh opened this issue Jan 9, 2019 · 2 comments
Closed

Feature request: sort by update or create time #42

AdriaandeJongh opened this issue Jan 9, 2019 · 2 comments

Comments

@AdriaandeJongh
Copy link

There doesn't seem to be a way to sort results by update or create time. This is useful for queries where I'd like to get the most recent changed files.

@aalfiann
Copy link

aalfiann commented Jan 9, 2019

There is little bit tricky for this :

require_once ('vendor/autoload.php');
use \Filebase\Database;

$database = new Database([
    'dir' => 'storage/user',
    'backupLocation' => 'storage/backup'
]);

// Get all data (way 1)
$list = $database->findAll();

// or get all data with query (way 2)
$list = $database->query()
  ->limit(10)
  ->resultDocuments();

// Create new array sort the list
foreach ($list as $key => $item) {
    $resort[$key] = $item->createdAt();
}
// Re-sorting list
array_multisort($resort, SORT_DESC, $list);

// Echo the sorted list
foreach($list as $key => $item) {
    echo $key.'. '.$item->getId().' | '.$item->createdAt().' | '.$item->updatedAt().'<br>';
}

Note:

  • Way 1 is not efficient.
  • Way 2 is better, because you are able to use cache.

sumpygump pushed a commit to sumpygump/Filebase that referenced this issue Feb 8, 2019
@timothymarois
Copy link
Member

timothymarois commented Feb 23, 2019

This has been added in the latest update based on merge #45 - I've added it to the readme within querying

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants