2

I have a Schema where I store the following information (as Metadata):

  1. Event date
  2. Latitude
  3. Longitude

When I publish a Component using this Schema, the information getting stored in the Custom_Meta Table in the Broker database is in the following format:

Custom_Meta Table sample content

I would like to group this data based on ITEM_ID and retrieve the details in the following format using DD4T:

desired grouped results

Would this be possible using DD4T and the Tridion.ContentDelivery.dll's?

3
  • Is this metadata then? If you query for components using the DD4T library each component will carry its own metadata available to you through the model.
    – Neil
    Nov 21 '13 at 12:51
  • Neil I got what you are trying to explain, the purpose we dont what to go through the Component model is it going to take a long time to retrieve, if the records are huge(as in my case). Nov 21 '13 at 12:55
  • 2
    @KarthikRaghavan indeed tables are not (easily) possible in a question, but you could have written the text and just used images for the tables as I have done just now. That makes it a lot more accessible for everybody, please keep that in mind for your future questions. Nov 21 '13 at 14:31
3

You could turn this around and do your heavy-lifting on the CM side instead of runtime.

  1. You have your data in the Content Manager
  2. You create a "special" page with a "special" Page Template
  3. In the Page Template logic you loop through all the components of that type and gather all the data you need, and store it in a format (XML? JSON?) that your application can load easily and efficiently.
  4. You add a business rule (or event system) that every time you update this data, this page gets republished (or perhaps only republish once every 4 hours).
  5. Your application can now load this data from a structured data file in one go instead of having to query the database and format the data for your specific needs.

PS - I still think you should remove that image from here.

2
  • Even we where thinking about this as an alternative approach. Thanks a lot Nuno Nov 21 '13 at 13:41
  • 1
    I will remove it out ASAP Nov 21 '13 at 14:31
3

This is not a DD4T question. Querying the broker for custom metadata or other types of metadata is a feature of the Tridion broker.

Normally, such broker queries return a list of TCM URIs. You can then use the DD4T ComponentFactory to retrieve an object representing each of the matching components.

1

I think I understand that you want a list of all Component Presentations using that certain Schema from the Broker, you could use the following code sample for that:

StringBuilder sb = new StringBuilder();
string templateUri = "tcm:1-7-32";
int publicationId = 1;
int schemaId = 5;

using (ComponentPresentationAssembler cpa = new ComponentPresentationAssembler("tcm:0-0-0", Page))
using (ComponentPresentationFactory cpf = new ComponentPresentationFactory(publicationId))
{
  Criteria itemTypeCriteria = new ItemTypeCriteria(16);
  Criteria schemaCriteria = new ItemSchemaCriteria(schemaId);
  AndCriteria criteria = new AndCriteria(itemTypeCriteria, schemaCriteria);
  Query query = new Query(criteria);
  foreach (string uri in query.ExecuteQuery())
  {
    using (ComponentPresentation cp = cpf.GetComponentPresentation(uri, templateUri))
    {
      if (cp != null)
      {
        // use ComponentPresentationAssembler since cp.Content does not resolve REL
        sb.Append(cpa.GetContent(string.Format("tcm:{0}-{1}", 
                                               publicationId, 
                                               cp.ComponentId), 
                                 string.Format("tcm:{0}-{1}-32", 
                                               publicationId, 
                                               cp.ComponentTemplateId)));
      }
    }
  }
}

This sample is getting a list of all Components in the Broker based on your Schema and then get the Component Presentations available for those. Depending on your requirements, you could perhaps use cp.Content instead of using the ComponentPresentationAssembler, but this should give you a general idea of how to query the Broker.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.