Login

Username

Password





Register   Reset password

This is a read-only archive of the forum.

# Nicole 2/3/2007 5:17 PM
I thought I could struggle through this one on my own, but, perhaps becausing I'm working on a Saturday, it's just not happening. I'm trying to create a simple user control that I can include on each template to display the last modified date for the page -- meaning I need to display the most recent update timestamp for all StaticHtml content on the page. Really, I'd settle for the last modified date of all content, but StaticHtml is the most accurate portrayal of when the content was last updated.

My problem? I'm having difficulty organizing the path I need to take to get to this data. I can get to the basic section info, but making the leap from there to the StaticHtml-specific info is giving me fits. As I'm still learning how all the data is interconnected in Cuyahoga, I would appreciate any guidance a benevolent reader could provide. Thanks!

--Nicole
# Nicole 2/3/2007 7:22 PM
Well, I figured out a way to do it, although I suspect it's not the best way (should probably use a prepared statement query, for example). But! It works.
CoreRepository cr = HttpContext.Current.Items["CoreRepository"] as CoreRepository;
                                
this._page = (PageEngine)this.Page;
Node n = this._page.ActiveNode;
NHibernate.ISession session = cr.ActiveSession;
DateTime last_update = n.UpdateTimestamp;

string hql = "Select max(shc.UpdateTimestamp) from StaticHtmlContent shc, Section s where shc.Section.Id = s.Id AND s.Node.Id = " + n.Id;
IEnumerable res = session.Enumerable(hql);

if (res != null)
{
     IEnumerator ienum = res.GetEnumerator();
     ienum.MoveNext();
     last_update = (DateTime) ienum.Current;
}
# martijnb 2/4/2007 6:45 AM
Looks fine to me. Personally I'd just use Session.CreateQuery instead of Enumerable. You can use the same query, but it's slightly more elegant:
string hql = "Select max(shc.UpdateTimestamp) from StaticHtmlContent shc, Section s where shc.Section.Id = s.Id AND s.Node.Id = :nodeId";
IQuery q = session.CreateQuery(hql);
q.SetInt32("nodeId", n.Id);
object result = q.UniqueResult;
if (result != null)
{
    last_update = (DateTime)result;
}

Note that the nodeId parameter is a real parameter now instead of being concatenated to the query. It's recommendable to always use this kind of query to prevent SQL injection.