2010-07-12 03:03:18 -07:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Orchard.ContentManagement;
|
|
|
|
|
using Orchard.Core.Localization.Models;
|
|
|
|
|
using Orchard.Localization.Services;
|
2010-07-13 02:52:02 -07:00
|
|
|
|
using Orchard.Tasks.Scheduling;
|
2010-07-12 03:03:18 -07:00
|
|
|
|
|
|
|
|
|
namespace Orchard.Core.Localization.Services {
|
|
|
|
|
public class LocalizationService : ILocalizationService {
|
|
|
|
|
private readonly IContentManager _contentManager;
|
|
|
|
|
private readonly ICultureManager _cultureManager;
|
|
|
|
|
|
2010-07-13 10:14:46 -07:00
|
|
|
|
public LocalizationService(IContentManager contentManager, ICultureManager cultureManager) {
|
2010-07-12 03:03:18 -07:00
|
|
|
|
_contentManager = contentManager;
|
|
|
|
|
_cultureManager = cultureManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Localized ILocalizationService.GetLocalizedContentItem(IContent content, string culture) {
|
|
|
|
|
return _contentManager.Query(content.ContentItem.ContentType).Join<LocalizedRecord>()
|
|
|
|
|
.List()
|
|
|
|
|
.Select(i => i.As<Localized>())
|
|
|
|
|
.Where(l => l.MasterContentItem != null && l.MasterContentItem.ContentItem.Id == content.ContentItem.Id && string.Equals(l.Culture.Culture, culture, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
.SingleOrDefault();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string ILocalizationService.GetContentCulture(IContent content) {
|
|
|
|
|
return content.Is<Localized>() && content.As<Localized>().Culture != null
|
|
|
|
|
? content.As<Localized>().Culture.Culture
|
|
|
|
|
: _cultureManager.GetSiteCulture();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IEnumerable<IContent> ILocalizationService.GetLocalizations(IContent content) {
|
|
|
|
|
var localized = content.As<Localized>();
|
|
|
|
|
|
2010-07-13 11:31:39 -07:00
|
|
|
|
//todo: (heskew) get scheduled content as well
|
|
|
|
|
|
2010-07-12 03:03:18 -07:00
|
|
|
|
if (localized.MasterContentItem != null)
|
2010-07-13 11:31:39 -07:00
|
|
|
|
return _contentManager.Query(VersionOptions.Latest, content.ContentItem.ContentType).Join<LocalizedRecord>()
|
2010-07-12 03:03:18 -07:00
|
|
|
|
.List()
|
|
|
|
|
.Select(i => i.As<Localized>())
|
|
|
|
|
.Where(l => l.Id != content.ContentItem.Id && (l.Id == localized.MasterContentItem.ContentItem.Id || l.MasterContentItem != null && l.MasterContentItem.ContentItem.Id == localized.MasterContentItem.ContentItem.Id));
|
|
|
|
|
|
2010-07-13 11:31:39 -07:00
|
|
|
|
return _contentManager.Query(VersionOptions.Latest, content.ContentItem.ContentType).Join<LocalizedRecord>()
|
2010-07-12 03:03:18 -07:00
|
|
|
|
.List()
|
|
|
|
|
.Select(i => i.As<Localized>())
|
|
|
|
|
.Where(l => l.MasterContentItem != null && l.MasterContentItem.ContentItem.Id == content.ContentItem.Id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|