Skip to content

Instantly share code, notes, and snippets.

@mhulse
Created October 31, 2012 18:28
Show Gist options
  • Save mhulse/3988908 to your computer and use it in GitHub Desktop.
Save mhulse/3988908 to your computer and use it in GitHub Desktop.
Caché DTI ContentPublisher v7.7.3: COS to get a story's attached pictures and their priority...
<csp:comment>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</csp:comment>
<script language="cache" method="picinfo" arguments='fhid:%Integer=-1, item:%String=""' returntype="%String" procedureblock="1">
/// My half-baked attempt at an easy way to get an image's meta data.
/// @TODO: Make more robust; allow for multiple values to be retunred; return the fileheader as an object?
//----------------------------------
// Initialize:
//----------------------------------
set return = ""
if ($isvalidnum(fhid) && (fhid > 0) && $length(item)) {
//----------------------------------
// Query the dbo.fileheader table:
//----------------------------------
set sql = "SELECT " _ item _ " FROM fileheader, graphic WHERE fileheader.fileheaderid = ? AND graphic.fileheaderid = fileheader.fileheaderid"
try {
; Execute SQL queries in another namespace without doing any namespace switching:
set rs = ##class(dt.common.util.NsResultSet).Create(##class(dt.common.NamespaceProcs).GetNewsMediaName(), sql, .sc, fhid)
if ($$$ISOK(sc) && rs.Next()) {
//----------------------------------
// Get the queried item:
//----------------------------------
set return = rs.Data(item)
}
//----------------------------------
// Garbage collection:
//----------------------------------
kill rs
} catch (e) {
// What to log, and where?
}
}
//----------------------------------
// Return:
//----------------------------------
quit return
</script>
<script language="cache" runat="server">
//set priorityId = ##class(csp.rg.assets.methods.image).picinfo(cmsPicture.CMSPicture.fileheaderId, "priorityId")
//set caption = ..picinfo(4843836, "caption")
; https://groups.google.com/d/msg/intersystems-public-cache/dyT-SfizHDo/qvRrT1xi1NsJ
//write ##class(%SerialStream).%Open(caption).Read() // Last resort example for streams; use DTI's tags for what you can.
</script>
<csp:comment>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</csp:comment>
#[ new cmsPictures set cmsPictures = gStory.pictureMappings ]#
<csp:if condition=($isobject(cmsPictures))>
<csp:loop counter="x" from="1" to="#(cmsPictures.Count())#">
#[ new cmsPicture set cmsPicture = cmsPictures.GetAt(x) ]#
<csp:if condition='$isobject(cmsPicture)'>
#[ new priority set priority = ##class(csp.rg.assets.methods.image).picinfo(cmsPicture.CMSPicture.fileheaderId, "priorityId") ]#
<csp:if condition=((priority'=7)&&(priority'=0)&&(cmsPicture.CMSPicture.TheCMSPictureVersion.uiLabel="128pxw"))>
#("priority: " _ priority)#
<img src="#(##class(dt.cms.support.Rules).getSrcStream(cmsPicture.CMSPicture.%Id()))#" alt="">
<p><dti:story:image:caption table="fileheader" id="#(cmsPicture.CMSPicture.fileheaderId)#" property="caption"></p>
<hr>
</csp:if>
</csp:if>
#[ kill cmsPicture ]#
</csp:loop>
<hr>
</csp:if>
#[ kill cmsPictures ]#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment