Filter file manager

Permalink
I'm trying to filter the files shown in the file manager, but cannot figure out how. I've searched the forum and found some stuff, but none seems to work.

For example, I want the file manager to show only PDF files. The code I've found passes any array of extensions, but that doesn't work.

Any ideas? Thanks!

jizzle
 
synlag replied on at Permalink Reply
synlag
doesn't the search with filter for extension work?

at mine it does.
jizzle replied on at Permalink Reply
jizzle
Oh, sorry.... I didn't describe anything at all. I assumed that since it was in "Building with concrete5" that it would be understood.

I'm trying to do it in a block. I can open the file manager, but cannot filter by file type automatically (ie: only show pdf files)

<?php echo $al->file('ccm-b-file', 'fID', t('Choose Document'), $bf);?>
Tony replied on at Permalink Reply
Tony
just use the file list class:

$fileList = new FileList();
$fileList->filterByExtension('your_extension');
$files = $fileList->get( 20 );
jizzle replied on at Permalink Reply
jizzle
Thanks, that'll do it!
jizzle replied on at Permalink Reply
jizzle
Ok, I thought I could piece it together, but apparently not. Anyone got a more integrated example (showing the file manager with this filter in action)?

Thanks!
Tony replied on at Permalink Reply
Tony
oh, you're trying to recreate the whole file manager with that? not sure if there's an easy path headed there. are you trying to make that interface available to your users? in that case maybe the document libraries the way to go. it's not too hard to just add pagination and stuff to a list of files... not sure what you're trying to do.
jizzle replied on at Permalink Reply
jizzle
I'm not trying to recreate the file manager, just limit the display to certain file types. File manager = file helper if that helps any.

Example: In a custom block, user clicks "Select File". File manager opens only showing PDF & DOC files to select from.

I recently found how to filter the file help to 1 file type with the following code and am currently testing it:

<?php echo $al->file('ccm-b-file', 'fID', t('Choose Document'), $file, array('fExtension' => 'pdf'));?>
jizzle replied on at Permalink Reply
jizzle
In /concrete/helpers/concrete/asset_library.php, line 51, it loops through the arrary of extensions provided, but it only seems to take the last parameter passed. Is this a bug or am I doing something wrong? Here's how I'm passing multiple parameters:

<?php echo $al->file('ccm-b-file', 'fID', t('Choose Document'), $bf, array('fExtension' => 'pdf', 'fExtension' => 'ppt'));?>
Tony replied on at Permalink Reply
Tony
you probably want something more like:

array('fExtension'=>array('pdf','doc'))
jizzle replied on at Permalink Reply
jizzle
Nope, that didn't work.

Even in asset_library.php, if you hand code the filter, it still only uses the last entered filter.

It does work if you only pass a single parameter though.
Mnkras replied on at Permalink Reply
Mnkras
what happens if you do it like this?

$fileList = new FileList();
$fileList->filterByExtension('pdf');
$fileList->filterByExtension('doc');
$fileList->filterByExtension('ppt');
$files = $fileList->get( 20 );
russellfeeed replied on at Permalink Reply
russellfeeed
After a lot of searching through the core concrete5 code... this workaround solves the problem

echo $al->file('file', 'fileid', t('Select a File'),NULL,array('fKeywords'=>'','fExtension'=>'txt'));


To clarify, you need to set fKeywords to '' or it will add a whole WHERE clause to the SELECT which looks for *.* and %*.*%.

Despite searching for an hour, I couldn't find where fKeywords was being initialised to *.*
nerdess replied on at Permalink Reply
nerdess
This worked fine for me so only pdfs get shown:

$al->file('ccm-b-file', 'pdf', t('Choose a pdf'), $pdf, array('fExtension'=>'pdf'));