Get only taxa that apply to an album
Hey all,
I have a couple of custom classifications for images, so, for example:
Colors - white, beige, cherry, brown, black
Product Lines - Product Line 1, Product Line 2, Product Line 3, Product Line 4
And I have an album:
Img1 - beige, product line 1
Img2 - white, product line 1
Img3 - brown, product line 2
When I load this album into a custom control, I want to populate two drop-downs with the taxonomies, but I want to get only the taxa that have images in this album, so only beige, white, brown, and product lines 1 and 2 should appear in the drop-downs.
Is there something in the Sitefinity API that could accomplish this? I didn't see anything with a quick search, but I was hoping for a clean way of doing this.
If it helps, we're using Sitefinity 8.0.
Hi Chris,
Thank you for contacting us.
After further researching this on my side it appeared that it is possible to get all the tags assigned to the Images uploaded to Sitefinity. The ids of the tags can be taken from the statistics. Here is a sample code for your convenience:
var taxonomyManager = TaxonomyManager.GetManager();
var tagTaxonomy = taxonomyManager.GetTaxonomies<FlatTaxonomy>().SingleOrDefault(s => s.Name ==
"Tags"
);
var statistics = taxonomyManager.GetStatistics().Where(
t =>
t.TaxonomyId == tagTaxonomy.Id &&
t.MarkedItemsCount > 0 &&
t.StatisticType == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live &&
t.DataItemType ==
"Telerik.Sitefinity.Libraries.Model.Image"
).ToList();
foreach
(var item
in
statistics)
var taxonId = item.TaxonId;
Hi Sabrie,
Thanks for the help! I had a feeling the solution was going to require looking at each individual image, but I figured I would at least see if someone knew of something better. Still, this will work nicely.
Thanks again!