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

Forums / Developing with Sitefinity / Retrieve Media Field in Module Builder

Retrieve Media Field in Module Builder

6 posts, 0 answered
  1. Paul
    Paul avatar
    28 posts
    Registered:
    17 Jan 2012
    05 Mar 2012
    Link to this post
    Hi,

    I have created a Module for a Carousel that can have multiple rows for images and/or an external video link along with a page link and some text. The data will then be formatted and sent to a jquery file to build the Carousel. There will be many different Carousels so each one will be filtered on an "id"

    At present I have entered 2 rows of data into my Module to test the first Carousel with an id, SF Media images, short text links, text and short text video links. Everything is returned apart from the Sitefinity images which are set to null. I copied the code from the Module Builder reference to return a "Carousel through filtering" but I'm obviously missing something. I've also noticed that it is returning 4 rows instead of 2 as both rows are duplicated.

    public IQueryable RetrieveCollectionOfCarousels(int id)
    {
        DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
        Type carouselType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Carousels.Carousel");
     
        // This is how we get the collection of Carousel items
        var myFilteredCollection = dynamicModuleManager.GetDataItems(carouselType).Where("CarouselId == " + id);
     
        return myFilteredCollection;
    }

    Can anyone help with retrieving the Sitefinity images from the Module Builder as well

    Thanks 
  2. Dan Sorensen
    Dan Sorensen avatar
    256 posts
    Registered:
    13 Aug 2010
    06 Mar 2012
    Link to this post
    I am also getting double rows in my custom module code. Not sure what is causing it, but I would love to know.

    Does your ".Where()" code work? I was under the impression it would have to be formatted like this:

    .Where("CarouselId = \"" + id + "\"")

    using a single = and escaped "".


  3. Dan Sorensen
    Dan Sorensen avatar
    256 posts
    Registered:
    13 Aug 2010
    06 Mar 2012
    Link to this post
    Here is my code, I am also getting double copies returned. 8 items instead of 4.

    DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
     
    Type topMenuItemType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.TopMenus.TopMenuItem");
     
    var MenuItems = dynamicModuleManager.GetDataItems(topMenuItemType).Where("MenuName == \"" + SelectedMenu + "\"").OrderBy("MenuOrder").AsEnumerable();

  4. Dan Sorensen
    Dan Sorensen avatar
    256 posts
    Registered:
    13 Aug 2010
    06 Mar 2012
    Link to this post
    Did you reference the following?

    using Telerik.Sitefinity.Modules.Libraries;
  5. Paul
    Paul avatar
    28 posts
    Registered:
    17 Jan 2012
    06 Mar 2012
    Link to this post
    The way the query is formatted will probably depend on whether your value is a string or a decimal value, my id is a decimal so it does not need to be formatted as part of a string. In fact it wouldn't work that way.

    I've looked at the actual database table created and there are duplicate rows for each item keyed on a different GUID.

    I could not find an entry in the table for the Media Item (the image) that I added to the module, this I'm assuming is referenced in a seperate table (so, I think a seperate query will be required to pull back all the image URLs, although I need them all in the same LIST so would have to incorporate that query within my original). Problem is, I cannot find out where the image URL's are or the best way to get these so don't even know how to put this query together yet.
  6. Paul
    Paul avatar
    28 posts
    Registered:
    17 Jan 2012
    08 Mar 2012
    Link to this post
    I've finally sorted this out. For those that may be interested in future here is the code for reference:

    public IEnumerable<CarouselItem> RetrieveCollectionOfCarousels(int id)
    {
        DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
        Type carouselType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Carousels.Carousel");
     
        // This is how we get the collection of Carousel items
        var myFilteredCollection = dynamicModuleManager.GetDataItems(carouselType).Where(i => i.Status == ContentLifecycleStatus.Live).Where("CarouselId == " + id).AsEnumerable();
     
        IList<CarouselItem> myCarousel = new List<CarouselItem>();
     
        foreach (var row in myFilteredCollection)
        {
            var imageId = ((Telerik.Sitefinity.Model.ContentLinks.ContentLink[]) row.GetValue("CarouselImage"))[0].ChildItemId;
             
            LibrariesManager libManager = LibrariesManager.GetManager();
            var image = libManager.GetImages().Where(d => d.Id == imageId).First();
     
            // Create a new List collection, extract our details and put them in there
            CarouselItem item = new CarouselItem();
            item.SelectedImageSrc = image.Url;
            item.SelectedPageLink = row.GetValue("CarouselLink").ToString();
            item.SelectedVideoSrc = row.GetValue("CarouselVideo").ToString();
            item.LinkText = row.GetValue("CarouselText").ToString();
     
            myCarousel.Add(item);
        }
     
        return myCarousel;
    }

    The duplication of lines is removed by specifying LIVE content (the published item only).

    I have extracted the image and then put the url into a new List I have created so that I can bind it specifically to my control.
6 posts, 0 answered