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

Forums / Sitefinity SDK / Get Taxa of a Content item

Get Taxa of a Content item

8 posts, 0 answered
  1. Adam
    Adam avatar
    3 posts
    Registered:
    09 Mar 2011
    23 Mar 2011
    Link to this post

    IQueryable<Video> videos = App.WorkWith().Videos().Get()

                    .Where(v => v.Status == ContentLifecycleStatus.Live);
                foreach (Video v in videos)
                {
                    v.Organizer???
                }

    I know Organizer is not the right attribute, but I haven't had much luck finding the taxa, specifically hierarchical taxa(categories), that a Video or any Content object belong to given the object. 

    Alternatively if I could *anonymously* access GET only on /sitefinity/services/content/videoservice.svc// that also might work. I just need the list of all videos and what categories they belong to. 

    I have developed a method starting from the taxonomy and getting associated videos but that ends up being n queries where n is the number of categories. Would the method of getting a content item then getting its associated taxa actually result in m queries in the backend where m is the number of videos? 

    If so I'll go with the taxonomy-first route. 

    -OR-

    Just throw me a free AJAX paged media gallery for video with user-selectable category filters starting at a specific point in the category hierarchy with a depth of 2 and the starting node invisible. Also different CSS classes for tier 1 and tier 2 categories. Hey, a guy can dream right?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
  3. Adam
    Adam avatar
    3 posts
    Registered:
    09 Mar 2011
    23 Mar 2011
    Link to this post
    I've seen that post. It was helpful in finding Content given a specific Taxonomy. I'm looking to find a full listing of all videos and their associated taxonomies. 

    Or were you suggesting the route of getting the taxonomies I am interested in first, then get all of the videos matching each taxonomy and merging the list? I was hoping for < O(2n).
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    23 Mar 2011
    Link to this post
    Hello Adam,

    Each content item has a property GetValue where you can pass the dybanic filed name

    cnt.GetValue("Category"), so you can get the category for a specific item.

    Greetings,
    Ivan Dimitrov
    the Telerik team
  5. Adam
    Adam avatar
    3 posts
    Registered:
    09 Mar 2011
    24 Mar 2011
    Link to this post
    http://www.sitefinity.com/40/help/developers-guide/allmembers_t_telerik_sitefinity_libraries_model_video.html

    There is no GetValue method according to both your docs and my own experimentation. How do I get that?

    I am writing my own WCF Service to avoid requiring authentication to get the video attributes. I will have to use the query by taxon method and merge lists when multiple categories are selected.

    So I have a solution now. I would still like to know how to call the GetValue method as it doesn't appear to be a member of any Content class I have worked with, but is referenced often on the forum.
  6. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    28 Mar 2011
    Link to this post
    Hello Adam,

    GetValue(string) method is an extension method defined on the type IDynamicFieldsContainer. In order to have this method available, please import following namespace in your class:

    Telerik.Sitefinity.Model

    Yes, I know that this is, suboptimal, to say the least. I'll try to see if and when we can move this into Telerik.Sitefinity namespace, because it would be more obvious.

    I hope this helps. 

    Greetings,
    Ivan
    the Telerik team
  7. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    28 Oct 2013 in reply to Ivan Dimitrov
    Link to this post
    so we can get the specific taxa list by specifying the taxonomy field via GetValue("taxonomyname")

    HOWEVER, this requires that we know in advance the name of the custom field storing the value. Is it possible, as the OP asked, to get a list of ALL taxonomies including their types from the content item directly without specifying the taxonomy name?

    For example, if I'm processing items via API and need to do something based on the taxonomy coming from different content types (Which may have different custom fields for taxonomy) I can't assume they have a field or not, so I want to be able to simply get a result of all the taxonomy and types and process it that way...

    is this not possible?
  8. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    01 Nov 2013
    Link to this post
    Hello Josh,

    You can use type descriptor to get all properties of the item and iterate them. Then you have to get the property descriptor and get the value.

    public void GetTaxons(IDynamicFieldsContainer item)
    {
        var allProperties = TypeDescriptor.GetProperties(item);
        foreach (PropertyDescriptor propertyDescriptor in allProperties)
        {
            if (propertyDescriptor is TaxonomyPropertyDescriptor)
            {
                var value = item.GetValue<IList<Guid>>(propertyDescriptor.Name).ToArray();
            }
        }
    }

    Regards,
    Radoslav Georgiev
    Telerik

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

8 posts, 0 answered