Skip to content

Instantly share code, notes, and snippets.

/queryPapers.cfm Secret

Created February 19, 2018 19:10
Show Gist options
  • Save anonymous/997d88c6ef79ebe85490864006dd8946 to your computer and use it in GitHub Desktop.
Save anonymous/997d88c6ef79ebe85490864006dd8946 to your computer and use it in GitHub Desktop.
<cfscript>
// Simulate buildine query object from spreadsheet
queryPapers = queryNew("AuthorFirstName, AuthorLastName, AuthorType, AuthorInstitution, PrimarySession, Title");
queryAddRow(queryPapers,
[
{
"AuthorFirstName": "Jack",
"AuthorLastName": "Doe",
"AuthorType": "Co-Author",
"AuthorInstitution": "Penn State University",
"PrimarySession": "Aerodynamics",
"Title": "Aerodynamics Paper I"
},
{
"AuthorFirstName": "John",
"AuthorLastName": "Doe",
"AuthorType": "Co-Author",
"AuthorInstitution": "Penn State University",
"PrimarySession": "Acoustics",
"Title": "Acoustics Paper I"
},
{
"AuthorFirstName": "John",
"AuthorLastName": "Smith",
"AuthorType": "Co-Author",
"AuthorInstitution": "University of VA",
"PrimarySession": "Acoustics",
"Title": "Acoustics Paper I"
},
{
"AuthorFirstName": "Jane",
"AuthorLastName": "Doe",
"AuthorType": "Main Author",
"AuthorInstitution": "Penn State University",
"PrimarySession": "Acoustics",
"Title": "Acoustics Paper I"
},
{
"AuthorFirstName": "Bob",
"AuthorLastName": "Smith",
"AuthorType": "Main Author",
"AuthorInstitution": "GA Tech",
"PrimarySession": "Acoustics",
"Title": "Acoustics Paper II"
},
{
"AuthorFirstName": "Jack",
"AuthorLastName": "Smith",
"AuthorType": "Main Author",
"AuthorInstitution": "University of MD",
"PrimarySession": "Acoustics",
"Title": "Acoustics Paper III"
},
{
"AuthorFirstName": "Jill",
"AuthorLastName": "Smith",
"AuthorType": "Co-Author",
"AuthorInstitution": "University of MD",
"PrimarySession": "Acoustics",
"Title": "Acoustics Paper III"
},
{
"AuthorFirstName": "Bob",
"AuthorLastName": "Doe",
"AuthorType": "Main Author",
"AuthorInstitution": "Penn State University",
"PrimarySession": "Aerodynamics",
"Title": "Aerodynamics Paper I"
},
{
"AuthorFirstName": "Sergey",
"AuthorLastName": "Smith",
"AuthorType": "Main Author",
"AuthorInstitution": "University of Maryland",
"PrimarySession": "Dynamic Stall",
"Title": "Dynamic Stall Investigations"
},
{
"AuthorFirstName": "Tobias",
"AuthorLastName": "Lersdorf",
"AuthorType": "Co-Author",
"AuthorInstitution": "German University",
"PrimarySession": "Dynamic Stall",
"Title": "Dynamic Stall Investigations"
},
{
"AuthorFirstName": "Pascal",
"AuthorLastName": "Marceau",
"AuthorType": "Co-Author",
"AuthorInstitution": "University of Maryland",
"PrimarySession": "Dynamic Stall",
"Title": "Dynamic Stall Investigations"
}
]
);
// authorMain column added for sorting
authorMain = [];
for (paper in queryPapers){
findNoCase("Main", paper.AuthorType) ? arrayAppend(authorMain, "A") : arrayAppend(authorMain, "B");
}
queryPapers.addColumn("authorMain", authorMain);
</cfscript>
<!--- Sort query so "Main Author" is first within PrimarySession and Title --->
<cfquery name="queryPapers" dbtype="query">
select * from queryPapers
order by
PrimarySession,
Title,
AuthorMain
</cfquery>
<!--- Loop through above and update NON "Main-Author" rows "A2" if they have same University as "A" rows --->
<cfset MainInstitution = "">
<cfloop query="queryPapers">
<cfif queryPapers.authorMain eq "A">
<cfset MainInstitution = queryPapers.AuthorInstitution>
<cfelse>
<cfif MainInstitution eq queryPapers.AuthorInstitution>
<cfset QuerySetCell(queryPapers, "authorMain", "A2", queryPapers.currentRow)>
</cfif>
</cfif>
</cfloop>
<!--- Resort query for loop processing --->
<cfquery name="queryPapers" dbtype="query">
select * from queryPapers
order by
PrimarySession,
Title,
AuthorMain,
AuthorInstitution,
AuthorFirstName,
AuthorLastName
</cfquery>
<!--- Dump to display a visual of the resultant sorted query --->
<cfdump var="#queryPapers#">
<!--- Nested output loop for displaying required result --->
<cfoutput query="queryPapers" group="PrimarySession">
<strong>#Ucase(PrimarySession)#</strong><br />
<cfoutput group="Title">
<i>#Title#</i><br />
<cfoutput group="AuthorInstitution">
<cfoutput>
#AuthorFirstName# #AuthorLastName#,
</cfoutput>
#AuthorInstitution#; <!--- display institution once per group --->
</cfoutput>
<br /><br /> <!--- double-space after each title group --->
</cfoutput>
</cfoutput>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment