Skip to content

Instantly share code, notes, and snippets.

@hermanussen
Last active January 21, 2018 10:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hermanussen/67d5d17a1a1a6b95a9752774210c74c8 to your computer and use it in GitHub Desktop.
Save hermanussen/67d5d17a1a1a6b95a9752774210c74c8 to your computer and use it in GitHub Desktop.
<%@ Page Language="C#" AutoEventWireup="true"%>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.Linq" %>
<% DataBind(); %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Languages in Venn chart</title>
</head>
<body>
<form method="post">
<div>
Start with item ID: <input name="sitecoreid" value="<%# Request.Form["sitecoreid"] %>" />
<asp:Repeater runat="server" DataSource=<%# new int[] { 0, 1, 2 } %>>
<ItemTemplate>
<select name="lang<%# Container.DataItem %>">
<asp:Repeater runat="server" DataSource=<%# new string[] { "en", "nl-NL", "de-DE" } %>>
<ItemTemplate><option value="<%# Container.DataItem %>" <%# Request.Form["lang" + DataBinder.Eval(Container, "Parent.Parent.DataItem")] != null && Request.Form["lang" + DataBinder.Eval(Container, "Parent.Parent.DataItem")].Equals(Container.DataItem) ? "selected=\"selected\"" : "" %>><%# Container.DataItem %></option></ItemTemplate>
</asp:Repeater>
</select>
</ItemTemplate>
</asp:Repeater>
<input type="submit" name="submit" value="Generate" />
</div>
<%
if (Request.HttpMethod.Equals("POST") && Sitecore.Data.ID.IsID(Request.Form["sitecoreid"]))
{
Sitecore.Data.Items.Item item = Sitecore.Context.Database.GetItem(Sitecore.Data.ID.Parse(Request.Form["sitecoreid"]));
if (item != null)
{
List<Sitecore.Data.ID>[] lists = new List<Sitecore.Data.ID>[3];
var descendantsAndLanguages = item.Axes.GetDescendants().Select(descendant => new { ID = descendant.ID, LanguageNames = descendant.Languages.Select(language => language.Name) });
for (int i = 0; i < lists.Length; i++)
{
lists[i] = descendantsAndLanguages.Where(desc => desc.LanguageNames.Contains(Request.Form["lang" + i])).Select(desc => desc.ID).ToList();
}
Response.Write(string.Format("<p><img src=\"http://chart.apis.google.com/chart?chs=600x500&cht=v&chco=FF6342,ADDE63,63C6DE&chds=0,120&chd=t:{0},{1},{2},{3},{4},{5},{6}&chdl={7}|{8}|{9}&chtt=Available+languages+and+overlaps+under+{10}&chts=000000,12.5\" alt=\"Venn diagram\" /></p>",
lists[0].Count,
lists[1].Count,
lists[2].Count,
lists[0].Intersect(lists[1]).Count(),
lists[0].Intersect(lists[2]).Count(),
lists[1].Intersect(lists[2]).Count(),
lists[0].Intersect(lists[1]).Intersect(lists[2]).Count(),
Request.Form["lang0"],
Request.Form["lang1"],
Request.Form["lang2"],
Request.Form["sitecoreid"]
));
Response.Write(string.Format("<p>Items available in {0}: {1}</p>", Request.Form["lang0"], lists[0].Count));
Response.Write(string.Format("<p>Items available in {0}: {1}</p>", Request.Form["lang1"], lists[1].Count));
Response.Write(string.Format("<p>Items available in {0}: {1}</p>", Request.Form["lang2"], lists[2].Count));
Response.Write(string.Format("<p>Items available in both {0} and {1}: {2}</p>", Request.Form["lang0"], Request.Form["lang1"], lists[0].Intersect(lists[1]).Count()));
Response.Write(string.Format("<p>Items available in both {0} and {1}: {2}</p>", Request.Form["lang0"], Request.Form["lang2"], lists[0].Intersect(lists[2]).Count()));
Response.Write(string.Format("<p>Items available in both {0} and {1}: {2}</p>", Request.Form["lang1"], Request.Form["lang2"], lists[1].Intersect(lists[2]).Count()));
Response.Write(string.Format("<p>Items available in {0}, {1} and {2}: {3}</p>", Request.Form["lang0"], Request.Form["lang1"], Request.Form["lang2"], lists[0].Intersect(lists[1]).Intersect(lists[2]).Count()));
}
}
%>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment