Hi,
I can’t find a way to select all assets from a folder in a “gallery”-field.
3000 images in 40 galleries to go! I really don’t want to click them one by one - there must be an easy way. Please help. (hope I am just blind)
Select one an click with shift doesn’t work
Selecting multiple images with one click is not possible right now and you’ll also lose the current selection after clicking on the next page.
A quick workaround is to do it programmatically (not tested).
// select entry
$entry = $app->module('collections')->findOne(['title' => 'my-site-title']);
// get folder id
$assetFolder = $app->storage->findOne('cockpit/assets_folders', ['name' => 'folder-name']);
// select assets with folder id
$assets = $app->storage->find('cockpit/assets', ['folder' => $assetFolder['_id']])->toArray();
$gallery = [];
foreach ($assets as $a) {
$gallery[] = ... // meta/title and meta/asset, path
}
// save assets to gallery field
$entry['gallery'] = $gallery;
// save entry
$app->module('collections')->save($entry);
Hi, thanks (again ) for your answer.
I’ve solved that problem with an own PHP script which I am targeting in another API request. This script returns all asset entries from an asset folder by the asset folders name. So in my case the only point to remember and to do is to name the asset folder excatly with the name in my galleries-collection.
Maybe I can help someone else with a similar issue by sharing my solution. I would appreciate some feedback about security because I am not really a guy from the backend
<?php
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, X-Requested-With");
$gallery = array();
$db = new SQLite3("data/cockpit.sqlite");
$data=json_decode(file_get_contents('php://input'),1);
$name = $data['folder'];
if (isset($data['limit'])) {
$limit = "LIMIT :limit";
} else {
$limit = '';
}
$gallery = array();
// entries
$stmt = $db->prepare("
SELECT
a.document as adoc,
json_extract(a.document, '$.folder') as afolder,
json_extract(f.document, '$._id') as fid,
json_extract(f.document, '$.name') as fname
FROM assets_folders AS f
JOIN assets AS a
ON afolder = fid
WHERE fname = :name
".$limit);
$stmt->bindValue(':name', $name, SQLITE3_TEXT);
if (isset($data['limit'])) {
$stmt->bindValue(':limit', $data['limit'], SQLITE3_INTEGER);
}
$result = $stmt->execute();
while ($row = $result->fetchArray()) {
$gallery[] = json_decode($row['adoc']);
}
// total
$stmttotal = $db->prepare("
SELECT
COUNT(a.document) as total,
json_extract(a.document, '$.folder') as afolder,
json_extract(f.document, '$._id') as fid,
json_extract(f.document, '$.name') as fname
FROM assets_folders AS f
JOIN assets AS a
ON afolder = fid
WHERE fname = :name
");
$stmttotal->bindValue(':name', $name, SQLITE3_TEXT);
$result = $stmttotal->execute();
while ($row = $result->fetchArray()) {
$total = $row['total'];
}
$arr['entries'] = $gallery;
$arr['total'] = $total;
echo json_encode($arr);
?>