Retrieve Media Field in Module Builder
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;
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 + "\"")
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();
Did you reference the following?
using Telerik.Sitefinity.Modules.Libraries;
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.
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;