public PairsView GetViewModel() { var pairs = _db.Fetch <PairTranslations>(new Sql().Select("*").From("dbo.cmsDictionary")); var translations = GetTranslations(); var tasks = GetTasks(); foreach (var v in pairs) { v.TranslationTexts = translations[v.UniqueId].ToDictionary(x => x.LanguageId, x => x.Value); v.TranslationTasks = tasks[v.UniqueId].ToDictionary(x => x.LanguageId, x => true); } return(new PairsView { Pairs = pairs, Languages = GetUserLanguages(), IsEditor = _urh.IsEditor(UmbracoContext.Security.GetUserId()) }); }
public void AcceptProposal(int id) { if (!_urh.IsEditor(UmbracoContext.Security.GetUserId())) { return; } var proposal = _db.FirstOrDefault <TranslationProposal>(new Sql("SELECT * FROM dbo.simpleTranslationProposals WHERE pk=@tag", new { tag = id })); var service = ApplicationContext.Services.LocalizationService; IDictionaryItem idi = service.GetDictionaryItemById(proposal.UniqueId); var translation = idi.Translations.FirstOrDefault(x => x.LanguageId == proposal.LanguageId); if (translation == null) { var translations = idi.Translations.ToList(); translations.Add(new DictionaryTranslation(service.GetLanguageById(proposal.LanguageId), proposal.Value, proposal.UniqueId)); idi.Translations = translations; } else { translation.Value = proposal.Value; } service.Save(idi); _db.Delete <TranslationProposal>(new Sql().Where("id=@tag1 AND languageId=@tag2", new { tag1 = proposal.UniqueId, tag2 = proposal.LanguageId })); _db.Delete <TranslationTask>(new Sql().Where("id=@tag1 AND languageId=@tag2", new { tag1 = proposal.UniqueId, tag2 = proposal.LanguageId })); }
protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings) { TreeNodeCollection nodes = new TreeNodeCollection(); using (var db = DatabaseContext.Database) { var userRoleHelper = new UserRoleHelper(db); var userId = UmbracoContext.Security.GetUserId(); if (id == "-1" && userRoleHelper.CanUseSimpleTranslation(userId)) { nodes.Add(CreateTreeNode("1", id, queryStrings, "Translatable strings", "icon-folder", CreateRoute("pairs"))); nodes.Add(CreateTreeNode("2", id, queryStrings, "Translation Tasks", "icon-folder", CreateRoute("tasks"))); if (userRoleHelper.IsEditor(userId)) { nodes.Add(CreateTreeNode("3", id, queryStrings, "Translation Proposals", "icon-folder", CreateRoute("proposals"))); } } return(nodes); } }
public TasksView GetViewModel() { var model = new TasksView { Languages = _db.Fetch <Language>(new Sql().Select("*").From("dbo.umbracoLanguage")) }; var tasksQuery = new Sql() .Select("t.*, l.languageCultureName AS language, d.[key] AS [key]") .From("dbo.simpleTranslationTasks t LEFT OUTER JOIN dbo.umbracoLanguage l ON t.languageId=l.id LEFT OUTER JOIN dbo.cmsDictionary d ON t.id=d.id"); // Only translators are limited to languages they are responsible for. Administrators and Editors can view tasks for all languages. if (_urh.IsTranslator(UmbracoContext.Security.GetUserId())) { tasksQuery = tasksQuery.Where("t.languageId IN (select languageId from dbo.simpleTranslationUserLanguages where id=@tag)", new { tag = UmbracoContext.Security.GetUserId() }); } var tasks = _db.Fetch <TranslationTask>(tasksQuery); // Skip further processing if there are no tasks. if (!tasks.Any()) { return(model); } var currentTranslations = _db.Fetch <TranslationText>(new Sql("select * from dbo.cmsLanguageText where UniqueId in (@ids)", new { ids = tasks.Select(x => x.UniqueId).Distinct() })).ToLookup(x => x.UniqueId, x => x); var latestPersonalProposals = _db.Fetch <TranslationProposal>( new Sql("select p1.* from dbo.simpleTranslationProposals p1 INNER JOIN" + "(select MAX(pk) AS pk, id, languageId from dbo.simpleTranslationProposals where userId=@userId GROUP BY id, languageId)" + "AS p2 ON p1.pk=p2.pk", new { userId = UmbracoContext.Security.GetUserId() })).ToDictionary(x => new { x.UniqueId, x.LanguageId }, x => x); foreach (var v in tasks) { TranslationProposal p; latestPersonalProposals.TryGetValue(new { v.UniqueId, v.LanguageId }, out p); v.LatestPersonalProposal = p; v.CurrentTranslations = currentTranslations[v.UniqueId].ToDictionary(x => x.LanguageId, x => x.Value); } model.Tasks = tasks; model.IsEditor = _urh.IsEditor(UmbracoContext.Security.GetUserId()); return(model); }