Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > How to Get Culture Versions from node id View modes: 
User avatar
Member
Member
aneeshsiva-gmail - 5/9/2011 11:04:25 PM
   
How to Get Culture Versions from node id
How to get culture versions of a document by specifying node id. I want to know a particular document exist in how many cultures.

User avatar
Member
Member
kentico_michal - 5/10/2011 5:31:11 AM
   
RE:How to Get Culture Versions from node id
Hello,

You will need to execute custom SQL query and retrieve the number of rows with the appopriate NodeID from the View_CMS_Tree_Joined table.

So, you can use following code:

object[,] parameters = new object[1, 3];
int NodeID = 100;
parameters[0, 0] = "@NodeID";
parameters[0, 1] = NodeID;

UserInfo ui = UserInfoProvider.GetUserInfo("administrator");
CMS.TreeEngine.TreeProvider tree = new CMS.TreeEngine.TreeProvider(ui);
CMS.DataEngine.GeneralConnection connection = tree.Connection;

int numberOfCultures = CMS.GlobalHelper.ValidationHelper.GetInteger(connection.ExecuteScalar("SELECT Count(DocumentCulture) FROM View_CMS_Tree_Joined WHERE NodeID = @NodeID", parameters, QueryTypeEnum.SQLQuery, false), 0);


I hope this will help you.

Best regards,
Michal Legen

User avatar
Member
Member
aneeshsiva-gmail - 5/10/2011 5:48:02 AM
   
RE:How to Get Culture Versions from node id
Thank you very much Michal..

User avatar
Member
Member
aneeshsiva-gmail - 5/10/2011 6:36:35 AM
   
RE:How to Get Culture Versions from node id
Is any other way by using Kentico API?



Regards: Aneesh Sivan

User avatar
Member
Member
aneeshsiva-gmail - 5/10/2011 8:23:08 AM
   
RE:How to Get Culture Versions from node id
I have documents with multiple cultures and it is populating using cms: repeater. I need to show the available culture versions with the document title while displaying.

E.g. Water is precious. Let’s Save each drop – US, UK, FR

The following method is currently using

public static DataTable GetCultureVersionUrls(int nodeID)
{
DataTable nodeList = new DataTable();
SqlConnection sqlConnection = new SqlConnection(mySiteCore.kenticoConnectionString);

try
{
sqlConnection.Open();
SqlCommand sqlCommand = new SqlCommand();
sqlCommand.Connection = sqlConnection;
sqlCommand.CommandType = CommandType.StoredProcedure;
sqlCommand.CommandText = "my_stored_procedure";
sqlCommand.Parameters.AddWithValue("@NodeID", nodeID);
SqlDataAdapter nodeAdapter = new SqlDataAdapter(sqlCommand);
nodeAdapter.Fill(nodeList);

}
catch (Exception ex)
{
throw new Exception(ex.ToString());
// Error handler
}
finally
{
sqlConnection.Close();
sqlConnection.Dispose();
}

return nodeList;
}

And it’s calling from the transformation

<h2><%# Eval("Title") %></h2>- <%# CMSCustom.GetCultureNames(Eval("NodeID").ToString()%>

Its working fine but I need to get some other solutions that should not use any query or stored procedure. Is it possible? Can I use any Kentico API for solving this?


Thanks and Regards

Aneesh Sivan

User avatar
Member
Member
kentico_michal - 5/16/2011 2:55:05 AM
   
RE:How to Get Culture Versions from node id
Hello Aneesh,

Regrettably, Kentico CMS does not provide any special method. However, you could consider using following code instead of executing custom query:


int NodeID = 100;
DataSet ds = CultureInfoProvider.GetSiteCultures(CMSContext.CurrentSiteName);
string cultures = "";
if (!DataHelper.DataSourceIsEmpty(ds) && (ds.Tables[0].Rows.Count > 1))
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
CMS.TreeEngine.TreeNode node = null;
UserInfo ui = UserInfoProvider.GetUserInfo("administrator");
CMS.TreeEngine.TreeProvider tree = new CMS.TreeEngine.TreeProvider(ui);

node = tree.SelectSingleNode(NodeID, dr["CultureCode"].ToString());

if (node != null)
{
cultures += dr["CultureCode"].ToString() + ",";
}
}
}


Best regards,
Michal Legen

User avatar
Member
Member
aneeshsiva-gmail - 5/17/2011 10:57:05 PM
   
RE:How to Get Culture Versions from node id
Thank you very much Michal


Aneesh Sivan