Filter by custom attributes

Permalink Browser Info Environment
Hi I am new to c5, and I really like the style and functionality of this add on. However I would really like to be able filter images by custom attributes as well as by file sets. Can anyone give me some pointers on how I can adapt the code to do this? Or is anyone aware of any other addons that have this functionality? Thanks in advance

Type: Discussion
Status: New
yodaddyp
View Replies: View Best Answer
jordanlev replied on at Permalink Reply
jordanlev
Hi,
The easiest thing to do would be to create file sets based on those attributes.
But unfortunately those won't be updated automatically -- you'd have to update the file set every time a new image with the attribute in question was uploaded.

If you are an experienced php coder I can give you some pointers on how to hack this addon to do what you want, but unfortunately it's not a straightforward task so if you aren't already comfortable with code it's not going to be possible.

I don't know of any other addons that do this either (although I am not familiar with all of them so it's possible there is one -- might be worth posting a message to the "Building with Concrete5" forum -- many more people will see your question there).

-Jordan
yodaddyp replied on at Permalink Reply
yodaddyp
Hi Jordan,

Thanks for the reply.

I did play around with creating file sets based on these attributes, however your right they do not update automatically, and updating them all the time would be a hassle.

I am familiar with PHP, however I haven't programmed in an object orientated style since university! - I think that is what is throwing me off. Since posting this question I found thishttp://www.concrete5.org/api/ (which has helped a lot!) and have started writing my own simple gallery as a single_page, which displays images based on their attributes - so I'll see how I get on with that for now.

Thanks very much for your help, I will checkout the "Building with Concrete5" forum.

Ta,

Paul
jordanlev replied on at Permalink Best Answer Reply
jordanlev
If you want to implement this yourself, there are two parts to it:

1) Doing the actual filtering. This probably isn't too difficult to figure out.

2) Changing the editing interface to allow users to choose the custom attribute to filter on. This is probably going to be more time-consuming than the first task!

For the first task, you will want to look in the file that's in the "models" folder, and change the SQL query in the "getSortedFileIDs()" function so that it's UNION'ing with files having the custom attribute instead of with the filesets table. Then change the "getUnsortedPermittedFilesetImages()" function so that it retrieves files having the custom attribute instead of fileset files (and you'll probably want to change the name of this function as well so it's clear what it's doing, and then find the places this function is being called elsewhere in the addon code and change them to refer to the new name).

For the second task... I guess you'll want to change the fileset dropdown menu to a dropdown of custom attributes. The tricky part here is that you need both the custom attribute and the desired value (like 'files whose custom attribute "X" is set to value "Y"'). Not sure how to go about this, but I imagine it would be similar to how you filter the File Manager list based on attributes, so maybe you can look at that code to see what it's doing. You're also going to want to examine the auto.js file which does a lot of javascripty things around populating that dropdown menu (I imagine you can probably get rid of most of that code, but there may be something in there of use).

Feel free to ask more questions if you try this and run into problems.

Good luck!

-Jordan

concrete5 Environment Information

Browser User-Agent String

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You have not specified a license for this support ticket. You must have a valid license assigned to a support ticket to request a refund.