+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Get only taxa that apply to an album

Get only taxa that apply to an album

3 posts, 0 answered
  1. Chris
    Chris avatar
    2 posts
    Registered:
    20 May 2015
    28 Aug 2015
    Link to this post

    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.

  2. Sabrie Nedzhip
    Sabrie Nedzhip avatar
    534 posts
    Registered:
    07 Dec 2016
    02 Sep 2015
    Link to this post
    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;
                }

    As you can see from the above sample I get the statistics for a specific content type - Telerik.Sitefinity.Libraries.Model.Image and then foreach the statistics and get the ids of the tags assigned to this content type. After you get the ids of the tags, you can use the API to get the taxon object and get its title or any other data.

    As for getting the tags assigned to images from a specific library, you need to get the images from this specific library and then get the tags assigned to each image and then get a distinct list of tag ids.

    You may refer to the below article for more details and samples for working with images and tags using the API:

    Query images
    Flat taxonomies API

    I hope that the above information helps. Please do not hesitate to get back to me if you need any further assistance.

    Regards,
    Sabrie Nedzhip
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  3. Chris
    Chris avatar
    2 posts
    Registered:
    20 May 2015
    14 Sep 2015 in reply to Sabrie Nedzhip
    Link to this post

    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!

3 posts, 0 answered