Filter a file set by custom attributes
Permalink
Hi I have recently started making my first concrete5 website and I am trying to make a simple single page that retrieves a list of image files sorted by a given file set and filtered by a given attribute.
This is my code so far:
The only way I can get this to work is if I change the comparison operator from '=' to 'LIKE' and add wild cards to the attribute value :
This solution is not ideal as the colour BLACK will also return images which are METALLIC BLACK.
Is there any reason why my custom attributes would be behaving like this? If I change the $attributeKeyHandle to 'height' or 'width' and alter the attribute value to match the height or width of an image the code works fine!
If anyone has any ideas or suggestions that would be greatly appreciated. I have been tearing my hair out over this.
This is my code so far:
Loader::model('file_set'); Loader::model('file_list'); $attributeKeyHandle = "BottleColour"; $value = 'BLACK'; $fs = FileSet::getByName('gallery images'); $fl = new FileList(); $fl->filterBySet($fs); $fl->filterByAttribute($attributeKeyHandle, $value, $comparison = '='); $files = $fl->get(); foreach($files as $f) { // echo file information }
The only way I can get this to work is if I change the comparison operator from '=' to 'LIKE' and add wild cards to the attribute value :
Loader::model('file_set'); Loader::model('file_list'); $attributeKeyHandle = "BottleColour"; $value = '%BLACK%'; $fs = FileSet::getByName('gallery images'); $fl = new FileList(); $fl->filterBySet($fs); $fl->filterByAttribute($attributeKeyHandle, $value, $comparison = 'LIKE'); $files = $fl->get(); foreach($files as $f) { // echo file information }
This solution is not ideal as the colour BLACK will also return images which are METALLIC BLACK.
Is there any reason why my custom attributes would be behaving like this? If I change the $attributeKeyHandle to 'height' or 'width' and alter the attribute value to match the height or width of an image the code works fine!
If anyone has any ideas or suggestions that would be greatly appreciated. I have been tearing my hair out over this.
http://www.concrete5.org/developers/bugs/5-4-1/select-attribute-val...
I got round this in the end however I had to take all the images out of the database and then filter with if statements when comparing with getAttribute() :-( not ideal but 1 solution anyway.