This is a pretty basic question so I hope it makes sense, as I'm curious
to know what other techniques are available to achieve the same result
as the code below (hopefully in a more efficient manner).
This is for a photo gallery of winning garments from a recent awards
evening. Here is the current process (and yes, one day soon this will
all be databased and I can match the images to a separate results table,
but for now the quick dirty solution will suffice). Only the relevant
code is included.
Query the gallery folder:
<cfdirectory
name="getGalleryJpegs"
action="list"
directory="#attributes.galleryDir#"
filter="*.jpg"
/>
Do some processing next to add a friendly display name (strippedName),
the image dimensions etc.
<..code_truncated..>
>From all the images found, get the details for the selected photo when a
user clicks on a thumb.
<cfquery dbtype="query" name="getImageInfo">
SELECT name
,strippedName
,size
,width
,height
,dateLastModified
,recordID
FROM getGalleryJpegs
WHERE recordID = #attributes.recordID#
</cfquery>
As an FYI, recordID is the image position taken from a value list of
names from the above query.
<!--- Check the image name and add category and designer --->
<!--- this is the part I think could be optimized --->
What I've done is, instead of listing every single image and matching
the name against a description (in which case I would've used a text
file and read it in), I've used a common naming theme (the winning
garment of each category has multiple photos). For instance, every image
in the Heartlands Nightlife category has 'Heartlands' in the image name,
but in order to determine the category and winner I have to do the
following.
<cfscript>
if (getImageInfo.name CONTAINS "doosh") {
category = "DOOSH Collections";
winner = "Carol Yeung";
}
else if (getImageInfo.name CONTAINS "heartlands") {
attributes.category = "Heartlands Hotel Croydon Nightlife";
attributes.winner = "Charmaine Cowlishaw";
}
else if (getImageInfo.name CONTAINS "kiwiana") {
attributes.category = "Hokonui Heritage Centre Kiwiana";
attributes.winner = "Margaret Lewis";
}
else if (getImageInfo.name CONTAINS "MPP") {
attributes.category = "Macdonald Pearce Perniskie Menswear and
Overall";
attributes.winner = "Laura Marshall";
}
else if (getImageInfo.name CONTAINS "nu-dax") {
attributes.category = "Nu-Dax Denim";
attributes.winner = "Gregory Wiseman Spence";
}
else if (getImageInfo.name CONTAINS "SIT") {
attributes.category = "SIT Knitted";
attributes.winner = "Ruth Bucknell";
}
else if (getImageInfo.name CONTAINS "streetwear") {
attributes.category = "Streetwear and Young Designer";
attributes.winner = "Elise Barnes";
}
else if (getImageInfo.name CONTAINS "vnc") {
attributes.category = "VnC Cocktails Avant-Garde";
attributes.winner = "Marie Kelly";
}
else if (getImageInfo.name CONTAINS "westpac") {
attributes.category = "Westpac Wool";
attributes.winner = "Roberta Lee Davis";
}
else {
attributes.category = "N.A";
attributes.winner = "N.A";
}
</cfscript>
The above is all working fine, but if there were 30+ categories this
approach doesn't seem the best. In an OO world I know polymorphism is
the answer (but unfortunately that doesn't apply in this case).
I know I could use cfswitch and cfcase but that really doesn't seem to
change the process much. Any other ideas on how to match the winner and
category to a particular image without a bunch of if else if
statements??
Please note, I googled before posting.
TIA
Mark
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Want to reach the ColdFusion community with something they want? Let them know
on the House of Fusion mailing lists
Archive:
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:325063
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4