File set filtering for image gallery

Permalink
Hi guys

Now.. im wondering how i can create a gallery block to get all the client images that are in one fileset (e.g. "portfolio") filtered into arrays by an image file attribute (e.g. "client 1" sets up an array of 6 images && "client 2" sets an array of 4 images) ?

I can handle the html side, just my php + concrete5.7's new structure left my knowledge base feeling as a fart.

xzeeno
 
hutman replied on at Permalink Reply
hutman
You should be able to do something like this:

$fs = FileSet::getByName('portfolio');
$fl = new FileList();
$fl->filterBySet($fs);
$fl->filterByAttribute('client_id', '', '<>');
$files = $fl->get(100);
$filesArray = array();
foreach($files as $file){
    $fv = $file->getRecentVersion();
    $fileClientID = $fv->getAttribute('client_id');
    $filesArray[$fileClientID][] = $fv->getRelativePath();
}


Which ends you with an array that looks like this

Array
(
    [1] => Array
        (
            [0] => /application/files/6214/2165/4274/shoes.jpg
            [1] => /application/files/2314/2165/4271/plants.jpg
        )
    [2] => Array
        (
            [0] => /application/files/3114/2165/4270/subway.jpg
            [1] => /application/files/6614/2165/4269/balloon.jpg
            [2] => /application/files/3514/2165/4267/houses.jpg
        )
)
xzeeno replied on at Permalink Reply
xzeeno
Nice, thanks

I shall test it out
and if you want, i can leave a comment in the php marking you as the provider of that section of code.
hutman replied on at Permalink Reply
hutman
If it works for you and you publish it a shout out in the code would be cool, thanks.
xzeeno replied on at Permalink Reply
xzeeno
How would i go about to get extra details about the file added to the array.

Such as title, description, category (e.g. website or designs) and website url link.

These would be into the view function of the controller. But what would i put into the view.php to extract each detail into variables that i can echo into sections of the html tags.
hutman replied on at Permalink Reply
hutman
You could change the array builder to be

$filesArray[$fileClientID][] = $file;


and then in your view you have the file object and you can do whatever you want with it

http://www.concrete5.org/documentation/developers/5.6/files/files-a...